;KGEN:NOPARSE 
;HEADER:Lib-DB:1.11:Jens Meyer:A collection of Database functions 
;; 
;;=====================================================================================----- 
;; 
;;LIBRARY        Lib-DB() - Database Interface Function Library 
;; 
;;OVERVIEW       A collection of database connectivity functions. 
;; 
;;ACTION         A library of database connectivity functions: 
;;               DBConnOpen() - Open a connection to a database using ADODB 
;;               DBConnClose() - Closes a connection to a database that has previously been opened with DBConnOpen() 
;;               DBRecordsetOpen() - Opens a recordset object from a database 
;;               DBRecordsetClose() - Closes a recordset that has beeen previously opened with DBRecordsetOpen() 
;;               DBGetRecordset() - Retrives a recordset from a database as the result of a SQL query 
;;               DBCommand() - Executes a SQL statement and returns an array of records if applicable 
;;               DBExecuteSQL() - Executes a SQL command on a database 
;; 
;;AUTHOR         Jens Meyer 
;; 
;;VERSION        1.11 - 2004/09/05 
;; 
;;REMARKS        Used to connect to any standard database supporting ADODB. Review the 
;;               individual function headers for details on usage 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K3, W2K8, W2K12 
;; 
; 
 
 
 
;FUNCTION      DBConnOpen() 
; 
;ACTION        Open a connection to a database using ADODB 
; 
;AUTHOR        Jens Meyer 
; 
;VERSION       1.11 - 2004/03/07 - (minor code changes) 
;              1.1  - 2002/09/05 
; 
;SYNTAX        RETCODE = DBConnOpen(DSN [,CONNTIMEOUT, CMDTIMEOUT]) 
; 
;PARAMETERS    DSN - Required - String 
;              - Database connection string (ODBC format) 
; 
;              CONNTIMEOUT - Optional - Integer 
;              - Denotes the time in seconds until a connection times out, 
;;             defaults to 15 seconds 
; 
;              CMDTIMEOUT - Optional - Integer 
;              - Optional integer denoting the time in seconds until a command times out, defaults to 30 seconds 
; 
;RETURN        Connection object if successful, otherwise empty string 
; 
;REMARKS       See also DBConnClose(), DBRecordsetOpen(), DBRecordsetClose(), DBGetRecordset(), DBCommand(), DBExecuteSQL() 
; 
;              Example connection strings (requires appropriate ODBC drivers):: 
; 
;              Microsoft Access        : "DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=database.mdb" 
;              Microsoft SQL Server    : "DRIVER={SQL Server};SERVER=servername;UID=user;PWD=password;DATABASE=mydatabase" 
;              Microsoft Visual FoxPro : "DRIVER={Microsoft Visual FoxPro Driver}; UID=; PWD=; DBQ=database.dbc" 
;              Oracle                  : "DSN=test;UID=username;PWD=password" 
;              For other connection strings please see http://www.connectionstrings.com 
; 
;DEPENDENCIES  none 
; 
;EXAMPLE       $objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=database.mdb') 
; 
;KIXTART BBS   http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82470 
; 
Function DBConnOpen($ConnDSN, optional $ConnTimeout, optional $CmdTimeout)
  Dim $objConn
 
  $ConnTimeout=iif(vartype($ConnTimeout),val($ConnTimeout),15)
  $CmdTimeout=iif(vartype($CmdTimeout),val($CmdTimeout),30)
 
  $ConnDSN=trim($ConnDSN)
  if not $ConnDSN
    exit 87
  endif
 
  $objConn = CreateObject("ADODB.Connection")
  if @ERROR
    exit @ERROR
  endif
 
  $objConn.ConnectionTimeout = $ConnTimeout
  if @ERROR
    exit @ERROR
  endif
 
  $objConn.CommandTimeout = $CmdTimeout
  if @ERROR
    exit @ERROR
  endif
 
  $objConn.Open($ConnDSN)
  if @ERROR
    exit @ERROR
  endif
 
  if not $objConn.State=1
    $objConn=''
    $DBConnOpen=''
    exit @ERROR
  endif
  $DBConnOpen=$objConn
  exit 0
 
