Symbian3/SDK/Source/GUID-1D35F788-A470-5269-93E0-7C33A0013489.dita
changeset 8 ae94777fff8f
parent 7 51a74ef9ed63
child 13 48780e181b38
equal deleted inserted replaced
7:51a74ef9ed63 8:ae94777fff8f
     7     Nokia Corporation - initial contribution.
     7     Nokia Corporation - initial contribution.
     8 Contributors: 
     8 Contributors: 
     9 -->
     9 -->
    10 <!DOCTYPE task
    10 <!DOCTYPE task
    11   PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
    11   PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
    12 <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-8-1-21-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;
    12 <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;
    13 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);");
    13 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);");
    14 _LIT(KCreateTable,"\nCreating a table\n");
    14 _LIT(KCreateTable,"\nCreating a table\n");
    15 ...
    15 ...
    16 CConsoleBase* iConsole;
    16 CConsoleBase* iConsole;
    17 ...
    17 ...