Create a table-SQLite tutorial (5)

Source: Internet
Author: User
Tags sqlite tutorial
Statement

You are welcome to repost this article, but please respect the author's Labor achievements. repost this article and keep the statement in this box. Thank you.
Article Source: http://blog.csdn.net/iukey

In the previous tutorial, we learned two functions: sqlite3_open and sqlite3_close. In this section, we will learn another very important function, sqlite3_exec. This function is used to execute SQL statements. Let's take a look at its statement:

Sqlite_api int sqlite3_exec (sqlite3 *,/* an Open Database an opened database, that is, our previous PDB */const char * SQL, /* SQL to be evaluated statements to be executed */INT (* callback) (void *, Int, char **, char **),/* callback function, with a fixed format, you can implement */void * by yourself *, /* 1st argument to callback the first parameter of the callback function */Char ** errmsg/* error MSG written here can bring back the error message */);

We cannot use the third and fourth parameters for the moment. It can be filled with null. You can see one of my instances.

Void createtable {char * err; char * SQL = "CREATE TABLE Dictionary (ID integer primary key autoincrement, name nvarchar (64), no integer, comment nvarchar (256 ))"; // The statement to be executed if (sqlite_ OK! = Sqlite3_open (getfilepath (), & PDB) {// open the database printf ("createdb failed in createtable \ n"); return;} If (sqlite_ OK = sqlite3_exec (PDB, SQL, null, null, & ERR) {// execute the SQL statement printf ("createtable succeed! \ N "); sqlite3_close (PDB); // close the database sqlite3_free (ERR); return;} else {printf (" Err: % s ", err ); // print the error code sqlite3_free (ERR); Return ;}} if the error message fails ;}}

That's simple. A table is created. Then we can insert records, delete records, query records, and modify records. Of course, this is all about later. After reading this article, you know how to create a table.

Related Article

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.