SQLite C++ 封装 easySQLite

码农软件 · 软件分类 · ORM/持久层框架 · 2019-09-23 22:44:20

软件介绍

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

本文地址:https://codercto.com/soft/d/15263.html

超越门户

超越门户

吴晨光 / 中国人民大学出版社 / 2015-4-17 / 39.80

在这个PC端影响力下降、人们对手机的依赖与日俱增的时代,这种探索的意义非同寻常,可以说是试图树立新媒体时代的行业标准。 ——陈彤(小米内容投资与运营副总裁、新浪网前总编辑、资深网络媒体人) 我将对此书的阅读,视作对往日岁月的怀念,它提醒我,自己曾 投身于多么富有蓬勃朝气和探索精神的事业。而对这种事业的原则、逻辑和方法的继承和继续学习,对于互联网时代的企业形象塑造 ,同样有融会变通的参考......一起来看看 《超越门户》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具