SQLite

SQLite简介

SQLite是一款开源的、嵌入式关系型数据库。简单地说,SQLite源代码只有三个文件,添加到项目中(此为嵌入式),通过调用SQLite提供的接口函数即可获得使用SQL语句读写数据库的能力,只是该数据库是内存数据库或本地文件数据库。www.sqlite.org

使用方法

#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
    // sqlite API大多数函数所需的字符串均为utf8字符串
    // 实际使用时需要考虑字符集转换
    // 以下示例中省略错误处理代码

    // 打开数据库
    sqlite3* db;
    sqlite3_open("foods.db", &db);

    // 编译查询语句
    sqlite3_stmt* stmt = nullptr;
    const char* tail = nullptr;
    char* sql = "select * from episodes";
    sqlite3_prepare_v2(db, sql, -1, &stmt, &tail);
   
    // 执行查询
    int rc = sqlite3_step(stmt);
    int columnCount = sqlite3_column_count(stmt);
    while (rc == SQLITE_ROW)
    {
        for (int i=0; i<columnCount; ++i)
            cout << sqlite3_column_text(stmt, i) << ' ';
        cout << endl;
        rc = sqlite3_step(stmt);
    }

    sqlite3_finalize(stmt);
    sqlite3_close(db);

    return 0;
}

推荐教程

《SQLite权威教程》 Grant Allen

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值