-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
On 11/03/12 05:21, Wei Song 2 wrote:
> And there may be a easier way to do this.
There is, and someone else already mentioned it. Simply prepare a
statement that uses the table. If the table doesn't exist then you will
get an error from prepare.
Once you have ascertained whether the table exists, what are you wanting to
do next?
Exit?
Or create it and then continue with inserts and so on?
If the latter, you can just do CREATE TABLE IF NOT EXISTS and then keep
going.
~~~
On Sun, Mar 11, 2012 at 8:21 AM, Wei Song 2
Now, I have the C code to check if a table exists:
#include
#include "sqlite3.h"
int main(int argc, const char *argv[]){
sqlite3 *db;
sqlite3_stmt *stmt;
int rc = 0;
int hasTable = 0;// flag for the result
rc = sqlite3_open("test.db", );
Try this
SELECT * FROM dbname.sqlite_master WHERE type='table' AND name='tbname';
Change dbname with name of your database and tbname with the name of table.
--
speco
> To: sqlite-users@sqlite.org
> From: itandet...@mvps.org
> Date: Fri, 9 Mar 2012 20:30:55 -0500
> Subject: Re:
Wei Song wrote:
> I'm developing an SQLite extension which uses a function to set data into a
> table. I'd like to know how to check if a table
> exists in a database?
Just prepare the statement that you are going to use to write the data, and
handle any errors.
--
Er, what do you mean by C Syntax -- SQL isn't C? If you meant ANSI SQL syntax,
you could use:
select count(*) from sqlite_master where type='table' and
lower(name)=lower('tablename');
Instead. But since you're accessing a metadata table that only exists in
SQLite, this isn't particularly
I'd like get the result in C Syntax. How can I do it?
Peter Aronson-3 wrote:
>
> You got to be a bit careful there, SQLite isn't case-sensitive about table
> names, but sqlite_master will preserve the case from the CREATE TABLE
> statement. Instead of
>
>
> select count(*) from
Yes, thank you.
/Wei
Roger Andersson-2 wrote:
>
> On 03/09/12 19:39, Wei Song wrote:
>> Hello,
>>
>> I'm developing an SQLite extension which uses a function to set data into
>> a table. I'd like to know how to check if a table exists in a database?
>>
> It's hard to say what you need but
You got to be a bit careful there, SQLite isn't case-sensitive about table
names, but sqlite_master will preserve the case from the CREATE TABLE
statement. Instead of
select count(*) from sqlite_master where type='table' and name='tablename';
You need something like
select count(*) from
On 03/09/12 19:39, Wei Song wrote:
Hello,
I'm developing an SQLite extension which uses a function to set data into a
table. I'd like to know how to check if a table exists in a database?
It's hard to say what you need but maybe
select count(*) from sqlite_master where type='table' and
Hello,
I'm developing an SQLite extension which uses a function to set data into a
table. I'd like to know how to check if a table exists in a database?
Thanks.
___
sqlite-users mailing list
sqlite-users@sqlite.org
11 matches
Mail list logo