1

Setup: MySQL Database with UpdateTracker table with column named ANY in it.

I run this to get my dataset:

RefData_UpdateTracker.request = new AP.MySQL.Request();

RefData_UpdateTracker.request.query("SELECT * FROM Common_RefData.RefData_UpdateTracker"); 

Was trying to do some conditions based of date comparisons, but none were working.. So I just set it to output the dataset with this:

response.body = JSON.stringify(RefData_UpdateTracker.response.data[0].ANY);

Below is what I get back instead of a date looking like "2016-02-11" as it is in the DB column of data type "DATE" .

MjAxNi0wMi0xMQ==

I thought I would get back a string like I do from all my other fields... So How do I handle what ever it is MySQL is sending back to me to convert it into a javascript Date()?

2 Answers 2

1

Looks like a base64 output, so to get it back to a proper date, just do:

atob('MjAxNi0wMi0xMQ=='); // "2016-02-11"

https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/atob

alert(atob('MjAxNi0wMi0xMQ=='));

Sign up to request clarification or add additional context in comments.

6 Comments

Thankyou, yes you were absolutely correct. It was base64 encoded. The question I have now is Where is this getting base64 encoded?? It doesn't appear to be base64 in the MySQL field. I will have to track that down, I have no need that I can see to be working with base64 encoded dates. and to top it off, the JS engine I'm working in (JustAPIs) does not have atop or btop it seems.
You're welcome! Hmm, I was wondering the same thing actually... It's probably something you're using to fetch the results. What are you using on the server-side?
DB is google.MySQL (5.6) The "java engine" I'm using is the Rapid api development software "JustAPIs" It is a self enclosed binary with build in js interpreter. it is supposed to have all javascript and underscore.js in it. But I try using atob, and I get not defined errors.
Hmm, very interesting, could it be that they don't have atob, but use base64 somewhere in the line? There has to be a better way then.
Finally got some info back from JustAPIs. After getting them to dig into it further, they discovered that Ooops, they are accidentally encoding "DATE" data types from MySQL as base64. They are to be publishing a fix soon.
|
0

Shomz hit the nail on the head. the problem is the JS engine I'm using (JustAPIs) does not have the atob or btob functions defined. So I still need to dig through and see WHY these dates are getting base64 encoded.

But in the meantime I found this nice little library that is equivalent to atob and btop. Luckily JustAPIs has a way to add shared libraries, so I just put the following code in there... now have a home made atob/btob.

function btob(a) {
  var c, d, e, f, g, h, i, j, o, b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", k = 0, l = 0, m = "", n = [];
  if (!a) return a;
  do c = a.charCodeAt(k++), d = a.charCodeAt(k++), e = a.charCodeAt(k++), j = c << 16 | d << 8 | e, 
  f = 63 & j >> 18, g = 63 & j >> 12, h = 63 & j >> 6, i = 63 & j, n[l++] = b.charAt(f) + b.charAt(g) + b.charAt(h) + b.charAt(i); while (k < a.length);
  return m = n.join(""), o = a.length % 3, (o ? m.slice(0, o - 3) :m) + "===".slice(o || 3);
}

function atob(a) {
  var b, c, d, e = {}, f = 0, g = 0, h = "", i = String.fromCharCode, j = a.length;
  for (b = 0; 64 > b; b++) e["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(b)] = b;
  for (c = 0; j > c; c++) for (b = e[a.charAt(c)], f = (f << 6) + b, g += 6; g >= 8; ) ((d = 255 & f >>> (g -= 8)) || j - 2 > c) && (h += i(d));
  return h;
}

Comments

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.