Android Question Storing and Retrieving MAP objects in SQL

Gary Milne

Active Member
Licensed User
Longtime User
When writing a MAP object to SQL it gets converted to a ByteArray. Is there an easy way to convert the ByteArray back into the original MAP object?

I know I could parse it and rebuild it that way but there has to be some existing method for doing that?
 

Gary Milne

Active Member
Licensed User
Longtime User
Yes, objects of type Map.

If a solution exists then it will result in simpler code as I won't have to explicity read and write to the 15 columns that would be needed in lieu. Ican also change the contents of the Map and not have to adjust the code.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Is the SQL just to store the map object? If so, see File.WriteMap. If you are storing other things as well then you are probably better off making a class that mimics your map and handles the save/load to the SQL internally.
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I'm sorry, I don't know enough about Map and SQL,
but a solution may be to transform the Map object to a string by JSONGenerator, and write this string into SQL database.
Then you can read this string from database, and convert to Map object with JSONParser.

Help here: http://www.b4x.com/android/forum/threads/android-json-tutorial.6923/#content

Only a few lines for to transform Map to String and String to Map

Sergio
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Since Maps and DBs can contain any type of data, I think that the best solution should be, as Jeffrey suggested, use classes.

In this way, in addition to be able to use executable code (eg for validation) will be possible to save bitmaps in the DB.

Gary could rightly argue that he does not want to manage 15 fields directly, let alone create an entire class.

Us (at least one of us ) should develop a tool for the generation of this type of classes once and for all.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…