SQLite3的C编程

前端之家收集整理的这篇文章主要介绍了SQLite3的C编程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

/*=================================
.* The Standard include file.
.*
.*===============================*/
#include <stdio.h>
#include <stdlib.h>

/*=================================
.*
.* The extend include file.
.*
.*===============================*/
#include "sqlite3.h"
/* #include "sqlite3ext.h" */

int main()
{
/* Connect sqlite system. */
sqlite3 *pDatabase = NULL;
int result;
char sql[500];
char *err_msg = NULL;
int i;

result = sqlite3_open("test.db3",&pDatabase);
if( result != sqlITE_OK ) {
printf("Failure to open the database./n");
return -1;
} else
printf("Good to open the database./n");

sprintf(sql,"BEGIN");
sqlite3_exec(pDatabase,sql,err_msg);
sprintf(sql,"CREATE TABLE [TestDB] (/
[id] int,[name] varchar(20),[age] int)");
/*
if (sqlITE_OK != sqlite3_exec(pDatabase,&err_msg)) {
printf("operate Failed: %s./n",err_msg);
return -1;
}*/
for(i = 0; i < 10000; i++) {
sprintf(sql,"INSERT INTO [TestDB] ([id],[name],[age]) /
VALUES (%d,'%s',%d)",i,"JGood",i);
sqlite3_exec(pDatabase,&err_msg);
}

sprintf(sql,"END");
sqlite3_exec(pDatabase,err_msg);
sqlite3_close(pDatabase);

return 0;}

猜你在找的Sqlite相关文章