HbQtScripts - Usando sintaxe SQL para acessar DBF.

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7929
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

HbQtScripts - Usando sintaxe SQL para acessar DBF.

Mensagem por Itamar M. Lins Jr. »

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.

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 
Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
fladimir
Colaborador
Colaborador
Mensagens: 2445
Registrado em: 15 Nov 2006 20:21

HbQtScripts - Usando sintaxe SQL para acessar DBF.

Mensagem por fladimir »

Show de bola...

Espero testar em breve, isso com certeza será muito útil
Sun Tzu há mais de três mil anos cita nas epígrafes de seu livro “A Arte da Guerra“:

“Concentre-se nos pontos fortes, reconheça as fraquezas, agarre as oportunidades e proteja-se contra as ameaças”.
“Se não é vantajoso, nunca envie suas tropas; se não lhe rende ganhos, nunca utilize seus homens; se não é uma situação perigosa, nunca lute uma batalha precipitada”
.


Até 2017    Desktop Console [ Legado ] Harbour | MinGW | DBF | CDX | FastReport | MySQL


Novos Projetos:

   Desktop Visual           Windev Desktop
   Celular Android/iOS   Windev Mobile
   WEB                            Windev Web


Sejamos gratos a Deus.
Responder