C++ with SQLite3
- Part 1: Downloading and Compiling
- Part 2: Creating Tables
- Part 3: Inserting and Selecting Data
- Part 4: Removing Data
- Part 5: Encapsulating Database Objects
SQLite3 is the most-used SQL implementation in the world. It is a self-contained C library included in everything from portable devices to web browsers.
Note: This tutorial assumes some familiarity with using the command-line to create and compile files. It was written using a MacOS X machine and also assumes easy access to g++. (For Windows systems, consider using MinGW.)
In the previous part, the function sqlite3_exec() was used create a new table using the CREATE TABLE keywords in SQL. To add data to the table, sqlite3_exec() can be used again.
To insert more data, multiple SQL statements can be run.
When working with SQL, the sqlite3_exec() will often be used. However, as with using CREATE TABLE, the use of INSERT INTO does not return data to the callback function. For that, a SELECT keyword in SQL would need to be used.
The SELECT keyword in SQL can be used to get data from a table. Because it returns data, the callback function used with sqlite3_exec() function.
The callback function takes four parameters:
- void *NotUsed: Not used. This can be passed from the sqlite3_exec() function directly.
- int argc: Number of results
- char **argv: Array of values
- char **azColName: Array of column names