[英]Calling two functions that use different database using sqlite3 in C
I'm developing C Application that displays History fi chrome and Firefox (using Sqlite3) . 我正在开发显示历史记录彩色和Firefox的C应用程序(使用Sqlite3)。
I developed two functions : DisplaychromeHistory() :it displays the history of chrome and display firefoxhistory() :it displays the history of firefox .
我开发了两个函数:DisplaychromeHistory():显示chrome的历史记录;显示firefoxhistory():显示firefox的历史记录。 The Problem that the two functions works well but when I call them in main only the first function works : Exemple if my program feels like :
这两个函数很好地工作的问题,但是当我在main中调用它们时,只有第一个函数起作用:例如,如果我的程序感觉像这样:
int main()
{
DisplayFirefoxHistory();
DisplayChromeHistory();
return 0;
}
then only DisplayFirefoxHistory(); 那么只有DisplayFirefoxHistory(); works but if my code seems like
可以,但是如果我的代码看起来像
int main()
{
DisplayChromeHistory();
DisplayFirefoxHistory();
return 0;
}
Only display chrome works : The program doesn't show any error . 仅显示chrome有效:该程序没有显示任何错误。 I think about clear the cache but it doesn't change anything
我考虑清除缓存,但不会改变任何内容
int main()
{
DisplayFirefoxHistory();
DisplayChromeHistory();
return 0;
}
int DisplayChromeHistory()
{
char pathFileh[] = "c:/Users//AppData/Local/Google/Chrome/User Data/Default/History";
char username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserName(username, &username_len);
insert_substring(pathFileh,username,10);
sqlite3 *db;
char *err_msg = 0;
if (chrome_is_running2())
system("taskkill /IM chrome.exe /F");
int rc = sqlite3_open(pathFileh, &db);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n",sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
char *sql = "select datetime(last_visit_time/1000000-11644473600,'unixepoch'),url from urls order by last_visit_time desc";
rc = sqlite3_exec(db, sql, callback, NULL, &err_msg);
if (rc != SQLITE_OK ) {
fprintf(stderr, "Failed to select data\n");
fprintf(stderr, "SQL error: %s\n", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
sqlite3_db_cacheflush(db);
return 1;
}
sqlite3_close(db);
return 0;
}
int DisplayFirefoxHistory()
{
char pathFileh[] = "C:/Users/ ****/AppData/Roaming/Mozilla/Firefox/Profiles/dbi1yjvy.default/places.sqlite";
char username[UNLEN+1];
sqlite3 *dbF;
char *err_msg = 0;
Sleep(1000);
int rc = sqlite3_open(pathFileh, &dbF);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n",sqlite3_errmsg(dbF));
sqlite3_close(dbF);
return 1;
}
char *sql = "select url,datetime(visit_date/1000000-11644473600,'unixepoch') from moz_historyvisits , moz_places order by visit_date desc";
rc = sqlite3_exec(dbF, sql, callbackFirefox, NULL, &err_msg);
if (rc != SQLITE_OK ) {
fprintf(stderr, "Failed to select data\n");
fprintf(stderr, "SQL error: %s\n", err_msg);
sqlite3_free(err_msg);
sqlite3_close(dbF);
return 1;
}
sqlite3_close(dbF);
return 0;
}
int callback(void *NotUsed, int argc, char **argv,
char **azColName) {
char pathFileRe[] = "c:/ResulatEpreuve/Exploit.txt";
FILE *fp ;
fp=fopen(pathFileRe,"a");
fprintf(fp,"%s = %s\n", argv[0], argv[1] );
return 0;
}
int callbackFirefox(void *NotUsed, int argc, char **argv,
char **azColName) {
char pathFileRe[] = "c:/ResulatEpreuve/Exploit2.txt";
FILE *fp ;
fp=fopen(pathFileRe,"a");
fprintf(fp,"%s = %s\n", argv[0], argv[1] );
return 0;
}
The problem is in function Callback and callbackFirefox I have to close File .When i add 问题出在函数Callback和callbackFirefox中,我必须关闭File。添加时
fclose (fp);
It works well . 它运作良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.