这个地址是下载 sqlite3的源码的地址:http://sqlite.org/download.html
到上面下载最新的源码,我开始的时候没有下载最新的源码,导致sqlite3的API用不了,非常的郁闷搞了两天终于知道,用sqlite最新的版本就解决了这个问题。
下载了源码在 虚拟机里面 新建一个目录 存放 安装的内容。
1.mkdir /home/cys/900
2 tar xvzf sqlite-autoconf-3080900.tar.gz
3.cd sqlite-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, 0, 207);">0</span>.<span class="hljs-number" style="color: rgb(28, 0, 207);">8.6</span> libsqlite3.so.<span class="hljs-number" style="color: rgb(28, 0, 207);">0</span>
<span class="hljs-variable" style="color: rgb(63, 110, 116);">$ </span>ln -s libsqlite3.so.<span class="hljs-number" style="color: rgb(28, 0, 207);">0</span>.<span class="hljs-number" style="color: rgb(28, 0, 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, 0, &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_callback, 0, &pErrMsg); if (ret != SQLITE_OK) { fprintf(stderr, "SQL insert error: %s\n", pErrMsg); sqlite3_free(pErrMsg); //这个要的哦,要不然会内存泄露的哦!!! sqlite3_close(db); return 1; } printf("数据库插入数据成功!\n"); //执行查询操作 ret = sqlite3_exec(db, sSQL3, _sql_callback, 0, &pErrMsg); if (ret != SQLITE_OK) { fprintf(stderr, "SQL error: %s\n", pErrMsg); sqlite3_free(pErrMsg); sqlite3_close(db); return 1; } printf("数据库查询成功!!\n"); //关闭数据库 sqlite3_close(db); db = 0; return 0; }