Advertisement
Guest User

Untitled

a guest
May 8th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.08 KB | None | 0 0
  1. import std.stdio;
  2. import std.string;
  3.  
  4. import ddbc.common;
  5. import ddbc.core;
  6. import ddbc.drivers.sqliteddbc;
  7.  
  8. import etc.c.sqlite3;
  9.  
  10. void main(){
  11.  
  12.     SQLITEDriver driver = new SQLITEDriver();
  13.  
  14.  
  15.     // creating Connection
  16.     auto conn = driver.connect("IP.db", null);
  17.     scope(exit) conn.close();
  18.  
  19.     // creating Statement
  20.     auto stmt = conn.createStatement();
  21.     scope(exit) stmt.close();
  22.  
  23.     // execute simple queries to create and fill table
  24.     stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ddbct1 (id bigint not null primary key AUTO_INCREMENT, name varchar(250), comment mediumtext, ts datetime)");
  25.     stmt.executeUpdate("INSERT INTO ddbct1 SET id=1, name='name1', comment='comment for line 1', ts='20130202123025'");
  26.     stmt.executeUpdate("INSERT INTO ddbct1 SET id=2, name='name2', comment='comment for line 2 - can be very long'");
  27.  
  28.     // reading DB
  29.     auto rs = stmt.executeQuery("SELECT id, name name_alias, comment, ts FROM ddbct1 ORDER BY id");
  30.     while (rs.next())
  31.         writeln(rs.getLong(1) , "\t" , rs.getString(2) , "\t" , rs.getString(3));
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement