Using Universal SQL with Arrays
Posted: Mon Oct 10, 2016 2:33 pm
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.
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