I've been curious about something for a while... We have a lot of table data that is stored as comma-delimited lists in varchar columns. These are simple arrays that the code INSERTs INTO the table. When we need to iterate the individual values in the comma-delimited string I've always found it necessary, after retrieving the data from the table, to strip the starting and ending parens, then split the resulting string on the commas back into an array. Is there a way to simply retrieve the data directly into an array?
This is what I mean:
<$theData='a' 'b' 'c' 'd' 'e' 'f'>
<sql "insert into myTable (data) values ($theData)"></sql>
<!-- This... -->
<sql "select data from myTable"></sql>
<sandr "[()]" "" $data>
<split "," $ret>
<$data=$ret>
<loop $data>$data</loop>
<!-- is not the same as this... -->
<sql "select data from myTable"></sql>
<loop $data>$data</loop>
<!-- and not the same as this... -->
<sql "select data from myTable">$data</sql>
Using <sandr> and <split> isn't really a problem. I'm just curious if there is a way to select directly into an array given that the data is already stored the way it is.
This is what I mean:
<$theData='a' 'b' 'c' 'd' 'e' 'f'>
<sql "insert into myTable (data) values ($theData)"></sql>
<!-- This... -->
<sql "select data from myTable"></sql>
<sandr "[()]" "" $data>
<split "," $ret>
<$data=$ret>
<loop $data>$data</loop>
<!-- is not the same as this... -->
<sql "select data from myTable"></sql>
<loop $data>$data</loop>
<!-- and not the same as this... -->
<sql "select data from myTable">$data</sql>
Using <sandr> and <split> isn't really a problem. I'm just curious if there is a way to select directly into an array given that the data is already stored the way it is.