• C语言操作SQLite数据库


    SQLite头文件和源文件下载地址http://www.sqlite.org/download.html

    以下是示例代码

    #include <stdio.h>
    #include "SQLite/sqlite3.h"
    int callback(void *data, int argc, char **argv, char **colName);
    int main()
    {
        sqlite3 *db;
        if (sqlite3_open("DBFile.db", &db))
        {
            printf("Can't open database: %s
    ", sqlite3_errmsg(db));
         exit(0); }
    else { printf("Opened database successfully "); const char *sql = "select * from Student"; const char* data = "Callback function called"; char *errMsg; if(SQLITE_OK == sqlite3_exec(db, sql, callback, (void*)data, &errMsg)) { printf("Operation done successfully "); if (SQLITE_OK == sqlite3_exec(db, "delete from Student where id=-100", NULL, NULL, &errMsg)) { printf("The record deleted"); } else { printf("SQL error: %s ", errMsg); sqlite3_free(errMsg); } } else { printf("SQL error: %s ", errMsg); sqlite3_free(errMsg); } } sqlite3_close(db); return 0; } int callback(void *data, int argc, char **argv, char **colName) { int i; fprintf(stderr, "%s: ", (const char*)data); for(i=0; i<argc; i++) { printf("%s = %s ", colName[i], argv[i] ? argv[i] : "NULL"); } printf(" "); return 0; }

    关于SQLite以及SQLite - C/C++的更多参考可在此站点http://www.runoob.com/sqlite/sqlite-tutorial.html查阅

  • 相关阅读:
    MQ
    redis
    MongoDB
    进程相关命令
    catalina.sh
    tomcat-jvm
    中间件简介
    websphere
    mysql
    shell变量与字符串操作
  • 原文地址:https://www.cnblogs.com/buyishi/p/8597541.html
Copyright © 2020-2023  润新知