www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Any sample how to use Sqlite-d?

reply Marc <jckj33 gmail.com> writes:
I was looking for a library to use SQLite with D, found this 
(https://code.dlang.org/packages/sqlite-d) but it has no 
documentation or code example. I looked into files in the source 
code and wrote this:

 Database db = Database(name);
auto table = db.table(tableName);
auto rows = table.findRows!(format!"(id,date) => id == %s"(id));
(i'm aware of sql injection above) but it doesnt work, it seems the library has changed. If happen to that library author see this, would be very helpful.
Jan 17
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Jan 17, 2018 at 01:36:26PM +0000, Marc via Digitalmars-d-learn wrote:
 I was looking for a library to use SQLite with D, found this
 (https://code.dlang.org/packages/sqlite-d) but it has no documentation
 or code example. I looked into files in the source code and wrote
 this:
 
 Database db = Database(name);
 auto table = db.table(tableName);
 auto rows = table.findRows!(format!"(id,date) => id == %s"(id));
(i'm aware of sql injection above) but it doesnt work, it seems the library has changed. If happen to that library author see this, would be very helpful.
You might want to try this instead: https://github.com/adamdruppe/arsd/blob/master/sqlite.d I've used it myself, and can vouch for its ease-of-use, depending on what you want to do. The equivalent of your code above is: Database db = new SQLite(filename); auto rows = db.query("SELECT * FROM " ~ tableName ~ " WHERE id=?", id); // Note: no SQL injection issue here foreach (row; rows) { ... } T -- Leather is waterproof. Ever see a cow with an umbrella?
Jan 17
prev sibling next sibling parent Stefan Koch <uplink.coder googlemail.com> writes:
On Wednesday, 17 January 2018 at 13:36:26 UTC, Marc wrote:
 I was looking for a library to use SQLite with D, found this 
 (https://code.dlang.org/packages/sqlite-d) but it has no 
 documentation or code example. I looked into files in the 
 source code and wrote this:

 Database db = Database(name);
auto table = db.table(tableName);
auto rows = table.findRows!(format!"(id,date) => id == %s"(id));
(i'm aware of sql injection above) but it doesnt work, it seems the library has changed. If happen to that library author see this, would be very helpful.
Hello Marc, I am the author of sqlite-d, since it is a very low level library it does correlate rows and names. I would need to see the schema to tell you which rows to compare. Otherwise there is an code example in the repo call example_app.d
Jan 17
prev sibling parent biozic <dransic gmail.com> writes:
On Wednesday, 17 January 2018 at 13:36:26 UTC, Marc wrote:
 I was looking for a library to use SQLite with D, found this 
 (https://code.dlang.org/packages/sqlite-d) but it has no 
 documentation or code example. I looked into files in the 
 source code and wrote this:

 Database db = Database(name);
auto table = db.table(tableName);
auto rows = table.findRows!(format!"(id,date) => id == %s"(id));
(i'm aware of sql injection above) but it doesnt work, it seems the library has changed. If happen to that library author see this, would be very helpful.
Also have a look at https://github.com/biozic/d2sqlite3 (documentation: http://biozic.github.io/d2sqlite3/d2sqlite3.html).
Jan 18