Using Universal SQL with Arrays

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4775
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Using Universal SQL with Arrays

#1 Post by rdonnay »

Here is a nice little sample that shows the power of Universal SQL in Xbase++ 2.0.

In this example, a SQL SELECT statement parses the data from a 2-dimensional array into object variables which can then be browsed using the DCBROWSECOL OBJECTVAR clause. What makes this powerful is the ability to convert array structures to object structures for a variety of purposes.

Code: Select all

#INCLUDE "dac.CH"
#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], aData, oBrowse, Size

Select Field1 AS Name, ;
       Field2 AS Size, ;
       Field3 AS Date, ;
       Field4 AS Time ;
       FROM (Directory("*.*")) ;
       WHERE Size > 100 ;
       INTO OBJECTS aData

ASort(aData,,,{|a,b|Upper(a:name) < Upper(b:name)})

@ 0,0 DCBROWSE oBrowse DATA aData SIZE 50,20 FIT ;
      HEADLINES 2 ;
      FONT '12.Lucida Console'

DCBROWSECOL OBJECTVAR Name WIDTH 20 HEADER 'File;Name' PARENT oBrowse ;
   SORT {||ASort(aData,,,{|a,b|Upper(a:name) < Upper(b:name)})} DEFAULT

DCBROWSECOL OBJECTVAR Size WIDTH 15 HEADER 'File;Size' PARENT oBrowse ;
   SORT {||ASort(aData,,,{|a,b|a:size < b:size})}

DCBROWSECOL OBJECTVAR Date WIDTH 12 HEADER 'File;Date' PARENT oBrowse ;
   SORT {||ASort(aData,,,{|a,b|a:date < b:date})}

DCBROWSECOL OBJECTVAR Time WIDTH 12 HEADER 'File;Time' PARENT oBrowse ;
   SORT {||ASort(aData,,,{|a,b|a:time < b:time})}

DCREAD GUI FIT TITLE 'Array SQL'

RETURN nil
arraysql.jpg
arraysql.jpg (86.36 KiB) Viewed 10904 times
The eXpress train is coming - and it has more cars.

Post Reply