//***************************************************************************** //*** SQL.pkg *** //*** *** //*** Author: Ben Weijers *** //*** Data Access Wordwide *** //*** 14 February 2000 *** //*** *** //*** Purpose: *** //*** Embedded SQL manager. *** //*** *** //*** Changes: *** //*** *** //*** March 14, 2001. CLI Connectivity Kits 2.0.0.13 *** //*** Allocate memory before call_driver command with spaces instead *** //*** of binary zeroes. *** //*** *** //***************************************************************************** Use UI Use CLI Use Case.mac //*** Global object handle for the manager Integer _embsqlghoSQLHandleMngr //*** Global stroage for results Integer SQLResult //*** Embedded SQL function constants Define FUNC_SQLCONNECT For 1000000 Define FUNC_SQLFILECONNECT For 1000001 Define FUNC_SQLDISCONNECT For 1000002 Define FUNC_SQLOPEN For 1000003 Define FUNC_SQLCLOSE For 1000004 Define FUNC_SQLPREPARE For 1000005 Define FUNC_SQLEXECUTE For 1000006 Define FUNC_SQLEXECDIRECT For 1000007 Define FUNC_SQLFETCH For 1000008 Define FUNC_SQLCOLUMNINFO For 1000009 Define FUNC_SQLCOLUMNVALUE For 1000010 Define FUNC_SQLBINDFILE For 1000011 Define FUNC_SQLGETDATA For 1000012 Define FUNC_SQLCOLSTRINGATTRIBLEN For 1000013 Define FUNC_SQLCOLSTRINGATTRIB For 1000014 Define FUNC_SQLCOLINTATTRIB For 1000015 Define FUNC_SQLSTMTINTATTRIB For 1000016 Define FUNC_SQLSETPROCNAME For 1000017 DEfine FUNC_SQLSETPROCARG For 1000018 Define FUNC_SQLCALL For 1000019 Define FUNC_SQLGETPROCARGLEN For 1000020 Define FUNC_SQLGETPROCARG For 1000021 Define FUNC_SQLGETPROCRETVALLEN For 1000022 Define FUNC_SQLGETPROCRETVAL For 1000023 Define FUNC_SQLNEXTRESULTSET For 1000024 Define FUNC_SQLBUFFERSTATUS For 1000025 Define FUNC_SQLSETPROCSCHEMA For 1000026 Define FUNC_SQLGETMESSAGE For 1000027 //*** Embedded SQL statement attribute constants Define SQLSTMTATTRIB_COLUMNCOUNT For 1 Define SQLSTMTATTRIB_ROWCOUNT For 2 Define SQLSTMTATTRIB_ROWCOUNT_TYPE For 3 Define SQLSTMTATTRIB_NUMMESSAGES For 4 //*** Embedded SQL column attribute constants Define SQLCOLATTRIB_SIZE For 1 Define SQLCOLATTRIB_LENGTH For 1 Define SQLCOLATTRIB_PRECISION For 2 Define SQLCOLATTRIB_LABEL For 3 Define SQLCOLATTRIB_BASECOLUMNNAME For 4 Define SQLCOLATTRIB_BASETABLENAME For 5 Define SQLCOLATTRIB_SQLTYPE For 6 Define SQLCOLATTRIB_NULLABLE For 7 Define SQLCOLATTRIB_DFTYPE For 8 //***************************************************************************** //*** Class : cSQLStatement *** //*** Purpose: Statement object for embedded sql *** //*** *** //*** Description: *** //*** An object is created for each statement. These will be children *** //*** of cSQLConnection objects which manage the create and destruction *** //*** of these. *** //***************************************************************************** //Doc/ ClassLibrary=Common Class cSQLStatement is an Array Procedure Construct_object Integer Image Forward Send Construct_object Image //Doc/ Interface=Private Property Integer phCLIHandle public 0 //Doc/ Interface=Private Property String psDriverID Public "" //Doc/ Interface=Private Property Integer phStmtConnection Public 0 //Doc/ Interface=Private Property Integer piLastColumn Public 0 //Doc/ Interface=Private Property Integer piLastArgument Public 0 //Doc/ Interface=Public Property Integer piBindFile Public 0 Set Delegation_mode To NO_Delegation End_procedure // Construct_object //*** //*** Procedure: StoreHandleInfo //*** Purpose : Store basic information about the statement handle. //*** //Doc/ Interface=Private Procedure StoreHandleInfo Integer iCLIHandle String sDrvrId Integer iParentHandle Set phCLIHandle To iCLIHandle Set psDriverID To sDrvrId Set phStmtConnection To iParentHandle End_Procedure // StoreHandleInfo //*** //*** Procedure: FreeHandle //*** Purpose : Free a handle. Since a handle is stored in an //*** cSQLStatement object, we destroy the object. //*** //Doc/ Interface=Private Procedure FreeHandle Send Destroy_Object End_Procedure // FreeHandle //*** //*** Procedure: HandleError //*** Puprose : Handle an error that has occured while checking properties. //*** //Doc/ Interface=Private Procedure HandleError Integer ihstmt Integer ihdbc String sDrvrId String sOriginMsg Local Integer iErrHandle Local Integer iErrNum Local String sLocationInfo //*** Get the DataFlex statement identifier Move Current_object To iErrHandle //*** Determine error number If (ihstmt = 0) ; Move CLIERR_SQLINVALID_CLI_STMT_HANDLE To iErrNum Else If (ihdbc = 0) ; Move CLIERR_SQLINVALID_CLI_CONN_HANDLE To iErrNum Else If (sDrvrId = "") ; Move CLIERR_SQLINVALID_DRIVER_ID To iErrNum Else ; Move CLIERR_SQL_ERROR To iErrNum //*** Create location ifnormation Move "[" To sLocationInfo If (sOriginMsg <> "") Begin Move (Append(sLocationInfo, sOriginMsg)) To sLocationInfo Move (Append(sLocationInfo, ", ")) To sLocationInfo End Move (Append(sLocationInfo, "DataFlex hstmt = ")) To sLocationInfo Move (Append(sLocationInfo, iErrHandle)) To sLocationInfo Move (Append(sLocationInfo, "]")) To sLocationInfo //*** Generate the error Error iErrNum sLocationInfo End_Procedure // HandleError //*** //*** Procedure: StmtError //*** Purpose : Handle general error not related to the properties //*** //Doc/ Interface=Private Procedure StmtError Integer iErrNum String sErrText String sOriginMsg Local Integer iErrHandle Local String sLocationInfo //*** Get the DataFlex statement identifier Move Current_object To iErrHandle //*** Create location information Move "[" To sLocationInfo If (sOriginMsg <> "") Begin Move (Append(sLocationInfo, sOriginMsg)) To sLocationInfo Move (Append(sLocationInfo, ", ")) To sLocationInfo End If (sErrtext <> "") Begin Move (Append(sLocationInfo, sErrtext)) To sLocationInfo Move (Append(sLocationInfo, ", ")) To sLocationInfo End Move (Append(sLocationInfo, "DataFlex hstmt = ")) To sLocationInfo Move (Append(sLocationInfo, iErrHandle)) To sLocationInfo Move (Append(sLocationInfo, "]")) To sLocationInfo //*** Generate the error Error iErrNum sLocationInfo End_Procedure // StmtError //*** //*** Procedure: SQLIllegalAttribute //*** Purpose : Handle an illegal attribute error //*** //Doc/ Interface=Private Procedure SQLIllegalAttribute String sErrText String sOriginMsg Local Integer bReport Get_attribute DF_REPORT_UNSUPPORTED_ATTRIBUTES To bReport If (bReport) ; Send StmtError CLIERR_SQLINVALID_ATTRIBUTE sErrtext sOriginMsg End_Procedure // SQLIllegalAttribute //*** //*** Function: SQLPrivateColumnIsLegal //*** Purpose : Check if a column number is legal //*** //Doc/ Interface=Private Function SQLPrivateColumnIsLegal Integer ihdbc String sDrvrId Integer ihstmt Integer iCol Returns Integer Local Integer bLegal Local Integer iNumColumns Get SQLPrivateStmtAttribute SQLSTMTATTRIB_COLUMNCOUNT ihdbc sDrvrId ihstmt To iNumColumns If (iCol > 0 And iCol <= iNumColumns) ; Move DFTRUE To bLegal Else ; Move DFFALSE To bLegal Function_Return bLegal End_Function // SQLPrivateColumnIsLegal //*** //*** Procedure: SQLClose //*** Purpose : Close a statement and free all alllocated resources //*** //Doc/ Interface=Public Procedure SQLClose Local Integer ihdbc Local Integer ihstmt Local Integer iVoid Local String sDrvrId Local String sEmpty //*** Initialize Move "" To sEmpty //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Free the CLI handle If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Call the driver function to close Call_driver 0 sDrvrId Function FUNC_SQLCLOSE ; Callback Current_Object ; Passing ihdbc sEmpty ihstmt ; Result iVoid //*** Free the DataFlex handle Send FreeHandle End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLClose" End_procedure // SQLClose //*** //*** Procedure: SQLPrepare //*** Purpose : Prepare a statement for execution //*** //Doc/ Interface=Public Procedure SQLPrepare String sStatement Local Integer ihdbc Local Integer ihstmt Local Integer iVoid Local String sDrvrId //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Prepare If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Call the driver function to prepare Call_driver 0 sDrvrId Function FUNC_SQLPREPARE ; Callback Current_Object ; Passing ihdbc sStatement ihstmt ; Result iVoid End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLPrepare" End_procedure // SQLPrepare //*** //*** Procedure: SQLExecute //*** Purpose : Execute a prepared statement //*** //Doc/ Interface=Public Procedure SQLExecute Local Integer ihdbc Local Integer ihstmt Local Integer iVoid Local String sDrvrId Local String sEmpty //*** Initialize Move "" To sEmpty //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Execute If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Call the driver function to execute Call_driver 0 sDrvrId Function FUNC_SQLEXECUTE ; Callback Current_Object ; Passing ihdbc sEmpty ihstmt ; Result iVoid End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLExecute" End_Procedure // SQLExecute //*** //*** Procedure: SQLExecDirect //*** Purpose : Prepare and execute a statement //*** //Doc/ Interface=Public Procedure SQLExecDirect String sStatement Local Integer ihdbc Local Integer ihstmt Local Integer iVoid Local String sDrvrId //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** ExecDirect If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Call the driver function to execdirect Call_driver 0 sDrvrId Function FUNC_SQLEXECDIRECT ; Callback Current_Object ; Passing ihdbc sStatement ihstmt ; Result iVoid End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLExecDirect" End_procedure // SQLExecDirect //*** //*** Procedure: SQLFetch //*** Purpose : Fetch the next row //*** Returns : 0 = No more data //*** <>0 = Success //*** //Doc/ Interface=Public Function SQLFetch Returns Integer Local Integer ihdbc Local Integer ihstmt Local Integer iResult Local String sDrvrId Local String sEmpty //*** Initialize Move "" To sEmpty Move 0 To iResult //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Fetch If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin Indicate Err False //*** Call the driver function to fetch Call_driver 0 sDrvrId Function FUNC_SQLFETCH ; Callback Current_Object ; Passing ihdbc sEmpty ihstmt ; Result iResult //*** If something went wrong, adjust the result If (Err) ; Move 0 To iResult Set piLastcolumn To 0 End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLFetch" Function_return iResult End_Function // SQLFetch //*** //*** Function: SQLNextColumn //*** Purpose : Get the next column //*** //Doc/ Interface=Private Function SQLNextColumn Returns String Local Integer iCol Local String sResult Get piLastColumn To iCol Increment iCol Get SQLColumnValue iCol To sResult Set piLastColumn To iCol Function_return sResult End_Function // SQLNextColumn //*** //*** Function: SQLColumnValue //*** Purpose : Return the value of a column in a fetched row of a given //*** statement. //*** //Doc/ Interface=Public Function SQLColumnValue Integer iCol Returns String Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local String sResult //*** Initialize Move "" To sResult //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Get the value If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") ; Get SQLPrivateColumnValue iCol ihdbc sDRvrId ihstmt To sResult Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLColumnValue" Function_return sResult End_Function // SQLColumnValue //Doc/ Interface=Private Function SQLPrivateColumnValue Integer iCol Integer ihdbc String sDrvrId Integer ihstmt Returns String Local Integer iVoid Local Integer iColSize Local String sResult Local String sEmpty Local Integer bLegalColumn //*** Initialize Move "" To sEmpty //*** Get the value If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Check if the column exists Get SQLPrivateColumnIsLegal ihdbc sDrvrId ihstmt iCol To bLegalColumn If (bLegalColumn) Begin //*** Determine the column size Get SQLPrivateColAttribute iCol SQLCOLATTRIB_SIZE ihdbc sDrvrId ihstmt To iColSize If (iColSize > 0) Begin //*** Setup function arguments Call_driver 0 sDrvrId Function FUNC_SQLCOLUMNINFO ; Callback Current_Object ; Passing ihdbc iCol ihstmt ; Result iVoid //*** Allocate Move (Repeat(' ', iColSize)) To sResult //*** Call the driver function to get the value Call_driver 0 sDrvrId Function FUNC_SQLCOLUMNVALUE ; Callback Current_Object ; Passing sResult sEmpty 0 ; Result iVoid End End Else ; Send StmtError CLIERR_SQLINVALID_COLUMN ("(Column number = " + String(iCol) + ")") "SQLPrivateColumnValue" End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLPrivateColumnValue" Function_return sResult End_Function // SQLColumnValue //*** //*** Procedure: SQLBindFile //*** Purpose : Add a file to the files used to place the statement result in. //*** //Doc/ Interface=Public Procedure SQLBindFile Integer iFileNum Local Integer ihdbc Local Integer ihstmt Local Integer iVoid Local String sDrvrId Local String sFileType Local Integer bIsOpen //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** If a file number is not passed see if we can use the statement's //*** default file number which is usually set with SetFileConnection If (iFileNum = 0) Begin Get piBindFile To iFileNum If (iFileNum = 0) Begin //*** Logic error, if 0 is passed as filenumber, piBindFile should be set. Send StmtError CLIERR_SQLINVALID_BIND_FILE "piBindFile should be set" "SQLBindFile" Move 0 to SQLResult Procedure_Return End End //*** Bind the file If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Chek if the file is open Get_attribute DF_FILE_OPENED Of iFileNum To bIsOpen If (bIsOpen) Begin //*** Check if the file has the correct type Get_attribute DF_FILE_DRIVER Of iFileNum To sFileType If (sFileType = sDrvrId) Begin //*** Call the driver function to add a file to a statement Call_driver 0 sDrvrId Function FUNC_SQLBINDFILE ; Callback Current_Object ; Passing ihdbc iFileNum ihstmt ; Result iVoid End Else ; Send StmtError CLIERR_SQLINVALID_BIND_FILE ("File" * String(iFileNum) * "type incompatible with statement (" + sFileType + ")") "SQLBindFile" End Else ; Send StmtError CLIERR_SQLINVALID_BIND_FILE ("File not open (number =" * String(iFileNum) + ")") "SQLBindFile" End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLBindFile" End_Procedure // SQLBindFile //************************************************************************* //*** Function: SQLGetData *** //*** Purpose : Get data of a column. *** //************************************************************************* //Doc/ Interface=Public Function SQLGetData Integer iCol Integer iLen Returns String Local Integer ihdbc Local Integer ihstmt Local Integer iVoid Local Integer iColSize Local Integer iResult Local String sDrvrId Local String sResult Local String sEmpty Local Integer bLegalColumn //*** Initialize Move "" To sEmpty Move 0 To iResult //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Get the data If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Check if the column exists Get SQLPrivateColumnIsLegal ihdbc sDrvrId ihstmt iCol To bLegalColumn If (bLegalColumn) Begin If (iLen = 0) ; Get SQLPrivateColumnValue iCol ihdbc sDrvrId ihstmt To sResult Else Begin //*** Setup function arguments Call_driver 0 sDrvrId Function FUNC_SQLCOLUMNINFO ; Callback Current_Object ; Passing ihdbc iCol ihstmt ; Result iVoid //*** Allocate Move (Repeat(' ', iLen)) To sResult Indicate Err False //*** Call the driver function to get the data Call_driver 0 sDrvrId Function FUNC_SQLGETDATA ; Callback Current_Object ; Passing sResult sEmpty iLen ; Result iResult //*** If something went wrong, adjust the result If (Err) ; Move 0 To iResult End End Else ; Send StmtError CLIERR_SQLINVALID_COLUMN ("(Column number = " + String(iCol) + ")") "SQLGetData" End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLGetData" //*** Fill global result Move iResult To SQLResult Function_Return sResult End_Function // SQLGetData //*** //*** Function: SQLColumnMap //*** Purpose : Map a column name to a number, if the name id not found no //*** error is generated the returned number will be 0 (zero) in //*** that case //*** //Doc/ Interface=Public Function SQLColumnMap String sColname Returns Integer Local Integer ihdbc Local Integer ihstmt Local Integer iNumColumns Local Integer iColCount Local Integer iColNum Local String sDrvrId Local String sCurColName //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Get the number by looping through the column names Move 0 To iColNum Get SQLPrivateStmtAttribute SQLSTMTATTRIB_COLUMNCOUNT ihdbc sDrvrId ihstmt To iNumColumns For iColCount From 1 To iNumColumns Get SQLPrivateColAttribute iColCount SQLCOLATTRIB_LABEL ihdbc sDrvrId ihstmt To sCurColName If (Uppercase(Trim(sColName)) = Uppercase(Trim(sCurColName))) ; Move iColCount To iColNum If (iColNum) ; Break Loop Function_return iColNum End_Function // SQLColumnMap //*** //*** Function: SQLStmtAttribute //*** Purpose : Get a statement attribute //*** //Doc/ Interface=Public Function SQLStmtAttribute Integer iAttribId Returns String Local Integer ihdbc Local Integer ihstmt Local String sResult Local String sDrvrId //*** Initialize Move "" To sResult //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Get the attribute If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") ; Get SQLPrivateStmtAttribute iAttribId ihdbc sDrvrId ihstmt To sResult Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLStmtAttribute" Function_Return sResult End_Function // SQLStmtAttibute //Doc/ Interface=Private Function SQLPrivateStmtAttribute Integer iAttribId Integer ihdbc String sDrvrId Integer ihstmt Returns String Local String sResult Local Integer iLen Local Integer bLegalAttrib //*** Initialize Move "" To sResult //*** Get the attribute If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin Case Begin Case (iAttribId = SQLSTMTATTRIB_COLUMNCOUNT) Case (iAttribId = SQLSTMTATTRIB_ROWCOUNT) Case (iAttribId = SQLSTMTATTRIB_ROWCOUNT_TYPE) Case (iAttribId = SQLSTMTATTRIB_NUMMESSAGES) Move DFTRUE To bLegalAttrib Break Case Else Move DFFALSE To bLegalAttrib Send SQLIllegalAttribute ("Attribute is = " + String(iAttribId) + ")") "SQLPrivateStmtAttribute" Case End If (bLegalAttrib) Begin //*** Setup function arguments Call_driver 0 sDrvrId Function FUNC_SQLSTMTINTATTRIB ; Callback Current_Object ; Passing ihdbc iAttribId ihstmt ; Result sResult End End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLPrivateStmtAttribute" Function_Return sResult End_Function // SQLPrivateStmtAttribute //*** //*** Function: SQLColAttribute //*** Purpose : Get a column's attribute //*** //Doc/ Interface=Public Function SQLColAttribute Integer iCol Integer iAttribId Returns String Local Integer ihdbc Local Integer ihstmt Local String sResult Local String sDrvrId //*** Initialize Move "" To sResult //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Get the attribute If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") ; Get SQLPrivateColAttribute iCol iAttribId ihdbc sDrvrId ihstmt To sResult Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLColAttribute" Function_Return sResult End_Function // SQLColAttribute //Doc/ Interface=Private Function SQLPrivateColAttribute Integer iCol Integer iAttribId Integer ihdbc String sDrvrId Integer ihstmt Returns String Local String sResult Local String sEmpty Local Integer bIsStringAttribute Local Integer iLen Local Integer iVoid Local Integer bLegalAttrib Local Integer bLegalColumn //*** Initialize Move "" To sResult Move "" To sEmpty MOve 0 To iLen //*** Get the attribute If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin Get SQLPrivateColumnIsLegal ihdbc sDrvrId ihstmt iCol To bLegalColumn If (bLegalColumn) Begin //*** Determine the atributes type Case Begin Case (iAttribId = SQLCOLATTRIB_SIZE) Case (iAttribId = SQLCOLATTRIB_LENGTH) Case (iAttribId = SQLCOLATTRIB_PRECISION) Case (iAttribId = SQLCOLATTRIB_SQLTYPE) Case (iAttribId = SQLCOLATTRIB_NULLABLE) Case (iAttribId = SQLCOLATTRIB_DFTYPE) Move DFFALSE To bIsStringAttribute Move DFTRUE To bLegalAttrib Break Case (iAttribId = SQLCOLATTRIB_LABEL) Case (iAttribId = SQLCOLATTRIB_BASECOLUMNNAME) Case (iAttribId = SQLCOLATTRIB_BASETABLENAME) Move DFTRUE To bIsStringAttribute Move DFTRUE To bLegalAttrib Break Case Else Move DFFALSE To bLegalAttrib Send SQLIllegalAttribute ("Attribute is = " + String(iAttribId) + ")") "SQLPrivateColAttribute" Case End If (bLegalAttrib) Begin //*** Setup function arguments Call_driver 0 sDrvrId Function FUNC_SQLCOLUMNINFO ; Callback Current_Object ; Passing ihdbc iCol ihstmt ; Result iVoid If (bIsStringAttribute) Begin //*** Call the driver function to get the data length Call_driver 0 sDrvrId Function FUNC_SQLCOLSTRINGATTRIBLEN ; Callback Current_Object ; Passing sEmpty sEmpty iAttribId ; Result iLen If (iLen) Begin //*** Allocate Move (Repeat(' ', iLen)) To sResult //*** Call the driver function to get the name Call_driver 0 sDrvrId Function FUNC_SQLCOLSTRINGATTRIB ; Callback Current_Object ; Passing sResult sEmpty iAttribId ; Result iVoid End End Else Begin //*** get the attribute Call_driver 0 sDrvrId Function FUNC_SQLCOLINTATTRIB ; Callback Current_Object ; Passing sEmpty sEmpty iAttribId ; Result sResult End End End Else ; Send StmtError CLIERR_SQLINVALID_COLUMN ("(Column number = " + String(iCol) + ")") "SQLPrivateColAttribute" End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLPrivateColAttribute" Function_Return sResult End_Function // SQLPrivateColAttribute //*** //*** Procedure: SQLSetProcedureName //*** Purpsoe : Preapre for calling a stored procedure, pass the procedure name. //*** //Doc/ Interface=Public Procedure SQLSetProcedureName String sProcName String sSchemaArg Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local Integer iVoid Local String sSchema Local String sEmpty //*** Initialize Move "" To sEmpty //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Call the procedure If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin If (Num_Arguments >= 2) ; Move sSchemaArg To sSchema Else ; Move "" To sSchema If (sSchema <> "") Begin Call_driver 0 sDrvrId Function FUNC_SQLSETPROCSCHEMA ; Callback Current_Object ; Passing ihdbc sSchema ihstmt ; Result iVoid End //*** Call the procedure Call_driver 0 sDrvrId Function FUNC_SQLSETPROCNAME ; Callback Current_Object ; Passing ihdbc sProcName ihstmt ; Result iVoid Set piLastArgument To 0 End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLSetProcedurename" End_Procedure // SQLSetProcedureName //*** //*** Function: SQLSetNextArgument //*** Purpose : Pass the next argument //*** //Doc/ Interface=Private Procedure SQLSetNextArgument String sArgument Local Integer iArgnum Get piLastArgument To iArgnum Increment iArgnum Send SQLSetArgument iArgnum sArgument Set piLastArgument To iArgnum End_Procedure // SQLSetNextArgument //*** //*** Procedure: SQLSetArgument //*** Purpose : Set the next argument //*** //Doc/ Interface=Public Procedure SQLSetArgument Integer iArgnum String sArgument Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local Integer iVoid Local String sEmpty //*** Initialize Move "" To sEmpty //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Call the procedure If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Pass the information Call_driver 0 sDrvrId Function FUNC_SQLCOLUMNINFO ; Callback Current_Object ; Passing ihdbc iArgnum ihstmt ; Result iVoid //*** Pass the argument Call_driver 0 sDrvrId Function FUNC_SQLSETPROCARG ; Callback Current_Object ; Passing sArgument sEmpty 0 ; Result iVoid End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLSetArgument" End_Procedure // SQLSetArgument //*** //*** Procedure: SQLCall //*** Purpose : Call a stored procedure //*** //Doc/ Interface=Public Procedure SQLCall Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local Integer iVoid Local String sEmpty //*** Initialize Move "" To sEmpty //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Call the procedure If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Call the procedure Call_driver 0 sDrvrId Function FUNC_SQLCALL ; Callback Current_Object ; Passing ihdbc sEmpty ihstmt ; Result iVoid Set piLastArgument To 0 End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLCall" End_Procedure // SQLCall //*** //*** Function: SQLGetNextArgument //*** Purpose : Get the next argument //*** //Doc/ Interface=Private Function SQLGetNextArgument Returns String Local Integer iArgnum Local String sResult Get piLastArgument To iArgnum Increment iArgnum Get SQLGetArgument iArgnum To sResult Set piLastArgument To iArgnum Function_return sResult End_Function // SQLGetNextArgument //*** //*** Function: SQLGetArgument //*** Purpose : Get the specified argument from a procedure //*** //Doc/ Interface=Public Function SQLGetArgument Integer iArgnum Returns String Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local Integer iVoid Local String sEmpty Local String sArgument Local Integer iLen //*** Initialize Move "" To sEmpty Move "" To sArgument //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Call the procedure If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Pass the information Call_driver 0 sDrvrId Function FUNC_SQLCOLUMNINFO ; Callback Current_Object ; Passing ihdbc iArgnum ihstmt ; Result iVoid //*** Get the length Call_driver 0 sDrvrId Function FUNC_SQLGETPROCARGLEN ; Callback Current_Object ; Passing sEmpty sEmpty 0 ; Result iLen If (iLen) Begin //*** Allocate Move (Repeat(' ', iLen)) To sArgument //*** Pass the argument Call_driver 0 sDrvrId Function FUNC_SQLGETPROCARG ; Callback Current_Object ; Passing sArgument sEmpty 0 ; Result iVoid End End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLGetArgument" Function_Return sArgument End_Function // SQLGetArgument //*** //*** Function: SQLReturnValue //*** Purpose : Get the reutn value of a stored function //*** //Doc/ Interface=Public Function SQLReturnValue Returns String Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local Integer iVoid Local String sEmpty Local String sRetval Local Integer iLen //*** Initialize Move "" To sEmpty Move "" To sRetval //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Call the procedure If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Get the length Call_driver 0 sDrvrId Function FUNC_SQLGETPROCRETVALLEN ; Callback Current_Object ; Passing ihdbc sEmpty ihstmt ; Result iLen If (iLen) Begin //*** Allocate Move (Repeat(' ', iLen)) To sRetval //*** Pass the argument Call_driver 0 sDrvrId Function FUNC_SQLGETPROCRETVAL ; Callback Current_Object ; Passing ihdbc sRetval ihstmt ; Result iVoid End End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLReturnValue" Function_Return sRetval End_Function // SQLReturnValue //*** //*** Function: SQLNextResultSet //*** Purpose : Switch to the next set //*** Returns : 0 = No more result sets //*** <>0 = Switched to next set //*** //Doc/ Interface=Public Function SQLNextResultSet Returns Integer Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local Integer iResult Local String sEmpty //*** Initialize Move "" To sEmpty Move 0 To iResult //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Call the procedure If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Get the length Call_driver 0 sDrvrId Function FUNC_SQLNEXTRESULTSET ; Callback Current_Object ; Passing ihdbc sEmpty ihstmt ; Result iResult Set piLastArgument To 0 End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLNextResultSet" Function_Return iResult End_Function // SQLNextResultSet //*** //*** Procedure: SQLFetchActivatesBuffer //*** Purpose : Setup a file that will be acivated after a succesfull //*** fetch on the statement //*** //Doc/ Interface=Public Procedure SQLFetchActivatesBuffer Integer iFileNum Integer bState Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local Integer iResult Local Integer bIsOpen Local Integer iVoid Local String sFileType //*** Check if file is open Get_attribute DF_FILE_OPENED Of iFileNum To bIsOpen If (bIsOpen) Begin //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Call the procedure If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Check if the file has the correct type Get_attribute DF_FILE_DRIVER Of iFileNum To sFileType If (sFileType = sDrvrId) Begin //*** Setup the buffer Call_driver iFileNum sDrvrId Function FUNC_SQLBUFFERSTATUS ; Callback Current_Object ; Passing ihdbc bState ihstmt ; Result iVoid End Else ; Send StmtError CLIERR_SQLINVALID_BIND_FILE ("File" * String(iFileNum) * "type incompatible with statement (" + sFileType + ")") "SQLBindFile" End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLFetchActivatesBuffer" End Else ; Send StmtError CLIERR_SQLINVALID_BUFFER ("File not open (number =" * String(iFileNum) + ")") "SQLFetchActivatesBuffer" End_Procedure // SQLFetchActivatesBuffer //Doc/ Interface=Public Function SQLGetMessage Integer iMessageNum Returns String Local Integer ihdbc Local Integer ihstmt Local String sDrvrId Local String sMessage Local Integer iVoid //*** Initialize Move "" To sMessage //*** Get the cli handle to the connection Get phCLIHandle To ihstmt Get psDriverId To sDrvrId Get phStmtConnection To ihdbc //*** Call the procedure If (ihstmt <> 0 And ihdbc <> 0 And sDrvrId <> "") Begin //*** Setup function arguments Call_driver 0 sDrvrId Function FUNC_SQLCOLUMNINFO ; Callback Current_Object ; Passing ihdbc iMessageNum ihstmt ; Result iVoid Move (Repeat(' ', 1024)) To sMessage //*** Get the length Call_driver 0 sDrvrId Function FUNC_SQLGETMESSAGE ; Callback Current_Object ; Passing iVoid sMessage iVoid ; Result iVoid End Else ; Send HandleError ihstmt ihdbc sDrvrId "SQLGetDiagRec" Function_Return sMessage End_Function // SQLGetMessage //*** //*** Function: RemoveComponentIdentifier //*** Purpose : Remove the component identifier from a diagnostic message //*** //Doc/ Interface=Public Function RemoveComponentIdentifier String sDiagMessage Returns String While (Left(sDiagMessage, 1) = "[") Move (Right(sDiagMessage, Length(sDiagMessage) - Pos("]", sDiagMessage))) To sDiagMessage End Function_Return sDiagMessage End_Function //*** //*** Function: DFDateToSQLDate //*** Purpose : Convert a DataFlex date to a SQL Date. Use dummy zero dates. //*** //Doc/ Interface=Private Function DFDateToSQLDate Date dDFDate Returns String Local Integer hoCLIHandler Local String sSQLDate //*** Create a CLI handler object Object oDFSQLCLIHandler Is A cCLIHandler Move Current_Object To hoCLIHandler End_object // oCLIHandler //*** Convert the date Get CLIDFDateToSQLDate Of hoCLIHandler (psDRiverID(Current_Object)) dDFDate To sSQLDate //*** Destroy the object Send Destroy_Object To hoCLIHandler Function_Return sSQLDate End_Function // DFDateToSQLDate //*** //*** Function: SQLDateToDFDate //*** Purpose : Convert a SQL date to a DataFlex Date. Use dummy zero dates. //*** //Doc/ Interface=Private Function SQLDateToDFDate String sSQLDate Returns String Local Integer hoCLIHandler Local Date dDFDate //*** Create a CLI handler object Object oSQLDFCLIHandler Is A cCLIHandler Move Current_Object To hoCLIHandler End_object // oCLIHandler //*** Convert the date Get CLISQLDateToDFDate Of hoCLIHandler (psDRiverID(Current_Object)) sSQLDate To dDFDate //*** Destroy the object Send Destroy_Object To hoCLIHandler Function_Return dDFDate End_Function // SQLDateToDFDate End_Class // cSQLStatement //***************************************************************************** //*** Class : cSQLConnection *** //*** Purpose: Connection object for embedded SQL *** //*** *** //*** Description: *** //*** This provides the ability to create a connection for a driver. *** //*** It will contain child statement objects *** //***************************************************************************** //Doc/ ClassLibrary=Common Class cSQLConnection is an Array Procedure Construct_object Integer Image Forward Send Construct_object Image //Doc/ Interface=Private Property Integer phCLIHandle Public 0 //Doc/ Interface=Private Property String psDriverID Public "" //Doc/ Interface=Public Property Integer piBindFile Public 0 Set Delegation_mode to NO_Delegation End_procedure // COnstruct_object //*** //*** Procedure: StoreHandleInfo //*** Purpose : Store basic information about the statement handle. //*** //Doc/ Interface=Private Procedure StoreHandleInfo Integer iCLIHandle String sDrvrId Integer iParentHandle Set phCLIHandle To iCLIHandle Set psDriverID To sDrvrId End_Procedure // StoreHandleInfo //*** //*** Procedure: FreeHandle //*** Purpose : Destroys handle object and all child statement objects //*** //Doc/ Interface=Private Procedure FreeHandle Send Destroy_Object End_Procedure // FreeHandle //*** //*** Function: SQLConnect //*** Purpose : Make a connectin to an embedded SQL server //*** Returns : The DataFlex handle to the connection //*** //Doc/ Interface=Private Function SQLConnect string sDrvrID String sConnect Returns Integer Local Integer ihdbc Local String sEmpty //*** Initialize Move "" To sEmpty Move 0 To ihdbc Indicate Err False //*** Call the driver function to connect Call_driver 0 sDrvrId Function FUNC_SQLCONNECT ; Callback current_object ; Passing sConnect sEmpty 0 ; Result ihdbc //*** If there was an error, make result invalid If (Err) ; Move 0 To ihdbc //*** Check result and store it If (ihdbc <> 0) ; Send StoreHandleInfo ihdbc sDrvrId 0 //*** Return success status Function_Return (ihdbc <> 0) End_function // SQLConnect //*** //*** Function: SQLFileConnect //*** Purpose : Use a connection of an already open file //*** //Doc/ Interface=Private Function SQLFileConnect Integer iFileNum Returns Integer Local Integer ihdbc Local Integer bIsOpen Local String sDrvrId Local String sEmpty //*** Initialize Move "" To sEmpty Move 0 To ihdbc //*** Check if file is open Get_attribute DF_FILE_OPENED Of iFileNum To bIsOpen If (bIsOpen) Begin //*** Fill the driver id, assume longest is 255 characters Move (Repeat(' ', 255)) To sDrvrId Get_attribute DF_FILE_DRIVER Of iFileNum To sDrvrId Indicate Err False //*** Call the driver function to connect Call_driver iFileNum sDrvrId Function FUNC_SQLFILECONNECT ; Callback current_object ; Passing sEmpty sEmpty 0 ; Result ihdbc //*** If there was an error, make result invalid If (Err) ; Move 0 To ihdbc //*** Check result and store it If (ihdbc <> 0) Begin //*** Somehow Call_driver overwrites the sDrvrId variable, restore it here Get_attribute DF_FILE_DRIVER Of iFileNum To sDrvrId Send StoreHandleInfo ihdbc sDrvrId 0 //*** Set filenum so it can be used for fetching Set piBindFile To iFileNum End End //*** Return success status Function_Return (ihdbc <> 0) End_Function // SQLFileConnect //*** //*** Procedure: SQLDisconnect //*** Purpose : Disconnect from an embedded SQL server and free allocated //*** resources //*** //Doc/ Interface=Public Procedure SQLDisconnect Local Integer ihdbc Local Integer iVoid Local String sDrvrId Local String sEmpty //*** Initialize Move "" To sEmpty //*** Get the cli handle Get phCLIHandle To ihdbc Get psDriverId To sDrvrId //*** Free the CLI handle If (ihdbc <> 0) Begin //*** Call the driver function to disconnect Call_driver 0 sDrvrId Function FUNC_SQLDISCONNECT ; Callback Current_object ; Passing sEmpty sEmpty ihdbc ; Result iVoid //*** Free the DataFlex handle Send FreeHandle End End_Procedure // SQLDisconnect //*** //*** Function: CreateHandle //*** Purpose : Creates a child statement handle //*** //Doc/ Interface=Private Function CreateHandle Returns Integer Local Integer hSQL Object oSQLStatement Is A cSQLStatement Move current_object To hSQL End_Object // oSQLStatement //*** If the connection has a default Bind File, assign it to the //*** statement object. The default is set when you open a file with a //*** SetFileConnection command. Set piBindFile Of hSQL To (piBindFile(Current_object)) Function_Return hSQL End_Function // CreateHandle //*** //*** Function: SQLOpen //*** Prupose : Open a statement for use //*** //Doc/ Interface=Public Function SQLOpen Returns Integer Local Integer hDFHandle Local Integer ihdbc Local Integer ihstmt Local Integer iVoid Local String sDrvrId Local String sEmpty //*** Initialize Move "" To sEmpty //*** Get the cli handle to the connection Get phCLIHandle To ihdbc Get psDriverId To sDrvrId //*** Allocate a new handle and populate it If (ihdbc <> 0) Begin //**** Create a new DataFlex handle Get CreateHandle To hDFHandle //*** Call the driver function to allocate a statement handle Call_driver 0 sDrvrId Function FUNC_SQLOPEN ; Callback Current_object ; Passing hDFHandle sEmpty ihdbc ; Result ihstmt //*** If unsuccessful destroy DF side info If (ihstmt = 0) Begin Send FreeHandle to hDFHandle Move 0 to hDFHandle End Else ; Send StoreHandleInfo to hDFHandle ihstmt sDrvrId ihdbc End Function_return hDFHandle End_function // SQLOpen End_Class // cSQLConnection //***************************************************************************** //*** Class : cSQLHandlemanager *** //*** Purpose: Manager for embedded SQL handles. *** //*** *** //*** Description: *** //*** We want to be able to use multiple drivers and multiple *** //*** connections within a driver and multiple statements within a *** //*** connection. To allow this we have palced our own handle logic on *** //*** top of the driver handle logic. This way we can handle the *** //*** situation where two driver handles may be equal. *** //***************************************************************************** //Doc/ ClassLibrary=Common Class cSQLHandleManager Is A Array Procedure Construct_object Integer Image Forward Send Construct_object Image //Doc/ Interface=Private Property String psDefaultDriver Public "" //Doc/ Interface=Private Property String psDefaultConnection Public "" Set Delegation_mode to NO_Delegation End_procedure // COnstruct_object //*** //*** Function: CreateHandle //*** Purpose : Allocate memory for the desired type of handle //*** //Doc/ Interface=Private Function CreateHandle Returns Integer Local Integer hSQL //*** Create a connection object Object oSQLConnection Is A cSQLConnection Move current_object To hSQL End_Object // oSQLConnection Function_Return hSQL End_Function // CreateHandle //*** //*** Procedure: SQLSetConnect //*** Purpose : Store default connection information //*** //Doc/ Interface=Public Procedure SQLSetConnect String sDriver String sConnect Set psDefaultDriver To sDriver Set psDefaultConnection To sConnect End_Procedure // SQLSetConnect //*** //*** Function: SQLConnect //*** Purpose : Make a connectin to an embedded SQL server //*** Returns : The DataFlex handle to the connection //*** //Doc/ Interface=Public Function SQLConnect String sDrvrID String sConnect Returns integer Local Integer hDFHandle Local Integer bOK //*** Check arguments If (sDrvrID = "" And sConnect = "") Begin Get psDefaultDriver To sDrvrId Get psDefaultConnection To sConnect End //*** Allocate a new handle Get CreateHandle To hDFHandle Get SQLConnect of hDFHandle sDrvrID sConnect To bOK //*** If failure, kill the handle and return a 0 handle If (Not(bOK)) Begin Send FreeHandle to hDFHandle Move 0 to hDFHandle End Function_return hDFHandle End_function // SQLConnect //*** //*** Function: SQLFileConnect //*** Purpose : Make an existing connection available for use with Embedded //*** SQL. The connection is identified by the number opf a file //*** that is open for that connection. //*** //Doc/ Interface=Public Function SQLFileConnect Integer iFileNum Returns Integer Local Integer hDFHandle Local Integer bOK //*** Allocate a new handle Get CreateHandle To hDFHandle Get SQLFileConnect of hDFHandle iFileNum To bOK //*** If failure, kill the handle and return a 0 handle If (Not(bOK)) Begin Send FreeHandle to hDFHandle Move 0 to hDFHandle End Function_return hDFHandle End_Function // SQLFileConnect End_Class // cSQLHandleManager //Doc/ Ignore=True //*** //*** Function: CreateSQLManager //*** Purpose : Create the embedded SQL manager, this is an internal function! //*** //Doc/ Interface=Private Function CreateSQLmanager For Desktop Returns Integer Local Integer hoSQlMngr Object oSQLHandleManager Is A cSQLHandleManager MOve Current_object To hoSQLMngr End_Object // oSQLHandleManager Function_Return hoSQLMngr End_Function // CreateSQLMngr //*** Make sure the object is global by creating it under DESKTOP Get CreateSQLManager Of Desktop To _embsqlghoSQLHandleMngr //Doc/ Ignore=False //***************************************************************************** //*** Command: SQLSetConnect *** //*** Purpose: Setup default connection information for embedded SQL. *** //*** *** //*** Syntax : SQLSetConnect sSDriverId sConnectString *** //***************************************************************************** #COMMAND SQLSetConnect R R . Send SQLSetConnect To _embsqlghoSQLHandleMngr !1 !2 #ENDCOMMAND //***************************************************************************** //*** Command: SQLConnect *** //*** Purpose: Connect to a server for embedded SQL usage. *** //*** *** //*** Syntax : SQLConnect To hdbc *** //*** SQLConnect [sDriverId sConnectString] To hdbc *** //***************************************************************************** #COMMAND SQLConnect //*** Check form command is used in #IFSAME !1 TO SQLConnect "" "" to !2 #ELSE Get SQLConnect Of _embsqlghoSQLHandleMngr !1 !2 To !4 #ENDIF #ENDCOMMAND //***************************************************************************** //*** Command: SQLFileConnect *** //*** Purpsoe: Return the handle to a connection of an open file. This *** //*** connection is (obviously) already opened. We are just using *** //*** the same connection for Embedded SQL. This allows the *** //*** programmer not to know connection details. *** //*** *** //*** Syntax : SQLFileConnect Filex To hdbc *** //***************************************************************************** #COMMAND SQLFileConnect R "TO" R . #IFDEF !1 Get SQLFileConnect Of _embsqlghoSQLHandleMngr !1 To !3 #ELSE Get SQLFileConnect Of _embsqlghoSQLHandleMngr !1.File_number To !3 #ENDIF #ENDCOMMAND //***************************************************************************** //*** Command: SQLDisconnect *** //*** Purpose: Connect to a server for embedded SQL usage. *** //*** *** //*** Syntax : SQLDisConnect hdbc *** //***************************************************************************** #COMMAND SQLDisconnect R . If (!1) Send SQLDisconnect to !1 #ENDCOMMAND //***************************************************************************** //*** Command: SQLOpen *** //*** Purpose: Allocate the memory to stroe statement information. *** //*** *** //*** Syntax : SQLOpen hdbc To hstmt *** //***************************************************************************** #COMMAND SQLOpen R "TO" R . If (!1) Get SQLOpen Of !1 To !3 #ENDCOMMAND //***************************************************************************** //*** Command: SQLClose *** //*** Purpose: Close a statement and free all associated memory. *** //*** *** //*** Syntax : SQLClose hstmt *** //***************************************************************************** #COMMAND SQLClose R . If (!1) Send SQLClose to !1 #ENDCOMMAND //***************************************************************************** //*** Command: SQLPrepare *** //*** Purpose: Prepare a statement for execution. *** //*** *** //*** Syntax : SQLPrepare hstmt sStatement *** //***************************************************************************** #COMMAND SQLPrepare R R . If (!1) Send SQLPrepare to !1 !2 #ENDCOMMAND //***************************************************************************** //*** Command: SQLExecute *** //*** Purpose: Execute a prepared statement *** //*** *** //*** Syntax : SQLExecute hstmt *** //***************************************************************************** #COMMAND SQLExecute R . If (!1) Send SQLExecute to !1 #ENDCOMMAND //***************************************************************************** //*** Command: SQLExecDirect *** //*** Purpose: Prepare and execute a statement. *** //*** *** //*** Syntax : SQLExecDirect hstmt sStatement *** //***************************************************************************** #COMMAND SQLExecDirect R R . If (!1) Send SQLEXECDirect to !1 !2 #ENDCOMMAND //***************************************************************************** //*** Command: SQLFileFetch *** //*** Purpose: Get a row from a statement result set. *** //*** *** //*** Syntax : SQLFileFetch hstmt [To File1 [File2 ...]] *** //***************************************************************************** #COMMAND SQL$NextFile R R #IFDEF !2 If (!1) Send SQLBindFile To !1 !2 #ELSE If (!1) Send SQLBindFile To !1 !2.File_number #ENDIF #IF (!0>2) SQL$NextFile !1 !3 !4 !5 !6 !7 !8 !9 #ENDIF #ENDCOMMAND #COMMAND SQLFileFetch R If (!1) Get SQLFetch Of !1 To SQLResult #IF (!0=1) //*** zero tells statement object to use file property If (SQLResult) ; Send SQLBindFile To !1 0 #ENDIF #IFSAME !2 TO If (SQLResult) Begin #IF (!0>2) SQL$NextFile !1 !3 !4 !5 !6 !7 !8 !9 #ENDIF End #ENDIF #ENDCOMMAND //***************************************************************************** //*** Command: SQLBindFetchFile *** //*** Purpose: Binds a file number to a statement so it can be used for *** //*** fetching data. Only needed in non fileconnect. Note that *** //*** can be assigned to the connection or the statement handle *** //*** *** //*** Syntax : SQLBindFileForFetch hstmt|hdbc FileName|FileNumber *** //***************************************************************************** #COMMAND SQLBindFetchFile R R . #IFDEF !2 If (!1) Set piBindFile Of !1 To !2 #ELSE If (!1) Set piBindFile Of !1 To !2.File_Number #ENDIF #ENDCOMMAND //***************************************************************************** //*** Command: SQLFetch *** //*** Purpose: Get a row from a statement result set. *** //*** *** //*** Syntax : SQLFetch hstmt [To Var1 [Var2 ...]] *** //***************************************************************************** #COMMAND SQL$NextColumn R R If (!1) Get SQLNextColumn Of !1 To !2 #IF (!0>2) SQL$NextColumn !1 !3 !4 !5 !6 !7 !8 !9 #ENDIF #ENDCOMMAND #COMMAND SQLFetch R If (!1) Get SQLFetch Of !1 To SQLResult #IFSAME !2 TO If (SQLResult) Begin #IF (!0>2) SQL$NextColumn !1 !3 !4 !5 !6 !7 !8 !9 #ENDIF End #ENDIF #ENDCOMMAND //***************************************************************************** //*** Command: SQLGetData *** //*** Purpose: Get a column's data. *** //*** *** //*** Syntax : SQLGetData hstmt iColumnNUmber [Length iLen] To Var *** //***************************************************************************** #COMMAND SQLGetData R If (!1) Begin #IF (!0>2) #IF (!0=6) Get SQLGetData Of !1 !2 !4 To !6 #ELSE Get SQLGetData Of !1 !2 0 To !4 #ENDIF #ENDIF End #ENDCOMMAND //***************************************************************************** //*** Command: SQLColumnMap *** //*** Purpose: Determine the column number based on the column name. *** //*** *** //*** Syntax : SQLColumnMap hstmt sColName To iColNumber *** //***************************************************************************** #COMMAND SQLColumnMap R R "TO" R . Move 0 To !4 If (!1) ; Get SQLColumnMap Of !1 !2 To !4 #ENDCOMMAND //***************************************************************************** //*** Command: SQLColAttribute *** //*** Purpose: Get an attribute of a column in a statements result set. *** //*** *** //*** Syntax : SQLColAttribute hstmt iCol iAttrId To sAttrib *** //***************************************************************************** #COMMAND SQLColAttribute R R R "TO" R . Move "" To !5 If (!1) ; Get SQLColAttribute Of !1 !2 !3 To !5 #ENDCOMMAND //***************************************************************************** //*** Command: SQLStmtAttribute *** //*** Purpose: Get an atribute of a statement. *** //*** *** //*** Syntax : SQLStmtAttribute hstmt iAttribId To sAttrib *** //***************************************************************************** #COMMAND SQLStmtAttribute R R "TO" R . Move "" To !4 If (!1) ; Get SQLStmtAttribute Of !1 !2 To !4 #ENDCOMMAND //***************************************************************************** //*** Command: SQLCall *** //*** Purpose: Call a stored procedure. *** //*** *** //*** Syntax : SQLCall hstmt ProcedureName SchemaName [Arg1 ...] [To Var] *** //*** You can pass "" for SchemaName. *** //***************************************************************************** #COMMAND SQL$SetNextArgument R R #IFSAME !2 TO //*** We do not need to set a return value before calling the procedure //*** afert all, return values are filled after it is called. Simply //*** stop when a TO is found. #ELSE If (!1) Send SQLSetNextArgument To !1 !2 #IF (!0>2) SQL$SetNextArgument !1 !3 !4 !5 !6 !7 !8 !9 #ENDIF #ENDIF #ENDCOMMAND #COMMAND SQL$GetNextArgument R R #IFSAME !2 TO #IF (!0>2) Get SQLReturnValue Of !1 To !3 #ENDIF #ELSE If (!1) Get SQLGetNextArgument Of !1 To !2 #IF (!0>2) SQL$GetNextArgument !1 !3 !4 !5 !6 !7 !8 !9 #ENDIF #ENDIF #ENDCOMMAND #COMMAND SQLCall R R R If (!1) Begin #IF (!0>1) //*** Setup name, arguments and return value before actually calling Send SQLSetProcedureName To !1 !2 !3 #IF (!0>2) SQL$SetNextArgument !1 !4 !5 !6 !7 !8 !9 #ENDIF //*** Call Send SQLCall To !1 //*** Get arguments and return value after the call #IF (!0>2) SQL$GetNextArgument !1 !4 !5 !6 !7 !8 !9 #ENDIF #ENDIF End #ENDCOMMAND //***************************************************************************** //*** Command: SQLGetArguments *** //*** Purpsoe: Get the arguments of a stored procedure. This command should *** //*** be used when a procedure has multiple result sets. Some *** //*** backends (SQL SErver for example) will return these as the *** //*** last result set. This emans you first process all other *** //*** result sets and then get the arguments and return value. *** //*** *** //*** Syntax : SQLGetArguments hstmt [Arg1...] [To Var] *** //***************************************************************************** #COMMAND SQLGetArguments R SQL$GetNextArgument !1 !2 !3 !4 !5 !6 !7 !8 !9 #ENDCOMMAND //***************************************************************************** //*** Command: SQLNextResultSet *** //*** Purpose: Go the the next result set. This command should be used when *** //*** a procedure call results in multiple result sets. Processing *** //*** such procedures can be done by loping through the result *** //*** sets. *** //*** *** //*** Syntax : SQLNextResultSet hstmt *** //***************************************************************************** #COMMAND SQLNextResultSet R . If (!1) Get SQLNextResultSet Of !1 To SQLResult #ENDCOMMAND //***************************************************************************** //*** Command: SQLFetchActivatesBuffer *** //*** Purpose: Setup fetch behavior for a file. When set to true a *** //*** succesfull fetch of the statement resutl set will *** //*** automatically set the status of the file's bufer to *** //*** DF_FILE_ACTIVE. *** //*** *** //*** Syntax : SQLFetchActivatesBuffer hstmt FileNUmber|FileName sState *** //***************************************************************************** #COMMAND SQLFetchActivatesBuffer R R R . #IFDEF !2 If (!1) Send SQLFetchActivatesBuffer To !1 !2 !3 #ELSE If (!1) Send SQLFetchActivatesBuffer To !1 !2.File_number !3 #ENDIF #ENDCOMMAND