Re: [sqlite] New default table on DB initialization
Can't you use create table if not exists ... On 8 April 2011 07:17, RAKESH HEMRAJANI rakesh_hemraj...@hotmail.com wrote: Hi, Need a default table to be created on database initialization. i was able to achieve that by executing one create statement query at the end of the function openDatabase. however the problem is that on opening the same DB for the second time, the query fails with error table already exist. findtable function doesnt work since the database is opened but not initialized (via the function sqliteinit3 and find table fails because of that). Need a place where findtable should work in both the cases (new as well as existing database) if the table already exist, skip else run the create statement the default table should be created before any user query runs the table name will be hardcoded and create statement as well. just need the right place to write the below code: if (sqlite3FindTable(db, emp, 0) ==0 ) { //Table not found, create the table rc = sqlite3_exec(db, create table emp..;,0, 0, 0); } ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] New default table on DB initialization
On Fri, Apr 8, 2011 at 1:17 AM, RAKESH HEMRAJANI rakesh_hemraj...@hotmail.com wrote: if (sqlite3FindTable(db, emp, 0) ==0 ) { //Table not found, create the table rc = sqlite3_exec(db, create table emp..;,0, 0, 0); } I feel compelled to point out that sqlite3FindTable() is part of the private API, which you are not supposed to use. (I can't immediately find a link for that statement, sorry.) The naming convention is that all public API functions start with sqlite3_, any function in camelCase is an internal function, subject to change at any time. I'd go with the 'CREATE TABLE IF NOT EXISTS' route as suggested by others. Glenn McAllister ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] New default table on DB initialization
Hi, Need a default table to be created on database initialization. i was able to achieve that by executing one create statement query at the end of the function openDatabase. however the problem is that on opening the same DB for the second time, the query fails with error table already exist. findtable function doesnt work since the database is opened but not initialized (via the function sqliteinit3 and find table fails because of that). Need a place where findtable should work in both the cases (new as well as existing database) if the table already exist, skip else run the create statement the default table should be created before any user query runs the table name will be hardcoded and create statement as well. just need the right place to write the below code: if (sqlite3FindTable(db, emp, 0) ==0 ) { //Table not found, create the table rc = sqlite3_exec(db, create table emp..;,0, 0, 0); } ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users