HbQtScripts - Usando sintaxe SQL para acessar DBF.
Enviado: 05 Dez 2016 12:16
Ola!
Deixando registrado aqui.
; Yes, you read it right. HbQtScripts now implement a sub-set of
SQL SELECT statement which is translated to database commands and
result is displayed via Browse(). Let us understand the difference
in true SQL statement components vs HbQt.
Saudações,
Itamar M. Lins Jr.
Deixando registrado aqui.
; Yes, you read it right. HbQtScripts now implement a sub-set of
SQL SELECT statement which is translated to database commands and
result is displayed via Browse(). Let us understand the difference
in true SQL statement components vs HbQt.
Código: Selecionar todos
+ Added: FUNCTION __hbqtExecSelect( cFields, cFrom, cWhere, cOrder, cInto )
which is activated with a statement like:
SELECT first,last,age,state FROM c:\harbour\tests\test.dbf ;
ORDER BY age-desc,state WHERE age>60
#command SELECT <fld,...> FROM <from> ;
[INTO <into>] ;
[ORDER BY <order,...>] ;
[WHERE <*whr*>] ;
=> ;
__hbqtExecSelect( #<fld>, <"from">, #<whr>, #<order>, <"into"> )
preprocessor directive is sent with the script buffer automatically.
; Yes, you read it right. HbQtScripts now implement a sub-set of
SQL SELECT statement which is translated to database commands and
result is displayed via Browse(). Let us understand the difference
in true SQL statement components vs HbQt.
SELECT * | comma sapartaed list of valid field names - no UDFs yet.
FROM fully qualified table name with path and extention. By default
DBFCDX driver is used, but to use another driver prefix the
table name with driver and "|", like:
dbfcdx|c:\harbour\tests\test.dbf
This must be the 2nd component of the statement.
INTO fully qualified table name with path and extention where
results will be deposited. DBFCDX is used for this purpose.
ORDER BY a comma separated list of field names contained in the result
set. Keyword "-desc" can be post-fixed with a fieldname to
present in descending order. In example statement as above
it is represented as - age-desc,state - where the whole result
is sorted descending on age first, then within each age group
state is sorted ascending.
WHERE This must be the last component of the statement.
The only operator supported for multiple conditions is
"AND" only, like: age > 90 and last = 'Thomas'.
The supported operators within a single condition are
>=, <=, !=, <>, =, <, >.
A condition has 3 components
//
1. FieldName - must be present in the table
2. Operator - one of the >=, <=, !=, <>, =, <, >
3. Value - string 'Thomas', numeric 90.0, date '2016-12-02'
a '=' condition is looked for if any index starting with its
FieldName is available or not. If available, then index order
is set to it and seek is performed with Value part which
greately enhances the speed.
; You can test it by simply placing the above SQL statement in a function
and just run it in console mode, assuming that test.dbf actually resides
where it is pointed to.
FUNCTION __test()
SELECT first,last,age,state FROM c:\harbour\tests\test.dbf ;
ORDER BY age-desc,state WHERE age>60
RETURN NIL
Itamar M. Lins Jr.