1.sqlite3 the creation order of the database:
- Use the C language function first [Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) Lastobject] To obtain the document directory of the database, and then through the stringByAppendingPathComponent method to splice out the database file directory;
- Creates a Sqlite3 pointer object and assigns a null value;
- Use the C language function Sqlite3_open (database directory. Utf8string, &sqlite3 pointer object);
- Determine whether the return value of the Open database function is SQLITE_OK by using the IF statement to determine if the opening is successful;
2.sqlite3 the order in which database tables are created:
- The const char *sql is created first, and the pointer object is used to hold the SQL statement;
- Create char *ERRORMESG = NULL;
- Using the C-language function sqlite3_exec (sqlite3 pointer object, SQL statement, NULL, NULL, &ERRORMESG) method to execute the SQL statement, there is also a return value of type int, which can be judged as the fourth step of creating a database. If the failure can use the%s direct printing ERRORMESG to determine success or failure;
The update of the 3.SQLITE3 database and the order of delete operations are almost the same as creating the table, just change the next statement.
The order of query statements for the 4.SQLITE3 database is more complex, as follows:
- Defines a const char *SQL statement;
- Defines a sqlite3_stmt pointer object;
- Use SQLITE3_PREPARE_V2 (SQLite pointer object, SQL statement, 1 (length of data, 1 is automatically calculated), stmt pointer object address, NULL) to detect the legality of SQL statements;
- The return value is judged correct;
- If correct, use while (Sqlite_step (stmt) = = Sqlite_row) to determine if a row is found;
- Use the Sqlite_column_ data type (Result pointer object, column number) in the loop to obtain the C language function;
5. When defining a query statement, you should change the string to the right of the equal sign. , and then use the Sqlite_bind_ data type (the result set pointer object, the index of the question mark (starting from 1), the data to be replaced, 1 (the length of the data, 1 is calculated automatically), and NULL (callback function) before executing;
Last week has been doing a little practice, a week of the interface, but also encountered some problems, but also solved a part, although the solution is a bit trickery, but I think the first solution to the problem before considering optimization is the best way to develop. Learn the logical part of practicing this week while learning.
iOS Learning notes----15/09/14