What is "Special" about "Column" ??

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
aetaylorBUSBnWt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Thu Sep 20, 2012 5:11 pm

What is "Special" about "Column" ??

Post by aetaylorBUSBnWt » Sat Oct 08, 2022 7:26 pm

Hi,

Specifically:

combine tArray by column

I am pulling data from a sqlite database and displaying it in a table.

If I just get all records in a variable and put it into the Table field - fine.
(no don't bug me about Data Grids just yet)

So next I wanted to get the table sorted. but that can mean using record sets.
Ok fine.

My SQLite statement:
"select * from datatable order by dateField"
But record sets require you to get each column from the current selected record, field by field.
OK, did that, now have an array, indexed by a number, 1 through n, as I get the fields in order.

But I need a text variable to put into a table.
BUT, I don't want that bull going on where magic sorting of an array happens.
I put them in numerically and all I want out is the actual values, in the order that they were put in.

So I combine the array and get a single variable out.

combine tArray by column

So far, good.

NOW is when trouble happens.

I want ONLY a FEW of the fields from the record.
That means a different select statement

"select field1,fid2,fld3,fl9,fld12 from datatable order by dateField"

At this point the ONLY thing that does not work is:

combine tArray by column
!!!

It takes in the array with the data in it and returns empty.
That array is single dimensional - only has numerically indexed values from a single database record.
If the SQLite Select query is for ALL fields in the record, then "combine" works.
If the SQLite Select query is for some fields in the record, then "combine" returns empty.
NOTE: prior to the combine call, everything is perfect.

So somewhere in the SQLite magic, somebody is screwing with some property or whatever and changes how COMBINE uses "COLUMN"!

Where, how and WHY!!
Most importantly how do I get whatever changed put back so combine works the way it does when all the fields are present.

Thanks for your help

Given the troubles with combine acting weird: the following Never has problems with hidden stuff or array magic.

Code: Select all

function recordFromArray @pArray
    local tIndex, tRecord, tCount;
    put empty into tRecord;
    put the number of lines of the keys of pArray into tCount;
    if tCount > 0 then
        put pArray[1] into tRecord;
        repeat with tIndex = 2 to tCount
            put tab & pArray[tIndex] after tRecord;
        end repeat
    end if
    return tRecord
end recordFromArray

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: What is "Special" about "Column" ??

Post by stam » Sat Oct 08, 2022 8:53 pm

TL;DR

but scanning your post i think i got the gist of it; i can't see why, if you have a full array extracted from a db, you'd need a new SQL query to show only *some* fields from the array data.

Why not just created handler that extracts this from the array for you?

In my experience, the less one messes with SQL the higher level of happiness one achieves. It's not complicated to return a text object with only certain keys from an array, filter it for certain values in keys and order it any way you want. Likely a lot quicker than an SQL call as well...

S.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: What is "Special" about "Column" ??

Post by bn » Sun Oct 09, 2022 8:59 pm

Could you post some sample data of what is not working?

The one example I do not understand. What is in the array when you try to combine by column and what do you expect?

Kind regards
Bernd

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 161
Joined: Tue Feb 23, 2010 10:53 pm

Re: What is "Special" about "Column" ??

Post by bobcole » Mon Oct 10, 2022 3:49 am

aetaylorBUSBnWt:
My first thought was to determine if the results (tResults) of your query are in an array:

Code: Select all

   if tResults is an array then
      put "tResults is an array" & return after message box
   else
      put "tResults is NOT an array." & return after message box
   end if
After digging around the Dictionary, I think it is important to know what LC command you are using to query the database:
  • revQueryDatabase() or
  • revExecuteSQL or
  • revDataFromQuery()
    ...
My favorite is revDataFromQuery() because it does not return an array.
Rather, simply, that command returns a list of delimited records that contain delimited columns.

Bob

Post Reply