栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

sqlite与C语言与Windows

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

sqlite与C语言与Windows

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
``

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/994727.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号