Re: [sqlite] Getting callback with an INSERT

2006-08-02 Thread Olaf Beckman Lapré
Isn't it easier to just call:  sqlite3_last_insert_rowid()?

Olaf

- Original Message - 
From: "Jay Sprenkle" <[EMAIL PROTECTED]>
To: <sqlite-users@sqlite.org>
Sent: Monday, July 24, 2006 5:17 PM
Subject: Re: [sqlite] Getting callback with an INSERT


> On 7/24/06, Dennis Cote <[EMAIL PROTECTED]> wrote:
> >
> > You can do this by adding an insert trigger to your table and
> > registering a user function that will call back to your code.
> >
> >   create trigger t_in after insert on t
> >   begin
> > select do_insert_callback(new.rowid);
> >   end;
> >
> > You will have to write and register the user defined function
> 
> Nifty trick Dennis!
>  :)
> 


RE: [sqlite] Getting callback with an INSERT

2006-07-24 Thread Robert Simpson
> -Original Message-
> From: John Stanton [mailto:[EMAIL PROTECTED] 
> Sent: Monday, July 24, 2006 2:14 PM
> To: sqlite-users@sqlite.org
> Subject: Re: [sqlite] Getting callback with an INSERT
> 
> Olaf Beckman Lapré wrote:
> > No, that's not the case since I'm using an AUTOINCREMENT 
> key and I can't
> > know the value of the key until the INSERT is completed.
> > 

use sqlite3_last_insert_rowid() as John suggests ...

And if you do want insert/update notifications, check out
sqlite3_update_hook():
http://www.sqlite.org/capi3ref.html#sqlite3_update_hook

Robert




Re: [sqlite] Getting callback with an INSERT

2006-07-24 Thread John Stanton

Olaf Beckman Lapré wrote:

No, that's not the case since I'm using an AUTOINCREMENT key and I can't
know the value of the key until the INSERT is completed.

Olaf

- Original Message - 
From: "John Stanton" <[EMAIL PROTECTED]>

To: <sqlite-users@sqlite.org>
Sent: Monday, July 24, 2006 5:30 PM
Subject: Re: [sqlite] Getting callback with an INSERT




It hardly seems necessary to make it a callback since you could just
call your function concurrently with the INSERT SQL.

Olaf Beckman Lapré wrote:


Is it possible to get a callback when doing an INSERT on a table similar


to a SELECT callback? The callback would then contain the same parameters
but only contain the row(s) being inserted.


The reason I'm asking is that this may be usefull in GUI applications


where you insert table rows into a listcontrol. Instead of emptying the
listcontrol and using the SELECT callback to fill it again, one could simply
add the row being added from the INSERT callback.


Olaf





There is an API call sqlite3_last_insert_rowid(..) which gives you the 
rowid after the insert.  Here is a code fragment using it.


  
  if (bind_txt_arg(dbcmp_bchreg_ins, 7, bchr->bch_type)) return(TRUE);

  /*Now we execute the SQL statement in a single step.*/
  sqlite3_step(dbcmp_bchreg_ins);   /*Executes compiled SQL.*/
  rc = sqlite3_reset(dbcmp_bchreg_ins); /*Ready for next access.*/
  if (rc == SQLITE_DONE) bchr->rowid = sqlite3_last_insert_rowid(db);
  else {
sqlite_step_check(rc, fnm);
rollback_db_trans(trnm);
SetEvent(db_sync);
return(-1);
  }  /*if/else*/
  


Re: [sqlite] Getting callback with an INSERT

2006-07-24 Thread Olaf Beckman Lapré
No, that's not the case since I'm using an AUTOINCREMENT key and I can't
know the value of the key until the INSERT is completed.

Olaf

- Original Message - 
From: "John Stanton" <[EMAIL PROTECTED]>
To: <sqlite-users@sqlite.org>
Sent: Monday, July 24, 2006 5:30 PM
Subject: Re: [sqlite] Getting callback with an INSERT


> It hardly seems necessary to make it a callback since you could just
> call your function concurrently with the INSERT SQL.
>
> Olaf Beckman Lapré wrote:
> > Is it possible to get a callback when doing an INSERT on a table similar
to a SELECT callback? The callback would then contain the same parameters
but only contain the row(s) being inserted.
> >
> > The reason I'm asking is that this may be usefull in GUI applications
where you insert table rows into a listcontrol. Instead of emptying the
listcontrol and using the SELECT callback to fill it again, one could simply
add the row being added from the INSERT callback.
> >
> > Olaf
>
>



Re: [sqlite] Getting callback with an INSERT

2006-07-24 Thread John Stanton
It hardly seems necessary to make it a callback since you could just 
call your function concurrently with the INSERT SQL.


Olaf Beckman Lapré wrote:
Is it possible to get a callback when doing an INSERT on a table similar to a SELECT callback? The callback would then contain the same parameters but only contain the row(s) being inserted. 


The reason I'm asking is that this may be usefull in GUI applications where you 
insert table rows into a listcontrol. Instead of emptying the listcontrol and 
using the SELECT callback to fill it again, one could simply add the row being 
added from the INSERT callback.

Olaf




Re: [sqlite] Getting callback with an INSERT

2006-07-24 Thread Jay Sprenkle

On 7/24/06, Dennis Cote <[EMAIL PROTECTED]> wrote:


You can do this by adding an insert trigger to your table and
registering a user function that will call back to your code.

  create trigger t_in after insert on t
  begin
select do_insert_callback(new.rowid);
  end;

You will have to write and register the user defined function


Nifty trick Dennis!
:)


Re: [sqlite] Getting callback with an INSERT

2006-07-24 Thread Dennis Cote

Olaf Beckman Lapré wrote:
Is it possible to get a callback when doing an INSERT on a table similar to a SELECT callback? The callback would then contain the same parameters but only contain the row(s) being inserted. 


The reason I'm asking is that this may be usefull in GUI applications where you 
insert table rows into a listcontrol. Instead of emptying the listcontrol and 
using the SELECT callback to fill it again, one could simply add the row being 
added from the INSERT callback.

Olaf
  

Olaf,

You can do this by adding an insert trigger to your table and 
registering a user function that will call back to your code.


 create trigger t_in after insert on t
 begin
   select do_insert_callback(new.rowid);
 end;

You will have to write and register the user defined function 
do_insert_callback(). It should pass the new record's rowid value back 
to you main application which can then use it to retrieve the record for 
addition to your display list.


See section 2.3 User Defined function at 
http://www.sqlite.org/capi3.html for additional information on creating 
a user defined function.


HTH
Dennis Cote