微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

easySQLite 一个简单的 SQLite C++ 封装. SQLite C++ 封装

程序名称:easySQLite 一个简单的 SQLite C++ 封装.

授权协议: BSD

操作系统: 跨平台

开发语言: C/C++

easySQLite 一个简单的 SQLite C++ 封装. 介绍

一个简单的 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());
    }

easySQLite 一个简单的 SQLite C++ 封装. 官网

https://code.google.com/p/easysqlite/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