Sqlite3封装类:easysqlite

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

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

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

//define table structure 
Field definition_tbPerson[] =  

        Field(FIELD_KEY), 
        Field("fname", type_text, flag_not_null), 
        Field("lname", type_text, flag_not_null), 
        Field("birthdate", type_time), 
        Field(DEFINITION_END), 
}; 
 
//define database object 
sql::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: %s\r\n", e.msg().c_str()); 
}


 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值