0

I'm using GTK+ and SQLite as a front end for a small database program, and I cannot get SQLite to properly detect file type on open. Not matter what is opened, it returns SQLITE_OK.

I tried sqlite3_open and sqlite3_open_v2, the problem still persists. The output is always the same, regardless of what filetype is opened:

/home/shawn/Programming/languagedb/lang.db
0 6304656
good
/home/shawn/Programming/languagedb/Makefile
0 6304656
good

And here is the related code:

void OpenDialog()
{
    GtkWidget *WinOpen;

    WinOpen = gtk_file_chooser_dialog_new("Open Database",GTK_WINDOW(WinOpen),GTK_FILE_CHOOSER_ACTION_OPEN,GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN,GTK_RESPONSE_ACCEPT,NULL);

    if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(WinOpen)))
    {
        char *filename;
        filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(WinOpen));
        printf("%s\n",filename);

        db = NULL;
        rc = sqlite3_open_v2(filename,&db,SQLITE_OPEN_READONLY,NULL);

        printf("%i %i\n",rc,&db);

        if(SQLITE_OK == rc && NULL != db)
        {
            printf("good\n");
        }

        sqlite3_close(db);
    }

    gtk_widget_destroy(WinOpen);
}

1 Answer 1

1

As I also said in this answer you need to execute a non-pragma statement against the open database handle before SQLite tries to read, and then verify the file's contents.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I wasn't sure what that meant, so I'll do some more research.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.