This tutorial shows you how to create a Symbian SQL table.
This tutorial uses code from the Basic SQL example application.
Assumptions
You have a database. The database has no tables and therefore no data.
SQL statements
The following SQL statements are used for this example:
CREATE TABLE Pets( person TEXT, cat SMALLINT, dog SMALLINT, rodent SMALLINT, bird SMALLINT)
The RSqlDatabase::Exec function provides a mechanism for executing Symbian SQL statements.
Create a table
The steps required to create a table are shown here:Declare a constant to hold the table handle:
Example:
_LIT(KTabCreate,"CREATE TABLE Pets( person TEXT, cat SMALLINT, dog SMALLINT, rodent SMALLINT, bird SMALLINT);");
KTabCreate
will be used later by the SQL EXECUTE command. Instantiate the required objects:
Example:
RSqlDatabase db; CConsoleBase* iConsole;
Execute the SQL statement:
Example:
db.Exec(KTabCreate)
Your database now has at least one table. You can begin to add data to the table and you can query and edit it.
The following code snippet is from the example used for this tutorial:
_LIT(KTabCreate,"CREATE TABLE Pets( person TEXT, cat SMALLINT, dog SMALLINT, rodent SMALLINT, bird SMALLINT);"); _LIT(KCreateTable,"\nCreating a table\n"); ... CConsoleBase* iConsole; ... RSqlDatabase db; iConsole->Printf(KCreateTable); ... User::LeaveIfError(db.Exec(KTabCreate)); ...
Now that you have created a table you need to populate it with some data. The following tasks will show you how to populate a table: