VS2010 C++配置sqlite3.33.0及破姐Navicat for SQLite15.0.19

参考:https://blog.csdn.net/segen_jaa/article/details/7938959

http://www.mamicode.com/info-detail-2155554.html

https://www.cnblogs.com/tommy-huang/p/8574137.html

navicat12:找了个Navicat for SQLite 15.0.19 中文破姐下载https://www.weidown.com/xiazai/7502.html,破姐教程参考https://blog.csdn.net/cungudafa/article/details/84674811

第一步:前往sqlite官网http://www.sqlite.org/download.html分别下载

其中第一个sqlite-amalgamation-3330000.zip包含sqlite3.c、sqlite3.h、sqlite3ext.h以及shell.c,用到前三个文件;

第二个sqlite-dll-win32-x86-3330000.zip包含sqlite3.def和sqlite3.dll,两个都要用到;

第三个sqlite-tools-win32-x86-3330000.zip包含sqlite3.exe,没用到;

第二步:生成sqlite3.lib

PS:(我的VS2010安装目录为C:\Softwares\VS2010\)

参考文章需要使用Visual Studio安装目录下的Visual Studio Tools——>Visual Studio 20XX Command Prompt,但我安装的VS2010没找到这个,参考https://www.cnblogs.com/tommy-huang/p/8574137.html表明Visual Studio 20XX Command Prompt文件只是执行了C:\Softwares\VS2010\VC\vcvarsall.bat批处理的指向cmd.exe命令行程序的快捷方式,那好办了,也不用费劲去下个VS2005的Visual Studio 2005 Command Prompt命令行程序。直接打开cmd命令行程序,执行一下C:\Softwares\VS2010\VC\vcvarsall.bat批处理,然后依次执行https://blog.csdn.net/segen_jaa/article/details/7938959中给出的命令,我将sqlite-dll-win32-x86-3330000.zip解压到了C:\sqlite-dll-win32-x86-3330000,下面第二条命令"C:"应该指的是解压文件sqlite3.def和sqlite3.dll所在的盘符?

#1、执行Visual Studio安装目录的VC\vcvarsall.bat批处理设置环境
C:\>cd C:\Softwares\VS2010\VC
C:\Softwares\VS2010\VC>vcvarsall.bat
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

#2、cd到sqlite-dll-win32-x86-3330000.zip的解压目录
C:\Softwares\VS2010\VC>cd C:\sqlite-dll-win32-x86-3330000

#3、指定盘符?
C:\sqlite-dll-win32-x86-3330000>C:

#4、生成sqlite3.lib
C:\sqlite-dll-win32-x86-3330000>lib /def:sqlite3.def /machine:ix86
Microsoft (R) Library Manager Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

   正在创建库 sqlite3.lib 和对象 sqlite3.exp

C:\sqlite-dll-win32-x86-3330000>

给出这个C:\Softwares\VS2010\VC\vcvarsall.bat,哪天再研究下:

@echo off
if "%1" == "" goto x86
if not "%2" == "" goto usage

if /i %1 == x86       goto x86
if /i %1 == amd64     goto amd64
if /i %1 == x64       goto amd64
if /i %1 == ia64      goto ia64
if /i %1 == x86_amd64 goto x86_amd64
if /i %1 == x86_ia64  goto x86_ia64
goto usage

:x86
if not exist "%~dp0bin\vcvars32.bat" goto missing
call "%~dp0bin\vcvars32.bat"
goto :eof

:amd64
if not exist "%~dp0bin\amd64\vcvars64.bat" goto missing
call "%~dp0bin\amd64\vcvars64.bat"
goto :eof

:ia64
if not exist "%~dp0bin\ia64\vcvars64.bat" goto missing
call "%~dp0bin\ia64\vcvars64.bat"
goto :eof

:x86_amd64
if not exist "%~dp0bin\x86_amd64\vcvarsx86_amd64.bat" goto missing
call "%~dp0bin\x86_amd64\vcvarsx86_amd64.bat"
goto :eof

:x86_ia64
if not exist "%~dp0bin\x86_ia64\vcvarsx86_ia64.bat" goto missing
call "%~dp0bin\x86_ia64\vcvarsx86_ia64.bat"
goto :eof

