persistentstorage/sql/SRC/Client/SqlDbSession.inl
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2006-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 // Initializes RSqlDbSession data members with their default values.
       
    15 // 
       
    16 //
       
    17 
       
    18 inline RSqlDbSession::RSqlDbSession() :
       
    19 	iLastErrorMessage(NULL)
       
    20 	{
       
    21 	}
       
    22 
       
    23 /**
       
    24 Sends a command to the server to detach previously attached database.
       
    25 
       
    26 @param aDbName Logical database name. 
       
    27 
       
    28 @return KErrNone, operation has completed successfully;
       
    29 		KErrNotFound, no attached database with aDbName name.
       
    30                       Note that database specific errors categorised as ESqlDbError, and
       
    31                       other system-wide error codes may also be returned.
       
    32 
       
    33 Usage of the IPC call arguments: 
       
    34 Arg 0: [out]	Logical database name length.
       
    35 Arg 1: [out]	Logical database name.
       
    36 */
       
    37 inline TInt RSqlDbSession::Detach(const TDesC& aDbName)
       
    38 	{
       
    39 	return SendReceive(ESqlSrvDbDetach, TIpcArgs(aDbName.Length(), &aDbName));
       
    40 	}
       
    41 
       
    42 /**
       
    43 Executes one or more 16-bit SQL statements.
       
    44 
       
    45 The method sends a message to the SQL server containing one or more 16-bit SQL statements to be executed.
       
    46 SQL statements of any kind can be executed, but the method won't return any record(s) 
       
    47 if the SQL statement type is "SELECT".
       
    48 If the SQL statement(s) contains one or more parameters, these parameters will be set to NULL before the
       
    49 execution.
       
    50 If the call fails and the error class is ESqlDbError, a text description of the error can be obtained using
       
    51 LastErrorMessage() method.
       
    52 
       
    53 @param aSqlStmt String containing one or more 8/16-bit SQL statements, separated with ';'.
       
    54 
       
    55 @return >=0, The operation has completed successfully. The number of database rows that were 
       
    56 			 changed/inserted/deleted by the most recently completed INSERT/UPDATE/DELETE sql statement.
       
    57 			 Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0 
       
    58 			 if the operation has completed successfully (disregarding the number of the deleted rows);
       
    59 		KErrNoMemory, an out of memory condition has occured;
       
    60 		KSqlErrGeneral, Syntax error. A text message describing the problem can be obtained calling
       
    61 						LastErrorMessage().
       
    62 
       
    63 Usage of the IPC call arguments: 
       
    64 Arg 0: [out]	16-bit character length of SQL statement.
       
    65 Arg 1: [out]	SQL statement(s).
       
    66 */
       
    67 inline TInt RSqlDbSession::Exec(const TDesC& aSqlStmt)
       
    68 	{
       
    69 	return SendReceive(ESqlSrvDbExec16, TIpcArgs(aSqlStmt.Length(), &aSqlStmt));
       
    70 	}
       
    71 
       
    72 /**
       
    73 Executes one or more 8-bit SQL statements.
       
    74 
       
    75 The method sends a message to the SQL server containing one or more 8-bit SQL statements to be executed.
       
    76 SQL statements of any kind can be executed, but the method won't return any record(s) 
       
    77 if the SQL statement type is "SELECT".
       
    78 If the SQL statement(s) contains one or more parameters, these parameters will be set to NULL before the
       
    79 execution.
       
    80 If the call fails and the error class is ESqlDbError, a text description of the error can be obtained using
       
    81 LastErrorMessage() method.
       
    82 
       
    83 @param aSqlStmt String containing one or more 8-bit SQL statements, separated with ';'.
       
    84 
       
    85 @return >=0, The operation has completed successfully. The number of database rows that were 
       
    86 			 changed/inserted/deleted by the most recently completed INSERT/UPDATE/DELETE sql statement.
       
    87 			 Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0 
       
    88 			 if the operation has completed successfully (disregarding the number of the deleted rows);
       
    89 		KErrNoMemory, an out of memory condition has occured;
       
    90 		KSqlErrGeneral, Syntax error. A text message describing the problem can be obtained calling
       
    91 						LastErrorMessage().
       
    92 
       
    93 Usage of the IPC call arguments: 
       
    94 Arg 0: [out]	8-bit character length of SQL statement.
       
    95 Arg 1: [out]	SQL statement(s).
       
    96 */
       
    97 inline TInt RSqlDbSession::Exec(const TDesC8& aSqlStmt)
       
    98 	{
       
    99 	return SendReceive(ESqlSrvDbExec8, TIpcArgs(aSqlStmt.Length(), &aSqlStmt));
       
   100 	}
       
   101 
       
   102 /**
       
   103 Executes one or more 16-bit SQL statements asynchronously.
       
   104 
       
   105 The method sends a message to the SQL server containing one or more 16-bit SQL statements to be executed.
       
   106 SQL statements of any kind can be executed, but the method won't return any record(s) 
       
   107 if the SQL statement type is "SELECT".
       
   108 If the SQL statement(s) contains one or more parameters, these parameters will be set to NULL before the
       
   109 execution.
       
   110 If the call fails and the error class is ESqlDbError, a text description of the error can be obtained using
       
   111 LastErrorMessage() method.
       
   112 
       
   113 @param aSqlStmt String containing one or more 16-bit SQL statements, separated with ';'.
       
   114 @param aStatus Completion status of asynchronous request, one of the following:
       
   115 @code
       
   116 		- >=0, The operation has completed successfully. The number of database rows that were 
       
   117 			   changed/inserted/deleted by the most recently completed INSERT/UPDATE/DELETE sql statement.
       
   118 			 Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0 
       
   119 			 if the operation has completed successfully (disregarding the number of the deleted rows);
       
   120         - KSqlErrStmtExpired, the SQL statement has expired (if new functions or
       
   121                             collating sequences have been registered or if an
       
   122                             authorizer function has been added or changed);
       
   123         - KErrNoMemory, an out of memory condition has occurred - the statement
       
   124                       will be reset.
       
   125                       Note that aStatus may be set with database specific errors categorised as ESqlDbError, 
       
   126                       and other system-wide error codes.
       
   127 @endcode
       
   128 
       
   129 Usage of the IPC call arguments: 
       
   130 Arg 0: [out]	16-bit character length of SQL statement.
       
   131 Arg 1: [out]	SQL statement(s).
       
   132 */
       
   133 inline void RSqlDbSession::Exec(const TDesC& aSqlStmt, TRequestStatus& aStatus)
       
   134 	{
       
   135 	SendReceive(ESqlSrvDbExec16, TIpcArgs(aSqlStmt.Length(), &aSqlStmt), aStatus);
       
   136 	}
       
   137 
       
   138 /**
       
   139 Executes one or more 8-bit SQL statements asynchronously.
       
   140 
       
   141 The method sends a message to the SQL server containing one or more 8-bit SQL statements to be executed.
       
   142 SQL statements of any kind can be executed, but the method won't return any record(s) 
       
   143 if the SQL statement type is "SELECT".
       
   144 If the SQL statement(s) contains one or more parameters, these parameters will be set to NULL before the
       
   145 execution.
       
   146 If the call fails and the error class is ESqlDbError, a text description of the error can be obtained using
       
   147 LastErrorMessage() method.
       
   148 
       
   149 @param aSqlStmt String containing one or more 8-bit SQL statements, separated with ';'.
       
   150 @param aStatus Completion status of asynchronous request, one of the following:
       
   151 @code
       
   152 		- >=0, The operation has completed successfully. The number of database rows that were 
       
   153 			   changed/inserted/deleted by the most recently completed INSERT/UPDATE/DELETE sql statement.
       
   154 			 Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0 
       
   155 			 if the operation has completed successfully (disregarding the number of the deleted rows);
       
   156         - KSqlErrStmtExpired, the SQL statement has expired (if new functions or
       
   157                             collating sequences have been registered or if an
       
   158                             authorizer function has been added or changed);
       
   159         - KErrNoMemory, an out of memory condition has occurred - the statement
       
   160                       will be reset.
       
   161                       Note that aStatus may be set with database specific errors categorised as ESqlDbError, 
       
   162                       and other system-wide error codes.
       
   163 @endcode
       
   164 
       
   165 Usage of the IPC call arguments: 
       
   166 Arg 0: [out]	8-bit character length of SQL statement.
       
   167 Arg 1: [out]	SQL statement(s).
       
   168 */
       
   169 inline void RSqlDbSession::Exec(const TDesC8& aSqlStmt, TRequestStatus& aStatus)
       
   170 	{
       
   171 	SendReceive(ESqlSrvDbExec8, TIpcArgs(aSqlStmt.Length(), &aSqlStmt), aStatus);
       
   172 	}
       
   173 
       
   174 /**
       
   175 Sets the transaction isolation level.
       
   176 
       
   177 The method sends a message to the SQL server to set the desired isolation level.
       
   178 The default isolation level is RSqlDatabase::ESerializable, but can be changed to 
       
   179 RSqlDatabase::EReadUncommitted for database connections which share the access to the same database file.
       
   180 
       
   181 @param aIsolationLevel Desired isolation level: RSqlDatabase::ESerializable or RSqlDatabase::EReadUncommitted.
       
   182 @return KErrNone, the operation has completed successfully.
       
   183                   The function may also return some other system-wide error codes.
       
   184 
       
   185 Usage of the IPC call arguments: 
       
   186 Arg 0: [out]	Isolation level type.
       
   187 */
       
   188 inline TInt RSqlDbSession::SetIsolationLevel(RSqlDatabase::TIsolationLevel aIsolationLevel)
       
   189 	{
       
   190 	return SendReceive(ESqlSrvDbSetIsolationLevel, TIpcArgs(static_cast <TInt> (aIsolationLevel)));
       
   191 	}
       
   192 
       
   193 /**
       
   194 Usage of the IPC call arguments: 
       
   195 Arg 0: [out]	(16-bit character length of SQL statement) | (expected column value type << 24).
       
   196 Arg 1: [out]	SQL statement.
       
   197 Arg 2: [out]	Byte max length of the receiving buffer
       
   198 Arg 3: [in/out]	The receiving buffer
       
   199 */
       
   200 inline TInt RSqlDbSession::ExecScalarFullSelect(const TDesC& aSqlStmt, TSqlColumnType aType, TDes8& aRes)
       
   201 	{
       
   202 	return SendReceive(ESqlSrvDbScalarFullSelect16, TIpcArgs(aSqlStmt.Length() | (aType << 24), &aSqlStmt, aRes.MaxLength(), &aRes));
       
   203 	}
       
   204 	
       
   205 /**
       
   206 Usage of the IPC call arguments: 
       
   207 Arg 0: [out]	(8-bit character length of SQL statement) | (expected column value type << 24).
       
   208 Arg 1: [out]	SQL statement.
       
   209 Arg 2: [out]	Byte max length of the receiving buffer
       
   210 Arg 3: [in/out]	The receiving buffer
       
   211 */
       
   212 inline TInt RSqlDbSession::ExecScalarFullSelect(const TDesC8& aSqlStmt, TSqlColumnType aType, TDes8& aRes)
       
   213 	{
       
   214 	return SendReceive(ESqlSrvDbScalarFullSelect8, TIpcArgs(aSqlStmt.Length() | (aType << 24), &aSqlStmt, aRes.MaxLength(), &aRes));
       
   215 	}
       
   216 	
       
   217 /**
       
   218 The method sends a message to the SQL server.
       
   219 
       
   220 @param aFunction Function code
       
   221 
       
   222 @return KErrNone or system-wide error codes.
       
   223 */
       
   224 inline TInt RSqlDbSession::SendReceive(TInt aFunction)
       
   225 	{
       
   226 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(TPtrC8 funcStr = GetIPCFuncStr(aFunction));
       
   227 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EBorder), KDbMsgStr, &funcStr));
       
   228 	return RSessionBase::SendReceive(aFunction);	
       
   229 	}
       
   230 
       
   231 /**
       
   232 The method sends a message asynchronously to the SQL server.
       
   233 
       
   234 @param aFunction Function code
       
   235 
       
   236 @return KErrNone or system-wide error codes.
       
   237 */
       
   238 inline void RSqlDbSession::SendReceive(TInt aFunction, TRequestStatus& aStatus)
       
   239 	{
       
   240 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(TPtrC8 funcStr = GetIPCFuncStr(aFunction));
       
   241 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EBorder), KDbMsgStr, &funcStr));
       
   242 	RSessionBase::SendReceive(aFunction, aStatus);
       
   243 	}
       
   244 
       
   245 /**
       
   246 The method sends a message with arguments to the SQL server.
       
   247 
       
   248 @param aFunction Function code
       
   249 @param aArgs Message arguments
       
   250 
       
   251 @return KErrNone or system-wide error codes.
       
   252 */
       
   253 inline TInt RSqlDbSession::SendReceive(TInt aFunction, const TIpcArgs& aArgs)
       
   254 	{
       
   255 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(TPtrC8 funcStr = GetIPCFuncStr(aFunction));
       
   256 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EBorder), KDbMsgStr, &funcStr));
       
   257 	return RSessionBase::SendReceive(aFunction, aArgs);	
       
   258 	}
       
   259 	
       
   260 /**
       
   261 The method sends asynchronously a message with arguments to the SQL server.
       
   262 
       
   263 @param aFunction Function code
       
   264 @param aArgs Message arguments
       
   265 @param aStatus Completion status of asynchronous request
       
   266 */
       
   267 inline void RSqlDbSession::SendReceive(TInt aFunction,const TIpcArgs& aArgs, TRequestStatus& aStatus)
       
   268 	{
       
   269 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(TPtrC8 funcStr = GetIPCFuncStr(aFunction));
       
   270 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EBorder), KDbMsgStr, &funcStr));
       
   271 	RSessionBase::SendReceive(aFunction, aArgs, aStatus);	
       
   272 	}