0

I am developing an application in Adobe Flash Builder 4.6 (AIR APP) in which a user fills forms and stores data like name, phone, address (along with some report data) in Local SQL Database. My coding is all Okay but have a just one problem. Along with data, there is an array which I am trying to store on Local SQL Database, but my all attempts have failed. I store array in text datatype in database and when I access the stored array it give an error. Cannot convert "[object Object]" to Array. I dont know what is the problem. Please Help ... Thanks.

I use array with nested array like.. My array is

var ar:Array=["report_name", {label: report_label, number: 5}, [{label: Label1, data: Data1}, {label: Label2, data: Data2}, {label: Label3, data: Data3}]];

Now I store this array in database like.

sqlstatement.text ="INSERT INTO table (id, data) VALUES ('', '"+ar+"')";

In this statement data has TEXT datatype. Now when I access it like

var array:Array = [];
array = Array(sqlstatement.getResult().data[0].data;

It give coercion error.

5
  • 1
    Not enough information. Show us how you store and retrieve the data that you have issues with. Commented Mar 19, 2018 at 12:02
  • Friend I have edited my question. Please help. Commented Mar 19, 2018 at 12:19
  • @MSJuGnu Please respect those people who may be willing to help you and format your code as a code, not as an unreadable mess of a text. Commented Mar 19, 2018 at 12:46
  • 1
    I suggest you to user SharedObjects for user's local data: republicofcode.com/tutorials/flash/as3sharedobject But if you insist to user SQL data base, pars your received data from SQK ( the line that caused the Error ) with JSON.stringify(receivedObject) to get understand what the receivedObjec model is. Commented Mar 19, 2018 at 12:54
  • Bro. SharedObject is not a secure place for data storage. And I dont know the use of json. Please if you elaborate your answer. Thanks. Commented Mar 19, 2018 at 13:46

1 Answer 1

1

You get the result you get because SQL query is a basically a string, so it is equal to

"INSERT INTO table (id, data) VALUES ('', '" + ar.toString() + "')"

where you lose all generic objects {...} and the data structure.

MESepehr is absolutely correct, what you need is JSON data format, which will work fine for you as long, as you keep only Numbers, ints, Strings, Booleans, Arrays, Objects and nulls there.

Then, it is as easy as the following.

Store:

sqlstatement.text = "INSERT INTO table (id, data) VALUES ('', '" + JSON.stringify(ar) + "')";

Restore:

var array:Array = JSON.parse(sqlstatement.getResult().data[0].data) as Array;
Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely perfect :) Thanks a lot... Actually, @MESepehr give the same answer in comments but I didn't understand, So thanks for explanation. It is working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.