persistentstorage/sql/SRC/Server/SqlSrvStatement.inl
branchRCL_3
changeset 23 26645d81f48d
parent 21 28839de615b4
child 24 cc28652e0254
equal deleted inserted replaced
21:28839de615b4 23:26645d81f48d
    31  @panic SqlDb 4 In _DEBUG mode. Parameter index negative.
    31  @panic SqlDb 4 In _DEBUG mode. Parameter index negative.
    32 */
    32 */
    33 inline HSqlSrvStmtParamBuf* HSqlSrvStmtParamBuf::NewL(CSqlSrvStatement& aStatement, TInt aParamIndex, 
    33 inline HSqlSrvStmtParamBuf* HSqlSrvStmtParamBuf::NewL(CSqlSrvStatement& aStatement, TInt aParamIndex, 
    34 													  HSqlSrvStmtParamBuf::TDataType aDataType, HSqlSrvStmtParamBuf::TBufType aBufType)
    34 													  HSqlSrvStmtParamBuf::TDataType aDataType, HSqlSrvStmtParamBuf::TBufType aBufType)
    35 	{
    35 	{
    36 	__SQLASSERT(aParamIndex >= 0, ESqlPanicBadArgument);
    36 	__ASSERT_DEBUG(aParamIndex >= 0, __SQLPANIC2(ESqlPanicBadArgument));
    37 	HSqlSrvStmtParamBuf* self = new (ELeave) HSqlSrvStmtParamBuf(aStatement, aParamIndex, aDataType, aBufType);
    37 	HSqlSrvStmtParamBuf* self = new (ELeave) HSqlSrvStmtParamBuf(aStatement, aParamIndex, aDataType, aBufType);
    38 	self->PushL();
    38 	self->PushL();
    39 	self->ConstructL();
    39 	self->ConstructL();
    40 	CleanupStack::Pop();
    40 	CleanupStack::Pop();
    41 	return self;
    41 	return self;
    51 
    51 
    52 @panic SqlDb 2 In _DEBUG mode. Invalid HSqlSrvStmtParamBuf object.
    52 @panic SqlDb 2 In _DEBUG mode. Invalid HSqlSrvStmtParamBuf object.
    53 */
    53 */
    54 inline void HSqlSrvStmtParamBuf::Reset(HSqlSrvStmtParamBuf::TDataType aDataType, HSqlSrvStmtParamBuf::TBufType aBufType)
    54 inline void HSqlSrvStmtParamBuf::Reset(HSqlSrvStmtParamBuf::TDataType aDataType, HSqlSrvStmtParamBuf::TBufType aBufType)
    55 	{
    55 	{
    56 	__SQLASSERT(iBuf != NULL, ESqlPanicInvalidObj);
    56 	__ASSERT_DEBUG(iBuf != NULL, __SQLPANIC(ESqlPanicInvalidObj));
    57 	
    57 	
    58 	iStatementFinalized = EFalse;
    58 	iStatementFinalized = EFalse;
    59 	iAlive = ETrue;
    59 	iAlive = ETrue;
    60 	iDataType = aDataType;
    60 	iDataType = aDataType;
    61 	iBufType = aBufType;
    61 	iBufType = aBufType;
    63 	
    63 	
    64 	iBuf->Delete(0, iBuf->Size());
    64 	iBuf->Delete(0, iBuf->Size());
    65 	if(iBuf->Capacity() > (HSqlSrvStmtParamBuf::EExpandSize * 2))
    65 	if(iBuf->Capacity() > (HSqlSrvStmtParamBuf::EExpandSize * 2))
    66 		{
    66 		{
    67 		TRAPD(err, iBuf->SetReserveL(HSqlSrvStmtParamBuf::EExpandSize * 2));//the buffer size is minimized, the call can't fail
    67 		TRAPD(err, iBuf->SetReserveL(HSqlSrvStmtParamBuf::EExpandSize * 2));//the buffer size is minimized, the call can't fail
    68 		__SQLASSERT_ALWAYS(err == KErrNone, ESqlPanicInternalError);
    68 		__ASSERT_ALWAYS(err == KErrNone, __SQLPANIC(ESqlPanicInternalError));
    69 		}
    69 		}
    70 	Set(*iBuf, 0, MStreamBuf::ERead | MStreamBuf::EWrite);
    70 	Set(*iBuf, 0, MStreamBuf::ERead | MStreamBuf::EWrite);
    71 	}
    71 	}
    72 
    72 
    73 /**
    73 /**
    81 @panic SqlDb 2 In _DEBUG mode. Invalid HSqlSrvStmtParamBuf object.
    81 @panic SqlDb 2 In _DEBUG mode. Invalid HSqlSrvStmtParamBuf object.
    82 @panic SqlDb 7 In _DEBUG mode. The buffer type is not HSqlSrvStmtParamBuf::EBufSimpleBind
    82 @panic SqlDb 7 In _DEBUG mode. The buffer type is not HSqlSrvStmtParamBuf::EBufSimpleBind
    83 */
    83 */
    84 inline const TPtrC8 HSqlSrvStmtParamBuf::SetDataL(const TDesC8& aData)
    84 inline const TPtrC8 HSqlSrvStmtParamBuf::SetDataL(const TDesC8& aData)
    85 	{
    85 	{
    86 	__SQLASSERT(iBuf != NULL, ESqlPanicInvalidObj);
    86 	__ASSERT_DEBUG(iBuf != NULL, __SQLPANIC(ESqlPanicInvalidObj));
    87 	__SQLASSERT(iBufType == HSqlSrvStmtParamBuf::EBufSimpleBind, ESqlPanicInternalError);
    87 	__ASSERT_DEBUG(iBufType == HSqlSrvStmtParamBuf::EBufSimpleBind, __SQLPANIC(ESqlPanicInternalError));
    88 	iBuf->ResizeL(aData.Length());
    88 	iBuf->ResizeL(aData.Length());
    89 	iBuf->Write(0, aData);
    89 	iBuf->Write(0, aData);
    90 	//If the size is 0, then return KNullDesC8, where an empty string is hold, not a null one ("" instead of NULL)
    90 	//If the size is 0, then return KNullDesC8, where an empty string is hold, not a null one ("" instead of NULL)
    91 	return iBuf->Size() == 0 ? KNullDesC8() : iBuf->Ptr(0);
    91 	return iBuf->Size() == 0 ? KNullDesC8() : iBuf->Ptr(0);
    92 	}
    92 	}
    98 
    98 
    99 @panic SqlDb 2 In _DEBUG mode. Invalid HSqlSrvStmtParamBuf object.
    99 @panic SqlDb 2 In _DEBUG mode. Invalid HSqlSrvStmtParamBuf object.
   100 */
   100 */
   101 inline const TPtrC8 HSqlSrvStmtParamBuf::Data() const
   101 inline const TPtrC8 HSqlSrvStmtParamBuf::Data() const
   102 	{
   102 	{
   103 	__SQLASSERT(iBuf != NULL, ESqlPanicInvalidObj);
   103 	__ASSERT_DEBUG(iBuf != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   104 	//If the size is 0, then return KNullDesC8, where an empty string is hold, not a null one ("" instead of NULL)
   104 	//If the size is 0, then return KNullDesC8, where an empty string is hold, not a null one ("" instead of NULL)
   105 	return iBuf->Size() == 0 ? KNullDesC8() : iBuf->Ptr(0);
   105 	return iBuf->Size() == 0 ? KNullDesC8() : iBuf->Ptr(0);
   106 	}
   106 	}
   107 
   107 
   108 /**
   108 /**
   120 
   120 
   121 @return Parameter index, zero based.
   121 @return Parameter index, zero based.
   122 */
   122 */
   123 inline TInt HSqlSrvStmtParamBuf::ParamIndex() const
   123 inline TInt HSqlSrvStmtParamBuf::ParamIndex() const
   124 	{
   124 	{
   125 	__SQLASSERT(iParamIndex >= 0, ESqlPanicInternalError);
   125 	__ASSERT_DEBUG(iParamIndex >= 0, __SQLPANIC(ESqlPanicInternalError));
   126 	return iParamIndex;
   126 	return iParamIndex;
   127 	}
   127 	}
   128 
   128 
   129 /**
   129 /**
   130 Initializes the HSqlSrvStmtParamBuf instance data members.
   130 Initializes the HSqlSrvStmtParamBuf instance data members.
   180 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   180 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   181 @panic SqlDb 7 In _DEBUG mode. SQLITE internal error. (SQLITE_ERROR, followed by a sqlite3_reset(), which returns SQLITE_OK)
   181 @panic SqlDb 7 In _DEBUG mode. SQLITE internal error. (SQLITE_ERROR, followed by a sqlite3_reset(), which returns SQLITE_OK)
   182 */	
   182 */	
   183 inline TInt CSqlSrvStatement::Next()
   183 inline TInt CSqlSrvStatement::Next()
   184 	{
   184 	{
   185 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   185 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   186 	TInt err = ::StmtNext(iStmtHandle);
   186 	TInt err = ::StmtNext(iStmtHandle);
   187 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   187 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   188 	iBufFlat.ResetAndMinimize();
   188 	iBufFlat.ResetAndMinimize();
   189 	return err;
   189 	return err;
   190 	}
   190 	}
   200 
   200 
   201 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   201 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   202 */	
   202 */	
   203 inline TInt CSqlSrvStatement::Reset()
   203 inline TInt CSqlSrvStatement::Reset()
   204 	{
   204 	{
   205 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   205 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   206 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   206 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   207 	iBufFlat.ResetAndMinimize();
   207 	iBufFlat.ResetAndMinimize();
   208 	return ::StmtReset(iStmtHandle);
   208 	return ::StmtReset(iStmtHandle);
   209 	}
   209 	}
   210 
   210 
   219 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   219 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   220 @panic SqlDb 7 In _DEBUG mode. SQLITE internal error. (SQLITE_ERROR, followed by a sqlite3_reset(), which returns SQLITE_OK)
   220 @panic SqlDb 7 In _DEBUG mode. SQLITE internal error. (SQLITE_ERROR, followed by a sqlite3_reset(), which returns SQLITE_OK)
   221 */	
   221 */	
   222 inline TInt CSqlSrvStatement::Exec()
   222 inline TInt CSqlSrvStatement::Exec()
   223 	{
   223 	{
   224 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   224 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   225 	TInt err = ::StmtExec(iStmtHandle);
   225 	TInt err = ::StmtExec(iStmtHandle);
   226 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   226 	iBufFlatType = static_cast <TSqlBufFlatType> (-1);
   227 	iBufFlat.ResetAndMinimize();
   227 	iBufFlat.ResetAndMinimize();
   228 	return err;
   228 	return err;
   229 	}
   229 	}
   231 /**
   231 /**
   232 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   232 @panic SqlDb 2 In _DEBUG mode. Invalid (not created) CSqlSrvStatement object.
   233 */
   233 */
   234 inline const RSqlBufFlat& CSqlSrvStatement::BufFlatL(TSqlBufFlatType aWhat) const
   234 inline const RSqlBufFlat& CSqlSrvStatement::BufFlatL(TSqlBufFlatType aWhat) const
   235 	{
   235 	{
   236 	__SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj);
   236 	__ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   237 	if(aWhat != iBufFlatType)
   237 	if(aWhat != iBufFlatType)
   238 		{
   238 		{
   239 		__SQLLEAVE(KErrArgument);
   239 		__SQLLEAVE(KErrArgument);
   240 		}
   240 		}
   241 	return iBufFlat;
   241 	return iBufFlat;
   260 
   260 
   261 @panic SqlDb 4 In _DEBUG mode. aDbHandle is NULL.
   261 @panic SqlDb 4 In _DEBUG mode. aDbHandle is NULL.
   262 */	
   262 */	
   263 inline void CSqlSrvStatement::ConstructL(sqlite3* aDbHandle, const TDesC16& aSqlStmt)
   263 inline void CSqlSrvStatement::ConstructL(sqlite3* aDbHandle, const TDesC16& aSqlStmt)
   264 	{
   264 	{
   265 	__SQLASSERT(aDbHandle != NULL, ESqlPanicBadArgument);
   265 	__ASSERT_DEBUG(aDbHandle != NULL, __SQLPANIC(ESqlPanicBadArgument));
   266 	iStmtHandle = ::StmtPrepare16L(aDbHandle, aSqlStmt);
   266 	iStmtHandle = ::StmtPrepare16L(aDbHandle, aSqlStmt);
   267 	DoCommonConstructL();
   267 	DoCommonConstructL();
   268 	}
   268 	}
   269 	
   269 	
   270 /**
   270 /**
   280 
   280 
   281 @panic SqlDb 4 In _DEBUG mode. aDbHandle is NULL.
   281 @panic SqlDb 4 In _DEBUG mode. aDbHandle is NULL.
   282 */	
   282 */	
   283 inline void CSqlSrvStatement::ConstructL(sqlite3* aDbHandle, const TDesC8& aSqlStmt)
   283 inline void CSqlSrvStatement::ConstructL(sqlite3* aDbHandle, const TDesC8& aSqlStmt)
   284 	{
   284 	{
   285 	__SQLASSERT(aDbHandle != NULL, ESqlPanicBadArgument);
   285 	__ASSERT_DEBUG(aDbHandle != NULL, __SQLPANIC(ESqlPanicBadArgument));
   286 	iStmtHandle = ::StmtPrepare8L(aDbHandle, aSqlStmt);
   286 	iStmtHandle = ::StmtPrepare8L(aDbHandle, aSqlStmt);
   287 	DoCommonConstructL();
   287 	DoCommonConstructL();
   288 	}
   288 	}