Array with no/open size in structures
Posted: Sat May 22, 2010 9:32 pm
It would be great to have a special kind of 'sizeless' arrays to address (imported) arrays of unknown*/variable size.
*unknown on structure definition time
For example MYSQL_ROW:
The C definition is »typedef char **MYSQL_ROW; /* return data as array of strings */«
The PB structure could look like this:
- OR -
In this case PureBasic will not take control of the array. It just makes it possible to access the MYSQL_ROW data.
mySQL still controls, fills and frees the memory - AND - off course knows the size of the array. (FieldCount = mysql_num_fields(*mySQL_Result))
This would be possible:Direct access to the field string...
Or if there is no zero at the end:
instead of:
This one works:
..but what happens if there are more than 255 fields?
I hope I was clear enough.
Any chance to implement this? - Would be great!
Thanks - sverson
*unknown on structure definition time
For example MYSQL_ROW:
The C definition is »typedef char **MYSQL_ROW; /* return data as array of strings */«
The PB structure could look like this:
Code: Select all
Structure MYSQL_ROW
Array field.s()
EndStructure
Structure MYSQL_LENGTHS
Array length.l()
EndStructure
Code: Select all
Structure MYSQL_ROW
OpenArray field.s
EndStructure
Structure MYSQL_LENGTHS
OpenArray length.l
EndStructure
mySQL still controls, fills and frees the memory - AND - off course knows the size of the array. (FieldCount = mysql_num_fields(*mySQL_Result))
This would be possible:
Code: Select all
*myRow.MYSQL_ROW = mysql_fetch_row(*mySQL_Result)
debug *myRow\field(3)
Or if there is no zero at the end:
Code: Select all
*myRow.MYSQL_ROW = mysql_fetch_row(*mySQL_Result)
*myLengths.MYSQL_LENGTHS = mysql_fetch_lengths(*mySQL_Result)
debug PeekS(*myRow\field(3), *myLengths\length(3))
Code: Select all
*mySQL_Row = mysql_fetch_row(*mySQL_Result)
*mySQL_Lengths = mysql_fetch_lengths(*mySQL_Result)
mySQL_FieldLength.l = PeekL(*mySQL_Lengths+4*3)
*mySQL_FieldPtr = PeekL(*mySQL_Row+4*3)
debug PeekS(*mySQL_FieldPtr, mySQL_FieldLength)
Code: Select all
Structure MYSQL_ROW
field.s[255]
EndStructure
I hope I was clear enough.
Any chance to implement this? - Would be great!
Thanks - sverson