Cameron Tofer wrote:

The rowid of the table's record in the sqlite_master table would be great, but really any unique integer that I can later use to get the table's name would be fine.

Cameron,

Then you should be able to execute the following SQL query in your sqlite3_update_hook handler itself to convert the table name to an integer rowid.

 select rowid from database_name.sqlite_master
 where type = 'table' and name = table_name

This rowid value will not be useful if you are using multiple databases, because you won't know which database it comes from. But, if you have a single database then you can ignore the database name (i.e. it is always the same and matches the open database). The query then simplifies to

 select rowid from sqlite_master
 where type = 'table' and name = table_name

To do anything useful with the table you will have to convert this rowid back into a table name to build an SQL query. You can convert the rowid back to a table name using the inverse lookup:

 select name from sqlite_master
 where rowid = table_id

You could make a modified version of SQLite that does this before calling the sqlite3_update_hook handler, and then passing this rowid back. If you do this you will have a nonstandard library which you have to maintain yourself.

If you are trying to avoid storing the names, you could create a small cache in your application that maps the names to integers. A vector or array of strings should work. You scan the array looking for the name. If found, use its index as your integer id, if not, add it to the array and then use its index as your id.

I don't know what your applications requires, but it seems to me there must be a better way than creating a modified library that returns pseudo ids for tables which you can't use directly.

HTH
Dennis Cote

Reply via email to