SQLITE3查看表的字段

ret = sqlite3_get_table(datb,"select * from demoF",&dbresult,&nrow,&ncolumn,&errmsg);

上面那句在页表中有内容时可以查看页表的字段,不过页表中如果没有记录,上面那句就不能查看页表中的字段.

不过下面这句可以查看(不管你的页表是否有内容)

sprintf(sql,"PRAGMA table_info(%s)",str11);


我下面演示的是将页表中的字段及其数据类型存放到数组中(部分代码)

	ret = sqlite3_get_table(datb,"select * from demoF",&dbresult,&nrow,&ncolumn,&errmsg);
	if(ret == SQLITE_OK)
	{
		cout << "查询到 " << nrow << " 行结果" << endl;
		//index = ncolumn;
		index = 0;
		for(int i = 0;i < nrow; i++)
		{
			printf("[%2i]",i);
			for(j = 0;j < ncolumn;j++)
			{
				printf(" %-8s",dbresult[index]);
				index++;
			}
			printf("\n");
		}
		sqlite3_free_table(dbresult);
	}
	sprintf(sql,"PRAGMA table_info(%s)",str11);
	char * lijixin[521] = {0};
	char * lijixin1[521] = {0};
	int rec = sqlite3_get_table(datb,sql,&dbresult,&nrow,&ncolumn,&errmsg);
	if(ret == SQLITE_OK)
	{
		cout << "查询到 " << nrow << " 行结果" << endl;
		index = ncolumn;
		int count1 = index + 1;
		int count2 = index + 2;
        for(int i = 0;i <= nrow; i++)
		{
             lijixin[i] = dbresult[count1];
             printf("%s",dbresult[count1]);
            // if( dbresult[count2] == "1")
			 cout << " " ;
			 lijixin1[i] = dbresult[count2];
                 printf("%s",dbresult[count2]);

             count1+= ncolumn;
             count2+= ncolumn;
			 cout << endl;
           strcat(lijixin[i], " ");
            strcat(lijixin[i], lijixin1[i]);
           cout << lijixin[i] << endl;
		}
       /*  cout << "nihao" << endl;
		for(int i = 0;i < 3;i++)
		{
			cout << lijixin[i] << endl;
		}*/

		sqlite3_free_table(dbresult);
	}

运行结果


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值