Installation and Use of sqlite3 in Linux

Source: Internet
Author: User

From: http://blog.163.com/18_2/blog/static/2174448200851045114653/

Installation and Use of sqlite3 in Linux: Ubuntu online installation of sqlite3 database method: System Platform: ubuntu12.04
Run the following command in Ubuntu: sudo apt-Get install sqlite3 :........................ Libsqlite3-0 (= 3.7.9-2ubuntu1) But 3.7.9-2ubuntu1. 1 is to be installed ......
........................ My solution is to execute the following three commands in sequence: 1. sudo dpkg -- force-depends -- purge libsqlite3-0: i386
2. sudo apt-get-F install
3. sudo apt-Get install sqlite3

Read more: how to install SQLite 3 in Ubuntu | eHow http://www.ehow.com/how_8463512_install-sqlite-3-ubuntu.html#ixzz2U4yhrano

Http://askubuntu.com/questions/230619/cannot-install-sqlite3

16:51:14 | category: SQLite | font size subscription
1. installation and configuration of local sqlite3

Download the sqlite3 source code package

Tar xvfz sqlite-src-3.3.5

CD sqlite-3.3.5

./Configure-no-tcl

Make

(If you need to modify the makefile on the arm board, add-L/usr/local/ARM/3.3.2/lib to the libs item and save the file and exit. Then make)

After the installation is successful, the generated file will be copied to the specified directory.

Add another environment variable.

VI/etc/profile

Add sqlite3_path =/usr/local/sqlite-3.3.5 in the export region save and exit

Source/etc/profile

Useful files: $ sqlite3_path/include/sqlite3.h header files

$ Sqlite3_path/bin/sqlite3 Executable File

$ Sqlite3_path/lib/libsqlite3.a

Libsqlite3.la

Libsqlite3.so-> libsqlite3.so. 0.8.6

Libsqlite3.so. 0-> libsqlite3.so. 0.8.6

Libsqlite3.so. 0.8.6

When the program is used in the database

# Include <sqlite3.h>

Add the following in the. Pro file:

Includepath + = $ (sqlite3_path)/include

Dependpath + = $ (sqlite3_path)/include

Libs + =-L $ (sqlite3_path)/lib

Libs + =-lsqlite3

Save and exit

Tmake hello. Pro-O makefile

Make

Ii. programming:

Sqlite3 * dB;

Int rc = sqlite3_open ("Data. DB", & dB); // open the database data. DB

If (RC! = Sqlite_ OK); // opening failed

Create a table rc = sqlite3_exec (dB, "create table student (ID integer

Primarykey, name nvarchar (32) ", null, null, & mrrmsg );

Insert rc = sqlite3_exec (dB, "insert into student values ('3', 'zhangsan')", & mrrmsg );

Modify rc = sqlite3_exec (dB, "update student set name = 'Li si' where id = '4'", & mrrmsg );

Delete rc = sqlite3_exec (dB, "delete * from student where name = 'wang wu'", 0, & mrrmsg );

Query is the key

Debug query rc = sqlite3_exec (dB, "select * from student where ID> 2

And name <> 'zhangsan' ", loadinfo, null, & mrrmsg );

The query result is exported using the loadinfo function.

Typedef int (* sqlite3_callback) (void *, int char **, char **);

Int loadinfo (void * para, // DB

Int n_column, // number of record Columns

Char ** column_value, // locate the value

Char ** column_name) // field name

{

Int I;

Printf ("records contain % d fields \ n", n_column );

For (I = 0; I <n_column; I ++)

Printf ("field name: % s, field value: % s \ n", column_name [I], column_value [] I );

Return 0;

}

Function query rc = sqlite_get_table (dB, "select ID from student where ID> 2

And name <> 'zhangsan' ", & result, & nrow, & ncolumn, & errmsg );

Char ** result;

Int nrow, ncolumn;

Int RC;

Char * errmsg = NULL;

Rc = sqlite_get_table (dB, "select * from student where ID> 2

And name <> 'zhangsan' ", & result, & nrow, & ncolumn, & errmsg );

Int I;

Char ID [10];

Char name [10];

For (INT I = 1; I <= nrow; I ++)

{

Id [I] = Result [I * 2];

Name [I] = Result [I * 2 + 1];

}

Iii. sqlite3 command:

Sqlite3 data. DB // open data. DB

. Tables

. Schema output format

. Mode line/column/list // format single row, column, list

. Timeout // time

. Output test.txt // output to test.txt

. Q exit

Execute common SQL statements

[Root @ localhost root] # sqlite3 data. DB

SQLite> Create Table student (ID integer primary key, name nvarchar (32 ));

SQLite> insert into student values (1, 'Sun Wukong ');

SQLite> insert into student values (2, 'ang seng ');

SQLite> select * from student;

1 | Sun Wukong

2 | Tang Seng

SQLite> Update student set name = 'zhu Bajie 'Where id = '2 ';

SQLite> select * from student;

1 | Sun Wukong

2 | Zhu Bajie

SQLite> Delete from student where id = '2' and name = 'zhu Bajie ';

SQLite> select * from student;

1 | Sun Wukong

SQLite>. Tables

Student

Chinese support

[Root @ localhost root] # sqlite3 data. DB

SQLite> Create Table student (ID integer primary key, Name text); // Note: The name type is text.

SQLite> insert into student values (1, 'Sun wukong ');

SQLite> insert into student values (2, 'tangsan ');

SQLite> select * from student;

1 | Sun Wukong

2 | Tang Seng

SQLite> Update student set name = ' 'Where id = '2 ';

SQLite> select * from student;

1 | Sun Wukong

2 | pig

SQLite> Delete from student where id = '2' and name = 'pig ';

SQLite> select * from student;

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.