EndFunction
 
 
 
;FUNCTION      DBConnClose() 
; 
;ACTION        Closes a connection to a database that has previously been opened with DBConnOpen() 
; 
;AUTHOR        Jens Meyer (sealeopard@usa.net) 
; 
;VERSION       1.1 
; 
;KIXTART       4.12+ 
; 
;SYNTAX        RETCODE = DBConnClose(CONNECTION) 
; 
;PARAMETERS    CONNECTION - Required - Connection Object 
;              - open connection object to a data source from DBConnOpen() 
; 
;RETURN        0 if successful, otherwise error code 
; 
;REMARKS       See also DBConnOpen(), DBRecordsetOpen(), DBRecordsetClose(), DBGetRecordset(), DBCommand(), DBExecuteSQL() 
; 
;DEPENDENCIES  none 
; 
;EXAMPLE       $retcode = DBConnClose($objConn) 
; 
;KIXTART BBS   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000195 
; 
Function DBConnClose($objConn)
  Dim $adStateOpen
 
  $adStateOpen = 1
 
  If vartype($objConn)=9
    If $objConn.State = $adStateOpen
      $objConn.Close()
      if @ERROR
        exit @ERROR
      endif
    EndIf
    $objConn=''
  else
    exit 87
  endif
 
  $DBConnClose=0
  exit 0
EndFunction
 
 
 
 
;FUNCTION      DBRecordsetOpen() 
; 
;ACTION        Opens a recordset object from a database 
; 
;AUTHOR        Jens Meyer (sealeopard@usa.net) 
; 
;VERSION       1.1 
; 
;KIXTART       4.12+ 
; 
;SYNTAX        RETCODE = DBRECORDSETOPEN(CONNECTION, SQL [,CMDTYPE, CURTYPE, LOCKTYPE]) 
; 
;PARAMETERS    CONNECTION - Required - Connection object 
;              - open connection object to a data source from DBConnOpen() 
; 
;              SQL - Required - String 
;              - SQL query to be executed 
; 
;              CMDTYPE - Optional - Integer 
;              - value denoting the command type 
; 
;              CURTYPE - Optional - Integer 
;              - value denoting the cursor type 
; 
;              LOCKTYPE - Optional - Integer 
;              - value denoting the lock type 
; 
;RETURN        Recordset object 
; 
;REMARKS       See also DBConnOpen(), DBConnClose(), DBRecordsetClose(), DBGetRecordset(), DBCommand(), DBExecuteSQL() 
; 
;              The recordset object must be closed with DBRECORDSETCLOSE() 
; 
;DEPENDENCIES  none 
; 
;EXAMPLE       $objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=database.mdb') 
;              $recordset = DBRecordsetOpen($objConn,'SELECT * FROM Table') 
;              $retcode = DBRecordsetClose($recordset) 
;              $retcode = DBConnClose($objConn) 
; 
;KIXTART BBS   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000198 
; 
function DBRecordsetOpen($objConn, $sql, optional $cmdType, optional $curType, optional $lockType)
  dim $cmdCommand, $rsRecordset
  dim $adCmdUnspecified, $adCmdText, $adCmdTable, $adCmdStoredProc, $adCmdUnknown, $adCmdFile, $adCmdTableDirect
  dim $adLockUnspecified, $adLockReadOnly, $adLockPessimistic, $adLockOptimistic, $adLockBatchOptimistic
  dim $adOpenUnspecified, $adOpenForwardOnly, $adOpenKeyset, $adOpenDynamic, $adOpenStatic
  dim $adClipString, $adStateOpen
 
  $adClipString = 2
  $adStateOpen = 1
 
  ; permitted values for database locking 
  $adLockUnspecified     = -1
  $adLockReadOnly        = 1
  $adLockPessimistic     = 2
  $adLockOptimistic      = 3
  $adLockBatchOptimistic = 4
 
  ; permitted values for database cursor 
  $adOpenUnspecified = -1
  $adOpenForwardOnly = 0
  $adOpenKeyset      = 1
  $adOpenDynamic     = 2
  $adOpenStatic      = 3
 
  ; permitted values for database query types 
  $adCmdUnspecified = -1
  $adCmdText        = 1
  $adCmdTable       = 2
  $adCmdStoredProc  = 4
  $adCmdUnknown     = 8
  $adCmdFile        = 256
  $adCmdTableDirect = 512
 
  if vartype($cmdType)
    $cmdType=val($cmdType)
  else
    $cmdType=$adCmdText
  endif
 
  if vartype($curType)
    $curType=val($curType)
  else
    $curType=$adOpenStatic
  endif
 
  if vartype($lockType)
    $lockType=val($lockType)
  else
    $lockType=$adLockReadOnly
  endif
 
  $sql=trim($sql)
 
  if vartype($objConn)<>9 or $sql=''
    exit 87
  endif
 
  $cmdCommand = CreateObject('ADODB.Command')
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordSet = CreateObject('ADODB.Recordset')
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.ActiveConnection = $objConn
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.CommandType = $cmdType
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordset.CursorType = $curType
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordset.LockType = $lockType
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.CommandText = $sql
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordset.Open($cmdCommand)
  if @ERROR
    exit @ERROR
  endif
 
  $DBRecordsetOpen=$rsRecordset
 
  $rsRecordset=''
  $cmdCommand=''
  exit 0
