Use the callback function in sqlite3

Source: Internet
Author: User
The callback function format is as follows:  Int  Sqlite_callback (  Void * PV, /*  Passed by the fourth parameter of sqlite3_exec ()  */      Int Argc, /*  Number of columns in the table  */      Char ** Argv, /*  The pointer array pointing to the query result, which can be obtained by sqlite3_column_text ().  */     Char ** Col /*  Pointer array pointing to the header name, which can be obtained by sqlite3_column_name ()  */  );

Parameter format: The callback function passed to sqlite3_exec to display the query result. Each query result is called once. The callback function parameter: PV: the number of columns in the table header. Col: header name array pointer argv: header data array pointer returned value: 1: interrupted search 0: continue listing queried data
Example Table: + ------------------------------- + | ID | PIC | data (hexadecimal data) | ------------------------------------- | 1 | a.jpg | 00 00 00... | ------------------------------- | 2 | B .jpg | xx | + ------------------------------------- + for the first row of data: argc = 3 [0]... [2] argv [0] = "1", argv [1] = "a.jpg", argv [2] = "00 00 00... "(actual hexadecimal data, not the string format shown here) COL [0] =" ID ", Col [1] =" pic ", col [2] = "data"
   
  note: the callback function of sqlite3_exec () must follow this format. Of course, the parameter name is arbitrary. if the data type of a column is not Char  *, you can convert the result. For example, you can use atoi () to convert the result to an integer ), if it is binary data, you can directly force type conversion, such as: ( void  * ) argv [I]. the callback function has two types of return values.   1  . return zero: sqlite3_exec (). The query continues.   2  . return non-zero: sqlite3_exec () will immediately interrupt the query, and sqlite3_exec () will return sqlite_abort. example:   int   I;   for  (I =  0 ; I 
  
   ) {printf ( 
    " 
    % s \ t % s \ n  
   "  
   , Col [I], argv [I]) ;} 
  

girls don't cry (QQ: 191035066) @ 2012-05-29 13:13:48 @ http://www.cnblogs.com/nbsofer

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.