Subject Re: [IBO] Inserts using TIB_Cursor
Author Jason Wharton
Frankly, I don't like your coding style where there are things being created
with nil owners, type casting and drilling dereferencing of objects. I don't
know what design or paradyme is behind this but it suggests to me some
things are potentially messed up.

I don't see the sense in forcing a transaction to surround this insert. What
if this is a part of a transaction rather than being a transaction in and of
itself. If it is just a transaction in and of itself then do the insert and
either post and commit it or cancel it. There is no need to perform a
rollback.

My guess is you haven't traced execution flow and debugged this fully to see
just exactly what is going on. For all I know you are getting an exception
somehwere and you are just clearing it out. I suppose we would need to see
what this modal form is doing.

Jason

> At 11:00 AM 3/7/03, you wrote:
> >Cursor's are not ideal for handling inserts.
>
> Then it shouldn't have a public insert method.
>
> >Use a TIB_Query since it has buffering capabilities.
>
> Thanks for the help.
>
>
> >Jason Wharton
> >CPS - Mesa AZ
> >http://www.ibobjects.com
> >
> >-- We may not have it all together --
> >-- But together we have it all --
> >
> >
> >----- Original Message -----
> >From: "Ross Williams" <ross@...>
> >To: <IBObjects@yahoogroups.com>
> >Sent: Friday, March 07, 2003 11:16 AM
> >Subject: Re: [IBO] Inserts using TIB_Cursor
> >
> >
> > > I obviously wasn't very clear.
> > >
> > > My code for the insert looks like this:
> > >
> > > Function InsertMediaRecord: TModalResult;
> > > Begin
> > > With TMediaEditForm.Create(nil) do
> > > Try
> > > With TIB_CURSOR(MediaCursorDataSource.DataSet) do
> > > Begin
> > > IB_Transaction.StartTransaction;
> > > Open;
> > > Insert;
> > > end;
> > > Result := ShowModal;
> > > If Result = mrOK then
> > > Begin
> > > MediaCursorDataSource.DataSet.Post;
> > > MediaCursorDataSource.DataSet.IB_Transaction.Commit;
> > > end
> > > else
> > > Begin
> > > MediaCursorDataSource.DataSet.Cancel;
> > > MediaCursorDataSource.DataSet.Close;
> > > MediaCursorDataSource.DataSet.IB_Transaction.Rollback;
> > > end;
> > > finally
> > > Free;
> > > end;
> > > end;
> > >
> > > MediaCursorDataSource is on the TMediaEditForm and has its dataset set
at
> > > design time to the TIBO_Cursor on a datamodule. This similar procedure
> >does
> > > work for editing a record:
> > >
> > > Function EditMediaRecord(ID:Integer): TModalResult;
> > > Begin
> > > With TMediaEditForm.Create(nil) do
> > > Try
> > > With TIB_CURSOR(MediaCursorDataSource.DataSet) do
> > > Begin
> > > IB_Transaction.StartTransaction;
> > > ParamByName('p' + MEDIAID).AsInteger := ID;
> > > Open;
> > > Edit;
> > > end;
> > > Result := ShowModal;
> > > If Result = mrOK then
> > > Begin
> > > MediaCursorDataSource.DataSet.Post;
> > > MediaCursorDataSource.DataSet.IB_Transaction.Commit;
> > > end
> > > else
> > > Begin
> > > MediaCursorDataSource.DataSet.Cancel;
> > > MediaCursorDataSource.DataSet.Close;
> > > MediaCursorDataSource.DataSet.IB_Transaction.RollBack;
> > > end;
> > > finally
> > > Free;
> > > end;
> > > end;
> > >
> > > This cursor is used exclusively for editing and inserting records.
> > >
> > >
> > > At 09:43 AM 3/7/03, you wrote:
> > > >Ross Williams wrote:
> > > > >
> > > > > I can't get an insert to work with the TIB_Cursor. I have a form
set up
> > > > > that I use for editing that works fine. I set the cursor to live
and it
> > > > > edits. When I try inserting a new record - I start the
transaction, insert
> > > > > the record, enter values in the same form I am using for editing
and then
> > > > > post it and commit the transaction. There is no error, but the
record is
> > > > > not posted or committed. I then tried adding insertsql property to
> > > > > explicitly create the insert. I used the sql generated by a
TIB_Query for
> > > > > the same table and pasted it into the instertsql property. The
result was
> > > > > the same.
> > > > >
> > > > > How does this work?
> > > > >
> > > >
> > > >The TIB_Cursor is basically for reports. Start at the beginning and
> > > >process once.
> > > >
> > > >Use the grid.
> > > >--
> > > >Raymond Kennington
> > > >Programming Solutions
> > > >W2W Team B
> >
> Ross Williams
> Citizens for Sensible Transportation/
> Coalition for a Livable Future
> Terminal Sales Building
> 1220 SW Morrison, Suite 535
> Portland OR 97205
>
> Phone: 503-225-0003
> Fax: 503-225-0333
> Web: www.cfst.org
> Email: ross@...
>