gpt4 book ai didi

c++ - sqlite3 c++ 中的主键错误

转载 作者:行者123 更新时间:2023-11-28 02:16:50 27 4
gpt4 key购买 nike

我的代码在编译和执行时显示如下:

  1. Opened database successfully
  2. SQL error: near ";": syntax error
  #include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstring>
#include <sstream>
#include <sqlite3.h>
#include <stdio.h>

using namespace std;

static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}

static void createTrackTable(){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
char *sql;

rc = sqlite3_open("idk.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
exit(0);
}else{
fprintf(stdout, "Opened database successfully\n");
}

sql = "CREATE TABLE TRACK (" \
"CD_ID INTEGER NOT NULL," \
"TRACK_ID INTEGER NOT NULL," \
"TITLE VARCHAR(70) NOT NULL," \
"PRIMARY KEY(CD_ID, TRACK_ID);";

rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
fprintf(stdout, "Track table created successfully\n");
}
sqlite3_close(db);
}

int main(){
createTrackTable();

return 0;

}

我相信当我声明 PRIMARY KEY(CD_ID, TRACK_ID) 时会发生错误

如有任何帮助,我们将不胜感激。谢谢!

最佳答案

缺少查询中的最后一个 )。

关于c++ - sqlite3 c++ 中的主键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33796737/

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