Subject Re: [IBO] Inserts using TIB_Cursor
Author Ross Williams
At 12:16 PM 3/7/03, you wrote:
>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.

Probably none.

> 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.

It is a transaction in and of itself. The transaction code all got added in
an effort to make sure the record was getting committed since it posted
with no error but never showed up in the database. I thought the rollback
was overkill, but I don't have a good enough understanding of what your
code does to know. I was just assuring that whatever changes were made as
a result to changes in the visual controls on the form were cleaned up.
Apparently that is not necessary?

>My guess is you haven't traced execution flow and debugged this fully to see
>just exactly what is going on.

Well no I haven't, I thought a simple insert was just that, a simple
insert. And debugging the IBO_code seemed like a last resort.


>For all I know you are getting an exception
>somehwere and you are just clearing it out.

I don't know where that would be. Neither the Query or Cursor components
have any hand-written code attached to them.

>I suppose we would need to see
>what this modal form is doing.

The modal form consists of nothing but an IB_DataSource, controls attached
to the datasource and an OK and Cancel button with appropriate
modalresult's set. There is no other code in it. The two procedures I
posted are also contained in the same unit and are the only hand-written
code in the unit. One procedure creates an instance of the form, shows it
modally and edits an existing record, the other does the same thing and
creates a new record. Depending on how the form is closed they either
cancel or post the change. Then they free the instance of the form. Does
that make it clear?

The problem is that when an insert is posted it doesn't post.

One issue that may be the source of this is that there is trigger on the
table that creates the MEDIAID which is a unique and required value. That
trigger only generates if MEDIAID is null. So I am submitting the insert
with a null MediaID. Is that the problem? If so, how do I fix it.

>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@...
> >
>
>
>
>
>___________________________________________________________________________
>IB Objects - direct, complete, custom connectivity to Firebird or InterBase
> without the need for BDE, ODBC or any other layer.
>___________________________________________________________________________
>http://www.ibobjects.com - your IBO community resource for Tech Info papers,
>keyword-searchable FAQ, community code contributions and more !
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

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@...