KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: 4D v11 SQL List Boxes and dynamically assigned arrays
PRODUCT: 4D | VERSION: 11.3 | PLATFORM: Mac & Win
Published On: December 18, 2008

When assigning the result of an SQL query into a 4D v11 SQL List Box instead of into predefined arrays, and the number of columns returned is greater that the number of columns that have been pre-assigned to the List Box, the SQL engine has to create additional arrays to hold the results. Though it is a sufficient feature for viewing the result, the arrays created by the SQL engine do not allow you as the developer to work with them; they are only useful for viewing data.

As can be seen in the Debugger screenshot below, the original List Box had two columns pre-assigned which are named "Column1" and "Column2". The names of the columns that the SQL engine had to create to contain the overflow of the SQL query begin with the prefix "sql_column". The pointers to these arrays point to "NULL" making any access to these arrays impossible.



To overcome this situation, all you need do is to assign more columns to the List Box than is expected to be needed. This is done in the "Number of Columns" property in the Property List of the List Box object.

All of the columns that contain data as a result of an SQL query will be marked as visible, and those that are in excess of the number of columns returned will be typed as TEXT, sized, and contain no data. The result is that you now have access to all the data returned by the SQL query and the excess number of columns occupy little if any memory.

Commented by Charlie Vass on February 18, 2009 at 10:09 AM
As written, this technique works in interpreted mode but does not in compiled mode. For a technique that works in Compiled mode please see TN 09-07 which contains a technique of dynamically building arrays, and then filling a list box with those arrays.

To use the technique mentioned in the TN you will have to have prior knowledge of the order of the columns being returned and their types. This is all demonstrated in the TN.