My Setup:
What I'm doing is pulling a very large table from MySQL (40,000+ Rows)
SpoolInfo.request.query("SELECT SpoolNumber AS a, DrawingNumber AS b, LineSize AS c, PipeSpec AS d, CU AS e, SheetNumber AS f, FluidCode AS g FROM Job" + JobNumber + ".SpoolInfo ORDER BY SpoolNumber ASC");
Doing a simple operation to it to format it how it is needed for the application I have to send it to:
if(SpoolInfo.response.data){
SpoolInfoRowsObj = {"Cache":[]};
SpoolInfo.response.data.forEach(function(d,di){
SpoolInfoRowsObj.Cache.push(_.values(SpoolInfo.response.data[di]));
});
Then storing it back into a Cache table for quicker access:
(This is needed because I can't find a way to make the .forEach loop to run faster, and currently takes over 20 seconds.)
UpdateCacheTable1.request = new AP.MySQL.Request();
UpdateCacheTable1.request.execute("UPDATE `Job" + JobNumber + "`.`CacheTable_SpoolInfo` SET `SpoolInfoObj` = '" + JSON.stringify(SpoolInfoRowsObj.Cache) + "' WHERE ID = 1");
The Problem:
When I retrieve that data back later:
CacheSpoolInfo.request.query("SELECT SpoolInfoObj FROM Job" + GetJobNumber.response.data[0].JobNumber + ".CacheTable_SpoolInfo ");
CommRef_.SpoolInfo = CacheSpoolInfo.response.data
And try to use is like this:
....
}else if (t == "SpoolInfo"){
rowsObj = {"Rows":[]};
rowsObj = {"Rows":JSON.parse(CommRef_.SpoolInfo[0].SpoolInfoObj)};
}else{
....
It has a bunch of extra "\" stuff in it for all the special characters like:
"Rows": [
[
"[[\" 1-AII22-84042S01 \",\"1040\r\"],[\"0-A102-27564S01 \",\"110\r\"],.....
]
]
So of course the ouput is not the same JSON structured format that I saved.
I kinda thought using JSON.stringify() and JSON.parse() as I did would handle this.
My Question:
How can I handle this so the data I pull back can be handled the same way it would have been before I sent it to the DB?? AKA get rid of all the little slashes so JSON can parse it again.