I am experimenting with C ++, recently switched from python; is currently writing a function that creates a table in the sqlite3 database.
It seems that I hit some newbie bugs:
int db_build()
{
sqlite3 *db;
int rc;
int sql;
rc = sqlite3_open("test.db", &db);
sql = "CREATE TABLE WORDS(" \
"ID INT PRIMARY KEY NOT NULL," \
"CURRENT_WORD TEXT NOT NULL," \
"BEFORE_WORD TEXT NOT NULL," \
"AFTER_WORD TEXT NOT NULL," \
"OCCURANCES INT NOT NULL);";
rc = sqlite3_exec(db, sql);
sqlite3_close(db);
return 0;
}
My terminal returns the following:
akf@akf-v5 ~/c/HelloWorld $ g++ main.cpp -l sqlite3
main.cpp: In function ‘int db_build()’:
main.cpp:30:8: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
sql = "CREATE TABLE WORDS(" \
^
main.cpp:38:29: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]
rc = sqlite3_exec(db, sql);
^
main.cpp:38:29: error: too few arguments to function ‘int sqlite3_exec(sqlite3*, const char*, int (*)(void*, int, char**, char**), void*, char**)’
In file included from main.cpp:4:0:
/usr/include/sqlite3.h:379:16: note: declared here
SQLITE_API int sqlite3_exec(
^
If I change 'int sql' to 'char sql', I push even more errors. Any idea how to do this?
source
share