dingmaotu/mql-sqlite3

getColumn and getExtendedSql returning blank when string is over around 120 characters

beerb0x opened this issue · 6 comments

I am using build 1280 of mt4 and I ran into this wierd problem, im not sure if its just me or it will effect others but i wanted to post my (dodgy) fix if anyone else runs into it. Any time i used getColumn on a table field that was larger than around 120characters or used getExtendedSql and the query was over 120 chars long i was getting a blank return value. Im no c programer but i dug around and worked out a dodgy fix just to get me out, I made a single line addition to StringFromUtf8Pointer in Common.mqh after the second call to MultiByteToWideChar.

string StringFromUtf8Pointer(intptr_t psz,int len)
  {
   if(len < 0) return NULL;
   string res;
   int required=MultiByteToWideChar(CP_UTF8,0,psz,len,res,0);
   StringInit(res,required);
   int resLength = MultiByteToWideChar(CP_UTF8,0,psz,len,res,required);
   res = StringFormat("%s",res);
   if(resLength != required)
     {
      return NULL;
     }
   else
     {
      return res;
     }
  }

Im no C programer and i have very little idea of what im doing so im unsure what caused this (maybe the copied string in memory doesnt quite jazz with mt4 perfectly) but my hack seems to have fixed it

OK the code formating isnt very good, basically i just added this line:
res = StringFormat("%s",res);
after the second call to MultiByteToWideChar and it fixed my issue

Im not sure what was causing it it seems to be a very strange problem to have. It was just a basic table with text & date fields populated via a Python script

Ok I finally added my sqllite code to my system thats using the ZeroMQ library and found the actual issue. It appears the SQLITE bindings are using earlier versions of the functions from the mql4-lib library. The bug appears to have been fixed with the newer mql4-lib functions. I think the fix would be to update the sqlite bindings with the current mql4-lib project.

string StringFromUtf8Pointer(intptr_t psz,int len)
  {
   if(len < 0) return NULL;
   string res;
   int required=MultiByteToWideChar(CP_UTF8,0,psz,len,res,0);
// need to include the NULL terminating character
   StringInit(res,required+1);
   int rlen=MultiByteToWideChar(CP_UTF8,0,psz,len,res,required);
   return rlen != required ? NULL : res;
  }

It appears the null terminating character is the problem and that is not included in the sqllite library

@beerb0x
If you use tripple back-ticks (```) to enclose your code markup, we can actually read it.

No probs, new to github signed up to post this heh, ive fixed the others.