SQLite port Note 1

Source: Internet
Author: User

SQLite implements most sql92 standard SQL statements and supports acid. There are many other features that should be used in the embedded field.

Download:
Download Page: http://www.sqlite.org/download.html
I am still using the latest version: sqlite-3.3.7.tar.gz
(Version 3.3.8 has been updated at the time of writing. It's so fast ......)

Installation:
The installation process is briefly described as follows:
Decompress SQLite to uClinux-Dist/user/SQLite/

============== Modify uClinux ==========
1. Download SQLite and decompress it to uClinux-Dist/user /.
2. Edit the makefile under uClinux-Dist/user/and add:

Dir _ $ (config_user_sqlite_sqlite) + = SQLite

3. added the following to uClinux-Dist/config/configure. Help:

Config_user_sqlite_sqlite database.

4. uClinux-Dist/config. In is added at the end:

Mainmenu_option next_comment comment 'database' bool 'sqlite 'config_user_sqlite_sqlite endmenu

============== Modify SQLite ==========
1. In uClinux-Dist/user/SQLite/Main. mk:
Change tccx:

Tccx = $ (TCC) $ (OPTs) $ (threadsafe) $ (usleep)-I.-I $ (top)/src $ (cflags)

Change libobj to (some modules are not required, such as TCL ):

Libobj + = alter. O analyze. O attach. O Auth. O btree. o build. O callback. o complete. o date. O Delete. O expr. O func. O hash. O insert. O loadext. O main. O Opcodes. o OS. O OS _unix.o pager. O parse. O Pragma. O prepare. O printf. O random. O select. O table. O tokenize. O trigger. o Update. O util. O vacuum. O vdbe. O vdbeapi. O vdbeaux. O vdbefifo. O vdbemem. O where. o utf. O legacy. O vtab. O

Modify the sqlite3 $ (exe) Rule section:

Shell. o: $ (top)/src/shell. c sqlite3.h $ (tccx) $ (readline_flags)-C $ (top)/src/shell. c sqlite3 $ (exe): shell. O libsqlite3.a $ (TCC) $ (ldflags)-o $ @ shell. O libsqlite3.a $ (libreadline) $ (threadlib) $ (ldlibs)

Remove install and add:

Distclean: Clean Rm-F config. h

2. Copy makefile. Linux-GCC as makefile and modify it as follows:

TCC = $ (Cross) gcc ar = $ (Cross) Ar Cr ranlib = $ (Cross) ranlib # tcl_flags =-I/home/DRH/tcltk/8.4 Linux # libtcl =/home/DRH/tcltk/8.4 Linux/libtcl8.4g. a-lm-LDL

Compile:
In the "user application" section of make menuconfig, you can see the newly added database-> menu, enter and select SQLite, save and exit, and recompile the kernel following the previous steps. If you only need the SQLite library, make user_only.
After compilation, libsqlite3.a is generated in the user/SQLite directory.

Test:
Compile a test program sqlitetest. C. The Code is as follows (from the official Quick Start ):

# Include static int callback (void * notused, int argc, char ** argv, char ** azcolname) {int I; for (I = 0; I then write a makefile for it, roughly as follows: uclinux_path =/home/uClinux-Dist sqlite_path = $ (uclinux_path) /user/SQLite cross = arm-elf-cpu_cflags =-O3-wall-mapcs-32-mtune = ARM7TDMI-fno-builtin-msoft-float-OS-D _ uClinux __- d__arm_cpu _-I $ (uclinux_path) /lib/uclibc/include-I $ (uclinux_path)/linux-2.4.x/include-I $ (sqlite_path)-d_debug _ cpu_ldflags =-nostartfiles-wl,-elf2flt-L $ (uclinux_path) /lib/uclibc/lib cpu_arflags = r cpu_ldlibs = $ (uclinux_path)/lib/uclibc/lib/crt0.o $ (uclinux_path)/lib/uclibc/lib/crti. o $ (uclinux_path)/lib/uclibc/lib/crtn. o-LC my_ldflags =-L $ (sqlite_path) Labels =-lsqlite3 cflags = $ (cpu_cflags) ldflags = $ (cpu_ldflags) $ (my_ldflags) ldlibs = $ (cpu_ldlibs) $ (my_ldlibs) topdir =. /CC = $ (Cross) GCC exec = sqlitetest  = sqlitetest. c objs =$ (patsubst %. c, %. o, $ () All: $ (EXEC) $ (objs): %. o: %. C $ (CC) $ (cflags)-C $ run make to compile the test program. The generated program size is about KB: Linux: /home/work/SQLite # ll total usage 688 drwxr-XR-x 2 root Root 264. drwxr-XR-x 4 Root 160 .. -RW ------- 1 Root 982 makefile-rwxr -- r -- 1 Root 315584 sqlitetest-RW ------- 1 Root 788 sqlitetest. c-rwxr-XR-x 1 Root 396538 sqlitetest. GDB-RW-r -- 1 Root 1600 sqlitetest. O

Download the test program to the target board. The test result is as follows:

#/Home/sqlitetest/home/testdb. DB "create table my_table (ID int, name varchar (20)" #/home/sqlitetest/home/testdb. DB "insert into my_table values (1, 'jianglj')" #/home/sqlitetest/home/testdb. DB "insert into my_table values (2, 'hily Jiang ')" #/home/sqlitetest/home/testdb. DB "select * From my_table" id = 1 name = jianglj id = 2 name = hily Jiang

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.