|
|
|
| 13 May 2002 | DBGetRecordSet() |
| Author | Jens Meyer (sealeopard@usa.net) |
| Action | Retrives a recordset from a database as the result of a SQL query. |
| Syntax | DBGetRecordSet (connection, SQL [,cmdType, curType, lockType]) |
| Parameters | |
| Remarks | Kixtart cannot handle two-dimensional arrays without third-party UDFs. Thus, the returned recordset is an array of records. Each record consists of a CHR(10)-delimited string of the recordset fields. This use of delimiters implies that the recordset field values cannot contain the CHR(10) character. If values can potentialy contain a CHR(10) character (like a BLOB) then this function must not be used. Instead, you can manually retrieve values after using DBRecordsetOpen(). KIXTART BBS http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000197 |
| Returns | Array of records with CHR(10)-delimited fields or an empty string if the SQL query results in an empty recordset. |
| Dependencies | None. |
| Examples |
$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=database.mdb')
$recordset = DBGetRecordset($objConn,"SELECT Field1, Field2 FROM Demo WHERE Field1<>'' ORDER BY Field1")
$retcode = DBConnClose($objConn)
for each $record in $recordset
$recordsetfields=split($record,chr(10))
next
|
| Source |
FUNCTION DBGetRecordSet ($objconn, $sql, OPTIONAL $cmdtype, OPTIONAL $curtype, OPTIONAL $locktype)
DIM $cmdcommand, $rsrecordset
DIM $records, $rowdelimiter, $columndelimiter
DIM $adcmdunspecified, $adcmdtext, $adcmdtable, $adcmdstoredproc, $adcmdunknown, $adcmdfile, $adcmdtabledirect
DIM $adlockunspecified, $adlockreadonly, $adlockpessimistic, $adlockoptimistic, $adlockbatchoptimistic
DIM $adopenunspecified, $adopenforwardonly, $adopenkeyset, $adopendynamic, $adopenstatic
DIM $adclipstring, $adstateopen
$rowdelimiter=Chr(10)+Chr(10)
$columndelimiter=Chr(10)
$adlockunspecified = -1
$adlockreadonly = 1
$adlockpessimistic = 2
$adlockoptimistic = 3
$adlockbatchoptimistic = 4
$adopenunspecified = -1
$adopenforwardonly = 0
$adopenkeyset = 1
$adopendynamic = 2
$adopenstatic = 3
$adclipstring = 2
$adstateopen = 1
$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
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
$records=''
ELSE
IF @error
EXIT @error
ENDIF
$records=$rsrecordset.getstring($adclipstring,,$columndelimiter,$rowdelimiter,'')
IF @error
EXIT @error
ENDIF
$records=Left($records,Len($records)-Len($rowdelimiter))
$records=Split($records,$rowdelimiter)
ENDIF
IF $rsrecordset.state=$adstateopen
$rsrecordset.close()
IF @error
EXIT @error
ENDIF
ENDIF
$rsrecordset=''
$cmdcommand=''
$dbgetrecordset=$records
ENDFUNCTION ; - DBGetRecordSet -
|
|
|
|