Sqlite
Paul via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 11 12:00:03 PST 2015
Can someone please tell me what I'm doing wrong here, the sql
INSERT statement fails for some reason. I don't fully understand
the callback function yet (I borrowed this from a C tutorial on
the subject), maybe that is the source of the problem?
import etc.c.sqlite3;
import std.stdio;
//stub
extern(C) int aCallback(void *n, int c, char **v, char **col)
{
return 0;
}
void main(){
sqlite3 *db;
int result = sqlite3_open("myDatabase.db", &db);
if (result) {
writeln("Failed to open database");
return;
}
//create table
char *msg = null;
result = sqlite3_exec(db, "CREATE TABLE people('id INT PRIMARY
KEY NOT NULL, surname TEXT NOT NULL');", &aCallback, null, &msg);
if (result) {
writeln("Failed to create table");
//tidy up on exit
sqlite3_close(db);
return;
}
//insert record
msg = null;
result = sqlite3_exec(db, "INSERT INTO people (id, surname)
VALUES (1, 'Smith');", &aCallback, null, &msg);
if (result) {
writeln("Failed to insert record");
//tidy up on exit
sqlite3_close(db);
return;
}
sqlite3_free(msg);
sqlite3_close(db);
}
Many thanks
Paul
More information about the Digitalmars-d-learn
mailing list