To determine whether a specific database exists, check to see if the file exists before calling sqlite3_open(), using stat() or some other call.

To determine if a specific schema exists within an open database, use the query "SEELCT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name IN ('Table12', 'Table2', ...)" and check that the resulting count is the expected value.

-ken

On 9-Apr-05, at 6:18 AM, Jochen Müller wrote:

Hello!

I am new to SQL and have a simple question concerning sqlite. I am using the functions sqlite3_open, sqlite3_get_table and sqlite3_free_table and sqlite3_close.

Because i do not yet know how to check whether a database exists or not, i always call the sqlite3_get_table function. If it returns an error, the database probably not exist. But if this function returns an error, all further calls to sqlite3 fail. In detail:

sqlite3_open(...)
sqlite3_get_table(...)
copy the columns to a string grid if sqlite3_get_table(...) succeeded
sqlite3_free_table(...)
sqlite3_close(...)

The first time sqlite3_get_table(...) fails, no further starts of this sequence work. I get no errors when executing the statements, but there's no table sqlite3_get_table copies to the given pointer variables.

There would be two solutions to my problem. I have to check first if a database exists or i have to make sqlite keep on working after sqlite3_get_table fails.

Sorry for my poor english.

Regards,
  Jochen





Reply via email to