开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 4726|回复: 3

C++下的sqlite操作库easysqlite

[复制链接]

0

精华

135

贡献

111

赞扬

管理员

帖子
155
软币
3622
在线时间
419 小时
注册时间
2013-6-7

黄马甲胡吹海聊

发表于 2013-6-22 23:22:54 | 显示全部楼层 |阅读模式
这是很方便操作sqlite的easy sqlite c++操作库,开源,供大家学习一下
//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 赞扬 +1 收起 理由
羽叶 + 2 + 1

查看全部评分

回复

使用道具 举报

0

精华

56

贡献

21

赞扬

帖子
250
软币
1755
在线时间
199 小时
注册时间
2013-8-28
发表于 2013-9-10 05:46:44 | 显示全部楼层
SQLite的C++ Wrapper不少,没有比较一下谁更好
回复

使用道具 举报

0

精华

1

贡献

6

赞扬

帖子
54
软币
332
在线时间
25 小时
注册时间
2014-8-22
发表于 2014-8-23 09:10:03 | 显示全部楼层
好东西,要拿出来晒
回复

使用道具 举报

0

精华

0

贡献

11

赞扬

帖子
81
软币
323
在线时间
23 小时
注册时间
2015-12-19
发表于 2016-7-9 14:01:00 | 显示全部楼层
谢谢分享,非常实用
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-26 04:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表