Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
beerb0x opened this issue Nov 8, 2020 · 6 comments

Comments

@beerb0x
Copy link

beerb0x commented Nov 8, 2020

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

@beerb0x
Copy link
Author

beerb0x commented Nov 8, 2020

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

@radulovicattila
Copy link

radulovicattila commented Nov 9, 2020 via email

@beerb0x
Copy link
Author

beerb0x commented Nov 9, 2020

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

@beerb0x
Copy link
Author

beerb0x commented Nov 9, 2020

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

@eabase
Copy link

eabase commented Nov 9, 2020

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

@beerb0x
Copy link
Author

beerb0x commented Nov 9, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants