persistentstorage/sql/SRC/Client/SqlStmtSession.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
    14 // Description:
    14 // Description:
    15 //
    15 //
    16 
    16 
    17 #include <s32mem.h>
    17 #include <s32mem.h>
    18 #include "SqlStmtSession.h"		//RSqlStatementSession
    18 #include "SqlStmtSession.h"		//RSqlStatementSession
    19 #include "OstTraceDefinitions.h"
       
    20 #ifdef OST_TRACE_COMPILER_IN_USE
       
    21 #include "SqlStmtSessionTraces.h"
       
    22 #endif
       
    23 #include "SqlTraceDef.h"
       
    24 
       
    25 /**
       
    26  Sends a request to the SQL server to prepare 16-bit aSqlStmt statement.
       
    27  
       
    28  Usage of the IPC call arguments:
       
    29  Arg 0: [in/out]        data buffer for the column and parameter count.
       
    30  Arg 1: [out]       statement length in characters
       
    31  Arg 2: [out]       16-bit statement
       
    32  
       
    33  @param aDbSession A reference to RSqlDbSession instance.
       
    34  @param aSqlStmt 16-bit SQL statement.
       
    35  @param aColumnCount Output parameter. Statement column count.
       
    36  @param aParamCount Output parameter. Statement parameter count.
       
    37  
       
    38  @return KErrNoMemory, an out of memory condition has occured;
       
    39  KErrArgument, bad argument, for example - the SQL string contains more than one SQL statements.
       
    40  Note that the function may return some database specific errors categorised as 
       
    41  ESqlDbError or other system-wide error codes;
       
    42  KErrNone      The operation has completed successfully. 
       
    43  
       
    44  @panic SqlDb 7 In _DEBUG mode if the statement handle is 0.
       
    45 */
       
    46 TInt RSqlStatementSession::Prepare(RSqlDbSession& aDbSession, const TDesC& aSqlStmt, 
       
    47                                           TInt& aColumnCount, TInt& aParamCount)
       
    48     {
       
    49     iDbSession = &aDbSession;
       
    50     TSqlIpcData data;
       
    51     TPckg<TSqlIpcData> pckg(data);
       
    52     TUint stmtLen = aSqlStmt.Length();
       
    53     iHandle = iDbSession->SendReceive(ESqlSrvStmtPrepare16, TIpcArgs(&pckg, stmtLen, &aSqlStmt));
       
    54     __ASSERT_DEBUG(iHandle != 0, __SQLPANIC(ESqlPanicInternalError));   
       
    55     aColumnCount = static_cast <TInt> (data.iPrm1);
       
    56     aParamCount = static_cast <TInt> (data.iPrm2);
       
    57     SQL_TRACE_SESSION(OstTraceExt2(TRACE_INTERNALS, RSQLSTATEMENTSESSION_PREPARE16, "0x%X;RSqlStatementSession::Prepare-16;iHandle=%d", (TUint)this, iHandle));
       
    58     return iHandle > 0 ? KErrNone : iHandle;
       
    59     }
       
    60 
       
    61 /**
       
    62 Sends a request to the SQL server to prepare 8-bit aSqlStmt statement.
       
    63 
       
    64 Usage of the IPC call arguments:
       
    65 Arg 0: [in/out]     data buffer for the column and parameter count.
       
    66 Arg 1: [out]        statement length in characters
       
    67 Arg 2: [out]        8-bit statement
       
    68 
       
    69 @param aDbSession A reference to RSqlDbSession instance.
       
    70 @param aSqlStmt 8-bit SQL statement.
       
    71 @param aColumnCount Output parameter. Statement column count.
       
    72 @param aParamCount Output parameter. Statement parameter count.
       
    73 
       
    74 @return KErrNoMemory, an out of memory condition has occured;
       
    75         KErrArgument, bad argument, for example - the SQL string contains more than one SQL statements.
       
    76                       Note that the function may return some database specific errors categorised as 
       
    77                       ESqlDbError or other system-wide error codes;
       
    78         KErrNone      The operation has completed successfully. 
       
    79 
       
    80 @panic SqlDb 7 In _DEBUG mode if the statement handle is 0.
       
    81 */
       
    82 TInt RSqlStatementSession::Prepare(RSqlDbSession& aDbSession, const TDesC8& aSqlStmt, 
       
    83                                           TInt& aColumnCount, TInt& aParamCount)
       
    84     {
       
    85     iDbSession = &aDbSession;
       
    86     TSqlIpcData data;
       
    87     TPckg<TSqlIpcData> pckg(data);
       
    88     TUint stmtLen = aSqlStmt.Length();
       
    89     iHandle = iDbSession->SendReceive(ESqlSrvStmtPrepare8, TIpcArgs(&pckg, stmtLen, &aSqlStmt));
       
    90     __ASSERT_DEBUG(iHandle != 0, __SQLPANIC(ESqlPanicInternalError));
       
    91     aColumnCount = static_cast <TInt> (data.iPrm1);
       
    92     aParamCount = static_cast <TInt> (data.iPrm2);
       
    93     SQL_TRACE_SESSION(OstTraceExt2(TRACE_INTERNALS, RSQLSTATEMENTSESSION_PREPARE8, "0x%X;RSqlStatementSession::Prepare-8;iHandle=%d", (TUint)this, iHandle));
       
    94     return iHandle > 0 ? KErrNone : iHandle;
       
    95     }
       
    96 
    19 
    97 /**
    20 /**
    98 Sends a request to the server to close the statement handle.
    21 Sends a request to the server to close the statement handle.
    99 Closes the session object.
    22 Closes the session object.
   100 */
    23 */
   101 void RSqlStatementSession::Close()
    24 void RSqlStatementSession::Close()
   102 	{
    25 	{
   103 	SQL_TRACE_SESSION(OstTraceExt2(TRACE_INTERNALS, RSQLSTATEMENTSESSION_CLOSE, "0x%X;RSqlStatementSession::Close;iHandle=%d", (TUint)this, iHandle));
       
   104 	if(iDbSession && iHandle > 0)
    26 	if(iDbSession && iHandle > 0)
   105 		{
    27 		{
   106 		(void)iDbSession->SendReceive(::MakeMsgCode(ESqlSrvStmtClose, ESqlSrvStatementHandle, iHandle));
    28 		(void)iDbSession->SendReceive(::MakeMsgCode(ESqlSrvStmtClose, ESqlSrvStatementHandle, iHandle));
   107 		}
    29 		}
   108 	iDbSession = NULL;
    30 	iDbSession = NULL;