:usage
echo Error in script usage. The correct usage is:
echo     %0 [option]
echo where [option] is: x86 ^| ia64 ^| amd64 ^| x86_amd64 ^| x86_ia64
echo:
echo For example:
echo     %0 x86_ia64
goto :eof

:missing
echo The specified configuration type is missing.  The tools for the
echo configuration might not be installed.
goto :eof

第三步:使用sqlite3

创建Win32控制台应用程序测试一下:

1、将sqlite3.h添加到解决方案头文件,并将sqlite3.h的目录添加到项目的"配置属性/VC++目录/包含目录"或者"配置属性/C/C++/常规/附加包含目录";2、将生成的sqlite3.lib的目录添加到项目的"配置属性/VC++目录/库目录"或者"配置属性/链接器/常规/附加库目录";3、在"配置属性/链接器/输入/附加依赖项"中添加sqlite3.lib;4、当然,要把下载的sqlite3.dll放到exe启动文件同目录下,或者自定义加载DLL路径

第四步:测试

// SQLite3_train.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "sqlite3.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
	sqlite3* psql=nullptr;// 一个打开的数据库实例
	const char* path="./test.db";
	// 根据文件路径打开数据库连接。如果数据库不存在,则创建。
	// 数据库文件的路径必须以C字符串传入。
	int res=sqlite3_open_v2(path,&psql,SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_NOMUTEX|SQLITE_OPEN_SHAREDCACHE,nullptr);
	if(res==SQLITE_OK){
		std::cout<<"打开数据库连接成功\t\n";
	}else std::cout<<"打开数据库连接失败\t\n";
	const char* strCreate="create table if not exists t_person (id integer primary key autoincrement,name text not null,age integer not null);";
	sqlite3_stmt *pstmt=nullptr;//stmt语句句柄
	res=sqlite3_prepare_v2(psql,strCreate,-1,&pstmt,nullptr);
	if(res==SQLITE_OK){
		std::cout<<"建表成功\t\n";
		sqlite3_step(pstmt);
	}else std::cout<<"建表失败\t\n";
	sqlite3_finalize(pstmt);//清理语句句柄,准备执行下个语句

	const char* strinsert="insert into t_person(name,age) values('haypin',27);";
	res=sqlite3_prepare_v2(psql,strinsert,-1,&pstmt,nullptr);
	if(res==SQLITE_OK){
		std::cout<<"插入数据成功\t\n";
		sqlite3_step(pstmt);
	}else std::cout<<"插入数据失败\t\n";
	sqlite3_finalize(pstmt);//清理语句句柄,准备执行下个语句
	strinsert="insert into t_person(name,age) values('learner',27);";
	res=sqlite3_prepare_v2(psql,strinsert,-1,&pstmt,nullptr);
	if(res==SQLITE_OK){
		std::cout<<"插入数据成功\t\n";
		sqlite3_step(pstmt);
	}else std::cout<<"插入数据失败\t\n";
	sqlite3_finalize(pstmt);//清理语句句柄,准备执行下个语句

	const char* strselect="select name,age from t_person where age=27;";
	res=sqlite3_prepare_v2(psql,strselect,-1,&pstmt,nullptr);
	if(res==SQLITE_OK){
		std::cout<<"查询成功\t\n";
		while(sqlite3_step(pstmt)==SQLITE_ROW){//每调用一次sqlite3_step()查询语句,pstmt语句句柄就会指向下一条查询出的记录
			const unsigned char* name=sqlite3_column_text(pstmt,0);//取出"查询结果组成的记录"的第0列值
			int age=sqlite3_column_int(pstmt,1);//取出第一列值
			std::cout<<"name="<<name<<",age="<<age<<"\t\n";
		}
	}else std::cout<<"查询语句有问题\t\n";
	sqlite3_finalize(pstmt);//清理语句句柄,准备执行下个语句

	if(psql){
		sqlite3_close_v2(psql);
		psql=nullptr;
	}
	return 0;
}

在工程目录应该看到生成的test.db:

下载安装破姐完Navicat for SQLite后看看表内容:

第五步:安装破姐Navicat for SQLite

下载https://www.weidown.com/xiazai/7502.html,破姐教程参考https://blog.csdn.net/cungudafa/article/details/84674811,记得断网还有选Products为SQLite!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值