Symbian3/SDK/Source/GUID-1D35F788-A470-5269-93E0-7C33A0013489.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 11 Jun 2010 12:39:03 +0100
changeset 8 ae94777fff8f
parent 7 51a74ef9ed63
child 13 48780e181b38
permissions -rw-r--r--
Week 23 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 2714, Bug 462.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE task
  PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
<task xml:lang="en" id="GUID-1D35F788-A470-5269-93E0-7C33A0013489"><title>Creating a Table </title><shortdesc>This tutorial shows you how to create a Symbian SQL table. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> <context id="GUID-6799E3F3-353E-5C00-A38C-D32F888392AA-GENID-1-10-1-22-1-1-6-1-1-9-1-8-1-6-1-3-1"><p>This tutorial uses code from the <xref href="GUID-C2FCE726-FD87-52BF-8AF8-7F54FB6D6CB1.dita">Basic SQL example application</xref>. </p> <p><b>Assumptions </b> </p> <p>You have a database. The database has no tables and therefore no data. </p> <p><b>SQL statements </b> </p> <p>The following SQL statements are used for this example: </p> <p><userinput>CREATE TABLE Pets( person TEXT, cat SMALLINT, dog SMALLINT, rodent SMALLINT, bird SMALLINT)</userinput> </p> <p>The <xref href="GUID-4688F6B7-E1B0-37CF-BAA2-C6BD103D4FDF.dita"><apiname>RSqlDatabase::Exec</apiname></xref> function provides a mechanism for executing Symbian SQL statements. </p> </context> <steps id="GUID-CF509D01-A43D-5B06-86B3-2F3F27E56DD1"><step id="GUID-8C01D480-6297-5663-B7B2-54988FABD459"><cmd>Create a table </cmd> <info>The steps required to create a table are shown here: </info> <substeps id="GUID-1A0FC730-B110-5EE6-8EB6-9CC10750CE9F"><substep id="GUID-4B88DCB9-FF03-5D4E-A061-FE5D8F686FC9"><cmd>Declare a constant to hold the table handle: </cmd> <stepxmp><codeblock id="GUID-98F9AF2B-5599-5490-A90A-6299814EE1FB" xml:space="preserve">_LIT(KTabCreate,"CREATE TABLE Pets( person TEXT, cat SMALLINT, dog SMALLINT, rodent SMALLINT, bird SMALLINT);");</codeblock> </stepxmp> <stepresult> <codeph>KTabCreate</codeph> will be used later by the SQL EXECUTE command. </stepresult> </substep> <substep id="GUID-A7BAF541-EF41-5A75-8560-2553B81B35CC"><cmd>Instantiate the required objects: </cmd> <stepxmp><codeblock id="GUID-69EC7894-C3C9-5BE3-B54A-66651C1647E1" xml:space="preserve">RSqlDatabase db;
CConsoleBase* iConsole;</codeblock> </stepxmp> <info>This creates an RSqlDatabase object, which is needed to execute the SQL statement. </info> </substep> <substep id="GUID-98878406-01F8-5162-818A-2A53BE5FF96B"><cmd>Execute the SQL statement: </cmd> <stepxmp><codeblock id="GUID-4E02D739-ABF7-54E5-89FF-3EDD943A8231" xml:space="preserve">db.Exec(KTabCreate)</codeblock> </stepxmp> <info>This will execute the SQL statement to create the table. </info> </substep> </substeps> <stepresult>The table now exists and you can begin adding data to it. </stepresult> </step> </steps> <result id="GUID-D697ACB5-9E8C-5F6A-972F-8D150AD5D469"><p>Your database now has at least one table. You can begin to add data to the table and you can query and edit it. </p> </result> <example id="GUID-630D1DAD-F3AA-58D1-9E92-7A07097D9DEF"><title>Create table example</title> <p>The following code snippet is from the example used for this tutorial: </p> <codeblock id="GUID-76426336-3BF5-5126-8224-C7E372E2CA29" xml:space="preserve">_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-&gt;Printf(KCreateTable);
...
User::LeaveIfError(db.Exec(KTabCreate));
...</codeblock> </example> <postreq id="GUID-AE41BAEA-E1DB-53B1-B289-3CD020CA0B4B"><p>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: </p> <ul><li id="GUID-B9AC3160-267B-57AD-B29A-19013EC2E05E"><p> <xref href="GUID-2610E11C-26FA-538E-A3E1-34AADA35F20B.dita">Querying Databases: Basic</xref>  </p> </li> <li id="GUID-92B5719B-D8C3-5215-B6EF-F7820F4514BD"><p> <xref href="GUID-CCB9C61B-FB28-5CD9-A366-4A9584097897.dita">Inserting Data into a Table</xref> </p> </li> <li id="GUID-F518E95A-3E3E-588A-831A-774B4F0540DB"><p> <xref href="GUID-B9A3B17E-BDEB-5F66-968C-080335A721AC.dita">Writing from a Data Stream</xref>  </p> </li> </ul> </postreq> </taskbody><related-links><link href="GUID-22844C28-AB5B-5A6F-8863-7269464684B4.dita"><linktext>SQL Overview</linktext> </link> <link href="GUID-C2FCE726-FD87-52BF-8AF8-7F54FB6D6CB1.dita"><linktext>Basic SQL Example
                Application</linktext> </link> </related-links></task>