簡體   English   中英

C,如何傳輸sqlite3數據庫句柄

[英]C, how to transfer sqlite3 database handle

我正在嘗試制作一些與sqlite數據庫一起使用的工具。 為此,我創建了sqlite3_ut.h和sqlite3_ut.c文件

sqlite_ut.h

#ifndef sqlite3_ut_h
#define sqlite3_ut_h

#include <stdio.h>
#include "sqlite3.h"

int drop_table(sqlite3 handle);

#endif

sqlite_ut.c

int drop_table(sqlite3 handle)
{
int dropped = 0;
printf("Begin Drop\n");

sqlite3_exec(handle, "BEGIN;", NULL, NULL, NULL);
sqlite3_stmt *droptab;
if (sqlite3_prepare_v2(handle, "DROP TABLE mytable;", -1, &droptab, 0) != SQLITE_OK)
    printf("db error: %s\n", sqlite3_errmsg(handle));

if(droptab)
{
    sqlite3_step(droptab);
    dropped = 1;
}
else
    printf("Error: drop_table");

sqlite3_finalize(droptab);
sqlite3_exec(handle, "COMMIT;", NULL, NULL, NULL);

printf("End Drop\n");
return dropped;
}

sqlite_ut.h包含在主文件中。

sqlite3 *db;

int rc = sqlite3_open("m_test.db", &db);
if (rc)...

//error here
int dropped = drop_table(db);

顯然,我無法將打開的數據庫的句柄正確地傳遞給sqlite3類型的drop_table函數。

如何使用建議的程序配置?

SQLite3句柄的類型為sqlite3 * ,而不是sqlite3 重新定義drop_table如下:

int drop_table(sqlite3 *handle) { … }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM