gpt4 book ai didi

在C中使用sqlite3调用两个使用不同数据库的函数

转载 作者:行者123 更新时间:2023-11-30 16:43:52 24 4
gpt4 key购买 nike

我正在开发 C 应用程序,用于显示 chrome 和 Firefox 的历史记录(使用 Sqlite3)。

I developed two functions : DisplaychromeHistory() :it displays the history of chrome and display firefoxhistory() :it displays the history of 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 :

int main()
{
DisplayFirefoxHistory();
DisplayChromeHistory();

return 0;
}

那么只有 DisplayFirefoxHistory();有效,但如果我的代码看起来像

int main()
{
DisplayChromeHistory();
DisplayFirefoxHistory();

return 0;
}

仅显示chrome工作:程序不显示任何错误。我考虑清除缓存,但它不会改变任何东西

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;
}

最佳答案

问题出在函数回调和回调Firefox中,我必须关闭文件。当我添加

fclose (fp);

效果很好。

关于在C中使用sqlite3调用两个使用不同数据库的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44899452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com