Install and use sqlitte3 in Linux

Source: Internet
Author: User

Http://19831028.blog.51cto.com/1333653/301419

Http://blog.csdn.net/androidbluetooth/article/details/6573588

After installation, but the library file is not compiled, it seems that the application cannot be developed to call the API

Sqlite3 database command operation sqlite3 database and MySQL Database Import Export http://www.cnblogs.com/wdpp/archive/2011/11/30/2386714.html

How can the callback function return all query results when sqlite3_exec is executed to query the entire database,

Struct olt_info
{

Int olt_index;
Int olt_logo;
Char * olt_line;
// Int nmber;
};

Int my_callback (void * olt_temp, int argc, char * value [], char * name [])
{
Struct olt_info * pdata = NULL;
Pdata = (struct olt_info *) olt_temp;

Int JJ;
For (INT I = 0; I <argc; I ++)
JJ = printf ("% s = % s \ n", name [I], value [I]);

Pdata-> olt_index = (INT) atoi (value [0]);
Pdata-> olt_logo = (INT) atoi (value [1]);
Pdata-> olt_line = value [2];

Return 0;
}

This can be printed, but cannot be returned. In this case, only the last one is returned. You cannot return all results .. How can I return all results ??

This callback function is executed once every time a row of results is obtained, so the content of pdata is constantly changing. You can only get the results of the last row.

Try to save it with a linked list or queue? [/Quote]

Copy the CP-RF/mnt/HGFS/share/Home file to the directory

Http://tech.ddvip.com/2007-10/119338075236567.html

SQLite database to MySQL program http://www.sqlite.com.cn/MySqlite/6/377.Html

Question 1:

After half a day of hard work, I finally typed the first C program under vim, but after using the compilation command, GCC hello. c. The following result is displayed. I don't know what the error is.
Bytes -----------------------------------------------------------------------------------------------------------
-Bash-3.1 $ GCC hello. c
Hello. C: In the 'main' function:
Hello. C: 5: Error: The program has a free '\ 100'
Hello. C: 5: Error: The program has a free '\ 100'
Hello. C: 5: Error: 'Hello' is not declared (used for the first time in this function)
Hello. C: 5: Error: (even if it appears multiple times in a function, each undeclared identifier
Hello. C: 5: Error: only one report is reported in the function .)
Hello. C: 5: Error: Expected ') 'before' world'
Hello. C: 5: Error: The program has a free '\'
Hello. C: 5: Error: The program has a free '\ 100'
Hello. C: 5: Error: The program has a free '\ 100'

How do you use Chinese quotation marks for your Hello World quotation marks?
I will post one for you. You should carefully compare the quotation marks.
# Include <stdio. h>

Int main ()
{
Printf ("Hello world! \ N ");
Return 0;
}


Question 2: Undefined reference to 'sqlite3 _ open'

Suppose you have compiled and installed SQLite correctly, and write a test program for testing:
# Include <stdlib. h>
# Include <stdio. h>
# Include "sqlite3.h"

Int main (void)
{
Sqlite3 * DB = NULL;
Char * zerrmsg = 0;
Int RC;
Rc = sqlite3_open ("test1.db", & dB );
If (RC)
{
Fprintf (stderr, "can't open database: % s \ n", sqlite3_errmsg (db ));
Sqlite3_close (db );
Exit (1 );
}
Else printf ("Open mydata successfully! \ N ");
Sqlite3_close (db );
Return 0;
}

Errors always occur when compiling with GCC. The compilation command is as follows:
Gcc-static-O hello-lsqlite3-L/usr/local/lib-I/usr/local/include hello. c
The error message is as follows:
/Tmp/cckekpx9.o (. Text + 0x37): In function 'main ':
: Undefined reference to 'sqlite3 _ open'
/Tmp/cckekpx9.o (. Text + 0x51): In function 'main ':
: Undefined reference to 'sqlite3 _ errmsg'
/Tmp/cckekpx9.o (. Text + 0x73): In function 'main ':
: Undefined reference to 'sqlite3 _ close'
/Tmp/cckekpx9.o (. Text + 0x9b): In function 'main ':
: Undefined reference to 'sqlite3 _ close'
Collect2: LD returned 1 exit status

Congratulations. The error is not in SQLite or your program, but in GCC. GCC compilation parameters are sequential. The correct compilation command is:
Gcc-O hello-L/usr/local/lib-I/usr/local/include-static hello. C-lsqlite3



After confirming that make install is correct, run
Ldconfig (man ldconfig, see files section. Or Add/usr/local/lib to/etc/lD. So. conf first. Check whether your SQLite is installed in/usr/local)
Then
Ldconfig-p | grep libsqlite
Confirm.
During program Compilation
Gcc-O executible-L/usr/local/lib-lsqlite SRC. c

We recommend that you use info gcc/LD/makefile.

This is because GCC cannot find the header file defining sqlite3_open and so on. After searching for information on the Internet,

The solution is found and compiled using the following method:

$ Gcc-O hello-L/usr/local/sqlite-autoconf-3070400/lib-I/usr/local/sqlite-autoconf-307040/include sqlitetest. C-lsqlite3

The main significance of the above compilation is-l code: the path where you install the sqlite3 class library,-I represents the path of the header file for installing sqlite3 and-l represents

Name of the executable program

After the above compilation, you can succeed.

The execution result is as follows:

~ $./Hello

Database Connection successful!

Data inserted

Data inserted

Query database content

Userid = zhangsan

Age = 20

Birthday = 2011-7-23

Userid = Li Si

Age = 20

Birthday = 2012-9-20

Database shut down successfully!

Http://blog.sina.com.cn/s/blog_7516537d0100tedt.html warning: Implicit declaration not compatible with built-in functions 'memcpy' and some header files

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.