SQLite3 C Language API usage records

Source: Internet
Author: User
Tags sqlite

A

#include  <stdio.h> #include  <sqlite3.h>static int callback (void *notused,  int argc, char **argv, char **azcolname) {    int i;     for (i=0;i<argc;i++) {        printf ("%s  = %s\n ", azcolname[i], argv[i] ? argv[i] : " NULL ");     }    printf ("\ n");     return 0 ;} Int main (INT&NBSP;ARGC,&NBSP;CHAR&NBSP;**ARGV) {    sqlite3 *db;     char *message =  0;    int rc ;      if (argc!=3) {        fprintf (stderr,  "Usage:  %s database sql-statement\n ",  argv[0]);         return 1;    }     rc = sqlite3_open (argv[1], &db);     if (RC) {         fprintf (stderr,  "Can ' t open database: %s\n",  sqlite3_ ErrMsg (db));         sqlite3_close (db);         return 1;    }    rc = sqlite3_exec ( Db , argv[2], callback,0 ,&message);     if ( rc!=SQLITE_OK  ) {        fprintf (stderr,  "sql error: %s\n",  message);         sqlite3_free (message);     }     sqlite3_close (db);      return 0;}

To run the command:

./example test_db "CREATE TABLE test_table (int val);"

A test_db file that appears in the directory is the test_db database:)



Reference documents:

[0] An Introduction to the SQLite/C + + Interface http://www.sqlite.org/cintro.html

[1] SQLite3 C language API Primer http://www.blogjava.net/xylz/archive/2012/09/25/388519.html


SQLite3 C Language API usage records

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.