persistentstorage/sql/SRC/Server/SqlSrvStatement.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 // NTT DOCOMO, INC - Fix for defect 1915 "SQL server panics when using long column type strings"
    12 // NTT DOCOMO, INC - Fix for Bug 1915 "SQL server panics when using long column type strings"
    13 //
    13 //
    14 // Description:
    14 // Description:
    15 //
    15 //
    16 
    16 
    17 #include <utf.h>					//CnvUtfConverter
    17 #include <utf.h>					//CnvUtfConverter
    19 #include "SqliteSymbian.h"			//sqlite3SymbianLastOsError()
    19 #include "SqliteSymbian.h"			//sqlite3SymbianLastOsError()
    20 #include "sqlite3.h"
    20 #include "sqlite3.h"
    21 #include "SqlSrvStatement.h"
    21 #include "SqlSrvStatement.h"
    22 #include "SqlBufIterator.h"			//TSqlBufRIterator
    22 #include "SqlBufIterator.h"			//TSqlBufRIterator
    23 #include "SqlSrvResourceProfiler.h"
    23 #include "SqlSrvResourceProfiler.h"
    24 #include "OstTraceDefinitions.h"
    24 #include "UTraceSql.h"
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "SqlSrvStatementTraces.h"
       
    27 #endif
       
    28 #include "SqlTraceDef.h"
       
    29 
       
    30 //////////////////////////////////////////////////////////////////////////////////////////////////////
    25 //////////////////////////////////////////////////////////////////////////////////////////////////////
    31 /////////////////////////////      local const data       ////////////////////////////////////////////
    26 /////////////////////////////      local const data       ////////////////////////////////////////////
    32 //////////////////////////////////////////////////////////////////////////////////////////////////////
    27 //////////////////////////////////////////////////////////////////////////////////////////////////////
    33 
    28 
    34 //This is the name prefix which will be given to the nameless parameters.
    29 //This is the name prefix which will be given to the nameless parameters.
   140 
   135 
   141 @panic SqlDb 4 In _DEBUG mode if aSqlStmt is not zero-terminated string.
   136 @panic SqlDb 4 In _DEBUG mode if aSqlStmt is not zero-terminated string.
   142 */	
   137 */	
   143 CSqlSrvStatement* CSqlSrvStatement::NewLC(sqlite3* aDbHandle, const TDesC16& aSqlStmt, TInt& aColumnCount, TInt& aParamCount)
   138 CSqlSrvStatement* CSqlSrvStatement::NewLC(sqlite3* aDbHandle, const TDesC16& aSqlStmt, TInt& aColumnCount, TInt& aParamCount)
   144 	{
   139 	{
   145     __SQLTRACE_INTERNALSEXPR(TPtrC sqlprnptr(aSqlStmt.Left(aSqlStmt.Length() - 1)));
   140 	__SQLASSERT(aSqlStmt.Length() > 0 ? (TInt)aSqlStmt[aSqlStmt.Length() - 1] == 0 : ETrue, ESqlPanicBadArgument);
   146     SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVSTATEMENT_NEWLC_ENTRY, "Entry;0;CSqlSrvStatement::NewLC-16;aDbHandle=0x%X;aSqlStmt=%S", (TUint)aDbHandle, __SQLPRNSTR(sqlprnptr)));
       
   147 	__ASSERT_DEBUG(aSqlStmt.Length() > 0 ? (TInt)aSqlStmt[aSqlStmt.Length() - 1] == 0 : ETrue, __SQLPANIC2(ESqlPanicBadArgument));
       
   148 	
   141 	
   149 	CSqlSrvStatement* self = new (ELeave) CSqlSrvStatement;
   142 	CSqlSrvStatement* self = new (ELeave) CSqlSrvStatement;
   150 	CleanupStack::PushL(self);
   143 	CleanupStack::PushL(self);
   151 	self->ConstructL(aDbHandle, aSqlStmt);
   144 	self->ConstructL(aDbHandle, aSqlStmt);
       
   145 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KSrvStmtCreated, self));
   152 	aColumnCount = self->iColumnCount;
   146 	aColumnCount = self->iColumnCount;
   153 	aParamCount = self->iParamCount;
   147 	aParamCount = self->iParamCount;
   154 	SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, CSQLSRVSTATEMENT_NEWLC_EXIT, "Exit;0x%X;CSqlSrvStatement::NewLC-16;iStmtHandle=0x%X;aColumnCount=%d;aParamCount=%d", (TUint)self, (TUint)self->iStmtHandle, aColumnCount, aParamCount));
       
   155 	return self;
   148 	return self;
   156 	}
   149 	}
   157 	
   150 	
   158 /**
   151 /**
   159 Creates a new CSqlSrvStatement instance.
   152 Creates a new CSqlSrvStatement instance.
   174 
   167 
   175 @panic SqlDb 4 In _DEBUG mode if aSqlStmt is not zero-terminated string.
   168 @panic SqlDb 4 In _DEBUG mode if aSqlStmt is not zero-terminated string.
   176 */	
   169 */	
   177 CSqlSrvStatement* CSqlSrvStatement::NewLC(sqlite3* aDbHandle, const TDesC8& aSqlStmt, TInt& aColumnCount, TInt& aParamCount)
   170 CSqlSrvStatement* CSqlSrvStatement::NewLC(sqlite3* aDbHandle, const TDesC8& aSqlStmt, TInt& aColumnCount, TInt& aParamCount)
   178 	{
   171 	{
   179     __SQLTRACE_INTERNALSEXPR(TPtrC8 sqlprnptr(aSqlStmt.Left(aSqlStmt.Length() - 1)));
   172 	__SQLASSERT(aSqlStmt.Length() > 0 ? (TInt)aSqlStmt[aSqlStmt.Length() - 1] == 0 : ETrue, ESqlPanicBadArgument);
   180 	__SQLTRACE_INTERNALSVAR(TBuf<100> des16prnbuf);
       
   181     SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVSTATEMENT_NEWLC_ENTRY2, "Entry;0;CSqlSrvStatement::NewLC-8;aDbHandle=0x%X;aSqlStmt=%s", (TUint)aDbHandle, __SQLPRNSTR8(sqlprnptr, des16prnbuf)));
       
   182 	__ASSERT_DEBUG(aSqlStmt.Length() > 0 ? (TInt)aSqlStmt[aSqlStmt.Length() - 1] == 0 : ETrue, __SQLPANIC2(ESqlPanicBadArgument));
       
   183 
   173 
   184 	CSqlSrvStatement* self = new (ELeave) CSqlSrvStatement;
   174 	CSqlSrvStatement* self = new (ELeave) CSqlSrvStatement;
   185 	CleanupStack::PushL(self);
   175 	CleanupStack::PushL(self);
   186 	self->ConstructL(aDbHandle, aSqlStmt);
   176 	self->ConstructL(aDbHandle, aSqlStmt);
       
   177 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KSrvStmtCreated, self));
   187 	aColumnCount = self->iColumnCount;
   178 	aColumnCount = self->iColumnCount;
   188 	aParamCount = self->iParamCount;
   179 	aParamCount = self->iParamCount;
   189 	SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, CSQLSRVSTATEMENT_NEWLC_EXIT2, "Exit;0x%X;CSqlSrvStatement::NewLC-8;iStmtHandle=0x%X;aColumnCount=%d;aParamCount=%d", (TUint)self, (TUint)self->iStmtHandle, aColumnCount, aParamCount));
       
   190 	return self;
   180 	return self;
   191 	}
   181 	}
   192 	
   182 	
   193 /**
   183 /**
   194 Destroys the allocated by CSqlSrvStatement instance memory and other resources.
   184 Destroys the allocated by CSqlSrvStatement instance memory and other resources.
   195 */	
   185 */	
   196 CSqlSrvStatement::~CSqlSrvStatement()
   186 CSqlSrvStatement::~CSqlSrvStatement()
   197 	{
   187 	{
   198 	SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVSTATEMENT_CSQLSRVSTATEMENT2_ENTRY, "Entry;0x%X;CSqlSrvStatement::~CSqlSrvStatement;iStmtHandle=0x%X", (TUint)this, (TUint)iStmtHandle));
       
   199 	DestroyParamBufArray();
   188 	DestroyParamBufArray();
   200 	iBufFlat.Close();
   189 	iBufFlat.Close();
   201 	if(iStmtHandle)
   190 	if(iStmtHandle)
   202 		{
   191 		{
   203 #ifdef SYMBIAN_USE_SQLITE_VERSION_3_6_4
   192 #ifdef SYMBIAN_TRACE_SQL_EVENTS
   204 		__SQLTRACE_INTERNALSEXPR(TInt scanCount = sqlite3_stmt_status(iStmtHandle, SQLITE_STMTSTATUS_FULLSCAN_STEP, ETrue));
   193 		TInt scanCount = sqlite3_stmt_status(iStmtHandle, SQLITE_STMTSTATUS_FULLSCAN_STEP, ETrue);
   205 		__SQLTRACE_INTERNALSEXPR(TInt sortCount = sqlite3_stmt_status(iStmtHandle, SQLITE_STMTSTATUS_SORT, ETrue));
   194 		TInt sortCount = sqlite3_stmt_status(iStmtHandle, SQLITE_STMTSTATUS_SORT, ETrue);
   206 		SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSRVSTATEMENT_CSQLSRVSTATEMENT2, "0x%X;CSqlSrvStatement::~CSqlSrvStatement;scan count=%d;sort count=%d", (TUint)this, scanCount, sortCount));
   195 		SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KSrvStmtStatus, this, scanCount, sortCount));
   207 #endif		
   196 #endif
   208 		(void)sqlite3_finalize(iStmtHandle);
   197 		(void)sqlite3_finalize(iStmtHandle);
   209 		}
   198 		}
   210 	SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSRVSTATEMENT_CSQLSRVSTATEMENT2_EXIT, "Exit;0x%X;CSqlSrvStatement::~CSqlSrvStatement", (TUint)this));
       
   211 	}
   199 	}
   212 
   200 
   213 /**
   201 /**
   214 Sets SQL statement parameter values.
   202 Sets SQL statement parameter values.
   215 
   203 
   224 
   212 
   225 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   213 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   226 */	
   214 */	
   227 void CSqlSrvStatement::BindL(const RSqlBufFlat& aParamBuf)
   215 void CSqlSrvStatement::BindL(const RSqlBufFlat& aParamBuf)
   228 	{
   216 	{
   229 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   217 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   230 	
   218 	
   231 	(void)sqlite3SymbianLastOsError();//clear last OS error
   219 	(void)sqlite3SymbianLastOsError();//clear last OS error
   232 
   220 
   233 	TSqlBufRIterator it;
   221 	TSqlBufRIterator it;
   234 	it.Set(aParamBuf);
   222 	it.Set(aParamBuf);
   292 
   280 
   293 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   281 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   294 */	
   282 */	
   295 const RSqlBufFlat& CSqlSrvStatement::ColumnNamesL()
   283 const RSqlBufFlat& CSqlSrvStatement::ColumnNamesL()
   296 	{
   284 	{
   297 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   285 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   298 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   286 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   299 	__SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iColumnCount));
   287 	__SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iColumnCount));
   300 	TSqlBufWIterator it;
   288 	TSqlBufWIterator it;
   301 	it.Set(iBufFlat);
   289 	it.Set(iBufFlat);
   302 	TInt colIdx = -1;
   290 	TInt colIdx = -1;
   321 
   309 
   322 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   310 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   323 */	
   311 */	
   324 const RSqlBufFlat& CSqlSrvStatement::ParamNamesL()
   312 const RSqlBufFlat& CSqlSrvStatement::ParamNamesL()
   325 	{
   313 	{
   326 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   314 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   327 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   315 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   328 	__SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iParamCount));
   316 	__SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iParamCount));
   329 	TSqlBufWIterator it;
   317 	TSqlBufWIterator it;
   330 	it.Set(iBufFlat);
   318 	it.Set(iBufFlat);
   331 	TInt prmIdx = 0;
   319 	TInt prmIdx = 0;
   363 
   351 
   364 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object
   352 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object
   365 */	
   353 */	
   366 const RSqlBufFlat& CSqlSrvStatement::ColumnValuesL()
   354 const RSqlBufFlat& CSqlSrvStatement::ColumnValuesL()
   367 	{
   355 	{
   368 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   356 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   369 	
   357 	
   370 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   358 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   371 	iBufFlat.SetCount(iColumnCount);
   359 	iBufFlat.SetCount(iColumnCount);
   372 	TSqlBufWIterator it;
   360 	TSqlBufWIterator it;
   373 	it.Set(iBufFlat);
   361 	it.Set(iBufFlat);
   403 					}
   391 					}
   404 				else
   392 				else
   405 					{//sqlite3_column_bytes16() already allocated the needed memory if a UTF8->UTF16 conversion
   393 					{//sqlite3_column_bytes16() already allocated the needed memory if a UTF8->UTF16 conversion
   406                      //had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed.
   394                      //had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed.
   407 					const TUint16* text = reinterpret_cast <const TUint16*> (sqlite3_column_text16(iStmtHandle, colIdx));
   395 					const TUint16* text = reinterpret_cast <const TUint16*> (sqlite3_column_text16(iStmtHandle, colIdx));
   408 					__ASSERT_DEBUG(text != NULL, __SQLPANIC(ESqlPanicInternalError));
   396 					__SQLASSERT(text != NULL, ESqlPanicInternalError);
   409 					__SQLLEAVE_IF_ERROR(it.SetText(TPtrC16(text, charLength)));
   397 					__SQLLEAVE_IF_ERROR(it.SetText(TPtrC16(text, charLength)));
   410 					}
   398 					}
   411 				}
   399 				}
   412 				break;
   400 				break;
   413 			case SQLITE_BLOB:
   401 			case SQLITE_BLOB:
   425 				break;
   413 				break;
   426 			case SQLITE_NULL:
   414 			case SQLITE_NULL:
   427 				it.SetNull();
   415 				it.SetNull();
   428 				break;
   416 				break;
   429 			default:
   417 			default:
   430 				__ASSERT_DEBUG(EFalse, __SQLPANIC(ESqlPanicInternalError));
   418 				__SQLASSERT(EFalse, ESqlPanicInternalError);
   431 				break;
   419 				break;
   432 			}//end of switch(...)
   420 			}//end of switch(...)
   433 		}//end of - while(it.Next())
   421 		}//end of - while(it.Next())
   434 	iBufFlatType = ESqlColumnValuesBuf;
   422 	iBufFlatType = ESqlColumnValuesBuf;
   435 	SQLPROFILER_REPORT_ALLOC(iBufFlat.MaxSize());
   423 	SQLPROFILER_REPORT_ALLOC(iBufFlat.MaxSize());
   447 
   435 
   448 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   436 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   449 */	
   437 */	
   450 TInt CSqlSrvStatement::ColumnSource(TInt aColumnIndex, TPtrC8& aColumnSource) const
   438 TInt CSqlSrvStatement::ColumnSource(TInt aColumnIndex, TPtrC8& aColumnSource) const
   451 	{
   439 	{
   452 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   440 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   453 	TInt colType = sqlite3_column_type(iStmtHandle, aColumnIndex);
   441 	TInt colType = sqlite3_column_type(iStmtHandle, aColumnIndex);
   454 	if(colType == SQLITE_TEXT)
   442 	if(colType == SQLITE_TEXT)
   455         {//Since the first called function after the Next() operation is always CSqlSrvStatement::ColumnValuesL(), then
   443         {//Since the first called function after the Next() operation is always CSqlSrvStatement::ColumnValuesL(), then
   456          //sqlite3_column_bytes16() (called from  ColumnValuesL()) already allocated the needed memory if a UTF8->UTF16 
   444          //sqlite3_column_bytes16() (called from  ColumnValuesL()) already allocated the needed memory if a UTF8->UTF16 
   457          //conversion had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed.
   445          //conversion had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed.
   458 		const void* text = sqlite3_column_text16(iStmtHandle, aColumnIndex);
   446 		const void* text = sqlite3_column_text16(iStmtHandle, aColumnIndex);
   459 		__ASSERT_DEBUG(text != NULL, __SQLPANIC2(ESqlPanicInternalError));
   447         __SQLASSERT(text != NULL, ESqlPanicInternalError);
   460  		TInt length  = sqlite3_column_bytes16(iStmtHandle, aColumnIndex);
   448 		TInt length  = sqlite3_column_bytes16(iStmtHandle, aColumnIndex);
   461 		aColumnSource.Set(reinterpret_cast <const TUint8*> (text), length);
   449 		aColumnSource.Set(reinterpret_cast <const TUint8*> (text), length);
   462 		}
   450 		}
   463 	else if(colType == SQLITE_BLOB)
   451 	else if(colType == SQLITE_BLOB)
   464 		{
   452 		{
   465 		const void* data = sqlite3_column_blob(iStmtHandle, aColumnIndex);
   453 		const void* data = sqlite3_column_blob(iStmtHandle, aColumnIndex);
   478 
   466 
   479 @panic SqlDb 4 In _DEBUG mode. aDbHandle is NULL.
   467 @panic SqlDb 4 In _DEBUG mode. aDbHandle is NULL.
   480 */	
   468 */	
   481 void CSqlSrvStatement::DoCommonConstructL()
   469 void CSqlSrvStatement::DoCommonConstructL()
   482 	{
   470 	{
   483 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   471 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   484 	iColumnCount = sqlite3_column_count(iStmtHandle);
   472 	iColumnCount = sqlite3_column_count(iStmtHandle);
   485 	iParamCount = sqlite3_bind_parameter_count(iStmtHandle);
   473 	iParamCount = sqlite3_bind_parameter_count(iStmtHandle);
   486 	__SQLLEAVE_IF_ERROR(iBufFlat.SetCount(Max(iColumnCount, iParamCount)));
   474 	__SQLLEAVE_IF_ERROR(iBufFlat.SetCount(Max(iColumnCount, iParamCount)));
   487 	}
   475 	}
   488 
   476 
   517 @panic SqlDb 4 In _DEBUG mode. No parameter buffer has been created yet for this parameter.
   505 @panic SqlDb 4 In _DEBUG mode. No parameter buffer has been created yet for this parameter.
   518 @panic SqlDb 4 In _DEBUG mode. Parameter index out of bounds.
   506 @panic SqlDb 4 In _DEBUG mode. Parameter index out of bounds.
   519 */
   507 */
   520 void CSqlSrvStatement::BindParamBufL(TInt aParamIndex)
   508 void CSqlSrvStatement::BindParamBufL(TInt aParamIndex)
   521 	{
   509 	{
   522 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   510 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   523 	__ASSERT_DEBUG(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), __SQLPANIC(ESqlPanicBadArgument));
   511 	__SQLASSERT(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), ESqlPanicBadArgument);
   524 	__ASSERT_DEBUG(aParamIndex < iParamBufArray.Count(), __SQLPANIC(ESqlPanicBadArgument));
   512 	__SQLASSERT(aParamIndex < iParamBufArray.Count(), ESqlPanicBadArgument);
   525 	__ASSERT_DEBUG(iParamBufArray[aParamIndex] != NULL, __SQLPANIC(ESqlPanicBadArgument));
   513 	__SQLASSERT(iParamBufArray[aParamIndex] != NULL, ESqlPanicBadArgument);
   526 	(void)sqlite3SymbianLastOsError();//clear last OS error
   514 	(void)sqlite3SymbianLastOsError();//clear last OS error
   527 	//Bind the parameter value.
   515 	//Bind the parameter value.
   528 	//SQLITE_STATIC is used as an argument, because the text/blob data will be kept and can be used by the next bind call
   516 	//SQLITE_STATIC is used as an argument, because the text/blob data will be kept and can be used by the next bind call
   529 	HSqlSrvStmtParamBuf& paramBuf = *iParamBufArray[aParamIndex];
   517 	HSqlSrvStmtParamBuf& paramBuf = *iParamBufArray[aParamIndex];
   530 	const TPtrC8 paramData(paramBuf.Data());
   518 	const TPtrC8 paramData(paramBuf.Data());
   556 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   544 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   557 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   545 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   558 */
   546 */
   559 TInt CSqlSrvStatement::ColumnInt(TInt aColIdx) const
   547 TInt CSqlSrvStatement::ColumnInt(TInt aColIdx) const
   560 	{
   548 	{
   561 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   549 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   562 	__ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument));
   550 	__SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument);
   563 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   551 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   564 	switch(colType)
   552 	switch(colType)
   565 		{
   553 		{
   566 		case SQLITE_FLOAT:
   554 		case SQLITE_FLOAT:
   567 			{
   555 			{
   596 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   584 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   597 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   585 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   598 */
   586 */
   599 TInt64 CSqlSrvStatement::ColumnInt64(TInt aColIdx) const
   587 TInt64 CSqlSrvStatement::ColumnInt64(TInt aColIdx) const
   600 	{
   588 	{
   601 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   589 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   602 	__ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument));
   590 	__SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument);
   603 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   591 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   604 	switch(colType)
   592 	switch(colType)
   605 		{
   593 		{
   606 		case SQLITE_FLOAT:
   594 		case SQLITE_FLOAT:
   607 			{
   595 			{
   633 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   621 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   634 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   622 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   635 */
   623 */
   636 TReal CSqlSrvStatement::ColumnReal(TInt aColIdx) const
   624 TReal CSqlSrvStatement::ColumnReal(TInt aColIdx) const
   637 	{
   625 	{
   638 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   626 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   639 	__ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument));
   627 	__SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument);
   640 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   628 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   641 	switch(colType)
   629 	switch(colType)
   642 		{
   630 		{
   643 		case SQLITE_INTEGER:
   631 		case SQLITE_INTEGER:
   644 			{
   632 			{
   667 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   655 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   668 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   656 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   669 */
   657 */
   670 TPtrC CSqlSrvStatement::ColumnTextL(TInt aColIdx) const
   658 TPtrC CSqlSrvStatement::ColumnTextL(TInt aColIdx) const
   671 	{
   659 	{
   672 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   660 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   673 	__ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument));
   661 	__SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument);
   674 	TPtrC res;
   662 	TPtrC res;
   675 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   663 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   676 	if(colType == SQLITE_TEXT)
   664 	if(colType == SQLITE_TEXT)
   677 		{
   665 		{
   678 		TInt charLength = (TUint)sqlite3_column_bytes16(iStmtHandle, aColIdx) / sizeof(TUint16);
   666 		TInt charLength = (TUint)sqlite3_column_bytes16(iStmtHandle, aColIdx) / sizeof(TUint16);
   683             __SQLLEAVE(KErrNoMemory);
   671             __SQLLEAVE(KErrNoMemory);
   684             }
   672             }
   685         //sqlite3_column_bytes16() already allocated the needed memory if a UTF8->UTF16 conversion
   673         //sqlite3_column_bytes16() already allocated the needed memory if a UTF8->UTF16 conversion
   686         //had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed.
   674         //had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed.
   687         const TUint16* text = reinterpret_cast <const TUint16*> (sqlite3_column_text16(iStmtHandle, aColIdx));
   675         const TUint16* text = reinterpret_cast <const TUint16*> (sqlite3_column_text16(iStmtHandle, aColIdx));
   688         __ASSERT_DEBUG(text != NULL, __SQLPANIC(ESqlPanicInternalError));
   676         __SQLASSERT(text != NULL, ESqlPanicInternalError);
   689  		res.Set(text, charLength);
   677 		res.Set(text, charLength);
   690 		}
   678 		}
   691 	return res;
   679 	return res;
   692 	}
   680 	}
   693 	
   681 	
   694 /**
   682 /**
   702 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   690 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   703 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   691 @panic SqlDb 4 In _DEBUG mode. Invalid aColIdx value.
   704 */
   692 */
   705 TPtrC8 CSqlSrvStatement::ColumnBinary(TInt aColIdx) const
   693 TPtrC8 CSqlSrvStatement::ColumnBinary(TInt aColIdx) const
   706 	{
   694 	{
   707 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   695 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   708 	__ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument));
   696 	__SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument);
   709 	TPtrC8 res;
   697 	TPtrC8 res;
   710 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   698 	TInt colType = sqlite3_column_type(iStmtHandle, aColIdx);
   711 	if(colType == SQLITE_BLOB)
   699 	if(colType == SQLITE_BLOB)
   712 		{
   700 		{
   713 		TInt byteLength = sqlite3_column_bytes(iStmtHandle, aColIdx);
   701 		TInt byteLength = sqlite3_column_bytes(iStmtHandle, aColIdx);
   726 
   714 
   727 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   715 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   728 */
   716 */
   729 const RSqlBufFlat& CSqlSrvStatement::GetDeclColumnTypesL()
   717 const RSqlBufFlat& CSqlSrvStatement::GetDeclColumnTypesL()
   730 	{
   718 	{
   731     __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   719 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   732  	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   720 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   733 	__SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iColumnCount));
   721 	__SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iColumnCount));
   734 	TSqlBufWIterator it;
   722 	TSqlBufWIterator it;
   735 	it.Set(iBufFlat);
   723 	it.Set(iBufFlat);
   736 	TInt colIdx = -1;
   724 	TInt colIdx = -1;
   737 	while(it.Next())
   725 	while(it.Next())
   771 @leave KErrNoMemory, an out of memory condition has occurred;
   759 @leave KErrNoMemory, an out of memory condition has occurred;
   772 */
   760 */
   773 HSqlSrvStmtParamBuf* CSqlSrvStatement::GetParamBufL(TInt aParamIndex, HSqlSrvStmtParamBuf::TDataType aDataType, 
   761 HSqlSrvStmtParamBuf* CSqlSrvStatement::GetParamBufL(TInt aParamIndex, HSqlSrvStmtParamBuf::TDataType aDataType, 
   774 													HSqlSrvStmtParamBuf::TBufType aBufType)
   762 													HSqlSrvStmtParamBuf::TBufType aBufType)
   775 	{
   763 	{
   776 	__ASSERT_DEBUG(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), __SQLPANIC(ESqlPanicBadArgument));
   764 	__SQLASSERT(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), ESqlPanicBadArgument);
   777 	ExtendParamBufArrayL(aParamIndex);
   765 	ExtendParamBufArrayL(aParamIndex);
   778 	HSqlSrvStmtParamBuf*& paramBuf = iParamBufArray[aParamIndex];
   766 	HSqlSrvStmtParamBuf*& paramBuf = iParamBufArray[aParamIndex];
   779 	if(paramBuf)
   767 	if(paramBuf)
   780 		{//Reset and reuse the existing buffer
   768 		{//Reset and reuse the existing buffer
   781 		__ASSERT_DEBUG(paramBuf->ParamIndex() == aParamIndex, __SQLPANIC(ESqlPanicInternalError));
   769 		__SQLASSERT(paramBuf->ParamIndex() == aParamIndex, ESqlPanicInternalError);
   782 		paramBuf->Reset(aDataType, aBufType);	
   770 		paramBuf->Reset(aDataType, aBufType);	
   783 		}
   771 		}
   784 	else
   772 	else
   785 		{
   773 		{
   786 		paramBuf = HSqlSrvStmtParamBuf::NewL(*this, aParamIndex, aDataType, aBufType);
   774 		paramBuf = HSqlSrvStmtParamBuf::NewL(*this, aParamIndex, aDataType, aBufType);
   799 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   787 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   800 @panic SqlDb 4 In _DEBUG mode. Parameter index out of bounds.
   788 @panic SqlDb 4 In _DEBUG mode. Parameter index out of bounds.
   801 */
   789 */
   802 void CSqlSrvStatement::ExtendParamBufArrayL(TInt aParamIndex)
   790 void CSqlSrvStatement::ExtendParamBufArrayL(TInt aParamIndex)
   803 	{
   791 	{
   804 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   792 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   805 	__ASSERT_DEBUG(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), __SQLPANIC(ESqlPanicBadArgument));
   793 	__SQLASSERT(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), ESqlPanicBadArgument);
   806 	TInt ext = aParamIndex - iParamBufArray.Count() + 1;
   794 	TInt ext = aParamIndex - iParamBufArray.Count() + 1;
   807 	while(ext-- > 0)
   795 	while(ext-- > 0)
   808 		{
   796 		{
   809 		__SQLLEAVE_IF_ERROR(iParamBufArray.Append(NULL));
   797 		__SQLLEAVE_IF_ERROR(iParamBufArray.Append(NULL));
   810 		}
   798 		}
   825 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   813 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   826 @panic SqlDb 4 In _DEBUG mode. Parameter index out of bounds.
   814 @panic SqlDb 4 In _DEBUG mode. Parameter index out of bounds.
   827 */
   815 */
   828 TPtrC8 CSqlSrvStatement::CopyAndStoreParamL(TInt aParamIndex, HSqlSrvStmtParamBuf::TDataType aDataType, const TDesC8& aParamValue)
   816 TPtrC8 CSqlSrvStatement::CopyAndStoreParamL(TInt aParamIndex, HSqlSrvStmtParamBuf::TDataType aDataType, const TDesC8& aParamValue)
   829 	{
   817 	{
   830 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   818 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   831 	__ASSERT_DEBUG(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), __SQLPANIC(ESqlPanicBadArgument));
   819 	__SQLASSERT(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), ESqlPanicBadArgument);
   832 	HSqlSrvStmtParamBuf* paramBuf = GetParamBufL(aParamIndex, aDataType, HSqlSrvStmtParamBuf::EBufSimpleBind);
   820 	HSqlSrvStmtParamBuf* paramBuf = GetParamBufL(aParamIndex, aDataType, HSqlSrvStmtParamBuf::EBufSimpleBind);
   833 	return paramBuf->SetDataL(aParamValue);
   821 	return paramBuf->SetDataL(aParamValue);
   834 	}
   822 	}