由于'long long int'(64位)数据类型,Sqlite数据库在目标上失败

时间:2013-07-26 11:34:05

标签: c sqlite embedded

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

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

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

当读取模式时,表的根页数是字顺序互换的。例如,根页码“ 2 ”读为“ 8589934592 ”(0x0200000000)。

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

目标说明:

  • 平台:Armv7
  • 编译:GCC
  • Arch type:little-endian

有关如何解决此问题的任何建议吗?

由于

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

1 个答案:

答案 0 :(得分:1)

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

这真是令人尴尬!有2份Sqlite.h&#39;项目中的头文件,每个头文件都有不同的SQLITE_INT64_TYPE配置。因此产出的差异。

非常感谢所有花时间在这上面的人。