persistentstorage/sql/SRC/Server/SqlSrvStatementUtil.cpp
changeset 55 44f437012c90
parent 51 7d4490026038
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
   111     //sqlite3_prepare16_v2() expects parameter #3 to be one of the following:
   111     //sqlite3_prepare16_v2() expects parameter #3 to be one of the following:
   112     // - byte length of the sql statement (parameter #2), excluding terminating zero;
   112     // - byte length of the sql statement (parameter #2), excluding terminating zero;
   113     // - negative value - the sql statement (parameter #2) is zero-terminated;
   113     // - negative value - the sql statement (parameter #2) is zero-terminated;
   114 	TInt err = sqlite3_prepare16_v2(aDbHandle, aSql.Ptr(), aSql.Length() * sizeof(TUint16) - sizeof(TUint16), &stmtHandle, &stmtTail);
   114 	TInt err = sqlite3_prepare16_v2(aDbHandle, aSql.Ptr(), aSql.Length() * sizeof(TUint16) - sizeof(TUint16), &stmtHandle, &stmtTail);
   115 	__ASSERT_DEBUG(err == SQLITE_OK ? !stmtTail || User::StringLength((const TUint16*)stmtTail) == 0 : !stmtHandle, __SQLPANIC2(ESqlPanicInternalError));
   115 	__ASSERT_DEBUG(err == SQLITE_OK ? !stmtTail || User::StringLength((const TUint16*)stmtTail) == 0 : !stmtHandle, __SQLPANIC2(ESqlPanicInternalError));
   116 	if(stmtHandle)	//stmtHandle can be NULL for statements like this: ";".
   116 	if(err == SQLITE_OK)
   117 		{
   117 		{
   118 		if(err == SQLITE_OK)
   118 		if(stmtHandle)	//stmtHandle can be NULL for statements like this: ";".
   119 			{
   119 			{
   120 			while((err = sqlite3_step(stmtHandle)) == SQLITE_ROW)
   120 			while((err = sqlite3_step(stmtHandle)) == SQLITE_ROW)
   121 				{
   121 				{
   122 				}
   122 				}
   123 			if(err == SQLITE_ERROR)	//It may be "out of memory" problem
   123 			if(err == SQLITE_ERROR)	//It may be "out of memory" problem
   124 				{
   124 				{
   125 				err = sqlite3_reset(stmtHandle);
   125 				err = sqlite3_reset(stmtHandle);
   126 				__ASSERT_DEBUG(err != SQLITE_OK, __SQLPANIC2(ESqlPanicInternalError));
   126 				__ASSERT_DEBUG(err != SQLITE_OK, __SQLPANIC2(ESqlPanicInternalError));
   127 				}
   127 				}
       
   128 			(void)sqlite3_finalize(stmtHandle);//sqlite3_finalize() fails only if an invalid statement handle is passed.
   128 			}
   129 			}
   129 		(void)sqlite3_finalize(stmtHandle);//sqlite3_finalize() fails only if an invalid statement handle is passed.
       
   130 		}
   130 		}
   131 	return err;
   131 	return err;
   132 	}
   132 	}
   133 
   133 
   134 /**
   134 /**