sqlite3_get_table

  • sqlite3_get_table函数原型:
  • int sqlite3_get_table(
    sqlite3 *db, /* An open database */
    const char *zSql, /* SQL to be evaluated */
    char ***pazResult, /* Results of the query */
    int *pnRow, /* Number of result rows written here */
    int *pnColumn, /* Number of result columns written here */
    char **pzErrmsg /* Error msg written here */
    );
    void sqlite3_free_table(char **result);
  • sqlite3_get_table主要是用于非回调的方式进行select查询,参数如下;
  • 参数1:打开数据库得到的指针;
  • 参数2:一条sql语句,跟sqlite3_exec中一样;
  • 参数3:查询的数据结果,他是一个指针数组,内存分布为:字段名称,后面是紧接着是每个字段的值;
  • 参数4:查询到的数据条数,(行数);
  • 参数5:查询到的字段数,(列数);
  • 参数6:错误信息;
  • char *str_he = "合";
    char *str_fen = "分"; //初始化表
    for(rc = ; rc < ; rc++) {
    sql = sqlite3_mprintf("INSERT INTO RELAY VALUES ('%d', '%q', '%q', '2019-7-12');", rc, str_he, str_fen);
    sqlite3_exec(db, sql, , , &zErrMsg);
    } rc = sqlite3_get_table(db, "SELECT * FROM RELAY", &dbresult, &nRow, &nColum, &zErrMsg);
    if(rc == SQLITE_OK) {
    index = nColum;
    for(i = ; i < nRow; i++) {
    for(j = ; j < nColum; j++) {
    printf("%d--%s : %s\n", i, dbresult[j], dbresult[index++]);
    // ++index;
    }
    printf("----------------------------------------------\n");
    }
    }
    sqlite3_free_table(dbresult);
  • 输出结果:
    --ID :
    --C_STATUS : 合
    --W_STATUS : 分
    --TIME : --
    ----------------------------------------------
    --ID :
    --C_STATUS : 合
    --W_STATUS : 分
    --TIME : --
    ----------------------------------------------
    --ID :
    --C_STATUS : 合
    --W_STATUS : 分
    --TIME : --
    ----------------------------------------------
    。。。。。。
    。。。。。。
    ----------------------------------------------
    --ID :
    --C_STATUS : 合
    --W_STATUS : 分
    --TIME : --
    ----------------------------------------------
    --ID :
    --C_STATUS : 合
    --W_STATUS : 分
    --TIME : --
    ----------------------------------------------
  • 从输出结果可以看出内存分布如下:

sqlite3_free_table

  • 用于释放保存查询内容的指针数组;

sqlite3入门之sqlite3_get_table,sqlite3_free_table的更多相关文章

  1. python sqlite3 入门 (视频讲座)

    python sqlite3 入门 (视频讲座) an SQLite mini-series! - Simple Databases with Python 播放列表: YouTube https:/ ...

  2. sqlite3 入门

    SQLite3 C语言API入门下载SQLite3 我们下载sqlite源码包,只需要其中的sqlite3.c.sqlite.h即可.最简单的一个创建表操作#include <stdio.h&g ...

  3. Sqlite3入门简记

    一,安装Sqlite3 1.入门时看http://www.runoob.com/sqlite/sqlite-intro.html,说的简单,但是适合入门 2.在终端输入sqlite3,没有返回信息,表 ...

  4. sqlite3入门之sqlite3_mprintf

    sqlite3_mprintf sqlite3_mprintf()函数原型: char *sqlite3_mprintf(const char*,...); sqlite3_mprintf()的作用是 ...

  5. sqlite3入门之sqlite3_open,sqlite3_exec,slite3_close

    sqlite3_open sqlite3_open函数原型: int sqlite3_open( const char *filename, /* Database filename (UTF-8) ...

  6. sqlite3数据库 sqlite3_get_table

    上一篇介绍的sqlite3_exec 是使用回调来执行对select结果的操作.还有一个方法可以直接查询而不需要回调.但是,我个人感觉还是回调好,因为代码可以更加整齐,只不过用回调很麻烦,你得声明一个 ...

  7. sqlite3使用入门

    sqlite的安装 1. 首先是下载sqlite,可以该页面下载:http://www.sqlite.org/download.html 当前的最新版本为:sqlite-shell-win32-x86 ...

  8. SQLite3简单入门及C++ API

    转载请注明出处:http://www.cnblogs.com/StartoverX/p/4660487.html 项目用到SQLite3,简单记录一下. MySQL不同,SQLite3的数据库基于文件 ...

  9. SQLITE3 使用总结

    转自: http://blog.chinaunix.net/uid-8447633-id-3321394.html 前序: Sqlite3 的确很好用.小巧.速度快.但是因为非微软的产品,帮助文档总觉 ...

随机推荐

  1. 【LeetCode算法-28/35】Implement strStr()/Search Insert Position

    LeetCode第28题 Return the index of the first occurrence of needle in haystack, or -1 if needle is not ...

  2. css重直居中代码

    老是忘,记在这里: vertical-align: middle;

  3. [图片问答]lodop注册相关

    相关博文:LODOP和C-LODOP注册与角色等简短问答[增强版]由于其他博文要么图片太花哨(PS做的所以太花哨),要么文字太啰嗦,所以做了简短问答的图片,更简洁直观方便.1.该购买哪种LODOP注册 ...

  4. [LeetCode] 787. Cheapest Flights Within K Stops K次转机内的最便宜航班

    There are n cities connected by m flights. Each fight starts from city u and arrives at v with a pri ...

  5. python:连接Oracle数据库后控制台打印中文为??

    打印查询结果,中文显示为了??? [('72H FCR', '2.0'), ('?????', '8.0')] E:\Python35\Lib\site-packages中新增文件: sitecust ...

  6. Spring boot后台搭建二集成Shiro实现用户验证

    上一篇文章中介绍了Shiro 查看 将Shiro集成到spring boot的步骤: (1)定义一个ShiroConfig,配置SecurityManager Bean,SecurityManager ...

  7. SpringMVC笔记1

    SpringMVC是一个一种基于Java的实现MVC设计模型的请求驱动类型的轻量级web框架 SpringMVC的入门案例 2.导入相关jar包 <?xml version="1.0& ...

  8. 嵌入式02 STM32 实验04跑马灯

    开学STM32 跑马灯的实验主要就是了解GPIO口的配置及使用,我这里是使用库函数进行编程,主要需要设置以下两方面: 1.使能需要使用的IO口的时钟,一共有A.B.C.D.E.F.G七组IO口 2.初 ...

  9. SpringBoot(1)

    SpringBoot 8/2 CRUD 发送put请求修改数据有三个步骤: SpringMVC中配置HiddenHttpMethodFilter 页面上创建一个post请求(form标签只能写get和 ...

  10. python函数知识六 内置函数二、匿名函数与内置函数三(重要)

    19.内置函数二 abs():绝对值 lst = [1,2,-3,1,2,-5] print([abs(i) for i in lst]) enumerate("可迭代对象",&q ...