加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Sqlite3封装类:easysqlite

发布时间:2020-12-12 20:06:32 所属栏目:百科 来源:网络整理
导读:感谢Piotr.Zagawa大神,现在可以很简单地连接上sqlite3数据库了: 传送门:http://code.google.com/p/easysqlite/ 使用example :(用VS2010直接有解决方案,更快捷:) //define table structureField definition_tbPerson[] = { Field(FIELD_KEY),Field("fn

感谢Piotr.Zagawa大神,现在可以很简单地连接上sqlite3数据库了:

传送门:http://code.google.com/p/easysqlite/

使用example:(用VS2010直接有解决方案,更快捷:)

//define table structureField definition_tbPerson[] = {    Field(FIELD_KEY),Field("fname",type_text,flag_not_null),Field("lname",Field("birthdate",type_time),Field(DEFINITION_END),};//define database objectsql::Database db;try{    //open database file    db.open("test.db");    //define table object    Table tbPerson(db.getHandle(),"person",definition_tbPerson);    //remove table from database if exists    if (tbPerson.exists())        tbPerson.remove();    //create new table    tbPerson.create();    //define new record    Record record(tbPerson.fields());    //set record data    record.setString("fname","Jan");    record.setString("lname","Kowalski");    record.setTime("birthdate",time::now());    //add 10 records    for (int index = 0; index < 10; index++)        tbPerson.addRecord(&record);    //select record to update    if (Record* record = tbPerson.getRecordByKeyId(7))    {        record->setString("fname","Frank");        record->setString("lname","Sinatra");        record->setNull("birthdate");        tbPerson.updateRecord(record);    }    //load all records    tbPerson.open();    //list loaded records    for (int index = 0; index < tbPerson.recordCount(); index++)        if (Record* record = tbPerson.getRecord(index))            sql::log(record->toString());    sql::log("");    sql::log("ALL OK");} catch (Exception e) {    printf("ERROR: %srn",e.msg().c_str());}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读