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\n", sqlite3_errmsg(db));
     exit(0); }
else { printf("Opened database successfully\n"); 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\n"); if (SQLITE_OK == sqlite3_exec(db, "delete from Student where id=-100", NULL, NULL, &errMsg)) { printf("The record deleted"); } else { printf("SQL error: %s\n", errMsg); sqlite3_free(errMsg); } } else { printf("SQL error: %s\n", errMsg); sqlite3_free(errMsg); } } sqlite3_close(db); return 0; } int callback(void *data, int argc, char **argv, char **colName) { int i; fprintf(stderr, "%s:\n", (const char*)data); for(i=0; i<argc; i++) { printf("%s = %s\n", colName[i], argv[i] ? argv[i] : "NULL"); } printf("\n"); return 0; }

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

    原文作者:sqlite
    原文地址: https://www.cnblogs.com/buyishi/p/8597541.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