endfunction
 
 
;FUNCTION      DBRecordsetClose() 
; 
;ACTION        Closes a recordset that has beeen previously opened with DBRecordsetOpen() 
; 
;AUTHOR        Jens Meyer (sealeopard@usa.net) 
; 
;VERSION       1.1 
; 
;KIXTART       4.12+ 
; 
;SYNTAX        RETCODE = DBRECORDSETCLOSE(RECORDSET) 
; 
;PARAMETERS    RECORDSET - Required - RecordSet Object 
;              - the recordset that is to be closed 
; 
;RETURN        0 if successful, otherwise error code 
; 
;REMARKS       See also DBConnOpen(), DBConnClose(), DBRecordsetOpen(), DBGetRecordset(), DBCommand(), DBExecuteSQL() 
; 
;DEPENDENCIES  none 
; 
;EXAMPLE       $objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=database.mdb') 
;              $recordset = DBRecordsetOpen($objConn,'SELECT * FROM Table') 
;              $retcode = DBRecordsetClose($recordset) 
;              $retcode = DBConnClose($objConn) 
; 
;KIXTART BBS   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000199 
; 
function DBRecordsetClose($rsRecordset)
  Dim $adStateOpen
 
  $adStateOpen = 1
 
  if $rsRecordset.state=$adStateOpen
    $rsRecordset.Close()
    if @ERROR
      exit @ERROR
    endif
  endif
 
  $rsRecordset=''
  $DBRecordsetClose=''
  exit 0
