Dealing with {EMPTY} as response of a custom MySQL DataBase

Hi guys,

I had a little problem with an AFL formula that seems to work well when processing with one or a few symbols, but fails with a watch list with many of them. It seems to fail randomly, I mean, processing the same watch list, it stops in one symbol one time and then in a different one, while when processing that one where the SCAN stopped individually, it works well.

Trying to find what happened I have seen my problem seems to be related to a query to a custom MySql database (via ODBC/SQL Plugin). When processing a huge amount of symbols, it seems my database sometimes responds to the Amibroker query with ‘{EMPTY}’, even when the result should be another one since it has the expected data stored). I mean, if I process this symbol individually, Amibroker receives the expected response (the correct data).

You can see an example with ‘CISXF’, where SQL response (stored in ‘LastQ’ variable) fails (due to the ‘{EMPTY}’ value) the first time but then, individually processed, works perfectly.
I have not found the right way to deal with this ‘{EMPTY}’ or wrong response given by my custom database. I am trying to find a way to add a conditional to my code to identify when it happens and to tell Amibroker what to do, but I am confused about what argument has this ’{EMPTY}’.

formula = "SELECT MAX(asOfDate) FROM " + ticker + " "; 
LastQ = odbcGetValueSQL(formula);
_TRACE("# " + Name() + "---LastQ: " + LastQ);
LastQ = StrReplace(LastQ, "-", "," );

image

Seeing ‘Error 5’, I would think ‘LastQ’ argument is a NUMBER, not STRING as expected, but when I use ‘IsEmpy(lastQ)’ or ‘IsTrue(LastQ)’ it seems ‘LastQ’ argument (storing the ‘{EMPTY}’ MySql response) is not a NUMBER, STRING neither an ARRAY.

image

image

It would be much appreciated if someone could help me to deal with this issue the right way.

Thanks,

_TRACE(typeof(LastQ));

https://www.amibroker.com/guide/keyword/typeof.html

2 Likes
formula = "SELECT MAX(asOfDate) FROM " + ticker + " "; 
LastQ = odbcGetValueSQL(formula);
_TRACE("# " + Name() + "---LastQ: " + LastQ);

if ( typeof(LastQ) == "string")
     LastQ = StrReplace(LastQ, "-", "," );
else
     _TraceF("Type of LastQ is not string but is: %s", typeof(LastQ)); 

Endless of posts already
https://forum.amibroker.com/search?q=typeof%20%20order:latest

2 Likes

Thanks a lot, @bysoaa and @fxshrat,

I'm afraid I am to apologize. I always try to find the answer to my questions by myself, before asking for help here.

I did the same this time, but I looked for the answer completely obfuscated, thinking in functions, not in a keyword. I didn't remember this one at all.

It works perfectly. Much appreciated.

You don't have to. It's fine.

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.