在海思开发板上面移植sqlite3

前端之家收集整理的这篇文章主要介绍了在海思开发板上面移植sqlite3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这个地址是下载 sqlite3的源码的地址:http://sqlite.org/download.html

到上面下载最新的源码,我开始的时候没有下载最新的源码,导致sqlite3的API用不了,非常的郁闷搞了两天终于知道,用sqlite最新的版本就解决了这个问题。

下载了源码在 虚拟机里面 新建一个目录 存放 安装的内容

1.mkdir /home/cys/900

2 tarxvzf sqlite-autoconf-3080900.tar.gz

3.cdsqlite-autoconf-3080900

4../configure --prefix=/home/cys/900 --disable-tcl —host=arm-hismall-linux

5.make

6.make install

7.编译程序的时候 要用到头文件和库文件 arm-hismall-linux-gcc -o test test.c -lsqlite3 -L/home/cys/900/lib -I/home/cys/900/include


连接文件无法拷贝到ARM里面,连接文件要重新生成

<span class="hljs-variable" style="color: rgb(63,110,116);">$ </span>ln -s libsqlite3.so.<span class="hljs-number" style="color: rgb(28,207);">0</span>.<span class="hljs-number" style="color: rgb(28,207);">8.6</span> libsqlite3.so.<span class="hljs-number" style="color: rgb(28,207);">0</span>
<span class="hljs-variable" style="color: rgb(63,207);">8.6</span> libsqlite3.so
/*  
 * File:   sqlite_test.cpp 
 * Author: Carl 
 * 
 * Created on September 20,2012,3:28 PM 
 */  
  
#include <stdlib.h>  
#include <stdio.h>  
#include <sqlite3.h>  
  
static int _sql_callback(void *notused,int argc,char **argv,char **szColName)  
{  
    int i = 0;  
      
    printf("notused:0x%x,argc:%d\n",notused,argc);  
    for (i = 0; i < argc; i++)  
    {  
        printf("%s = %s\n",szColName[i],argv[i] == 0 ? "NULL" : argv[i]);  
    }  
    printf("\n");  
      
    return 0;  
}  
  
/* 
 *  
 */  
int main(int argc,char** argv)  
{  
    printf("enter main \n");
    const char *ssql1 = "create table users(userid varchar(20) PRIMARY KEY,age int,birthday datetime);";  
    const char *ssql2 = "insert into users values('wang',20,'1989-5-4');";  
    const char *ssql3 = "select * from users;";  
//    const char *sql4 = "create table users(serial_num varchar(20),device_id varchar(20),route1_id varchar(20),route1_value int,route2_id varchar(20),route2_value int,route3_id varchar(20),route3_value int,route4_id varchar(20),route4_value int );";
	printf("enter deac \n");
	  
    sqlite3 *db = NULL;  
    char *pErrMsg = 0;  
    int ret = 0;  
      printf("before open \n");
    //连接数据库  
    //ret = sqlite3_open("fuck/fuckp.db",&db);  
	  ret = sqlite3_open_v2("fuck/fuckppp.db",&db,sqlITE_OPEN_READWRITE | sqlITE_OPEN_CREATE,NULL);  
	printf("before if \n");
	printf("ret = %d \n",ret);
   if (ret != sqlITE_OK)  
    {  
    printf("error  haha \n");
        fprintf(stderr,"无法打开数据库:%s\n",sqlite3_errmsg(db));  
		printf("error \n");
        sqlite3_close(db);  
        return 1;  
    }  
    printf("print   \n");
    printf("数据库连接成功\n");  
      
    //执行建表sql  
    ret = sqlite3_exec(db,ssql1,_sql_callback,&pErrMsg);  
    if (ret != sqlITE_OK)  
    {  
        fprintf(stderr,"sql create error: %s\n",pErrMsg);  
        sqlite3_free(pErrMsg); //这个要的哦,要不然会内存泄露的哦!!!  
        sqlite3_close(db);  
        return 1;  
    }  
    printf("数据库建表成功!!\n");  
      
    //执行插入数据  
    ret = sqlite3_exec(db,ssql2,"sql insert error: %s\n",pErrMsg);  
        sqlite3_free(pErrMsg); //这个要的哦,要不然会内存泄露的哦!!!  
        sqlite3_close(db);  
        return 1;  
    }  
    printf("数据库插入数据成功!\n");  
      
    //执行查询操作  
    ret = sqlite3_exec(db,ssql3,"sql error: %s\n",pErrMsg);  
        sqlite3_free(pErrMsg);  
        sqlite3_close(db);  
        return 1;  
    }  
    printf("数据库查询成功!!\n");  
      
    //关闭数据库  
    sqlite3_close(db);  
    db = 0;  
      
    return 0;  
}  

猜你在找的Sqlite相关文章