endfunction
 
 
;FUNCTION      DBGetRecordset() 
; 
;ACTION        Retrives a recordset from a database as the result of a SQL query 
; 
;AUTHOR        Jens Meyer (sealeopard@usa.net) 
; 
;VERSION       1.1 
; 
;KIXTART       4.12+ 
; 
;SYNTAX        RETCODE = DBGETRECORDSET(CONNECTION, SQL [,CMDTYPE, CURTYPE, LOCKTYPE]) 
; 
;PARAMETERS    CONNECTION - Required - Connection Object 
;              - open connection object to a data source from DBConnOpen() 
; 
;              SQL - Required - String 
;              - SQL query to be executed 
; 
;              CMDTYPE - optional - integer  
;              - value denoting the command type 
; 
;              CURTYPE - optional - integer 
;              - value denoting the cursor type 
; 
;              LOCKTYPE - optional - integer 
;              - value denoting the lock type 
; 
;RETURN        2-D array of records or an empty string if the SQL query results in an empty recordset. 
; 
;REMARKS       See also DBConnOpen(),  DBConnClose(), DBRecordsetOpen(), DBRecordsetClose(), DBCommand(), DBExecuteSQL() 
; 
;DEPENDENCIES  none 
; 
;EXAMPLE       $objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=database.mdb') 
;              $recordset = DBGetRecordset($objConn,"SELECT Field1, Field2 FROM Table1 WHERE Field1<>'' ORDER BY Field1") 
;              $retcode = DBConnClose($objConn) 
;              for $row=0 to ubound($recordset,1) 
;                for $column=0 to ubound($recordset,2) 
;                  ? 'Field ='+$recordset[$row,$column] 
;                next 
;              next 
; 
;KIXTART BBS   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000197 
; 
function DBGetRecordset($objConn, $sql, optional $cmdType, optional $curType, optional $lockType)
  dim $cmdCommand, $rsRecordset
  dim $Records, $FinalRecords
  dim $adCmdUnspecified, $adCmdText, $adCmdTable, $adCmdStoredProc, $adCmdUnknown, $adCmdFile, $adCmdTableDirect
  dim $adLockUnspecified, $adLockReadOnly, $adLockPessimistic, $adLockOptimistic, $adLockBatchOptimistic
  dim $adOpenUnspecified, $adOpenForwardOnly, $adOpenKeyset, $adOpenDynamic, $adOpenStatic
  dim $adClipString, $adStateOpen
  dim $row, $rows, $column, $columns
 
  $adClipString = 2
  $adStateOpen = 1
 
  ; permitted values for database locking 
  $adLockUnspecified     = -1
  $adLockReadOnly        = 1
  $adLockPessimistic     = 2
  $adLockOptimistic      = 3
  $adLockBatchOptimistic = 4
 
  ; permitted values for database cursor 
  $adOpenUnspecified = -1
  $adOpenForwardOnly = 0
  $adOpenKeyset      = 1
  $adOpenDynamic     = 2
  $adOpenStatic      = 3
 
  ; permitted values for database query types 
  $adCmdUnspecified = -1
  $adCmdText        = 1
  $adCmdTable       = 2
  $adCmdStoredProc  = 4
  $adCmdUnknown     = 8
  $adCmdFile        = 256
  $adCmdTableDirect = 512
 
  $sql=trim($sql)
 
  if vartype($cmdType)
    $cmdType=val($cmdType)
  else
    $cmdType=$adCmdText
  endif
 
  if vartype($curType)
    $curType=val($curType)
  else
    $curType=$adOpenStatic
  endif
 
  if vartype($lockType)
    $lockType=val($lockType)
  else
    $lockType=$adLockReadOnly
  endif
 
  if vartype($objConn)<>9 or $sql=''
    exit 87
  endif
 
  $cmdCommand = CreateObject('ADODB.Command')
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordSet = CreateObject('ADODB.Recordset')
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.ActiveConnection = $objConn
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.CommandType = $cmdType
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordset.CursorType = $curType
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordset.LockType = $lockType
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.CommandText = $sql
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordset.Open($cmdCommand)
  if @ERROR
    exit @ERROR
  endif
 
  if $rsRecordset.EOF and $rsRecordSet.BOF
    $FinalRecords=''
  else
    if @ERROR
      exit @ERROR
    endif
 
    $Records = $rsRecordset.GetRows()
 
    ; transpose the array 
    $rows=ubound($records,2)
    $columns=ubound($records,1)
    redim $FinalRecords[$rows,$columns]
    for $row=0 to $rows
      for $column=0 to $columns
        $FinalRecords[$row,$column]=$records[$column,$row]
      next
    next
  endif
 
  if $rsRecordset.state=$adStateOpen
    $rsRecordset.Close()
    if @ERROR
      exit @ERROR
    endif
  endif
 
  $rsRecordset=''
  $cmdCommand=''
 
  $DBGetRecordSet=$FinalRecords
  exit 0
