sqlite 基本回调用法

sqlite 基本回调用法,第1张

概述#include <sqlite3.h>#include <stdio.h>#include <stdlib.h> //n_column 是列数, 在select语句中采用了*, 而该表有两列, 所以此值为2 , column_value 和 column_name 应该看成是一维指针, 它指向的是一个 //char *的字符串int LoadMyInfo (void *para ,
#include <sqlite3.h>#include <stdio.h>#include <stdlib.h>	//n_column 是列数,在select语句中采用了*,而该表有两列,所以此值为2,column_value 和 column_name 应该看成是一维指针,它指向的是一个	//char *的字符串int LoadMyInfo (voID *para,int n_column,char ** column_value,char ** column_name){	int i;	printf("record %d fIEld \n",n_column);		for( i = 0; i < n_column; i++){		printf("fIEld name : %s  fIEld value: %s \n",column_name[i],column_value[i]);	}	printf("-------------------------\n");	return 0;}int main(){	sqlite3 *db;	int result;	char *errmsg = NulL ;	result = sqlite3_open("C://sely.db",&db);	if( result != sqlITE_OK){		return -1;	}		result = sqlite3_exec(db,"create table Mytable_1(ID integer primary key autoincrement,name varchar(32))",NulL,&errmsg);    if(result != sqlITE_OK){		printf("create table error: %d,reason : %s",result,errmsg);	}	result = sqlite3_exec(db,"insert into Mytable_1 (name)  values(\"walk\")",&errmsg);	if(result != sqlITE_OK){		printf("create table error: %d,errmsg);	}    result = sqlite3_exec(db,"insert into Mytable_1 (name) values(\"bus\")","insert into Mytable_1 (name)  values(\"bike\")","insert into Mytable_1 (name) values(\"car\")",errmsg);        }		//loadMyInfo 是回调函数,每次有一个记录被查询出,都会调用一次,结果集中有多少记录,就会执行多少次!    	result = sqlite3_exec(db,"select *from Mytable_1",LoadMyInfo,errmsg);	}	sqlite3_close(db);	system("pause");	return 0;}/* 执行结果如下:record 2 fIEldfIEld name : ID fIEld value: 1fIEld name : name fIEld value: walk-------------------------record 2 fIEldfIEld name : ID fIEld value: 2fIEld name : name fIEld value: bus-------------------------record 2 fIEldfIEld name : ID fIEld value: 3fIEld name : name fIEld value: bike-------------------------record 2 fIEldfIEld name : ID fIEld value: 4fIEld name : name fIEld value: car-------------------------Press any key to continue . . .*/
总结

以上是内存溢出为你收集整理的sqlite 基本回调用法全部内容,希望文章能够帮你解决sqlite 基本回调用法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1173531.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存