As I am writing a procedure to generate an JSON-string based on a rowset, I need to know how to handle the SQLite datatypes REAL and BLOB.
For example for strings I suggest this peace of code:
Var jsRecord As New JSONItem
For z As Integer = 0 To iCollumnCount
sName = Rs.ColumnAt(z).Name
sValue = Rs.ColumnAt(z).StringValue.DefineEncoding(Encodings.UTF8)
jsRecord.Value(sName) = sValue
Next
Hope someone can help me …
SQLite REAL is a floating point value, so we use Double in Xojo. BLOB is binary data so if it’s a file you’ll probably want to base64 encode it and store it as a String in the JSONItem. You can find a little bit of info about the data types in the Xojo docs.
1 Like
Instead of storing StringValue, store Value (a Variant), then check to see what type it is.
If it’s anything other than string, store it as-is. Otherwise, check if it’s valid UTF-8. If so, define the encoding, otherwise, encode it as Tim suggested above.
Thanks @Tim_Parnell and @Kem_Tekinay … Sometimes in the proces of coding you need some clues from professionals like you guys.
1 Like