On Tue, 2008-07-22 at 01:05 +0200, Markus Hoenicka wrote: > Balazs Scheidler writes: > > when the result is an empty set, it does not return the column headers - > > unlike other drivers -, and this causes problems with syslog-ng. > > I'd probably have to run a few more tests, but this seems to be the > result of some odd behaviour of the sqlite3_get_table() function. This > function adds a header with the column names to the result set, but > still returns the true number of rows and columns as if there was no > extra row. If there are zero rows in the result set (i.e. only the > header), the function appears to always return zero columns as well. In > this case, the driver skips the field type detection as it assumes > there are no columns to check. I'll have to ask the SQLite list if > this holds true. > > > For this it needs to detect whether a table exists, using this simple > > query: > > > > SELECT * FROM table WHERE 0=1 > > > > libdbi has the dbi_conn_get_table_list(dbi_conn Conn, const char *db, > const char *pattern) function. You should get zero or one [check with > dbi_result_get_numrows(dbi_result Result)] rows with an appropriate > pattern if the table is absent or present, respectively.
This sounds doable, however I potentially have hundreds of tables in the database, I'd prefer avoiding having to list all tables when I need to open a new one. > > If the table exists, would it hurt to create the required columns just > in case? I reckon all database engines would just do nothing if you > attempt to create an existing column again. Hmm, I tried but sqlite reports an error: sqlite> create table aaa (a,b,c); sqlite> alter table aaa add d; SQL error: duplicate column name: d -- Bazsi ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libdbi-drivers-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel
