Last active
August 29, 2015 13:57
-
-
Save burner/9900870 to your computer and use it in GitHub Desktop.
sqlite3 from inside D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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