[sqlite] How to recognize a sqlite database file?

2012-08-13 Thread daedae11
How can I judge whether a file is a database file? Is there a function that I 
can use for this purpose?
Help! 
Hope for you  reply.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to recognize a sqlite database file?

2012-08-13 Thread Simon Slavin

On 14 Aug 2012, at 2:57am, daedae11 daeda...@126.com wrote:

 How can I judge whether a file is a database file? Is there a function that I 
 can use for this purpose?

You can use the SQLite library call to open it and see whether you get an error 
back.  But it might be better to open the file as binary/text and read the 
beginning of it.  All SQLite files begin with

SQLite format 3

and then a 0x00 character.  Of course, there's nothing to stop someone writing 
such a file themself but it would have to be a joke.  See

http://www.sqlite.org/fileformat.html

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to recognize a sqlite database file?

2012-08-13 Thread Luis Mochan
In linux I use the command  'file yourfilenamehere' and I get as an
answer something like  'yourfilenamehere: SQLite 3.x database' if it
is an Sqlite3 database. 
Regards,
Luis


On Tue, Aug 14, 2012 at 09:57:33AM +0800, daedae11 wrote:
 How can I judge whether a file is a database file? Is there a function that I 
 can use for this purpose?
 Help! 
 Hope for you  reply.
 ___
 sqlite-users mailing list
 sqlite-users@sqlite.org
 http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

-- 

  o
W. Luis Mochán,  | tel:(52)(777)329-1734 /(*)
Instituto de Ciencias Físicas, UNAM  | fax:(52)(777)317-5388 `/   /\
Apdo. Postal 48-3, 62251 |   (*)/\/  \
Cuernavaca, Morelos, México  | moc...@fis.unam.mx   /\_/\__/

O ascii ribbon campaign - stop html mail - www.asciiribbon.org 


___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to recognize a sqlite database file?

2012-08-13 Thread daedae11
Thank you. I got it. And I have another question. Does function sqlite3_exec 
support UTF-16?





At 2012-08-14 10:01:13,Simon Slavin slav...@bigfraud.org wrote:

On 14 Aug 2012, at 2:57am, daedae11 daeda...@126.com wrote:

 How can I judge whether a file is a database file? Is there a function that 
 I can use for this purpose?

You can use the SQLite library call to open it and see whether you get an 
error back.  But it might be better to open the file as binary/text and read 
the beginning of it.  All SQLite files begin with

SQLite format 3

and then a 0x00 character.  Of course, there's nothing to stop someone writing 
such a file themself but it would have to be a joke.  See

http://www.sqlite.org/fileformat.html

Simon.
___
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] How to recognize a sqlite database file?

2012-08-13 Thread Simon Slavin

On 14 Aug 2012, at 3:05am, daedae11 daeda...@126.com wrote:

 Thank you. I got it. And I have another question. Does function sqlite3_exec 
 support UTF-16?

No.  sqlite3_exec() is a wrapper around sqlite3_prepare_v2(), and 
sqlite3_prepare_v2() expects UTF-8.  For UTF-16 you should be using 
sqlite3_prepare16_v2() .  But for some reason there's no sqlite3_exec16() .

However, _exec is relatively simple to write.  You can see what it does here:

http://sqlite.org/c3ref/exec.html

So all you should need to do is

sqlite3_prepare16_v2()
sqlite3_step()
andsqlite3_finalize()

Good luck with it.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to recognize a sqlite database file?

2012-08-13 Thread daedae11
If I use the group of:
sqlite3_prepare16_v2()
sqlite3_step()
andsqlite3_finalize()

how can I get the names of a table's columns from a SELECT sql sentence?




At 2012-08-14 10:11:31,Simon Slavin slav...@bigfraud.org wrote:

On 14 Aug 2012, at 3:05am, daedae11 daeda...@126.com wrote:

 Thank you. I got it. And I have another question. Does function sqlite3_exec 
 support UTF-16?

No.  sqlite3_exec() is a wrapper around sqlite3_prepare_v2(), and 
sqlite3_prepare_v2() expects UTF-8.  For UTF-16 you should be using 
sqlite3_prepare16_v2() .  But for some reason there's no sqlite3_exec16() .

However, _exec is relatively simple to write.  You can see what it does here:

http://sqlite.org/c3ref/exec.html

So all you should need to do is

sqlite3_prepare16_v2()
sqlite3_step()
andsqlite3_finalize()

Good luck with it.

Simon.
___
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] How to recognize a sqlite database file?

2012-08-13 Thread Igor Tandetnik
daedae11 daeda...@126.com wrote:
 If I use the group of:
 sqlite3_prepare16_v2()
 sqlite3_step()
 andsqlite3_finalize()
 
 how can I get the names of a table's columns from a SELECT sql sentence?

sqlite3_column_name[16]

-- 
Igor Tandetnik

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to recognize a sqlite database file?

2012-08-13 Thread Simon Slavin

On 14 Aug 2012, at 4:14am, daedae11  daeda...@126.com wrote:

 If I use the group of:
 sqlite3_prepare16_v2()
 sqlite3_step()
 andsqlite3_finalize()
 
 how can I get the names of a table's columns from a SELECT sql sentence?

To get the names of columns of a table, use the SQL command

PRAGMA table_info(table-name)

as documented here:

http://www.sqlite.org/pragma.html#pragma_table_info

You can use the above sequence to execute the PRAGMA command.  It works exactly 
the same way as if you were executing a SELECT command.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to recognize a sqlite database file?

2012-08-13 Thread daedae11
Thank you. And I found these functions:

const char *sqlite3_column_database_name(sqlite3_stmt*,int);
const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
const char *sqlite3_column_table_name(sqlite3_stmt*,int);
const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);

maybe it's more convenient.





At 2012-08-14 11:44:14,Igor Tandetnik itandet...@mvps.org wrote:
daedae11 daeda...@126.com wrote:
 If I use the group of:
 sqlite3_prepare16_v2()
 sqlite3_step()
 andsqlite3_finalize()
 
 how can I get the names of a table's columns from a SELECT sql sentence?

sqlite3_column_name[16]

-- 
Igor Tandetnik

___
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