All the Execute,
VExecute, CExecute and AExecute SQLite3 COM methods return data in
the same manner. When the query(-ies) executed with one of them return
some data (SELECT queries for example) it is packed in a result
collection which is described below.
The result collection is implemented using VarDictionary objects,
thus each node in it is a VarDictionary object over which you can use
any of the VarDictionary's
object methods or properties. For example VarDictionary supports
powerful Clone feature that enables you create copies of parts of the
data in a single simple statement. See VarDictionary
documentation for more information. In the description below the most
frequently used VarDictionary features are cited as they apply to the
result collection.
For the description below assume you have called one of the Execute
methods like this:
Set result = db.Execute("one or more
queries from which some return some results")
result - the root object of the result collection
result.Info - The last insert row ID. This is the row ID or
the primary key value of the last record inserted using an INSERT
statement. example: lastid = result.Info
result(N) - where N can be integer between 1 and
result.Count. Refers to the N-th row in the result. For example you
can use Set row = result(i) to assign the i-th row to a
variable.
result(N)(M) - where M is between 1 and result(N).Count.
Refers to the value of the M-th field in the row N.
result(N)(field_name) - where field_name is the name of
a field in the row. Refers to the value of the field named
field_name.
result(N).Key(M) - where M is between 1 and
result(N).Count. Refers to the name of the M-th field in the row.
result(N).Count - the count of the fields in the row.
result(N).Info - Refers to the type information for the
row. It contains the types of each field in it. Depending on the TypeInfoLevel
property it is returned in the following forms:
TypeInfoLevel = 0 A collection containing the variant
type constant corresponding to the field's value type. The type
of a field is obtained like this: t = result(N).Info(M) where M
can be field index in the row (1 to result(N).Count) or a field
name. The type value can be one of the following values:
vbLong (3) - integer
vbDouble (5) - double precision floating point number
vbString (8) - text (string)
8209 - BLOB (can be also specified in VBScript as vbArray Or
vbByte)
vbNull (1) - Null
TypeInfoLevel = 2 or 4 A collection containing the
type names corresponding to the field's value type. The type
of a field is obtained like this: t = result(N).Info(M) where M
can be field index in the row (1 to result(N).Count) or a field
name. The type value can be one of the following values:
INTEGER - integer
REAL - double precision floating point number
TEXT - text (string)
BLOB - binary data
NULL - Null value
TypeInfoLevel = 1 or 3 A string of the
type names separated with ; (semi-colon). To obtain the field's
type you need first to use the Split function over the type
info:
arrTypeInTheRowN = Split(result(N).Info,";")
and then refer to the field index - 1:
t = arrTypeInTheRowN(M - 1)
Generally this is not the most convenient way to query the
field type, but it is preserved for backward compatibility with
SQLite COM. The type names are the same as in the previous case:
INTEGER, REAL, TEXT, BLOB, NULL.
result.Count - the number of the rows in the result.
result.Key(N) - returns the index of the query which have
produced the N-th row. The Execute methods can execute more than one
query in a single call. Thus the returned data could be a combined
result from more than one query. Using the result.Key(N) you can keep
track of the query - data row connection. Usually the developers
execute the queries that return data one by one, but sometimes
executing many queries in a single call may be worthwhile - saving
some code typing work.
Example:
Assume table T has fields A and B, table X has fields Y and Z. We
will query the both tables in single call and display their contents
putting the type of each value in brackets after it.
db.TypeInfoLevel = 1
Set result = db.Execute("SELECT FROM T; SELECT * FROM X;")
Response.Write "Table T:" & <BR>
I = 1
While I <= result.Count And result.Key(I) = 1
Response.Write "A:" & result(I)("A") & "(" & result(I).Info("A") & "), B:" & result(I)("B") & "(" & result(I).Info("B") & ")<BR>"
I = I + 1
Wend
Response.Write "Table X:" & <BR>
While I <= result.Count And result.Key(I) = 2
Response.Write "Y:" & result(I)("Y") & "(" & result(I).Info("Y") & "), Z:" & result(I)("Z") & "(" & result(I).Info("Z") & ")<BR>"
I = I + 1
Wend
|