Porting SQLite to ARM platform and Testing

Source: Internet
Author: User
Tags sql error
File: Sqliteexample and example. rar
Size: 5kb
Download: Download

1. ========================================================== ====

Cross-compiling SQLite first backs up the configure file
CP configure. old1 ). modify the configure file, mainly because of errors (you can see config. log File to find the corresponding lines to delete ). /configure -- Host = arm-Linux -- disable-TCL -- prefix =/usr/local/ARM/3.3.2/arm-linux2 ).
Modify makefile
# BCC = arm-Linux-gcc-g-O2
BCC = gcc-g-O2
Because the generated lemon executable file needs to be executed on the host 2. ========================================================== ====
Create Database chmod 775 sqlite3
And then run sqlite3 like this
Sqlite3 ex2
, If you see the following messages:
SQLite version 3.3.6
Enter ". Help" for instructions
SQLite> input some commands to do something,
SQLite> Create Table TBL (one varchar (10), two smallint );
SQLite> insert into TBL values ('hello', 10 );
SQLite> insert into TBL values ('Goodbye ', 20 );
SQLite>. quitmore commands, please visit www.sqlite.org for details
Then use 'ls ex2' to list files in currect directory,
If you see 'ex2' file,
Congratulations, you have successfully making a standalone 'sqlite3 '. next step we shoshould compile the example code on www.sqlite.org's Quickstart page3. ==================== ============================ use the test make a' test. c 'file in 'built' directory, content as showed:
# Include <stdio. h>
# Include "sqlite3.h"/* orignal is <sqlite3.h> */static int callback (void * notused, int argc, char ** argv, char ** azcolname ){
Int I;
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 ){
Sqlite3 * dB;
Char * zerrmsg = 0;
Int RC; If (argc! = 3 ){
Fprintf (stderr, "Usage: % s Database SQL-STATEMENT \ n", argv [0]);
Exit (1 );
}
Rc = sqlite3_open (argv [1], & dB );
If (RC ){
Fprintf (stderr, "can't open database: % s \ n", sqlite3_errmsg (db ));
Sqlite3_close (db );
Exit (1 );
}
Rc = sqlite3_exec (dB, argv [2], callback, 0, & zerrmsg );
If (RC! = Sqlite_ OK ){
Fprintf (stderr, "SQL error: % s \ n", zerrmsg );
Sqlite3_free (zerrmsg );
}
Sqlite3_close (db );
Return 0;
} Arm-Linux-GCC test. c-l. libs-lsqlite3-static // arm-Linux-GCC test. c-l. libs-lsqlite3 dynamic explaination:-L. libs show that the Lib searching path is '. libs'
'-Lsqlite3-static' show that the Lib name is libsqlite3.a, the 'lib' and '. A' is added by linker.
With the above command, we can compile a standalone application with SQL Databse supported.
Use arm-Linux-strip to decrease its size:
Arm-Linux-strip A. outupload to arm9-board, make it runable and test it:
[Root @ Fa] # A. Out ex2 "select * From TBL"
One = Hello
Two = 10one = goodbye
Two = 20
[Root @ fa] #
If you see the above result, OK you make it.
Over.
Wish the article is usefull for you! 4. ========================================================== ===== SQL syntax sqlite3 * DB = NULL;
Char * zerrmsg = 0; open:
Sqlite3_open () Open the database
Sqlite3_close () closes the database connection
Sqlite3_exec (dB, SQL, 0, 0, & zerrmsg); Create and insert: Create insert
Char * SQL = "CREATE TABLE sensordata (ID integer primary key, sensorid integer, sitenum integer, time varchar (12), sensorparameter real );";
Char * sql1 = "insert into \" sensordata \ "values (null, 1, 1, '20170101', 200605011206 );";
Char * sql2 = "insert into \" sensordata \ "values (null, 1, 1, '20170101', 200605011306 );";
You can call this function (sqlite3_exec (dB, SQL, 0, 0, & zerrmsg);) to execute the SQL statement sqlite3_exec (dB, SQL, 0, 0, & zerrmsg); query: select
Char ** azresult;
SQL = "select * From sensordata
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.