Re: [sqlite] Is the file I'm about to open an SQLite Database

2017-09-04 Thread Papa

Yes, what I do to check for the existance of a database is:
//This method will returns true if the table does not exit, false otherwise.
bool SQLite3_RDB::notExist(const std::wstring& table) {
    // SQL statement
    sql_statement_request = "SELECT *  FROM " + table + " LIMIT 0";

    // Feed the statement to the SQL3
    rc = sqlite3_prepare_v2(this->db, sql_statement_request.c_str(), 
-1, _sql_statement, NULL);


    // If the Statement processor returns !=1 table does not exist
    if (rc != SQLITE_OK) {
    // Terminate the connection to the database and
    this->finalize();
    // Respond affirmative
    return true;
    }
    // If the table exit terminate the connection to the database
    this->finalize();
    // Respond negative
    return false;
    // Finished
}

I just started using SQLite3, so I am sure there are better ways to do 
this, but this seems to work for me.


On 2017-09-04 10:55 AM, Gwendal Roué wrote:

Le 4 sept. 2017 à 16:46, Phoenix  a écrit :

Is there anyway to confirm the file I am about to open, via
sqlite3_open, is in fact an SQLite Database?

You may have noticed that sqlite3_open doesn't fail if the file is not a 
database.

To check if the file is a valid database, read something. For example: "SELECT * 
FROM sqlite_master LIMIT 1" (I'm sure there are shorter/smarter test access, but 
this one does the job). SQLite will then fail unless the file is actually a database.

Gwendal Roué

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


--
ArbolOne.ca
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free 
services to charitable organizations.
ArbolOne on Java Development in progress [ í ]

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


Re: [sqlite] Is the file I'm about to open an SQLite Database

2017-09-04 Thread Gwendal Roué

> Le 4 sept. 2017 à 16:46, Phoenix  a écrit :
> 
> Is there anyway to confirm the file I am about to open, via
> sqlite3_open, is in fact an SQLite Database?

You may have noticed that sqlite3_open doesn't fail if the file is not a 
database.

To check if the file is a valid database, read something. For example: "SELECT 
* FROM sqlite_master LIMIT 1" (I'm sure there are shorter/smarter test access, 
but this one does the job). SQLite will then fail unless the file is actually a 
database.

Gwendal Roué

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


Re: [sqlite] Is the file I'm about to open an SQLite Database

2017-09-04 Thread Simon Slavin


On 4 Sep 2017, at 3:46pm, Phoenix  wrote:

> Is there anyway to confirm the file I am about to open, via
> sqlite3_open, is in fact an SQLite Database?

Read the file header from it using fopen()/fread()/fclose() (i.e. not the 
SQLite library).  The file will start with "SQLite format 3" followed by a x00 
byte.

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


[sqlite] Is the file I'm about to open an SQLite Database

2017-09-04 Thread Phoenix
Is there anyway to confirm the file I am about to open, via
sqlite3_open, is in fact an SQLite Database?

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