Under Linux, press the Sqllite

Source: Internet
Author: User

1 installation

Go to SQLite homepage http://www.sqlite.org/. Jump to download also http://www.sqlite.org/download.html. SOURCE Download sqlite-amalgamation-3.7.3.tar.gz

When I went to the 3.7.3 version, it was now estimated to be upgraded.

Go to the download directory and unzip the file TAR-ZXVF sqlite-amalgamation-3.7.3.tar.gz.

Generate sqlite-3.7.3 directory after decompression. CD into sqlite-3.7.3.

./configure

Make

sudo make install

Installation is complete.

2 Testing

Create a new database in any directory, such as student,

Command: Sqlite3 Student

The following prompt appears:

SQLite version 3.7.2
Enter '. Help ' for instructions
Enter SQL statements terminated with a ";"
Sqlite>

Enter. Help to see a list of commands.

Enter SQL statement CREATE table User (username text primary key, password text); Build a user table

Enter the SQL statement insert into user values ("tianyou121", "123"); Insert a user.

Input SQL statement SELECT * from user; You can view the user table.

Enter SQL command to remember the end of '; ' No.

You can enter the following program to test the database:

1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include <sqlite3.h>
5
6 int myfunc (void *p, int argc, char **argv, char **argvv)
7 {
8 int i;
9 * (int *) p = 0;
Ten for (I =0; i < argc; i++)
11 {
printf ("%s =%s", Argvv[i], argv[i]? Argv[i]: "NULL");
13}
Putchar ('/n ');
return 0;
16}
17
int main (int argc, char *argv[])
19 {
Sqlite3 *db;
*err char = 0;
int ret = 0;
$ int empty = 1;
24
ret = Sqlite3_open ("Student", &db);
if (ret!=SQLITE_OK)
27 {
Fputs ("/n", stderr);
Exit (1);
30}
ret = sqlite3_exec (db, "select * from User;", MyFunc, &empty, &err);
32
if (ret! = SQLITE_OK)
34 {
Fputs (Err,stderr);
Fputs ("/n", stderr);
Panax Notoginseng sqlite3_close (db);
$ exit (1);
39}
40
if (empty)
42 {
Fputs ("Table student is empty/n", stderr);
+ exit (1);
45}
46
Sqlite3_close (DB);
48
return 0;
50}

Save the file as sqlite3_t.c and the database file in a directory.
Compile with gcc: gcc-o sqlite_t sqlite3_t.c-lsqlite3

Remember to add-lsqlite3 to specify the library file, otherwise the compilation will not pass.

./sqlite_t

You can see the user information in the Users table.

Under Linux, press the Sqllite

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.