|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
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"); |
|
27 _LIT(KDatabaseMsg,"\nCreating a database\n"); |
|
28 RSqlDatabase db; |
|
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->Printf(KDatabaseMsg); |
|
37 User::LeaveIfError(db.Create(KDatabaseName)); |
|
38 iConsole->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">... |
|
51 _LIT(KDatabaseName, "\\Basic_db.db"); |
|
52 _LIT(KDatabaseMsg,"\nCreating a database\n"); |
|
53 ... |
|
54 CConsoleBase* iConsole; |
|
55 ... |
|
56 void CBasicSqlExample::CreateDatabaseL() |
|
57 { |
|
58 RSqlDatabase db; |
|
59 |
|
60 iConsole->Printf(KDatabaseMsg); |
|
61 //create the database |
|
62 User::LeaveIfError(db.Create(KDatabaseName)); |
|
63 |
|
64 iConsole->Printf(KDatabaseName); |
|
65 CleanupClosePushL(db); |
|
66 ... |
|
67 }</codeblock> </example> |
|
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> |