Pickle RowSet

Hi all,

Is there a way to pickle a RowSet in Xojo? (Not looking for a plugin.)

Thanks,

Byron

i guess with “pickle” you mean you will use it later or everywhere?
do not destroy the object, use a public property somewhere.
or do you mean database transactions?

Hi MarkusR,

In the Python programming language, they have a feature called Pickle that allows you to store data (serialize it) for later usage. Do you know if Xojo has anything like this that can be use with RowSet? This way, the query can be pickled (serialized), transmitted via the web, de-serialized, etc.

Thanks,

Byron

Short answer: no, but to be clear: are you talking about serializling the query, or the results?

Assuming you mean the actual result data:

Xojo does have ways to convert some data types to text, such as:

  • JSONitem
  • XMLDocument
  • Dictionary (sortof - only when you are using it as JSON)
  • String.FromArray

I don’t think RowSet has this built-in, but I bet with a short helper function you can get it to work.

Xojo has the Extends keyword which is handy, you can add methods to an existing class so you can use them as if they are builtins.

Edit to add:

here’s a rough version of how I’d do it:

Public Function Pickle(extends rs As RowSet) As String
' converts a RowSet to CSV string data
' Proof of concept only: 
' this is not production ready, will fail if data includes "," characters,
' does not handle BLOBs, etc.   

  var data as string ' results
  
  while not rs.AfterLastRow
    
    for i as integer = 0 to rs.LastColumnIndex
      var c as DatabaseColumn = rs.columnAt(i)
      var s as string = c.stringValue
      data = data + s + If( i < rs.LastcolumnIndex, ",", "")
    next
    data = data + EndOfLine
    rs.MoveToNextRow
    
  wend
  
  return data
End Function
2 Likes

ah, ok,
so Python object is converted into a byte stream, and back.

maybe use a sqlite db file,transfer it as binary, use it on the other side.

if you just need to display, maybe use json array with column names/data

1 Like

Hi Markus,

Ohh, that’s a good idea! Thanks… :+1:

Byron

Hi Mike,

Thanks for the good ideas! I’ll have to give this a try… That makes good sense. :+1:

Byron