Browsing projects by Tag(s)

Select a tag to browse associated projects and drill deeper into the tag cloud.

Showing page 1 of 1

Yet another C++ wrapper for libsqlite3

5.0
 
  0 reviews  |  1 user  |  492 lines of code  |  0 current contributors  |  Analyzed 3 days ago
 
 

SQLite3的轻量C++封装类库,使用方法类似Microsoft.net的Data Provider, 最新更新到sqlite3的3.6.3版本,如果需要更新sqlite3的版本,在 http://www.sqlite.org/download.html 下载最新的amalgamation ... [More] 方式源码,覆盖sqlite3.h和sqlite3.c两个文件后重新编译即可。 具体使用方法参见如下示例。 #include "sqlite3provider.h" int main() { try { SQLiteConnection conn("test.db"); cout << conn.version << endl; cout << conn.name << endl; conn.open(); SQLiteTransaction trans = conn.beginTransaction(); //================================================================ SQLiteCommand cmd(conn); cmd.setCommandText("create table IF NOT EXISTS TABLE_TEST( ID integer primary key autoincrement, field1 varchar(10), field2 int, field3 double, field4 BLOB)"); cmd.executeNonQuery(); cmd.setCommandText("insert into TABLE_TEST( field1, field2, field3, field4) values( ?, ?, ?, ? ); "); SQLiteParameter param1(cmd); param1.bind(1, "abc"); SQLiteParameter param2 = cmd.createParameter(); param2.bind(2, 100); SQLiteParameter param3 = cmd.createParameter(); param3.bind(3, 80.2345345); char dt = new char1024; memset(dt, 97, 1024); SQLiteParameter param4(cmd); param4.bind(4, dt, 1024); delete dt; cmd.executeNonQuery(); //cmd.executeScalar(); //================================================================ /SQLiteDataTable table_test(conn, "select from TABLE_TEST"); SQLiteDataTable table = table_test; for (int i = 0; i < table.rows(); i++) { cout << "row:" << i << endl; for (int j = 0; j < table.columns(); j++) { cout << table.getFieldName(j) << ": " << table.getFieldValue(i, j) << endl; } cout << endl; } //================================================================ SQLiteCommand cmd2(conn, "select from TABLE_TEST"); SQLiteDataReader dr = cmd2.executeReader(); while (dr.read()) { for (int i = 0; i < dr.getFieldCount(); i++) { if (!dr.isDbNull(i)) { cout << dr.getFieldName(i) << "[" << dr.getDataTypeName(i) << "]:"; switch(dr.getFieldDbType(i)) { case sqlite3provider::DT_INTERGER: cout << dr.getInt32(i) << endl; break; case sqlite3provider::DT_FLOAT: cout << dr.getFloat(i) << endl; break; case sqlite3provider::DT_TEXT: cout << dr.getString(i) << endl; break; case sqlite3provider::DT_BLOB: cout << dr.getBLOB(i) << endl; break; } } } cout << endl; } //================================================================ trans.commit(); conn.close(); } catch (SQLiteException& e) { cout << e.what() << endl; } cout << "All command has been executed!" << endl; cin.get(); } [Less]

0
 
  0 reviews  |  0 users  |  0 current contributors  |  Analyzed 1 day ago
 
 
 
 

Creative Commons License Copyright © 2013 Black Duck Software, Inc. and its contributors, Some Rights Reserved. Unless otherwise marked, this work is licensed under a Creative Commons Attribution 3.0 Unported License . Ohloh ® and the Ohloh logo are trademarks of Black Duck Software, Inc. in the United States and/or other jurisdictions. All other trademarks are the property of their respective holders.