endfunction
 
 
 
 
;FUNCTION      DBCommand() 
; 
;ACTION        Executes a SQL statement and returns an array of records if applicable 
; 
;AUTHOR        Jens Meyer (sealeopard@usa.net) 
; 
;VERSION       1.1 
; 
;KIXTART       4.12+ 
; 
;SYNTAX        RETCODE = DBCOMMAND(DSN, SQL) 
; 
;PARAMETERS    DSN - Required - String 
;              - Database connection string (ODBC format) 
; 
;              SQL - Required, String 
;              - SQL statement to be executed 
; 
;RETURN        2-D array of records or an empty string (SELECT) or 0 if other SQL 
;              statement (CREATE, INSERT, UPDATE, DELETE, DROP,...)  was executed successfully. 
; 
;REMARKS       See also DBConnOpen(), DBConnClose(), DBRecordsetOpen(), DBRecordsetClose(), DBGetRecordset(), DBExecuteSQL() 
; 
;DEPENDENCIES  none 
; 
;EXAMPLE       $dsn='DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=test.mdb' 
;              $sql="INSERT INTO Table1 VALUES('eee','fff')" 
;              $recordset = DBCommand($dsn,$sql) 
;              ? 'Error = '+@ERROR+' - '+@SERROR 
;              $sql="SELECT Field1, Field2 FROM Table1" 
;              $recordset = DBCommand($dsn,$sql) 
;              ? 'Error = '+@ERROR+' - '+@SERROR 
;              for $row=0 to ubound($recordset,1) 
;                for $column=0 to ubound($recordset,2) 
;                  ? 'Field(row='+$row+', column='+$column+') ='+$recordset[$row,$column] 
;                next 
;              next 
; 
;KIXTART BBS   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000328 
; 
function DBCommand($ConnDSN,$sql)
  Dim $objConn, $adStateOpen
  dim $Conntimeout, $CmdTimeout
  dim $cmdCommand, $rsRecordset
  dim $Records, $FinalRecords
  dim $adCmdText, $adLockReadOnly, $adOpenStatic
  dim $row, $rows, $column, $columns
 
  $ConnDSN=trim($ConnDSN)
  if not $ConnDSN
    exit 87
  endif
  $sql=trim($sql)
  if not $sql
    exit 87
  endif
 
  ; default database parameters 
  $adStateOpen=1
  $ConnTimeout=15
  $CmdTimeout=30
  $adCmdText = 1
  $adOpenStatic = 3
  $adLockReadOnly = 1
 
  ; open the database connection 
  $objConn = CreateObject("ADODB.Connection")
  if @ERROR
    exit @ERROR
  endif
  $objConn.ConnectionTimeout = $ConnTimeout
  if @ERROR
    exit @ERROR
  endif
  $objConn.CommandTimeout = $CmdTimeout
  if @ERROR
    exit @ERROR
  endif
  $objConn.Open($ConnDSN)
  if @ERROR
    exit @ERROR
  endif
  if not $objConn.State=$adStateOpen
    $objConn=''
    $DBCommand=''
    exit @ERROR
  endif
 
  ; create the database command object 
  $cmdCommand = CreateObject('ADODB.Command')
  if @ERROR
    exit @ERROR
  endif
  $cmdCommand.ActiveConnection = $objConn
  if @ERROR
    exit @ERROR
  endif
  $cmdCommand.CommandType = $adCmdText
  if @ERROR
    exit @ERROR
  endif
  $cmdCommand.CommandText = $sql
  if @ERROR
    $DBCommand=@ERROR
    exit @ERROR
  endif
 
  if instr($sql,'SELECT')=1
    ; create the recordset object 
    $rsRecordSet = CreateObject('ADODB.Recordset')
    if @ERROR
      exit @ERROR
    endif
    $rsRecordset.CursorType = $adOpenStatic
    if @ERROR
      exit @ERROR
    endif
    $rsRecordset.LockType = $adLockReadOnly
    if @ERROR
      exit @ERROR
    endif
    $rsRecordset.Open($cmdCommand)
    if @ERROR
      exit @ERROR
    endif
 
    if $rsRecordset.EOF and $rsRecordSet.BOF
      ; recordset is empty 
      $FinalRecords=''
    else
      if @ERROR
        exit @ERROR
      endif
 
      ; retrieve all records at once and transpose into tabular format 
      $Records = $rsRecordset.GetRows()
      $columns=ubound($records,1)
      $rows=ubound($records,2)
      redim $FinalRecords[$rows,$columns]
      for $row=0 to $rows
        for $column=0 to $columns
          $FinalRecords[$row,$column]=$records[$column,$row]
        next
      next
    endif
 
    ; close recordset 
    if $rsRecordset.state=$adStateOpen
      $rsRecordset.Close()
      if @ERROR
        exit @ERROR
      endif
    endif
 
    $rsRecordset=''
    $cmdCommand=''
 
    $DBCommand=$FinalRecords
  else
    $rsRecordset=$cmdCommand.Execute()
    $cmdCommand=''
    $rsRecordset=''
    if @ERROR
      exit @ERROR
    endif
 
    $DBCommand=0
  endif
 
  ; close the database connection 
  If $objConn.State = $adStateOpen
    $objConn.Close()
    if @ERROR
      exit @ERROR
    endif
  EndIf
  $objConn=''
 
  exit 0
