我正在使用GTK +和SQLite作为小型数据库程序的前端,我无法让SQLite在打开时正确检测文件类型。无论打开什么,它都会返回SQLITE_OK。
我尝试sqlite3_open
和sqlite3_open_v2
,问题仍然存在。无论打开什么文件类型,输出始终相同:
/home/shawn/Programming/languagedb/lang.db
0 6304656
good
/home/shawn/Programming/languagedb/Makefile
0 6304656
good
以下是相关代码:
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);
}