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.