HbDBU with HbQtScripts with SQL Implementation

Hello Everybody

The latest version of HbDBU can be downloaded from 

This is a stand-alone executable which does not need any Qt libraries.

This version implements a sub-set of SQL query statement which is applied on any table opened with any rdd.

The SQL specific details are as such:

    + 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:
                  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 

Looking for your critique and suggestions
Note that SQL dialect is so vast that it would be impossible to bring to Harbour, but effor is started...

Pritpal Bedi
a student of software analysis & concepts
12/3/2016 1:26:58 AM
comp.lang.xharbour 5470 articles. 0 followers. Post Follow

0 Replies

Similar Articles

[PageSpeed] 52