easySQLite SQLite C++ 封装

我要开发同款
匿名用户2015年01月19日
36阅读
开发技术C/C++
所属分类程序开发、ORM/持久层框架
授权协议BSD

作品详情

一个简单的SQLiteC++封装.

优势:

优雅的面向对象解决方案

显式命名和调用

使用异常以及方法返回值

容易理解

灵活而且可扩展

经过强测试

//define table structureField 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 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: %s\r\n", e.msg().c_str());}
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论