CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx

上传人:b****6 文档编号:19891335 上传时间:2023-01-11 格式:DOCX 页数:22 大小:28.60KB
下载 相关 举报
CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx_第1页
第1页 / 共22页
CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx_第2页
第2页 / 共22页
CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx_第3页
第3页 / 共22页
CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx_第4页
第4页 / 共22页
CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx

《CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx》由会员分享,可在线阅读,更多相关《CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx(22页珍藏版)》请在冰豆网上搜索。

CppSQLiteC++ Wrapper for SQLiteWord文档下载推荐.docx

canbefoundontheSQLitewebsite.

Linkingdynamicallystillrequiresthata 

.lib 

fileisbuiltforlinkingwithyourapplication.ThiscanbedoneusingMicrosoft'

LIB 

command.Onmysystem,thisislocatedat 

D:

\ProgramFiles\MicrosoftVisualStudio\VC98\Bin\lib.exe.

Unzip 

sqlite.zip 

whichcontains 

sqlite.dll 

and 

sqlite.def,andexecutethefollowingcommandtoproducethelibfile.

 

Collapse 

CopyCode

c:

\>

lib/def:

sqlite.def

sqlite.h 

needstobevisibletoyourapplicationatcompiletime,asdoes 

sqlite.lib.

needstobeavailabletoyourapplicationatruntime.

CppSQLiteDemoCode

ThefollowingcodedemonstrateshowtousethemainfeaturesofSQLitevia 

CppSQLite,withcommentsinline.

#include"

CppSQLite.h"

#include<

ctime>

iostream>

usingnamespacestd;

constchar*gszFile="

C:

\\test.db"

;

intmain(intargc,char**argv)

{

try

{

inti,fld;

time_ttmStart,tmEnd;

CppSQLiteDBdb;

cout<

<

"

SQLiteVersion:

<

db.SQLiteVersion()<

endl;

remove(gszFile);

db.open(gszFile);

endl<

Creatingemptable"

db.execDML("

createtableemp(empnoint,empnamechar(20));

"

);

///////////////////////////////////////////////////////////////

//ExecutesomeDML,andprintnumberofrowsaffectedbyeachone

DMLtests"

intnRows=db.execDML("

insertintoempvalues(7,'

DavidBeckham'

nRows<

rowsinserted"

nRows=db.execDML(

updateempsetempname='

ChristianoRonaldo'

whereempno=7;

rowsupdated"

nRows=db.execDML("

deletefromempwhereempno=7;

rowsdeleted"

/////////////////////////////////////////////////////////////////

//TransactionDemo

//Thetransactioncouldjustaseasilyhavebeenrolledback

intnRowsToCreate(50000);

Transactiontest,creating"

nRowsToCreate;

rowspleasewait..."

tmStart=time(0);

begintransaction;

for(i=0;

i<

i++)

charbuf[128];

sprintf(buf,"

insertintoempvalues(%d,'

Empname%06d'

i,i);

db.execDML(buf);

}

committransaction;

tmEnd=time(0);

////////////////////////////////////////////////////////////////

//DemonstrateCppSQLiteDB:

:

execScalar()

db.execScalar("

selectcount(*)fromemp;

rowsinemptablein"

tmEnd-tmStart<

seconds(thatwasfast!

)"

//Re-createemptablewithauto-incrementfield

Autoincrementtest"

droptableemp;

db.execDML(

createtableemp(empnointegerprimarykey,empnamechar(20));

5;

sprintf(buf,

insertintoemp(empname)values('

i+1);

primarykey:

db.lastRowId()<

///////////////////////////////////////////////////////////////////

//Querydataandalsoshowresultsofinsertsintoauto-incrementfield

//////////////////////////////////////////////////////////////////

Selectstatementtest"

CppSQLiteQueryq=db.execQuery("

select*fromemporderby1;

for(fld=0;

fld<

q.numFields();

fld++)

q.fieldName(fld)<

("

q.fieldType(fld)<

)|"

while(!

q.eof())

q.fieldValue(0)<

|"

q.fieldValue

(1)<

q.nextRow();

//SQLite'

sprintf()functionality.HandlesembeddedquotesandNULLs

SQLitesprintftest"

CppSQLiteBufferbufSQL;

bufSQL.format("

insertintoemp(empname)values(%Q);

"

He'

sbad"

(constchar*)bufSQL<

db.execDML(bufSQL);

NULL);

////////////////////////////////////////////////////////////////////

//Fetchtableatonce,andalsoshowhowto

//useCppSQLiteTable:

setRow()method

getTable()test"

CppSQLiteTablet=db.getTable("

t.numFields();

t.fieldName(fld)<

for(introw=0;

row<

t.numRows();

row++)

t.setRow(row);

for(intfld=0;

if(!

t.fieldIsNull(fld))

t.fieldValue(fld)<

else

NULL"

//TestCppSQLiteBinarybystoring/retrievingsomebinarydata,checking

//itafterwardstomakesureitisthesame

Binarydatatest"

createtablebindata(descchar(10),datablob);

unsignedcharbin[256];

CppSQLiteBinaryblob;

sizeofbin;

bin[i]=i;

blob.setBinary(bin,sizeofbin);

insertintobindatavalues('

testing'

%Q);

blob.getEncoded());

StoredbinaryLength:

sizeofbin<

q=db.execQuery("

selectdatafrombindatawheredesc='

blob.setEncoded((unsignedchar*)q.fieldValue("

data"

));

RetrievedbinaryLength:

blob.getBinaryLength()<

constunsignedchar*pbin=blob.getBinary();

if(pbin[i]!

=i)

Problem:

i:

"

bin[i]:

pbin[i]<

/////////////////////////////////////////////////////////

//Pre-compiledStatementsDemo

/////////////////////////////////////////////////////////////

CppSQLiteStatementstmt=pileStatement(

insertintoempvalues(?

?

charbuf[16];

EmpName%06d"

i);

stmt.bind(1,i);

stmt.bind(2,buf);

stmt.execDML();

stmt.reset();

seconds(thatwasevenfaster!

Endoftests"

catch(CppSQLiteException&

e)

cerr<

e.errorCode()<

e.errorMessage()<

//LoopuntiluserentersqorQ

///////////////////////////////////////////////////////////

charc('

'

while(c!

='

q'

&

&

c!

Q'

Pressqthenenter

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1