0

我正在开发一个使用 Sqlite 存储/检索数据的嵌入式项目。

SQLITE_INT64_TYPE 定义为 long long int(默认定义)。

读取数据库模式时,错误地解释了根页码。

读取模式时,表的根页码会按字序互换。例如,根页号“ 2 ”被读取为“ 8589934592 ”(0x0200000000)。

因此,提供给数据库的任何其他 SQL 语句都不会返回任何结果。

目标描述:

  • 平台:Armv7
  • 编译器:GCC
  • 拱型:小端

关于如何解决这个问题的任何建议?

谢谢

PS:现在确定根本原因后修改了原帖。

#include "sqlite3.h"


int sqlite3_port_exec_callback(void *data, int argc, char **argv, char **azColName){
   int i;
   printf("%s: ", (const char*)data);
   for(i=0; i<argc; i++){
      printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
   }
   printf("\n");
   return 0;
}


int main(int argc, char **argv)
{
    int rc, i, ncols;
    sqlite3 *db;
    sqlite3_stmt *stmt;
    char *sql;
    const char *tail;
    char *look_aside_buf;


    rc = sqlite3_open("USB1:\\foods.db", &db);
    if(rc) {
        printf( "Can't open database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        exit(1);
    }



    const char* data = "Callback function called";
    char *zErrMsg = 0;
    sql = "SELECT * from sqlite_master";


    /* Execute SQL statement */
    rc = sqlite3_exec(db, sql, &sqlite3_port_exec_callback, (void*)data, &zErrMsg);
    if( rc != SQLITE_OK ){
        printf( "SQL error: %s\n", zErrMsg);
        sqlite3_free(zErrMsg);
    }else{
        printf( "Operation done successfully\n");
    }


    zErrMsg = 0;
    /* Create SQL statement */
    sql = "SELECT * from episodes";


    /* Execute SQL statement */
    rc = sqlite3_exec(db, sql, &sqlite3_port_exec_callback, (void*)data, &zErrMsg);
    if( rc != SQLITE_OK ){
        printf( "SQL error: %s\n", zErrMsg);
        sqlite3_free(zErrMsg);
    }else{
        printf( "Operation done successfully\n");
    }




    zErrMsg = 0;
    /* Create SQL statement */
    sql = "SELECT count(*) from episodes";
    /* Execute SQL statement */
    rc = sqlite3_exec(db, sql, &sqlite3_port_exec_callback, (void*)data, &zErrMsg);
    if( rc != SQLITE_OK ){
        printf( "SQL error: %s\n", zErrMsg);
        sqlite3_free(zErrMsg);
    }else{
        printf( "Operation done successfully\n");
    }


    sqlite3_close(db);

    return 0;
}

输出如下:

Callback function called: type = table
name = episodes
tbl_name = episodes
rootpage = 8589934592
sql = CREATE TABLE episodes (
  id integer primary key,
  season int,
  name text )

Callback function called: type = table
name = foods
tbl_name = foods
rootpage = 30064771072
sql = CREATE TABLE foods(
  id integer primary key,
  type_id integer,
  name text )

Callback function called: type = table
name = foods_episodes
tbl_name = foods_episodes
rootpage = 77309411328
sql = CREATE TABLE foods_episodes(
  food_id integer,
  episode_id integer )

Callback function called: type = table
name = food_types
tbl_name = food_types
rootpage = 107374182400
sql = CREATE TABLE food_types(
  id integer primary key,
  name text )

Operation done successfully
Operation done successfully
Callback function called: count(*) = 0

Operation done successfully
4

1 回答 1

1

我找到了根本原因,并想结束这个线程。

好吧,这真的很尴尬!项目中有 2 个“Sqlite.h”头文件副本,每个副本都有不同的 SQLITE_INT64_TYPE 配置。因此输出的差异。

非常感谢所有为此花时间的人。

于 2014-11-27T10:58:51.750 回答