Scripting Example 88

; *****************************************************

; Example88.ftp

; =============

; This example shows how to open a Access Databases and

; Record sets.

; ---

; -----------------------------------------------------------

; Commands demonstrated:

;

; DBDeclare

; DBResult

; DBConnect

; DBOpen

; DBClose

;

; DBFirst

; DBNext

; DBPrev

; DBLast

;

; NOTE: "DBExecute" is left out of the demo. This command does the same as

; DBOpen except it does not return a query result. It is intended for

; other types of DB commands like DELETE, UPDATE, etc.

;

; Syntax:

; See example source.

;

; -----------------------------------------------------------

; NOTE: You are NOT able to execute this example unchanged

; because of Database availability.

; ***********************************************************

 

 

; -- Skip all auto-logs

SkipCommandLog

SkipExecutionLog

SkipResultLog

 

; -- Declare a database name and connect parameters - ADO style:

DBDeclare MyDatabase "File Name=D:\Butler\Data\Butler.UDL"

 

; -- Declare a dataset result to be used on table(s) in the

; previously declared database:

DBResult MyResult "MyDatabase"

 

; -- Now connect to the database:

DBConnect MyDatabase

if not success then

message "Unable to connect Database."

endscript

endif

 

; -- Perform a SQL call to the database using the

; prevsiously declared dataset result:

DBOpen MyResult "SELECT * FROM Items ORDER BY Item"

if not success then

message "Unable to open result."

endscript

endif

 

; -- DBOpen initializes these variables:

; "<dataset>.RecordCount"

; "<dataset>.FieldCount"

message "Records retrieved: %%MyResult.RecordCount%%"

message "Number of Fields: %%MyResult.FieldCount%%"

 

numvariable i

 

; -- DBOpen also initializes variables that contain

; the field names from the SQL call. The Field names

; are stored in variables as follows:

; "<dataset>.Fields.<index>"

log "=============== Fields =============="

for i=1 to %%MyResult.FieldCount%%

log %%MyResult.Fields.[%%i%%]%%

next i

 

if "%%MyResult.EOF%%" = "True" then

EndScript

endif

 

log ""

log "=============== Data =============="

DBFirst MyResult

:NextRecord

if "%%MyResult.EOF%%" != "True" then

; -- DBFirst, DBNext, DBLast and DBPrev initialize variables

; that contain the data of the fields from the SQL call.

; The data is stored in variables as follows:

; "<dataset>.<fieldname>"

log "%%MyResult.Item%% %%MyResult.Description%%"

DBNext MyResult

Goto "NextRecord"

endif

 

numvariable iRecord

log ""

log "=============== Data By Fields =============="

let iRecord = 0

DBFirst MyResult

:NextRecord1

if "%%MyResult.EOF%%" != "True" then

let iRecord = %%iRecord%% + 1

log "Record: %%iRecord%%"

for i = 1 to %%MyResult.FieldCount%%

; -- DBFirst, DBNext, DBLast and DBPrev also initialize other

; variables that contain the data of the fields from the SQL call

; and can be accessed by index. The data is stored in variables

; as follows:

; "<dataset>.Fields.<index>.Fieldname"

; "<dataset>.Fields.<index>.Value"

log " %%MyResult.Fields.[%%i%%].FieldName%% = '%%MyResult.Fields.[%%i%%].Value%%'"

next i

DBNext MyResult

Goto "NextRecord1"

endif

 

; -- Finally close the Dataset.

DBClose MyDatabase