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, &binary_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 <rwm.phoe...@btinternet.com> 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

Reply via email to