Discussion of article "SQL and MQL5: Working with SQLite Database" - page 2

 

Due to changes in copying struct - corrected ByteImg.mqh file to use union

download the new FastFile in its publication https://www.mql5.com/ru/forum/6291#comment_4967832
Files:
ByteImg.mqh  6 kb
 
 string query="SELECT COUNT(*) FROM '"+table+"' WHERE low<"+lowLevel+" AND high>"+highLevel+" AND date>'"+TimeToString(time)+"'";

if(sql3.Query(tbl,query)!=SQLITE_DONE)

        {

         Print(sql3.ErrorMsg());

         return 0.0;

        }

      sql3.Disconnect();

      CSQLite3Cell cell;

      tbl.Cell(0,0,cell);

      int gg=cell.GetInt64();


gg always outputs 0. Although if the query is entered directly into the database, it outputs the correct value.

And if instead of COUNT put some column and then look at the array size ArraySize(tbl.m_data), everything is fine. I.e. count doesn't work. I don't know, maybe I'm doing something wrong.....

 
it's better to make it through the year.
 
the cvera itself works. Either I'm getting the result from the wrong place or the class that passes the querier to the database doesn't work correctly.
 

I am currently experiencing this error, can anyone help me?

Files:
Immagine.jpg  268 kb
 
d.bignotti:

I am currently experiencing this error, can anyone help me?

thanks for posting

fix in the archive

 

Forum on trading, automated trading systems and testing trading strategies

Discussion of the article "SQL and MQL5: Working with SQLite Database"

Denis Kanapis, 2017.06.11 15:28

 string query="SELECT COUNT(*) FROM '"+table+"' WHERE low<"+lowLevel+" AND high>"+highLevel+" AND date>'"+TimeToString(time)+"'";

if(sql3.Query(tbl,query)!=SQLITE_DONE)

        {

         Print(sql3.ErrorMsg());

         return 0.0;

        }

      sql3.Disconnect();

      CSQLite3Cell cell;

      tbl.Cell(0,0,cell);

      int gg=cell.GetInt64();


gg always outputs 0. Although if you enter the query directly into the database, it outputs the correct value.

And if instead of COUNT put some column and then look at the array size ArraySize(tbl.m_data), everything is good. I.e. count doesn't work. I don't know, maybe I'm doing something wrong.....


The same thing - COUNT outputs 0, but when you run the script from SQLiteStuido - everything counts.

Practically it was found that this happens on tables with ~10000>number ofStrokes. Moreover, if the obtained table tbl, as in the above example, is printed (by a function built into the code) - columns of INTEGER type will be printed 0, although they are not 0, of course. And in the same printout DOUBLE outputs correctly.

Something seems to be wrong with ints(I haven't had time to test it yet).

 

Forum on trading, automated trading systems and testing trading strategies

Discussion of the article "SQL and MQL5: Working with SQLite Database"

BeforeFlight, 2017.08.31 07:55 AM


Same thing - COUNT outputs 0, but when running a script from SQLiteStuido - everything counts.

Practically found that this happens on tables with ~10000>number ofStrokes. Moreover, if the obtained table tbl, as in the above example, is printed (by a function built into the code) - the columns of INTEGER type will be printed 0, although they are not 0, of course. And in the same printout DOUBLE outputs correctly.

Something seems to be wrong with ints(I haven't had time to test it yet).


I found it - in the file "Include\MQH\Ctrl\ByteImg.mqh":

instead of:

int ViewInt() { __int d; d.v=0; ViewArray(d.b,0,4); return(d.v); }

apparently meant:

int ViewInt() { __int d={0}; ViewArray(d.b,0,4); return(d.v); }

after that everything is correct with COUNT, and the printout of the tables. At least my tests pass.

@o_o @Denis Kanapis

 
BeforeFlight:

Found it-- in the "Include\MQH\Ctrl\ByteImg.mqh" file:

instead of:

apparently meant:

after that, everything is correct with COUNT, and the printout of the tables. At least my tests pass.

@o_o @Denis Kanapis


Just wanted to tell you about this error, you were ahead of me :). For INT values the value 0 was given all the time.

 

you described a bug for SD, because __int is union

union __int { int v; uchar b[4]; };

and the difference between

__int d; d.v=0;

и

__int d={0};

there should be no difference between and

The code fragment you show doesn't understand how it affects your COUNT at all.

because the ViewInt function does not write, but just the opposite - it reads the number in d.v. And it doesn't care about the current value of d.v.

-----

I added your suggested edit to ByteImg to make you feel more comfortable.


But you please localise and provide a reprint of this bug. Since so far everything looks like a bug, but definitely not a bug of the lib.