endfunction
 
 
 
 
;FUNCTION      DBExecuteSQL() 
; 
;ACTION        Executes a SQL command on a database 
; 
;AUTHOR        Jens Meyer (sealeopard@usa.net) 
; 
;VERSION       1.11 (minor code changes) 
;              1.1 
; 
;DATE CREATED  2002/09/05 
; 
;DATE MODIFIED 2004/03/07 
; 
;KIXTART       4.20+ 
; 
;SYNTAX        RETCODE = DBEXECUTESQL(CONNECTION, SQL [,CMDTYPE]) 
; 
;PARAMETERS    CONNECTION - Required - Connection object 
;              - open connection object to a data source from DBConnOpen() 
; 
;              SQL - Required - String 
;              - SQL command to be executed 
; 
;              CMDTYPE - Optional - Integer 
;               - defines the command type (e.g. SQL statement, stored procedure) 
; 
;RETURN        0 if successful, otherwise error code 
; 
;REMARKS       See also DBConnOpen(), DBConnClose(), DBRecordsetOpen(), DBRecordsetClose(), DBGetRecordset(), DBCommand() 
; 
;              This routine does not return a recordset as the result of the SQL 
;              statement. Therefore, it should only be used with SQL commands 
;              like INSERT INTO, UPDATE. For SELECT statements one should rather 
;              use DBGetRecordset() or DBComand(). 
; 
;DEPENDENCIES  none 
; 
;EXAMPLE       $objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=database.mdb') 
;              $retcode = DBExecuteSQL($objConn,"INSERT INTO Demo(Field1,Field2) VALUES('Value1','Value2')") 
;              $retcode = DBConnClose($objConn) 
; 
;KIXTART BBS   http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82477 
; 
function DBExecuteSQL($objConn, $sql, optional $cmdType)
  dim $cmdCommand, $rsRecordset
  dim $adCmdUnspecified, $adCmdText, $adCmdTable, $adCmdStoredProc, $adCmdUnknown, $adCmdFile, $adCmdTableDirect
 
  $adCmdUnspecified = -1
  $adCmdText        = 1
  $adCmdTable       = 2
  $adCmdStoredProc  = 4
  $adCmdUnknown     = 8
  $adCmdFile        = 256
  $adCmdTableDirect = 512
 
  $cmdType=iif(vartype($cmdType),val($cmdType),$adCmdText)
 
  if vartype($objConn)<>9 or $sql=''
    exit 87
  endif
 
  $cmdCommand = CreateObject('ADODB.Command')
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.ActiveConnection = $objConn
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.CommandType = $cmdType
  if @ERROR
    exit @ERROR
  endif
 
  $cmdCommand.CommandText = $sql
  if @ERROR
    exit @ERROR
  endif
 
  $rsRecordset=$cmdCommand.Execute()
  $rsRecordset=''
  $cmdCommand=''
  $DBExecuteSQL=@ERROR
  exit @ERROR
endfunction