persistentstorage/sql/SRC/Client/SqlStatement.cpp
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "SqlStatementImpl.h"		//CSqlStatementImpl
       
    17 
       
    18 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    19 
       
    20 /**
       
    21 Initialises the pointer to the implementation object to NULL.
       
    22 
       
    23 @capability None
       
    24 */
       
    25 EXPORT_C RSqlStatement::RSqlStatement() :
       
    26 	iImpl(NULL)
       
    27 	{
       
    28 	}
       
    29 
       
    30 /**
       
    31 Prepares the supplied 16-bit SQL statement for execution.
       
    32 
       
    33 An RSqlStatement object can prepare and execute a parameterised SQL statement or
       
    34 an SQL statement without parameters.
       
    35 
       
    36 The function can only deal with one SQL statement at a time, i.e. if you
       
    37 supply more than one SQL statement, each separated by a ";" character, then
       
    38 the function returns an error.
       
    39 
       
    40 Note that when the statement is to be used to retrieve or write blob or text data
       
    41 that is over 2Mb in size then it is recommended that the RSqlBlobReadStream and 
       
    42 RSqlBlobWriteStream classes or the TSqlBlob class is used instead. 
       
    43 These classes provide a more RAM-efficient way of reading and writing large 
       
    44 amounts of blob or text data from a database.
       
    45 
       
    46 @param aDatabase     A reference to the RSqlDatabase object that represents 
       
    47                      the database for which the SQL statement is being prepared.
       
    48 @param aSqlStmt      A string of 16-bit wide characters containing the
       
    49                      SQL statement to be prepared.
       
    50 
       
    51 @return KErrNone,     the SQL statement has been prepared for execution successfully;
       
    52         KErrNoMemory, an out of memory condition has occurred;
       
    53         KErrArgument, the SQL statement is invalid, for example, the supplied
       
    54                       string contains more than one SQL statement, or it
       
    55                       contains an empty SQL statement.
       
    56                       Note that database specific errors categorised as ESqlDbError
       
    57                       can also be returned;
       
    58         KSqlErrGeneral, a syntax error has occurred - text describing the problem
       
    59                         can be obtained by calling 	RSqlDatabase::LastErrorMessage().
       
    60 		KErrPermissionDenied, the calling application does not satisfy the relevant database security policies.
       
    61                       Note that database specific errors categorised as ESqlDbError, and
       
    62                       other system-wide error codes may also be returned.
       
    63 
       
    64 @capability None, if current RSqlStatement object represents a handle which operates on a non-secure database;
       
    65             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement modifies a secure database schema; 
       
    66             RSqlSecurityPolicy::EReadPolicy or 
       
    67             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement reads from a secure database; 
       
    68             RSqlSecurityPolicy::EWritePolicy or
       
    69             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement writes to a secure database;
       
    70 
       
    71 @see TSqlRetCodeClass::ESqlDbError
       
    72 @see RSqlDatabase
       
    73 @see RSqlDatabase::LastErrorMessage()
       
    74 @see RSqlSecurityPolicy
       
    75 @see RSqlSecurityPolicy::TPolicyType
       
    76 @see RSqlBlobReadStream
       
    77 @see RSqlBlobWriteStream
       
    78 @see TSqlBlob
       
    79 */	
       
    80 EXPORT_C TInt RSqlStatement::Prepare(RSqlDatabase& aDatabase, const TDesC& aSqlStmt)
       
    81 	{
       
    82 	SQLUTRACE_PROFILER(this);
       
    83 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KHexStrParam16, &aDatabase, &aSqlStmt));
       
    84 
       
    85 	return CSqlStatementImpl::New(iImpl, aDatabase.Impl(), aSqlStmt);
       
    86 	}
       
    87 	
       
    88 /**
       
    89 Prepares the supplied 8-bit SQL statement for execution.
       
    90 
       
    91 An RSqlStatement object can prepare and execute a parameterised SQL statement or
       
    92 an SQL statement without parameters.
       
    93 
       
    94 The function can only deal with one SQL statement at a time, i.e. if you
       
    95 supply more than one SQL statement, each separated by a ";" character, then
       
    96 the function returns an error.
       
    97 
       
    98 Note that when the statement is to be used to retrieve or write blob or text data
       
    99 that is over 2Mb in size then it is recommended that the RSqlBlobReadStream and 
       
   100 RSqlBlobWriteStream classes or the TSqlBlob class is used instead. 
       
   101 These classes provide a more RAM-efficient way of reading and writing large 
       
   102 amounts of blob or text data from a database.
       
   103 
       
   104 @param aDatabase     A reference to the RSqlDatabase object that represents 
       
   105                      the database for which the SQL statement is being prepared.
       
   106 @param aSqlStmt      A string of 8-bit wide characters containing the
       
   107                      SQL statement to be prepared.
       
   108 
       
   109 
       
   110 @return KErrNone,     the SQL statement has been prepared for execution successfully;
       
   111         KErrNoMemory, an out of memory condition has occurred;
       
   112         KErrArgument, the SQL statement is invalid, for example, the supplied
       
   113                       string contains more than one SQL statement, or it
       
   114                       contains an empty SQL statement.
       
   115                       Note that database specific errors categorised as ESqlDbError
       
   116                       can also be returned;
       
   117         KSqlErrGeneral, a syntax error has occurred - text describing the problem
       
   118                         can be obtained by calling 	RSqlDatabase::LastErrorMessage().
       
   119 		KErrPermissionDenied, the calling application does not satisfy the relevant database security policies.
       
   120                       Note that database specific errors categorised as ESqlDbError, and
       
   121                       other system-wide error codes may also be returned.
       
   122 
       
   123 @capability None, if current RSqlStatement object represents a handle which operates on a non-secure database;
       
   124             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement modifies a secure database schema; 
       
   125             RSqlSecurityPolicy::EReadPolicy or 
       
   126             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement reads from a secure database; 
       
   127             RSqlSecurityPolicy::EWritePolicy or
       
   128             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement writes to a secure database;
       
   129 
       
   130 @see TSqlRetCodeClass::ESqlDbError
       
   131 @see RSqlDatabase
       
   132 @see RSqlDatabase::LastErrorMessage()
       
   133 @see RSqlSecurityPolicy
       
   134 @see RSqlSecurityPolicy::TPolicyType
       
   135 @see RSqlBlobReadStream
       
   136 @see RSqlBlobWriteStream
       
   137 @see TSqlBlob
       
   138 */	
       
   139 EXPORT_C TInt RSqlStatement::Prepare(RSqlDatabase& aDatabase, const TDesC8& aSqlStmt)
       
   140 	{
       
   141 	SQLUTRACE_PROFILER(this);
       
   142 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KHexStrParam, 
       
   143 			&aDatabase, &aSqlStmt));
       
   144 	
       
   145 	return CSqlStatementImpl::New(iImpl, aDatabase.Impl(), aSqlStmt);
       
   146 	}
       
   147 
       
   148 /**
       
   149 Prepares the supplied 16-bit SQL statement for execution.
       
   150 
       
   151 An RSqlStatement object can prepare and execute a parameterised SQL statement or
       
   152 an SQL statement without parameters.
       
   153 
       
   154 The function can only deal with one SQL statement at a time, i.e. if you
       
   155 supply more than one SQL statement, each separated by a ";" character, then
       
   156 the function returns an error.
       
   157 
       
   158 Note that when the statement is to be used to retrieve or write blob or text data
       
   159 that is over 2Mb in size then it is recommended that the RSqlBlobReadStream and 
       
   160 RSqlBlobWriteStream classes or the TSqlBlob class is used instead. 
       
   161 These classes provide a more RAM-efficient way of reading and writing large 
       
   162 amounts of blob or text data from a database.
       
   163 
       
   164 @param aDatabase     A reference to the RSqlDatabase object that represents 
       
   165                      the database for which the SQL statement is being prepared.
       
   166 @param aSqlStmt      A string of 16-bit wide characters containing the
       
   167                      SQL statement to be prepared.
       
   168 
       
   169 @leave  KErrNoMemory, an out of memory condition has occurred;
       
   170         KErrArgument, the SQL statement is invalid, for example, the supplied
       
   171                       string contains more than one SQL statement, or it
       
   172                       contains an empty SQL statement.
       
   173                       Note that database specific errors categorised as ESqlDbError
       
   174                       can also be returned;
       
   175         KSqlErrGeneral, a syntax error has occurred - text describing the problem
       
   176                         can be obtained by calling 	RSqlDatabase::LastErrorMessage().
       
   177 		KErrPermissionDenied, the calling application does not satisfy the relevant database security policies.
       
   178                       Note that the function may leave with database specific errors categorised as ESqlDbError and
       
   179                       other system-wide error codes.
       
   180 
       
   181 @capability None, if current RSqlStatement object represents a handle which operates on a non-secure database;
       
   182             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement modifies a secure database schema; 
       
   183             RSqlSecurityPolicy::EReadPolicy or 
       
   184             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement reads from a secure database; 
       
   185             RSqlSecurityPolicy::EWritePolicy or
       
   186             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement writes to a secure database;
       
   187 
       
   188 @see TSqlRetCodeClass::ESqlDbError
       
   189 @see RSqlDatabase
       
   190 @see RSqlDatabase::LastErrorMessage()
       
   191 @see RSqlSecurityPolicy
       
   192 @see RSqlSecurityPolicy::TPolicyType
       
   193 @see RSqlBlobReadStream
       
   194 @see RSqlBlobWriteStream
       
   195 @see TSqlBlob
       
   196 */
       
   197 EXPORT_C void RSqlStatement::PrepareL(RSqlDatabase& aDatabase, const TDesC& aSqlStmt)
       
   198 	{
       
   199 	SQLUTRACE_PROFILER(this);
       
   200 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KHexStrParam16, 
       
   201 			&aDatabase, &aSqlStmt));
       
   202 	
       
   203 	__SQLLEAVE_IF_ERROR(Prepare(aDatabase, aSqlStmt));
       
   204 	}
       
   205 	
       
   206 /**
       
   207 Prepares the supplied 8-bit SQL statement for execution.
       
   208 
       
   209 An RSqlStatement object can prepare and execute a parameterised SQL statement or
       
   210 an SQL statement without parameters.
       
   211 
       
   212 The function can only deal with one SQL statement at a time, i.e. if you
       
   213 supply more than one SQL statement, each separated by a ";" character, then
       
   214 the function returns an error.
       
   215 
       
   216 Note that when the statement is to be used to retrieve or write blob or text data
       
   217 that is over 2Mb in size then it is recommended that the RSqlBlobReadStream and 
       
   218 RSqlBlobWriteStream classes or the TSqlBlob class is used instead. 
       
   219 These classes provide a more RAM-efficient way of reading and writing large 
       
   220 amounts of blob or text data from a database.
       
   221 
       
   222 @param aDatabase     A reference to the RSqlDatabase object that represents 
       
   223                      the database for which the SQL statement is being prepared.
       
   224 @param aSqlStmt      A string of 8-bit wide characters containing the
       
   225                      SQL statement to be prepared.
       
   226 
       
   227 
       
   228 @leave  KErrNoMemory, an out of memory condition has occurred;
       
   229         KErrArgument, the SQL statement is invalid, for example, the supplied
       
   230                       string contains more than one SQL statement, or it
       
   231                       contains an empty SQL statement.
       
   232                       Note that database specific errors categorised as ESqlDbError
       
   233                       can also be returned;
       
   234         KSqlErrGeneral, a syntax error has occurred - text describing the problem
       
   235                         can be obtained by calling 	RSqlDatabase::LastErrorMessage().
       
   236 		KErrPermissionDenied, the calling application does not satisfy the relevant database security policies.
       
   237                       Note that the function may leave with database specific errors categorised as ESqlDbError and
       
   238                       other system-wide error codes.
       
   239 
       
   240 @capability None, if current RSqlStatement object represents a handle which operates on a non-secure database;
       
   241             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement modifies a secure database schema; 
       
   242             RSqlSecurityPolicy::EReadPolicy or 
       
   243             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement reads from a secure database; 
       
   244             RSqlSecurityPolicy::EWritePolicy or
       
   245             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the SQL statement writes to a secure database;
       
   246 
       
   247 @see TSqlRetCodeClass::ESqlDbError
       
   248 @see RSqlDatabase
       
   249 @see RSqlDatabase::LastErrorMessage()
       
   250 @see RSqlSecurityPolicy
       
   251 @see RSqlSecurityPolicy::TPolicyType
       
   252 @see RSqlBlobReadStream
       
   253 @see RSqlBlobWriteStream
       
   254 @see TSqlBlob
       
   255 */
       
   256 EXPORT_C void RSqlStatement::PrepareL(RSqlDatabase& aDatabase, const TDesC8& aSqlStmt)
       
   257 	{
       
   258 	SQLUTRACE_PROFILER(this);
       
   259 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KHexStrParam, 
       
   260 			&aDatabase, &aSqlStmt));
       
   261 
       
   262 	__SQLLEAVE_IF_ERROR(Prepare(aDatabase, aSqlStmt));
       
   263 	}
       
   264 
       
   265 
       
   266 /**
       
   267 Closes this SQL statement object.
       
   268 
       
   269 The function frees memory and any allocated resources.
       
   270 
       
   271 @see RSqlStatement::Prepare()
       
   272 
       
   273 @capability None
       
   274 */	
       
   275 EXPORT_C void RSqlStatement::Close()
       
   276 	{
       
   277 	SQLUTRACE_PROFILER(this);
       
   278 	delete iImpl;
       
   279 	iImpl = NULL;
       
   280 	}
       
   281 
       
   282 /**
       
   283 Tests whether the SQL statement points to a valid record.
       
   284 
       
   285 @return True, if the SQL statement points to a valid record, false otherwise.
       
   286 
       
   287 @capability None
       
   288 */
       
   289 EXPORT_C TBool RSqlStatement::AtRow() const
       
   290 	{
       
   291 	SQLUTRACE_PROFILER(this);
       
   292 	return Impl().AtRow();
       
   293 	}
       
   294 	
       
   295 /**
       
   296 Resets the prepared SQL statement to its initial state and makes it ready to be
       
   297 executed again.
       
   298 
       
   299 Any SQL statement parameters that had values bound to them, retain their values.
       
   300 
       
   301 If this object processes a parameterised SQL statement, then the parameter
       
   302 values can be bound after the call to Reset().
       
   303 
       
   304 If the call to this function fails because of a database-specific type error 
       
   305 (i.e. the error is categorised as of type ESqlDbError), then a textual description of
       
   306 the error can be obtained calling RSqlDatabase::LastErrorMessage().
       
   307 
       
   308 
       
   309 Usage pattern 1:
       
   310 
       
   311 @code
       
   312 RSqlStatement stmt;
       
   313 TInt err = stmt.Prepare(<database>, <SQL statement>);
       
   314 while(<condition>)
       
   315 	{
       
   316 	err = stmt.Bind<parameter type>(<parameter index>, <value>);
       
   317 	...
       
   318 	err = stmt.Exec();
       
   319 	....
       
   320 	err = stmt.Reset();
       
   321 	}
       
   322 stmt.Close();
       
   323 @endcode
       
   324 
       
   325 Usage pattern 2:
       
   326 
       
   327 @code
       
   328 RSqlStatement stmt;
       
   329 TInt err = stmt.Prepare(<database>, <SQL statement>);
       
   330 while(<condition>)
       
   331 	{
       
   332 	err = stmt.Bind<parameter type>(<parameter index>, <value>);
       
   333 	...
       
   334 	while((err = stmt.Next()) == KSqlAtRow)
       
   335 		{
       
   336 		....
       
   337 		}
       
   338 	err = stmt.Reset();
       
   339 	}
       
   340 stmt.Close();
       
   341 @endcode
       
   342 
       
   343 @return KErrNone, the reset operation has completed successfully;			
       
   344         KSqlErrStmtExpired, the SQL statement has expired (if new functions or
       
   345                             collating sequences have been registered or if an
       
   346                             authorizer function has been added or changed)
       
   347 
       
   348 @see TSqlRetCodeClass::ESqlDbError
       
   349 @see RSqlDatabase::LastErrorMessage()
       
   350 
       
   351 @capability None
       
   352 */	
       
   353 EXPORT_C TInt RSqlStatement::Reset()
       
   354 	{
       
   355 	SQLUTRACE_PROFILER(this);
       
   356 	return Impl().Reset();
       
   357 	}
       
   358 	
       
   359 /**
       
   360 Executes the prepared DDL/DML SQL statement. 
       
   361 
       
   362 The function is very useful when the SQL statement contains parameters, because
       
   363 the statement can be prepared once using RSqlStatement::Prepare(), and then
       
   364 bound and executed many times.
       
   365 
       
   366 Note that:
       
   367 - parameter values must be bound before calling Exec().
       
   368 - SQL statements that do not have parameters should use RSqlDatabase::Exec() instead.
       
   369 
       
   370 If the call to this function fails because of a database-specific type error 
       
   371 (i.e. the error is categorised as of type ESqlDbError), then a textual description of
       
   372 the error can be obtained calling RSqlDatabase::LastErrorMessage().
       
   373 
       
   374 Usage pattern:
       
   375 
       
   376 @code
       
   377 RSqlStatement stmt;
       
   378 TInt err = stmt.Prepare(<database>, <SQL statement>);
       
   379 while(<condition>)
       
   380 	{
       
   381 	err = stmt.Bind<parameter type>(<parameter index>, <value>);
       
   382 	...
       
   383 	err = stmt.Exec();
       
   384 	....
       
   385 	err = stmt.Reset();
       
   386 	}
       
   387 stmt.Close();
       
   388 @endcode
       
   389 
       
   390 @return >=0, The operation has completed successfully. The number of database rows that were 
       
   391 			 changed/inserted/deleted by the most recently completed DDL/DML sql statement.
       
   392 			 Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0 
       
   393 			 if the operation has completed successfully (disregarding the number of the deleted rows);
       
   394         KSqlErrStmtExpired, the SQL statement has expired (if new functions or
       
   395                             collating sequences have been registered or if an
       
   396                             authorizer function has been added or changed);
       
   397     	KErrDiskFull, There is no available disk space to complete the operation. If the executed statement is a DELETE
       
   398     			  statement, try to use the reserved disk space (if there is a reserved disk space) to complete the operation.
       
   399     			  In all other cases the statement and database connection should be closed and some disk space freed 
       
   400     			  before reopening the database; 
       
   401         KErrNoMemory, an out of memory condition has occurred - the statement
       
   402                       will be reset.
       
   403                       Note that database specific errors categorised as ESqlDbError
       
   404                       can also be returned.
       
   405 
       
   406 @see TSqlRetCodeClass::ESqlDbError
       
   407 @see RSqlStatement::Prepare()
       
   408 @see RSqlDatabase::Exec()
       
   409 @see RSqlDatabase::LastErrorMessage()
       
   410 
       
   411 @capability None
       
   412 */	
       
   413 EXPORT_C TInt RSqlStatement::Exec()
       
   414 	{
       
   415 	SQLUTRACE_PROFILER(this);
       
   416 	return Impl().Exec();
       
   417 	}
       
   418 
       
   419 /**
       
   420 Executes the prepared DDL/DML SQL statement asynchronously to allow client to avoid being blocked 
       
   421 by server activity.
       
   422 
       
   423 No other operations can be performed on current RSqlStatement object 
       
   424 until the asynchronous operation completes.
       
   425 
       
   426 The function is very useful when the SQL statement contains parameters, because
       
   427 the statement can be prepared once using RSqlStatement::Prepare(), and then
       
   428 bound and executed many times.
       
   429 
       
   430 Note that:
       
   431 - parameter values must be bound before calling Exec().
       
   432 - SQL statements that do not have parameters should use RSqlDatabase::Exec() instead.
       
   433 
       
   434 If the call to this function fails because of a database-specific type error 
       
   435 (i.e. the error is categorised as of type ESqlDbError), then a textual description of
       
   436 the error can be obtained calling RSqlDatabase::LastErrorMessage().
       
   437 
       
   438 @param aStatus Completion status of asynchronous request, one of the following:
       
   439 	>=0, The operation has completed successfully. The number of database rows that were 
       
   440 		changed/inserted/deleted by the most recently completed DDL/DML sql statement.
       
   441 		Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0 
       
   442 		if the operation has completed successfully (disregarding the number of the deleted rows);
       
   443 	KSqlErrStmtExpired, the SQL statement has expired (if new functions or 
       
   444 						collating sequences have been registered or if an 
       
   445 						authorizer function has been added or changed);
       
   446 	KErrDiskFull, There is no available disk space to complete the operation. If the executed statement is a DELETE 
       
   447 				statement, try to use the reserved disk space (if there is a reserved disk space) 
       
   448 				to complete the operation.
       
   449 				In all other cases the statement and database connection should be closed and some disk space freed 
       
   450 				before reopening the database; 
       
   451 	KErrNoMemory, an out of memory condition has occurred - the statement 
       
   452 	will be reset.
       
   453 	Note that aStatus may be set with database specific errors categorised as ESqlDbError,
       
   454 	and other system-wide error codes.
       
   455 
       
   456 
       
   457 @see TSqlRetCodeClass::ESqlDbError
       
   458 @see RSqlStatement::Prepare()
       
   459 @see RSqlDatabase::Exec()
       
   460 @see RSqlDatabase::LastErrorMessage()
       
   461 
       
   462 @capability None
       
   463 */	
       
   464 EXPORT_C void RSqlStatement::Exec(TRequestStatus& aStatus)
       
   465 	{
       
   466 	SQLUTRACE_PROFILER(this);
       
   467 	Impl().Exec(aStatus);
       
   468 	}
       
   469 	
       
   470 /**
       
   471 Retrieves a record.
       
   472 
       
   473 If the prepared SQL statement is a "SELECT" statement, and is expected to
       
   474 return a set of records, then this function can be used to retrieve that record data.
       
   475 
       
   476 If the SQL statement contains parameters, then their values must be bound before
       
   477 this function is called.
       
   478 
       
   479 If the call to this function completes successfully, i.e. it returns
       
   480 with KSqlAtRow, then this RSqlStatement object contains the record data, and 
       
   481 this data will remain valid for access until another call is made to any
       
   482 RSqlStatement function.
       
   483 
       
   484 The record data can be accessed using the following functions:
       
   485 - RSqlStatement::ColumnType()
       
   486 - RSqlStatement::ColumnSize()
       
   487 - RSqlStatement::ColumnInt()
       
   488 - RSqlStatement::ColumnInt64()
       
   489 - RSqlStatement::ColumnReal()
       
   490 - RSqlStatement::ColumnTextL()
       
   491 - RSqlStatement::ColumnText()
       
   492 - RSqlStatement::ColumnBinary()
       
   493 - RSqlStatement::ColumnBinaryL()
       
   494 
       
   495 Note that if this call to Next() fails, as indicated by a return code value
       
   496 other than KSqlAtRow, then calls to these RSqlStatement::Column...() functions
       
   497 will raise a panic.
       
   498 
       
   499 @return KSqlAtRow,      the record data is ready for processing by the caller;
       
   500         KSqlAtEnd,      there is no more record data;
       
   501         KSqlErrBusy,    the database file is locked;
       
   502         KErrNoMemory,   an out of memory condition has occurred - the statement
       
   503                         will be reset;
       
   504         KSqlErrGeneral, a run-time error has occured - this function must not
       
   505                         be called again;        
       
   506         KSqlErrMisuse,  this function has been called after a previous call
       
   507                         returned KSqlAtEnd or KSqlErrGeneral.
       
   508         KSqlErrStmtExpired, the SQL statement has expired (if new functions or
       
   509                             collating sequences have been registered or if an
       
   510                             authorizer function has been added or changed);
       
   511 
       
   512 @capability None
       
   513 */	
       
   514 EXPORT_C TInt RSqlStatement::Next()
       
   515 	{
       
   516 	SQLUTRACE_PROFILER(this);
       
   517 	return Impl().Next();
       
   518 	}
       
   519 
       
   520 /**
       
   521 Gets the index (starting from 0) of the parameter with the given name.
       
   522 
       
   523 The function does a case insensitive parameter name search.
       
   524 
       
   525 For example, if the parameter name is ":Prm", then the ":" prefix cannot
       
   526 be omitted when you call ParameterIndex().
       
   527 
       
   528 This function can be called at any time after the SQL statement has been prepared.
       
   529 
       
   530 @param aParameterName The parameter name.
       
   531 
       
   532 @return the parameter index value, if successful - this is a non-negative integer value;
       
   533         KErrNotFound, if no such parameter can be found.
       
   534         One of the other system-wide error codes may also be returned.
       
   535 
       
   536 @capability None
       
   537 */	
       
   538 EXPORT_C TInt RSqlStatement::ParameterIndex(const TDesC& aParameterName) const
       
   539 	{
       
   540 	SQLUTRACE_PROFILER(this);
       
   541 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam16, 1, &aParameterName));
       
   542 
       
   543 	return Impl().ParamIndex(aParameterName);
       
   544 	}
       
   545 
       
   546 /**
       
   547 Gets the number of columns that are to be returned by this SQL statement.
       
   548 
       
   549 This function can be called at any time after the SQL statement has been prepared,
       
   550 but it is useful only for SELECT statements. The column count of any other type of statement is always 0.
       
   551 
       
   552 @return The number of columns.
       
   553 
       
   554 @capability None
       
   555 */	
       
   556 EXPORT_C TInt RSqlStatement::ColumnCount() const
       
   557 	{
       
   558 	SQLUTRACE_PROFILER(this);
       
   559 	return Impl().ColumnCount();
       
   560 	}
       
   561 	
       
   562 /**
       
   563 Gets the index (starting from 0) of the column with the given name.
       
   564 
       
   565 The function does a case insensitive column name search.
       
   566 
       
   567 This function can be called at any time after the SQL statement has been prepared.
       
   568 
       
   569 @param aColumnName The column name.
       
   570 
       
   571 @return the column index value, if successful - this is a non-negative integer value;
       
   572         KErrNotFound, if no such parameter can be found.
       
   573         One of the other system-wide error codes may also be returned.
       
   574 
       
   575 @capability None
       
   576 */	
       
   577 EXPORT_C TInt RSqlStatement::ColumnIndex(const TDesC& aColumnName) const
       
   578 	{
       
   579 	SQLUTRACE_PROFILER(this);
       
   580 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam16, 1, &aColumnName));
       
   581 
       
   582 	return Impl().ColumnIndex(aColumnName);
       
   583 	}
       
   584 	
       
   585 /**
       
   586 Gets the runtime type of the column identified by the specified column index.
       
   587 
       
   588 This function returns the actual runtime datatype of the specified column as 
       
   589 opposed to its declared type.
       
   590   
       
   591 Note that the function can only be called after a successful call to Next(),
       
   592 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
   593 Calling this function after an unsuccessful call to Next() raises a panic.
       
   594 
       
   595 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
   596 
       
   597 @return The column type.
       
   598 
       
   599 @see KSqlAtRow
       
   600 @see TSqlColumnType
       
   601 @see RSqlStatement::DeclaredColumnType()
       
   602 @see RSqlStatement::Next()
       
   603 @see RSqlStatement::ColumnIndex()
       
   604 
       
   605 @panic SqlDb 5 Column index out of bounds.
       
   606 @panic SqlDb 11 Statement cursor not positioned on a row.
       
   607 
       
   608 @capability None
       
   609 */	
       
   610 EXPORT_C TSqlColumnType RSqlStatement::ColumnType(TInt aColumnIndex) const
       
   611 	{
       
   612 	SQLUTRACE_PROFILER(this);
       
   613 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
   614 
       
   615 	return Impl().ColumnType(aColumnIndex);
       
   616 	}
       
   617 
       
   618 /**
       
   619 Gets the declared type of the column identified by the specified column index.
       
   620 
       
   621 Note that the function can only be called when executing a SELECT query, and 
       
   622 only after a successful call to Prepare(). 
       
   623 
       
   624 This function returns the datatype that the specified column was originally declared to have.
       
   625 
       
   626 The declared type of a column is determined according to the following rules:
       
   627 @code
       
   628  - if the column type name contains the string "INT", then the declared column type is ESqlInt;
       
   629  - if the column type name contains any of the strings "CHAR, "TEXT" or "CLOB", then the declared column type is ESqlText;
       
   630  - if the column type name contains any of the strings "BLOB" or "BINARY", then the declared column type is ESqlBinary;
       
   631  - if the column type name contains any of the strings "FLOAT", "REAL" or "DOUBLE", then the declared column type is ESqlReal;
       
   632  - in all other cases the declared column type is assumed to be ESqlInt;
       
   633 @endcode
       
   634 
       
   635 @param aColumnIndex The index value identifying the column. This is 0 for the first column.
       
   636 @param aColumnType	Output parameter. If the call completes successfully, aColumnType contains the type of the column, one of
       
   637 					TSqlColumnType enum item values.
       
   638 
       
   639 @return KErrNone, the operation completed successfully;
       
   640         KErrNoMemory, an out of memory condition has occurred.
       
   641                   One of the other system-wide error codes may also be returned.
       
   642 
       
   643 @see TSqlColumnType
       
   644 @see RSqlStatement::ColumnType()
       
   645 @see RSqlStatement::ColumnIndex()
       
   646 
       
   647 @panic SqlDb 5 Column index out of bounds.
       
   648 
       
   649 @capability None
       
   650 */	
       
   651 EXPORT_C TInt RSqlStatement::DeclaredColumnType(TInt aColumnIndex, TSqlColumnType& aColumnType) const
       
   652 	{
       
   653 	SQLUTRACE_PROFILER(this);
       
   654 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
   655 
       
   656 	return Impl().DeclaredColumnType(aColumnIndex, aColumnType);
       
   657 	}
       
   658 	
       
   659 	
       
   660 	
       
   661 /**
       
   662 Gets the length of the data for the column identified by the specified column index.
       
   663 
       
   664 The length depends on the column type and is normally in bytes, except for
       
   665 the case where the column type is ESqlText, in which case the function returns
       
   666 the number of characters.
       
   667 
       
   668 In detail, the following table shows the size associated with a column type.
       
   669 Note that column types are identified by TSqlColumnType enum values.
       
   670 @code
       
   671 --------------------------------------------------------------
       
   672 | Column type | Column Size                                 
       
   673 --------------------------------------------------------------
       
   674 | ESqlInt.....|.4                                             
       
   675 | ESqlInt64...|.8                                             
       
   676 | ESqlReal....|.8                                             
       
   677 | ESqlText....|.the number of characters in the unicode string
       
   678 | ESqlBinary..|.the byte length of the binary data            
       
   679 | ESqlNull....|.0                                             
       
   680 --------------------------------------------------------------
       
   681 @endcode
       
   682 
       
   683 Note that the function can only be called after a successful call to Next(),
       
   684 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
   685 Calling this function after an unsuccessful call to Next() raises a panic.
       
   686 
       
   687 @param aColumnIndex The column index value; this is 0 for the first column.
       
   688 
       
   689 @return The size of the column, and depends on the type of column.
       
   690 
       
   691 @see KSqlAtRow
       
   692 @see TSqlColumnType
       
   693 @see RSqlStatement::Next()
       
   694 @see RSqlStatement::ColumnIndex()                
       
   695 
       
   696 @panic SqlDb 5 Column index out of bounds.
       
   697 @panic SqlDb 11 Statement cursor not positioned on a row
       
   698 
       
   699 @capability None
       
   700 */	
       
   701 EXPORT_C TInt RSqlStatement::ColumnSize(TInt aColumnIndex) const
       
   702 	{
       
   703 	SQLUTRACE_PROFILER(this);
       
   704 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
   705 
       
   706 	return Impl().ColumnSize(aColumnIndex);
       
   707 	}
       
   708 
       
   709 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   710 ///////////////////////////          Bind<Type>() implemenations           /////////////////////////////
       
   711 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   712 
       
   713 /**
       
   714 Sets the parameter to a NULL value.
       
   715 
       
   716 The parameter is identified by the specified index value.
       
   717 
       
   718 A parameter value can be set:
       
   719 - immediately after this SQL statement has been prepared
       
   720 - after a call to Reset()
       
   721 
       
   722 @param aParamIndex The index value identifying the parameter; this is 0 for the first parameter.
       
   723 
       
   724 @return KErrNone, the operation completed successfully.
       
   725                   One of the other system-wide error codes may also be returned.
       
   726 
       
   727 @see RSqlStatement::Prepare()
       
   728 @see RSqlStatement::Reset()                
       
   729 
       
   730 @panic SqlDb 5 Parameter index out of bounds.
       
   731 
       
   732 @capability None
       
   733 */	
       
   734 EXPORT_C TInt RSqlStatement::BindNull(TInt aParamIndex)
       
   735 	{
       
   736 	SQLUTRACE_PROFILER(this);
       
   737 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aParamIndex));
       
   738 	
       
   739 	return Impl().BindNull(aParamIndex);
       
   740 	}
       
   741 	
       
   742 /**
       
   743 Sets the parameter to the specified 32-bit integer value.
       
   744 
       
   745 The parameter is identified by the specified index value.
       
   746 
       
   747 A parameter value can be set:
       
   748 - immediately after this SQL statement has been prepared
       
   749 - after a call to Reset()
       
   750 
       
   751 @param aParamIndex The index value identifying the parameter; this is 0 for the first parameter.
       
   752 @param aParamValue The 32-bit integer value to be assigned to the parameter.
       
   753 
       
   754 @return KErrNone, the operation completed successfully;
       
   755         KErrNoMemory, an out of memory condition has occurred.
       
   756                   One of the other system-wide error codes may also be returned.
       
   757 
       
   758 @see RSqlStatement::Prepare()
       
   759 @see RSqlStatement::Reset()                
       
   760 
       
   761 @panic SqlDb 5 Parameter index out of bounds.
       
   762 
       
   763 @capability None
       
   764 */	
       
   765 EXPORT_C TInt RSqlStatement::BindInt(TInt aParamIndex, TInt aParamValue)
       
   766 	{
       
   767 	SQLUTRACE_PROFILER(this);
       
   768 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aParamIndex));
       
   769 	
       
   770 	return Impl().BindInt(aParamIndex, aParamValue);
       
   771 	}
       
   772 	
       
   773 /**
       
   774 Sets the parameter to the specified 64-bit integer value.
       
   775 
       
   776 The parameter is identified by the specified index value.
       
   777 
       
   778 A parameter value can be set:
       
   779 - immediately after this SQL statement has been prepared
       
   780 - after a call to Reset()
       
   781 
       
   782 @param aParamIndex The index value identifying the parameter; this is 0 for the first parameter.
       
   783 @param aParamValue The 64-bit integer value to be assigned to the parameter.
       
   784 
       
   785 @return KErrNone, the operation completed successfully;
       
   786         KErrNoMemory, an out of memory condition has occurred.
       
   787                   One of the other system-wide error codes may also be returned.
       
   788 
       
   789 @see RSqlStatement::Prepare()
       
   790 @see RSqlStatement::Reset()                
       
   791 
       
   792 @panic SqlDb 5 Parameter index out of bounds.
       
   793 
       
   794 @capability None
       
   795 */	
       
   796 EXPORT_C TInt RSqlStatement::BindInt64(TInt aParamIndex, TInt64 aParamValue)
       
   797 	{
       
   798 	SQLUTRACE_PROFILER(this);
       
   799 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aParamIndex));
       
   800 	
       
   801 	return Impl().BindInt64(aParamIndex, aParamValue);
       
   802 	}
       
   803 	
       
   804 /**
       
   805 Sets the parameter to the specified 64-bit floating point value.
       
   806 
       
   807 The parameter is identified by the specified index value.
       
   808 
       
   809 A parameter value can be set:
       
   810 - immediately after this SQL statement has been prepared
       
   811 - after a call to Reset()
       
   812 
       
   813 @param aParamIndex The index value identifying the parameter; this is 0 for the first parameter.
       
   814 @param aParamValue The 64-bit floating point value to be assigned to the parameter.
       
   815 
       
   816 @return KErrNone, the operation completed successfully;
       
   817         KErrNoMemory, an out of memory condition has occurred.
       
   818                   One of the other system-wide error codes may also be returned.
       
   819 
       
   820 @see RSqlStatement::Prepare()
       
   821 @see RSqlStatement::Reset()                
       
   822 
       
   823 @panic SqlDb 5 Parameter index out of bounds.
       
   824 
       
   825 @capability None
       
   826 */	
       
   827 EXPORT_C TInt RSqlStatement::BindReal(TInt aParamIndex, TReal aParamValue)
       
   828 	{
       
   829 	SQLUTRACE_PROFILER(this);
       
   830 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aParamIndex));
       
   831 
       
   832 	return Impl().BindReal(aParamIndex, aParamValue);
       
   833 	}
       
   834 	
       
   835 /**
       
   836 Sets the parameter to the specified 16-bit descriptor.
       
   837 
       
   838 The parameter is identified by the specified index value.
       
   839 
       
   840 A parameter value can be set:
       
   841 - immediately after this SQL statement has been prepared
       
   842 - after a call to Reset()
       
   843 
       
   844 Note that when the text data to be bound is over 2Mb in size then 
       
   845 use of the RSqlBlobWriteStream or TSqlBlob class should be considered instead. 
       
   846 
       
   847 These classes provide a more RAM-efficient way of writing large amounts of
       
   848 text data to a database, however no conversions are performed on the text data -
       
   849 it is simply stored as a stream of bytes. If the text data is part of a record 
       
   850 to be inserted into a database then BindZeroBlob() should be called on the 
       
   851 INSERT statement to create a placeholder for the text data, whose content 
       
   852 can then be written using the above classes.
       
   853 
       
   854 @param aParamIndex The index value identifying the parameter; this is 0 for the first parameter.
       
   855 @param aParamText  The 16-bit descriptor whose content is to be assigned to the parameter.
       
   856 
       
   857 @return KErrNone, the operation completed successfully;
       
   858         KErrNoMemory, an out of memory condition has occurred.
       
   859                   One of the other system-wide error codes may also be returned.
       
   860 
       
   861 @see RSqlStatement::Prepare()
       
   862 @see RSqlStatement::Reset()
       
   863 @see RSqlStatement::Next()                
       
   864 @see RSqlStatement::Exec()  
       
   865 @see RSqlStatement::BindZeroBlob()  
       
   866 @see RSqlBlobWriteStream
       
   867 @see TSqlBlob  
       
   868 
       
   869 @panic SqlDb 5 Parameter index out of bounds.
       
   870 
       
   871 @capability None
       
   872 */	
       
   873 EXPORT_C TInt RSqlStatement::BindText(TInt aParamIndex, const TDesC& aParamText)
       
   874 	{
       
   875 	SQLUTRACE_PROFILER(this);
       
   876 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntSizeParam, 
       
   877 			aParamIndex, aParamText.Length()));
       
   878 	
       
   879 	return Impl().BindText(aParamIndex, aParamText);
       
   880 	}
       
   881 	
       
   882 /**
       
   883 Sets the parameter to the specified 8-bit descriptor.
       
   884 
       
   885 The parameter is identified by the specified index value.
       
   886 
       
   887 A parameter value can be set:
       
   888 - immediately after this SQL statement has been prepared
       
   889 - after a call to Reset()
       
   890 
       
   891 Note that when the binary data to be bound is over 2Mb in size then it is 
       
   892 recommended that the RSqlBlobWriteStream or TSqlBlob class is used instead. 
       
   893 
       
   894 These classes provide a more RAM-efficient way of writing large amounts of
       
   895 binary data to a database. If the binary data is part of a record to be inserted 
       
   896 into a database then BindZeroBlob() should be called on the INSERT statement to create
       
   897 a placeholder for the binary data, whose content can then be written using the above classes.
       
   898 
       
   899 @param aParamIndex The index value identifying the parameter; this is 0 for the first parameter.
       
   900 @param aParamData  The 8-bit descriptor whose content is to be assigned to the parameter.
       
   901 
       
   902 @return KErrNone, the operation completed successfully;
       
   903         KErrNoMemory, an out of memory condition has occurred.
       
   904                   One of the other system-wide error codes may also be returned.
       
   905 
       
   906 @see RSqlStatement::Prepare()
       
   907 @see RSqlStatement::Reset()
       
   908 @see RSqlStatement::Next()                
       
   909 @see RSqlStatement::Exec()
       
   910 @see RSqlStatement::BindZeroBlob()  
       
   911 @see RSqlBlobWriteStream
       
   912 @see TSqlBlob  
       
   913 
       
   914 @panic SqlDb 5 Parameter index out of bounds.
       
   915 
       
   916 @capability None
       
   917 */	
       
   918 EXPORT_C TInt RSqlStatement::BindBinary(TInt aParamIndex, const TDesC8& aParamData)
       
   919 	{
       
   920 	SQLUTRACE_PROFILER(this);
       
   921 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntSizeParam, 
       
   922 			aParamIndex, aParamData.Length()));
       
   923 	
       
   924 	return Impl().BindBinary(aParamIndex, aParamData);
       
   925 	}
       
   926 	
       
   927 /**
       
   928 Binds a blob of length aBlobSize bytes that is filled with zeroes.
       
   929 
       
   930 The parameter is identified by the specified index value.
       
   931 
       
   932 A parameter value can be set:
       
   933 - immediately after this SQL statement has been prepared
       
   934 - after a call to Reset()
       
   935 
       
   936 A zeroblob acts as a placeholder for a blob whose binary content is later written
       
   937 using the RSqlBlobWriteStream or TSqlBlob class. 
       
   938 
       
   939 Using zeroblobs provides a much more RAM-efficient way of creating large blobs than 
       
   940 including the blob data in the INSERT statement and it is recommended for blobs that
       
   941 are over 2Mb in size.
       
   942 
       
   943 Note that a zeroblob should be created in a column after which there are no columns 
       
   944 that contain anything other than zeroblobs or NULLs, otherwise the zeroblob must be 
       
   945 allocated in full in RAM and its benefit is lost.
       
   946 
       
   947 When creating a zeroblob it is recommended, where possible, to create the zeroblob 
       
   948 and then write the blob content (using the RSqlBlobWriteStream or TSqlBlob class) 
       
   949 within the same transaction. Otherwise the zeroblob will have to be journalled 
       
   950 before being written to.
       
   951 
       
   952 @param aParamIndex The index value identifying the parameter; this is 0 for the first parameter.
       
   953 @param aBlobSize  The size in bytes of the blob.
       
   954 
       
   955 @return KErrNone, the operation completed successfully;
       
   956         KErrNoMemory, an out of memory condition has occurred.
       
   957                   One of the other system-wide error codes may also be returned.
       
   958 
       
   959 @see RSqlStatement::Prepare()
       
   960 @see RSqlStatement::Reset()
       
   961 @see RSqlStatement::Next()                
       
   962 @see RSqlStatement::Exec()   
       
   963 @see RSqlBlobWriteStream
       
   964 @see TSqlBlob 
       
   965 
       
   966 @panic SqlDb 5 Parameter index out of bounds.
       
   967 
       
   968 @capability None
       
   969 */	
       
   970 EXPORT_C TInt RSqlStatement::BindZeroBlob(TInt aParamIndex, TInt aBlobSize)
       
   971 	{
       
   972 	SQLUTRACE_PROFILER(this);
       
   973 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntSizeParam, 
       
   974 			aParamIndex, aBlobSize));
       
   975 	
       
   976 	return Impl().BindZeroBlob(aParamIndex, aBlobSize);
       
   977 	}
       
   978 
       
   979 
       
   980 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   981 ///////////////////////////          Column<Type>() implemenations           ///////////////////////////
       
   982 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   983 
       
   984 /**
       
   985 Tests whether the value of the specified column is NULL.
       
   986 
       
   987 The column is identified by the specified index value.
       
   988 
       
   989 Note that the function can only be called after a successful call to Next(),
       
   990 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
   991 Calling this function after an unsuccessful call to Next() raises a panic.
       
   992 
       
   993 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
   994 
       
   995 @return True, if the value of the column is NULL, false otherwise.
       
   996 
       
   997 @see KSqlAtRow
       
   998 @see RSqlStatement::Prepare()
       
   999 @see RSqlStatement::Next()                
       
  1000 
       
  1001 @panic SqlDb 5 Column index out of bounds.
       
  1002 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1003 
       
  1004 @capability None
       
  1005 */	
       
  1006 EXPORT_C TBool RSqlStatement::IsNull(TInt aColumnIndex) const
       
  1007 	{
       
  1008 	SQLUTRACE_PROFILER(this);
       
  1009 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1010 
       
  1011 	return Impl().ColumnType(aColumnIndex) == ESqlNull;
       
  1012 	}
       
  1013 
       
  1014 /**
       
  1015 Gets the value of the column as a 32-bit integer.
       
  1016 
       
  1017 The column is identified by the specified index value.
       
  1018 
       
  1019 Note that the function can only be called after a successful call to Next(),
       
  1020 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1021 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1022 
       
  1023 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1024 
       
  1025 @return The value of the column as a 32-bit integer.
       
  1026 
       
  1027 @see KSqlAtRow
       
  1028 @see RSqlStatement::Prepare()
       
  1029 @see RSqlStatement::Next()                
       
  1030 
       
  1031 @panic SqlDb 5 Column index out of bounds.
       
  1032 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1033 
       
  1034 @capability None
       
  1035 */	
       
  1036 EXPORT_C TInt RSqlStatement::ColumnInt(TInt aColumnIndex) const
       
  1037 	{
       
  1038 	SQLUTRACE_PROFILER(this);
       
  1039 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1040 
       
  1041 	return Impl().ColumnInt(aColumnIndex);
       
  1042 	}
       
  1043 	
       
  1044 /**
       
  1045 Gets the value of the column as a 64-bit integer.
       
  1046 
       
  1047 The column is identified by the specified index value.
       
  1048 
       
  1049 Note that the function can only be called after a successful call to Next(),
       
  1050 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1051 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1052 
       
  1053 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1054 
       
  1055 @return The value of the column as a 64-bit integer.
       
  1056 
       
  1057 @see KSqlAtRow
       
  1058 @see RSqlStatement::Prepare()
       
  1059 @see RSqlStatement::Next()                
       
  1060 
       
  1061 @panic SqlDb 5 Column index out of bounds.
       
  1062 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1063 
       
  1064 @capability None
       
  1065 */	
       
  1066 EXPORT_C TInt64 RSqlStatement::ColumnInt64(TInt aColumnIndex) const
       
  1067 	{
       
  1068 	SQLUTRACE_PROFILER(this);
       
  1069 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1070 
       
  1071 	return Impl().ColumnInt64(aColumnIndex);
       
  1072 	}
       
  1073 	
       
  1074 /**
       
  1075 Gets the value of the column as a 64-bit floating point value.
       
  1076 
       
  1077 The column is identified by the specified index value.
       
  1078 
       
  1079 Note that the function can only be called after a successful call to Next(),
       
  1080 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1081 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1082 
       
  1083 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1084 
       
  1085 @return The value of the column as a 64-bit floating point value.
       
  1086 
       
  1087 @see KSqlAtRow
       
  1088 @see RSqlStatement::Prepare()
       
  1089 @see RSqlStatement::Next()                
       
  1090 
       
  1091 @panic SqlDb 5 Column index out of bounds.
       
  1092 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1093 
       
  1094 @capability None
       
  1095 */	
       
  1096 EXPORT_C TReal RSqlStatement::ColumnReal(TInt aColumnIndex) const
       
  1097 	{
       
  1098 	SQLUTRACE_PROFILER(this);
       
  1099 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1100 
       
  1101 	return Impl().ColumnReal(aColumnIndex);
       
  1102 	}
       
  1103 
       
  1104 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1105 ///////////////////////////          ColumnText ()           ///////////////////////////////////////////
       
  1106 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1107 
       
  1108 /**
       
  1109 Gets the value of the column as a 16-bit descriptor (leaves on failure).
       
  1110 
       
  1111 The column is identified by the specified index value.
       
  1112 
       
  1113 Note that the function can only be called after a successful call to Next(),
       
  1114 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1115 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1116 
       
  1117 Note that when the text to be retrieved is over 2Mb in size then it is 
       
  1118 recommended that the RSqlBlobReadStream or TSqlBlob class is used instead. 
       
  1119 These classes provide a more RAM-efficient way of retrieving large amounts 
       
  1120 of text data from a database.
       
  1121 
       
  1122 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1123 
       
  1124 @return A non-modifiable pointer descriptor representing the 16-bit column text.
       
  1125 
       
  1126 @leave KErrNoMemory if the operation for retrieving the column value from the server
       
  1127                     fails with an out of memory condition.
       
  1128 
       
  1129 @see KSqlAtRow
       
  1130 @see RSqlStatement::ColumnText()
       
  1131 @see RSqlStatement::Prepare()
       
  1132 @see RSqlStatement::Next() 
       
  1133 @see RSqlBlobReadStream
       
  1134 @see TSqlBlob 
       
  1135 
       
  1136 @panic SqlDb 5 Column index out of bounds.
       
  1137 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1138 
       
  1139 @capability None
       
  1140 */
       
  1141 EXPORT_C TPtrC RSqlStatement::ColumnTextL(TInt aColumnIndex) const
       
  1142 	{
       
  1143 	SQLUTRACE_PROFILER(this);
       
  1144 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1145 
       
  1146 	TPtrC res;
       
  1147 	__SQLLEAVE_IF_ERROR(Impl().ColumnText(aColumnIndex, res));
       
  1148 	return res;
       
  1149 	}
       
  1150 
       
  1151 /**
       
  1152 Gets the value of the column as a 16-bit descriptor.
       
  1153 
       
  1154 The column is identified by the specified index value.
       
  1155 
       
  1156 Note that the function can only be called after a successful call to Next(),
       
  1157 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1158 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1159 
       
  1160 Note that when the text to be retrieved is over 2Mb in size then it is 
       
  1161 recommended that the RSqlBlobReadStream or TSqlBlob class is used instead. 
       
  1162 These classes provide a more RAM-efficient way of retrieving large amounts 
       
  1163 of text data from a database.
       
  1164 
       
  1165 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1166 @param aPtr         A non-modifiable pointer descriptor. On successful completion of this
       
  1167                     function, the pointer descriptor represents the 16-bit column text.
       
  1168                     The descriptor does not change if the function fails.
       
  1169 
       
  1170 @return KErrNone, if the function completes successfully,
       
  1171                   otherwise one of the other system-wide error codes.
       
  1172 
       
  1173 @see KSqlAtRow
       
  1174 @see RSqlStatement::ColumnTextL()
       
  1175 @see RSqlStatement::Prepare()
       
  1176 @see RSqlStatement::Next()   
       
  1177 @see RSqlBlobReadStream
       
  1178 @see TSqlBlob
       
  1179 
       
  1180 @panic SqlDb 5 Column index out of bounds.
       
  1181 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1182 
       
  1183 @capability None
       
  1184 */	
       
  1185 EXPORT_C TInt RSqlStatement::ColumnText(TInt aColumnIndex, TPtrC& aPtr) const
       
  1186 	{
       
  1187 	SQLUTRACE_PROFILER(this);
       
  1188 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1189 
       
  1190 	return Impl().ColumnText(aColumnIndex, aPtr);
       
  1191 	}
       
  1192 	
       
  1193 /**
       
  1194 Interprets the value of the column as a 16-bit descriptor, and copies the data
       
  1195 into a 16-bit modifiable descriptor supplied by the caller.
       
  1196 
       
  1197 The column is identified by the specified index value.
       
  1198 
       
  1199 Note that the function can only be called after a successful call to Next(),
       
  1200 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1201 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1202 
       
  1203 Note that when the text to be retrieved is over 2Mb in size then it is 
       
  1204 recommended that the RSqlBlobReadStream or TSqlBlob class is used instead. 
       
  1205 These classes provide a more RAM-efficient way of retrieving large amounts 
       
  1206 of text data from a database.
       
  1207 
       
  1208 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1209 @param aDest        A 16-bit modifiable descriptor into which the column data is to be copied.
       
  1210 
       
  1211 @return KErrNone,     the operation has completed successfully;
       
  1212         KErrOverflow, the maximum length of the target descriptor supplied by
       
  1213                       the caller (aDest) is less than the length of
       
  1214                       the column text - the column data
       
  1215                       is truncated to fit into the target descriptor.
       
  1216         KErrNoMemory, an out of memory condition has occurred.
       
  1217 
       
  1218 @see KSqlAtRow
       
  1219 @see RSqlStatement::Prepare()
       
  1220 @see RSqlStatement::Next()   
       
  1221 @see RSqlBlobReadStream
       
  1222 @see TSqlBlob
       
  1223 
       
  1224 @panic SqlDb 5 Column index out of bounds.
       
  1225 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1226 
       
  1227 @capability None
       
  1228 */	
       
  1229 EXPORT_C TInt RSqlStatement::ColumnText(TInt aColumnIndex, TDes& aDest) const
       
  1230 	{
       
  1231 	SQLUTRACE_PROFILER(this);
       
  1232 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1233 
       
  1234 	return Impl().ColumnText(aColumnIndex, aDest);
       
  1235 	}
       
  1236 
       
  1237 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1238 ///////////////////////////          ColumnBinary ()           /////////////////////////////////////////
       
  1239 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1240 	
       
  1241 /**
       
  1242 Gets the value of the column as an 8-bit descriptor (leaves on failure).
       
  1243 
       
  1244 The column is identified by the specified index value.
       
  1245 
       
  1246 Note that the function can only be called after a successful call to Next(),
       
  1247 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1248 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1249 
       
  1250 Note that when the binary data to be retrieved is over 2Mb in size then it 
       
  1251 is recommended that the RSqlBlobReadStream or TSqlBlob class is used instead. 
       
  1252 These classes provide a more RAM-efficient way of retrieving large amounts 
       
  1253 of binary data from a database.
       
  1254 
       
  1255 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1256 
       
  1257 @return A non-modifiable pointer descriptor representing the 8-bit column data.
       
  1258 
       
  1259 @leave KErrNoMemory if the operation for retrieving the column value from the server
       
  1260                     fails with an out of memory condition.
       
  1261 
       
  1262 @see KSqlAtRow
       
  1263 @see RSqlStatement::ColumnBinary()
       
  1264 @see RSqlStatement::Prepare()
       
  1265 @see RSqlStatement::Next()   
       
  1266 @see RSqlBlobReadStream
       
  1267 @see TSqlBlob
       
  1268 
       
  1269 @panic SqlDb 5 Column index out of bounds.
       
  1270 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1271 
       
  1272 @capability None
       
  1273 */
       
  1274 EXPORT_C TPtrC8 RSqlStatement::ColumnBinaryL(TInt aColumnIndex) const
       
  1275 	{
       
  1276 	SQLUTRACE_PROFILER(this);
       
  1277 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1278 
       
  1279 	TPtrC8 res;
       
  1280 	__SQLLEAVE_IF_ERROR(Impl().ColumnBinary(aColumnIndex, res));
       
  1281 	return res;
       
  1282 	}
       
  1283 
       
  1284 /**
       
  1285 Gets the value of the column as an 8-bit descriptor.
       
  1286 
       
  1287 The column is identified by the specified index value.
       
  1288 
       
  1289 Note that the function can only be called after a successful call to Next(),
       
  1290 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1291 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1292 
       
  1293 Note that when the binary data to be retrieved is over 2Mb in size then it 
       
  1294 is recommended that the RSqlBlobReadStream or TSqlBlob class is used instead. 
       
  1295 These classes provide a more RAM-efficient way of retrieving large amounts 
       
  1296 of binary data from a database.
       
  1297 
       
  1298 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1299 @param aPtr         A non-modifiable pointer descriptor. On successful completion of this
       
  1300                     function, the pointer descriptor represents the 8-bit column data.
       
  1301                     The descriptor does not change if the function fails.
       
  1302 
       
  1303 @return KErrNone, if the function completes successfully,
       
  1304                   otherwise one of the other system-wide error codes.
       
  1305 
       
  1306 @see KSqlAtRow
       
  1307 @see RSqlStatement::ColumnBinaryL()
       
  1308 @see RSqlStatement::Prepare()
       
  1309 @see RSqlStatement::Next()   
       
  1310 @see RSqlBlobReadStream
       
  1311 @see TSqlBlob
       
  1312 
       
  1313 @panic SqlDb 5 Column index out of bounds.
       
  1314 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1315 
       
  1316 @capability None
       
  1317 */	
       
  1318 EXPORT_C TInt RSqlStatement::ColumnBinary(TInt aColumnIndex, TPtrC8& aPtr) const
       
  1319 	{
       
  1320 	SQLUTRACE_PROFILER(this);
       
  1321 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1322 
       
  1323    	return Impl().ColumnBinary(aColumnIndex, aPtr);
       
  1324 	}
       
  1325 	
       
  1326 /**
       
  1327 Interprets the value of the column as an 8-bit descriptor, and copies the data
       
  1328 into an 8-bit modifiable descriptor supplied by the caller.
       
  1329 
       
  1330 The column is identified by the specified index value.
       
  1331 
       
  1332 Note that the function can only be called after a successful call to Next(),
       
  1333 i.e. after a call to Next() that has completed with a KSqlAtRow return code.
       
  1334 Calling this function after an unsuccessful call to Next() raises a panic.
       
  1335 
       
  1336 Note that when the binary data to be retrieved is over 2Mb in size then it 
       
  1337 is recommended that the RSqlBlobReadStream or TSqlBlob class is used instead. 
       
  1338 These classes provide a more RAM-efficient way of retrieving large amounts 
       
  1339 of binary data from a database.
       
  1340 
       
  1341 @param aColumnIndex The index value identifying the column; this is 0 for the first column.
       
  1342 @param aDest        An 8-bit modifiable descriptor into which the column data is to be copied.
       
  1343 
       
  1344 @return KErrNone,     the operation has completed successfully;
       
  1345         KErrOverflow, the maximum length of the target descriptor supplied by
       
  1346                       the caller (aDest) is less than the length of
       
  1347                       the column data - the column data
       
  1348                       is truncated to fit into the target descriptor.
       
  1349         KErrNoMemory, an out of memory condition has occurred.
       
  1350 
       
  1351 @see KSqlAtRow
       
  1352 @see RSqlStatement::Prepare()
       
  1353 @see RSqlStatement::Next()   
       
  1354 @see RSqlBlobReadStream
       
  1355 @see TSqlBlob
       
  1356 
       
  1357 @panic SqlDb 5 Column index out of bounds.
       
  1358 @panic SqlDb 11 Statement cursor not positioned on a row
       
  1359 
       
  1360 @capability None
       
  1361 */	
       
  1362 EXPORT_C TInt RSqlStatement::ColumnBinary(TInt aColumnIndex, TDes8& aDest) const
       
  1363 	{
       
  1364 	SQLUTRACE_PROFILER(this);
       
  1365 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1366 	
       
  1367    	return Impl().ColumnBinary(aColumnIndex, aDest);
       
  1368 	}
       
  1369 
       
  1370 /**
       
  1371 Obtain the name of a column after preparing a query.
       
  1372 
       
  1373 @param aColumnIndex Column index
       
  1374 @param aNameDest Descriptor which will be set to column name
       
  1375 @return KErrNone if successfull or one of the system-wide error codes on error
       
  1376 @capability None
       
  1377 */
       
  1378 EXPORT_C TInt RSqlStatement::ColumnName(TInt aColumnIndex, TPtrC& aNameDest)
       
  1379 	{
       
  1380 	SQLUTRACE_PROFILER(this);
       
  1381 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aColumnIndex));
       
  1382 	
       
  1383 	return Impl().ColumnName(aColumnIndex, aNameDest);
       
  1384 	}
       
  1385 
       
  1386 /**
       
  1387 Obtain the name of a parameter after preparing a DML query.
       
  1388 The parameter names are returned in exactly the same form as
       
  1389 supplied in SQL statement. For example, if the parameter name is ":Prm", 
       
  1390 then the ":" prefix will not be omitted.
       
  1391 
       
  1392 This function can be called at any time after the DML SQL statement has been prepared.
       
  1393 
       
  1394 @param aParameterIndex Parameter index
       
  1395 @param aNameDest Descriptor which will be set to column name
       
  1396 @return KErrNone if successfull or one of the system-wide error codes on error
       
  1397 @capability None
       
  1398 */
       
  1399 EXPORT_C TInt RSqlStatement::ParameterName(TInt aParameterIndex, TPtrC& aNameDest)
       
  1400 	{
       
  1401 	SQLUTRACE_PROFILER(this);
       
  1402 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KIntParam, 1, aParameterIndex));
       
  1403 	
       
  1404 	return Impl().ParameterName(aParameterIndex, aNameDest);
       
  1405 	}
       
  1406 
       
  1407 /**
       
  1408 Obtain the name of a parameter after preparing a DML query.
       
  1409 The parameter names are returned in exactly the same form as
       
  1410 supplied in SQL statement. For example, if the parameter name is ":Prm", 
       
  1411 then the ":" prefix will not be omitted.
       
  1412 
       
  1413 ParamName has the same behaviour as ParameterName. It is provided to maintain
       
  1414 source compatibility with previous Symbian releases.
       
  1415 
       
  1416 This function can be called at any time after the DML SQL statement has 
       
  1417 been prepared.
       
  1418 
       
  1419 @param aParameterIndex Parameter index
       
  1420 @param aNameDest Descriptor which will be set to parameter name
       
  1421 @return KErrNone if successful or one of the system-wide error codes on error
       
  1422 @capability None
       
  1423 */
       
  1424 EXPORT_C TInt RSqlStatement::ParamName(TInt aParameterIndex, TPtrC& aNameDest)
       
  1425 	{
       
  1426 	return ParameterName(aParameterIndex, aNameDest);
       
  1427 	}
       
  1428 
       
  1429 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1430 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1431 ////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1432 	
       
  1433 /**
       
  1434 Returns a reference to the implementation object of RSqlStatement - CSqlStatementImpl.
       
  1435 
       
  1436 @panic SqlDb 2  The SQL statement has not been prepared,
       
  1437                 i.e. Prepare() has not yet been called on this RSqlStatement object.
       
  1438 
       
  1439 @internalComponent
       
  1440 */
       
  1441 CSqlStatementImpl& RSqlStatement::Impl() const
       
  1442 	{
       
  1443 	__SQLASSERT_ALWAYS(iImpl != NULL, ESqlPanicInvalidObj);
       
  1444 	return *iImpl;	
       
  1445 	}