Skip to content

Instantly share code, notes, and snippets.

@burner
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burner/9900870 to your computer and use it in GitHub Desktop.
Save burner/9900870 to your computer and use it in GitHub Desktop.
sqlite3 from inside D
enum insertStmt = "INSERT INTO Entry(sym,open,close,volume) Values(?, ?, ?, ?);";
int errCode = sqlite3_prepare_v2(db, toCstr.toStringZ(insertStmt),
to!int(insertStmt.length), &stmt, null);
if(errCode != SQLITE_OK) {
scope(exit) sqlite3_finalize(stmt);
throw new Exception(insertStmt ~ " FAILED " ~
to!string(sqlite3_errmsg(db))
);
}
int i = 1;
sqlite3_bind_int64(stmt, i++, this.sym);
sqlite3_bind_double(stmt, i++, this.open);
sqlite3_bind_double(stmt, i++, this.close);
sqlite3_bind_int(stmt, i++, this.volume);
if(sqlite3_step(stmt) != SQLITE_DONE) {
scope(exit) sqlite3_finalize(stmt);
throw new Exception(to!string(sqlite3_errmsg(db)) ~ " " ~
insertStmt ~ " " ~ to!string(this)
);
}
sqlite3_finalize(stmt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment