Sqlite3_open - problems checking if a file is sqlite3 database

I am working with sqlite3 for the first time and cannot get it to validate the file correctly before it opens it. So far, sqlite always returns OK in any file.

In addition, the file name is a variable returned from the GTK selection file. It returns the absolute path, I assume this is not a problem.

Thanks for any help.

This is a piece of code:

int rc;
char *filename;
sqlite3 *db;

filename = gtk_file_chooser_get_filename(etc.);

if(SQLITE_OK == rc = sqlite3_open(filename,&db))
{  etc. }
+3
source share
2 answers

sqlite3_openactually does not read the file until the first statement is prepared pragma.

sqlite3_open_v2 provides other options.

+5
source

?
,

if (SQLITE_OK == rc = sqlite3_open(filename,&db)) { /* ... */ }

,

if ((SQLITE_OK == rc) = sqlite3_open(filename,&db)) { /* ... */ }

- ( sqlite3_open()) (SQLITE_OK == rc).

:

if ((rc = sqlite3_open(filename,&db)) == SQLITE_OK) { /* ... */ }
/* or, if you really want the constant on the left side of the comparison */
if (SQLITE_OK == (rc = sqlite3_open(filename,&db))) { /* ... */ }
-1

Source: https://habr.com/ru/post/1725227/


All Articles