Symbian3/SDK/Source/GUID-C474376E-1766-5781-B5BF-3786C5B4D72E.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 7 51a74ef9ed63
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?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 concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-C474376E-1766-5781-B5BF-3786C5B4D72E" xml:lang="en"><title>Performing
Scalar Queries</title><shortdesc>This tutorial describes the way in which you can execute scalar
queries. </shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<section id="GUID-AD7CD3A2-6B59-43F4-8DA0-CFDDC45FB180"><title>Introduction</title> <p>A
scalar query is a <codeph>SELECT</codeph> statement which refers to several
data fields and returns a single result, for example, a <codeph>COUNT</codeph> query
on a database column. This gives the number of records in the database. Symbian
platform provides a class <xref href="GUID-E7B775B0-A609-313A-8BFD-375C81D782A5.dita"><apiname>TSqlScalarFullSelectQuery</apiname></xref>, for
making scalar queries. This is more efficient than the <xref href="GUID-0176BF07-DF94-3259-8F90-DE030E35CE9A.dita"><apiname>RSqlStatement</apiname></xref> class. </p> </section>
<section id="GUID-746D0C94-4F0A-4BDC-8E24-C970B0E9848A"><title>Basic procedure</title> <p>The
high level steps to perform scalar queries are shown here: </p> <ol id="GUID-55223195-5C72-5F61-A0E7-96B6EE3274F3">
<li id="GUID-DCD1126E-F922-5D1F-84AE-DCEAD36005F4"><p>Declare the necessary
variables. </p> </li>
<li id="GUID-7218837C-3E0A-5B66-8814-234CB1DC5739"><p>Execute the query string. </p> </li>
</ol> </section>
<section id="GUID-5850F2FF-0B04-4D56-BD4C-14019B0A5C10"><title>Detailed steps</title> <p>To
make a scalar query, do the following: </p> <p><b>Declare
the necessary variables</b> </p> <ol id="GUID-9B0B542F-F123-5933-8C54-A376EBD6C97F">
<li id="GUID-6252DA75-22E2-5AB7-8F80-6C0EC52EEFD1"><p>Instantiate an object
of the database class. </p> <codeblock id="GUID-2EA8226E-5867-59C2-B4D9-BEE0A2D1F730" xml:space="preserve">RSqlDatabase myDatabase;</codeblock> </li>
<li id="GUID-95BB8C0A-4BCB-5F2F-AB02-4F30F9077CAB"><p>Declare a literal to
hold the query string </p> <codeblock id="GUID-D76C33E4-9914-5D82-9CEB-0C94BFF0E0F4" xml:space="preserve">_LIT(kQueryString,"SELECT COUNT (*) FROM myTable");</codeblock> </li>
<li id="GUID-2821B159-D8F7-5F8B-80D5-90A8EABE7D22"><p>Instantiate an object
of the <xref href="GUID-E7B775B0-A609-313A-8BFD-375C81D782A5.dita"><apiname>TSqlScalarFullSelectQuery</apiname></xref> class. This class has
a peculiar feature of instantiating an instance of it with a parameter that
refers to the database to be queried. The class supplies a number of functions
taking <codeph>SELECT</codeph> statements as parameters. </p> <codeblock id="GUID-FAF6DE03-B9CE-54B3-B58D-77BF47489E6E" xml:space="preserve">TSqlScalarFullSelectQuery myFullSelectQuery(myDatabase);</codeblock> </li>
</ol> <p><b> Execute
the query</b> </p><p>Execute the query</p><codeblock xml:space="preserve">TInt recCount = myFullSelectQuery.SelectIntL(kQueryString));</codeblock> </section>
<section id="GUID-00FF5330-86C2-4A26-8409-7D204746E92D"><title>See also</title> <p><xref href="GUID-C60DAE3D-7FB9-5619-9E5D-476A430705AF.dita">Querying a Database</xref>  </p> <p> <xref href="GUID-CCB9C61B-FB28-5CD9-A366-4A9584097897.dita">Inserting a Row into a Table</xref>  </p> <p><xref href="GUID-B61EA8C5-0966-51DE-AC73-01DD34C7D3CC.dita">Deleting Rows from a Table</xref>  </p> <p> <xref href="GUID-72511204-FC90-54AA-9E2E-833318020318.dita">Reading to a Buffer</xref>  </p> <p> <xref href="GUID-3CCA6503-54DA-5558-85DC-93A22A81F565.dita"> Reading to Memory </xref>  </p> <p> <xref href="GUID-183280EE-0C57-54FE-8ABB-E1CC3BDE525B.dita">Reading to a Data Stream</xref>  </p> <p> <xref href="GUID-B9A3B17E-BDEB-5F66-968C-080335A721AC.dita">Writing to a Data Stream</xref>  </p> <p>Performing
Scalar Queries - This document </p> </section>
</conbody></concept>