Reputation: 119
My code when compiled and executed shows this:
- Opened database successfully
- 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;
}
I believe that the error is happening when I declare the PRIMARY KEY(CD_ID, TRACK_ID)
Please any help would be greatly appreciated. Thank you!
Upvotes: 0
Views: 153