gpt4 book ai didi

c - SQLite3 : the database was created empty?

转载 作者:太空宇宙 更新时间:2023-11-04 06:28:13 27 4
gpt4 key购买 nike

我正在尝试在我的 C 程序上使用 sqlite3 创建一个带有表的数据库,但是该数据库始终创建为空,尽管它是使用 sqlite shell 创建的非空的, 下面是我的代码:

int main(void)
{
printf("hello\n");
sqlite3 *sqdb;
sqlite3_initialize();
const char* db = "test";
sqlite3_open(db, &sqdb);
const char* stmt = "CREATE TABLE IF NOT EXISTS testtable(creationdate DATE, data VARCHAR);";
sqlite3_stmt *ppstmt;
if (sqlite3_prepare_v2(sqdb, stmt, -1, &ppstmt, 0)!=SQLITE_OK)printf("error!\n");
sqlite3_finalize(ppstmt);
getch();
return 0;
}

请帮我解决这个问题。

最佳答案

sqlite3_prepare_v2() 单独编译 SQL 但不运行它。在编译后的语句上调用 sqlite3_step() 来运行它,或者使用 sqlite3_exec() 将 prepare+step+finalize 组合到一个函数调用中。

关于c - SQLite3 : the database was created empty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23525340/

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