sqlite笔记:
从官网下载sqlite3.c、sqlite3.h、sqliteext.h、shell.c、等文件。然后使用vsCode编写main.c。
sqlite_test.h
#ifdef __cplusplus
extern "C" {
#endif
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifdef __cplusplus // close out "C" linkage in case of c++ compiling
}
#endif
main.c
#include "sqlite_test.h" #include ".sqlitesqlite3.h" #include#define TEST_DB_PATH "./test_db" static sqlite3 *db; int sql_init(const char* cDbPath) { int ret; if (NULL == cDbPath) { printf("sqlite_init error"); return -1; } if (SQLITE_CONFIG_SERIALIZED != sqlite3_threadsafe()) { ret = sqlite3_config(SQLITE_CONFIG_SERIALIZED); if (ret != SQLITE_OK) { printf("SQLite3 is not compiled with serialized threading mode!n"); return -1; } } ret = sqlite3_initialize(); if (ret != SQLITE_OK) { printf("database_init sqlite_initalize error"); return -1;; } ret = sqlite3_open(cDbPath,&db); if (ret) { printf("Can't open sql: %s", sqlite3_errmsg(db)); return -1; } return 0; } int main(int argc, char *argv[]) { (void)argc; (void)argv; //sqlite3_shutdown(); //SQLITE_CONFIG_SINGLETHREAD //SQLITE_CONFIG_MULTITHREAD //SQLITE_CONFIG_SERIALIZED sql_init(TEST_DB_PATH); printf("all finish"); getchar(); }``` 使用下面命令运行
gcc -o main main.c ./sqlite/sqlite3.c -lpthread
``



