Symbian3/PDK/Source/GUID-B38EBDBA-2A30-5595-9639-6AE58C530DCB.dita
changeset 5 f345bda72bc4
parent 3 46218c8b8afa
child 14 578be2adaf3e
equal deleted inserted replaced
4:4816d766a08a 5:f345bda72bc4
     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-B38EBDBA-2A30-5595-9639-6AE58C530DCB"><title>Creating a Database </title><shortdesc>This document shows you how to create a database for Symbian SQL. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> <context id="GUID-9C6BDAAF-0547-51AF-8F47-5436C0D1697D"><p>Working with databases is not possible until the database exists. In this tutorial you will learn how to create a simple database. </p> <p>This tutorial uses code from the <xref href="GUID-C2FCE726-FD87-52BF-8AF8-7F54FB6D6CB1.dita">Basic SQL example application</xref>. </p> <p>The SQL statement used for this tutorial is shown here: </p> <codeblock id="GUID-EA0CADFD-53BF-5599-AD76-92EB15A94E9B" xml:space="preserve">CREATE DATABASE \\Basic_db.db</codeblock> </context> <steps id="GUID-65CD4149-1978-5FD9-84A3-ADACDE6C5B89"> <step id="GUID-3F8A65A1-7682-5C32-B92B-360CB923AA58"><cmd>Declare a constant to hold the database handle: </cmd> <info> <codeph>KDatabaseName</codeph> will be used when creating and accessing the database. </info> <stepxmp><codeblock id="GUID-7BAB1756-75A0-5C8A-B868-F8CD4BB3DEC1" xml:space="preserve">_LIT(KDatabaseName, "\\Basic_db.db");
    12 <task id="GUID-B38EBDBA-2A30-5595-9639-6AE58C530DCB" xml:lang="en"><title>Creating
       
    13 a Database </title><shortdesc>This document shows you how to create a database for Symbian SQL. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>
       
    14 
       
    15 
       
    16 <context id="GUID-9C6BDAAF-0547-51AF-8F47-5436C0D1697D"><p>Working with databases
       
    17 is not possible until the database exists. In this tutorial you will learn
       
    18 how to create a simple database. </p> <p>This tutorial uses code from the <xref href="GUID-C2FCE726-FD87-52BF-8AF8-7F54FB6D6CB1.dita">Basic SQL example application</xref>. </p> <p>The
       
    19 SQL statement used for this tutorial is shown here: </p> <codeblock id="GUID-EA0CADFD-53BF-5599-AD76-92EB15A94E9B" xml:space="preserve">CREATE DATABASE \\Basic_db.db</codeblock> </context>
       
    20 <steps id="GUID-65CD4149-1978-5FD9-84A3-ADACDE6C5B89">
       
    21 <step id="GUID-3F8A65A1-7682-5C32-B92B-360CB923AA58"><cmd>Declare a constant
       
    22 to hold the database handle: </cmd>
       
    23 
       
    24 <info> <codeph>KDatabaseName</codeph> will be used when creating and accessing
       
    25 the database. </info>
       
    26 <stepxmp><codeblock id="GUID-7BAB1756-75A0-5C8A-B868-F8CD4BB3DEC1" xml:space="preserve">_LIT(KDatabaseName, "\\Basic_db.db");
    13 _LIT(KDatabaseMsg,"\nCreating a database\n");
    27 _LIT(KDatabaseMsg,"\nCreating a database\n");
    14 RSqlDatabase db;
    28 RSqlDatabase db;
    15 CConsoleBase* iConsole;</codeblock> </stepxmp> <stepresult>The objects and constants needed to create the database are now ready. </stepresult> </step> <step id="GUID-677801E7-CCEB-5158-9853-5BFC800BA6C2"><cmd>Create the database: </cmd> <info>You are telling Symbian SQL to execute the CREATE DATABASE command. </info> <stepxmp><codeblock id="GUID-D3D95DE0-2C19-5216-8160-1E92CC4D7F20" xml:space="preserve">iConsole-&gt;Printf(KDatabaseMsg);
    29 CConsoleBase* iConsole;</codeblock> </stepxmp>
       
    30 <stepresult>The objects and constants needed to create the database are now
       
    31 ready. </stepresult>
       
    32 </step>
       
    33 <step id="GUID-677801E7-CCEB-5158-9853-5BFC800BA6C2"><cmd>Create the database: </cmd>
       
    34 
       
    35 <info>You are telling Symbian SQL to execute the CREATE DATABASE command. </info>
       
    36 <stepxmp><codeblock id="GUID-D3D95DE0-2C19-5216-8160-1E92CC4D7F20" xml:space="preserve">iConsole-&gt;Printf(KDatabaseMsg);
    16 User::LeaveIfError(db.Create(KDatabaseName));
    37 User::LeaveIfError(db.Create(KDatabaseName));
    17 iConsole-&gt;Printf(KDatabaseName);</codeblock> </stepxmp> <stepresult>The database now exists. <xref href="GUID-4688F6B7-E1B0-37CF-BAA2-C6BD103D4FDF.dita"><apiname>RSqlDatabase::Create()</apiname></xref> executes the SQL engine command that makes the actual database. You can look in the <filepath>C:\</filepath> drive on the device to confirm that the database object exists. </stepresult> </step> </steps> <result id="GUID-9814EF32-E1BA-52F3-8D2C-F1776D9EF8FE"><p>The database now exists. You can perform all the standard SQL operations on the database including creating and populating a table, querying the database, editing records and deleting the database, to name a few. </p> </result> <example id="GUID-4D518486-E7E1-57DB-AD33-CFFD29CA5DBA"><title>Create database example</title> <p>The following code snippet is from the example code used for this tutorial: </p> <codeblock id="GUID-2DD57F74-DEC1-54AC-82B8-9A186EF7E0B2" xml:space="preserve">...
    38 iConsole-&gt;Printf(KDatabaseName);</codeblock> </stepxmp>
       
    39 <stepresult>The database now exists. <xref href="GUID-4688F6B7-E1B0-37CF-BAA2-C6BD103D4FDF.dita"><apiname>RSqlDatabase::Create()</apiname></xref> executes
       
    40 the SQL engine command that makes the actual database. You can look in the <filepath>C:\</filepath> drive
       
    41 on the device to confirm that the database object exists. </stepresult>
       
    42 </step>
       
    43 </steps>
       
    44 <result id="GUID-9814EF32-E1BA-52F3-8D2C-F1776D9EF8FE"><p>The database now
       
    45 exists. You can perform all the standard SQL operations on the database including
       
    46 creating and populating a table, querying the database, editing records and
       
    47 deleting the database, to name a few. </p> </result>
       
    48 <example id="GUID-4D518486-E7E1-57DB-AD33-CFFD29CA5DBA"><title>Create database
       
    49 example</title> <p>The following code snippet is from the example code used
       
    50 for this tutorial: </p> <codeblock id="GUID-2DD57F74-DEC1-54AC-82B8-9A186EF7E0B2" xml:space="preserve">...
    18 _LIT(KDatabaseName, "\\Basic_db.db");
    51 _LIT(KDatabaseName, "\\Basic_db.db");
    19 _LIT(KDatabaseMsg,"\nCreating a database\n");
    52 _LIT(KDatabaseMsg,"\nCreating a database\n");
    20 ...
    53 ...
    21 CConsoleBase* iConsole;
    54 CConsoleBase* iConsole;
    22 ...
    55 ...
    29     User::LeaveIfError(db.Create(KDatabaseName));
    62     User::LeaveIfError(db.Create(KDatabaseName));
    30 
    63 
    31     iConsole-&gt;Printf(KDatabaseName);
    64     iConsole-&gt;Printf(KDatabaseName);
    32     CleanupClosePushL(db);
    65     CleanupClosePushL(db);
    33     ...
    66     ...
    34     }</codeblock> </example> <postreq id="GUID-762047BF-ED5B-51EF-9B90-2E7B0E8A8A89"><p>Now that you have created a database you need to add a table and populate it with some data. The following will show you how: </p> <ul><li id="GUID-FBF36438-2EC4-5E58-A70A-4C255B9315B6"><p> <xref href="GUID-1D35F788-A470-5269-93E0-7C33A0013489.dita">Creating a Table</xref>  </p> </li> <li id="GUID-53C27AF6-6B97-53AB-B72D-5BD92AB33BA8"><p> <xref href="GUID-CCB9C61B-FB28-5CD9-A366-4A9584097897.dita">Inserting Data into a Table</xref> </p> </li> <li id="GUID-7674D43E-0F60-5C6A-9D5D-4E007B6A9BEB"><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
    67     }</codeblock> </example>
    35                 Application</linktext> </link> </related-links></task>
    68 <postreq id="GUID-762047BF-ED5B-51EF-9B90-2E7B0E8A8A89"><p>Now that you have
       
    69 created a database you need to add a table and populate it with some data.
       
    70 The following will show you how: </p> <ul>
       
    71 <li id="GUID-FBF36438-2EC4-5E58-A70A-4C255B9315B6"><p> <xref href="GUID-1D35F788-A470-5269-93E0-7C33A0013489.dita">Creating
       
    72 a Table</xref>  </p> </li>
       
    73 <li id="GUID-53C27AF6-6B97-53AB-B72D-5BD92AB33BA8"><p> <xref href="GUID-CCB9C61B-FB28-5CD9-A366-4A9584097897.dita">Inserting
       
    74 Data into a Table</xref> </p> </li>
       
    75 <li id="GUID-7674D43E-0F60-5C6A-9D5D-4E007B6A9BEB"><p> <xref href="GUID-B9A3B17E-BDEB-5F66-968C-080335A721AC.dita">Writing
       
    76 from a Data Stream</xref>  </p> </li>
       
    77 </ul> </postreq>
       
    78 </taskbody><related-links>
       
    79 <link href="GUID-22844C28-AB5B-5A6F-8863-7269464684B4.dita"><linktext>SQL Overview</linktext>
       
    80 </link>
       
    81 <link href="GUID-C2FCE726-FD87-52BF-8AF8-7F54FB6D6CB1.dita"><linktext>Basic SQL
       
    82 Example                 Application</linktext></link>
       
    83 </related-links></task>