$loadcols $colcount

Kelly Burgess kellyb at montana.com
Sun Apr 17 23:38:40 UTC 2022


Hi Martin,

Sorry, I can't make sense of your code.  As I said before, this

> For lLineNum from 1 to  lTableClassColsList.$linecount        
>    Do lTableClassColsList.[lLineNum].$loadcols(lCol01,lCol02,lCol03,lCol04,lCol05,lCol06,lCol07)            
> End For        

does nothing but leave the last line's values in the locals.  Every $loadcols() is loading a line which the next iteration overwrites before anything else happens.  I'm not sure what you think is happening there.

I have some code that sets up an export of user-selected columns from a table class.  So I've got a list of the column names with a boolean telling me which columns the user has selected for export.  I go through that list (iSchemaCols) and for each checked column, I add a column to a 'columns' row.

   For fldLine from 1 to iSchemaCols.$linecount step 1
      If iSchemaCols.[fldLine].iIncludeCol     ## if this column is checked for export
         Calculate colName as iSchemaCols.[fldLine].iColName
         Do columns.$cols.$add(colName,kCharacter,kSimplechar)
      End If
   End For

So now I have a row defined the same as the table*, but only the checked columns are included. Then I define my output list using that column subset.

   Calculate define as con("$definefromsqlclass('",tableName,"',columns,tSessionRef)")
   Do outList.[define]

* except that column types are all character, because I'm just exporting to a text file, so numeric types don't need preserving, and I'm not expecting this to have to work with binary columns...

Now I can use outList with sql statments to select only the desired columns.  This illustrates two things, first that you can pass a row as the second parameter to $definefromsqlclass in order to restrict your list to include only the columns you want (the ones included in the row) - a good way to avoid loading large binary columns when you only want a reference list, or to downsize the column set to what the user selected.  The second point is that you can pass parameters to your table class $construct, like I do above with tSessionRef.  $definefromsqlclass's third parameter becomes the first parameter passed to $construct in the table class, and I use that so I can have my base table class assign the session reference:

    Do $cinst.$sessionobjref.$assign(pSessionRef)

I hope that gives you some ideas.

Kelly


More information about the omnisdev-en mailing list