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

 

Test script:

//--- INCLUDES 
#include <MQH\Lib\SQLite3\SQLite3Base.mqh>
//--- VARIABLES
CSQLite3Base   sql3;
CSQLite3Table  testTable;
CSQLite3Cell   testCell;
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void OnStart()
  {
//--- OPEN DATABASE CONNECTION
   if(sql3.Connect("test.db3")!=SQLITE_OK)
     {Print(sql3.ErrorMsg()); DebugBreak(); return;}
   else
      Print("CONNECTED TO DB.");
//--- CEATE TABLE
   if(sql3.Query("DROP TABLE IF EXISTS [test]")!=SQLITE_DONE)
     {Print(sql3.ErrorMsg()); DebugBreak(); return;}
   if(sql3.Query("CREATE TABLE [test] ([i] INT)")!=SQLITE_DONE)
     {Print(sql3.ErrorMsg()); DebugBreak(); return;}
   else
      Print("TABLE CREATED.");
//--- INSERT VALUE
   if(sql3.Query("INSERT INTO [test] VALUES(1)")!=SQLITE_DONE)
     {Print(sql3.ErrorMsg()); DebugBreak(); return;}
   else
      Print("VALUE \"1\" INSERTED.");
//--- COUNT TABLE ROWS
   if(sql3.Query(testTable,"SELECT COUNT(*) FROM [test]")!=SQLITE_DONE)
     {Print(sql3.ErrorMsg()); DebugBreak(); return;}
   testTable.Cell(0,0,testCell);
   Print("RETRIEVED DATA FROM TABLE : Count(*)=",testCell.GetInt());
   
  }
//+------------------------------------------------------------------+

+added Prints and test __int d0 inside int ViewInt() for comparison purposes

      Print(__FUNCSIG__," || ENTER FUNCTION");
      
      //--- TEST d0 
      __int d0={0};  Print ("TEST d0: d0.v=",d0.v, " DATA d.b:"); ArrayPrint(d0.b);
      ViewArray(d0.b,0,4);
      Print("ViewArray OUTPUT: d0.v=",d0.v," DATA d.b:"); ArrayPrint(d0.b);
      
      //--- d - AS WAS+some Prints
      __int d; d.v=0; Print("\n","d AS WAS: d.v=",d.v," DATA d.b:"); ArrayPrint(d.b);
      ViewArray(d.b,0,4);
      Print("ViewArray OUTPUT: d.v=",d.v, " DATA d.b:"); ArrayPrint (d.b);
      //---
       return(d.v);

OUTPUT:

//CONNECTED TO DB.
//TABLE CREATED.
//VALUE "1" INSERTED.
//int CSQLite3Cell::GetInt() || ENTER FUNCTION
//int CSQLite3Cell::GetInt() || type=CT_INT case
//int CByteImg::ViewInt() || ENTER FUNCTION
//TEST d0: d0.v=0 DATA d.b:
//0 0 0 0
//ViewArray OUTPUT: d0.v=1 DATA d.b:
//1 0 0 0
// 
//d AS WAS: d.v=0 DATA d.b:
//0 0 0 0
//ViewArray OUTPUT: d.v=0 DATA d.b:
//10 0 0
//RETRIEVED DATA FROM TABLE : Count(*)=0

I read your code, @o_o, before writing previous posts and saw perfectly well that there is a union - that's why this bug seemed strange to me too, but it is obviously there.

However, I didn't find the bug in the lib(further down the code - in ViewArray and constructors __int) . However, I can assume from what is highlighted in OUTPUT (obviously strange for union) that the "kind" compiler did not see the change in __int after ViewArray (which operates only .b) and returned the last known value for .v = 0 (highlighted) from the cache "without looking" at d. v itself.

But here I have only assumptions, because I haven't seen the compliator itself, and I repeat, I haven't found any errors related to this bug in your code.

 
MetaQuotes Software Corp.:

New article SQL and MQL5: Working with SQLite Database has been published:

Author: o_O


Hey man, great article.

 

Good afternoon,

I get 2 warnings when running the script:

2017.09.26 07:39:35.569 SQLite3Test 'C:\Users\Roman\AppData\Roaming\MetaQuotes\Terminal\MQL5\Libraries\sqlite3_32.dll' is not 64-bit version

2017.09.26 07:39:35.602 SQLite3Test (GAZP,H1) Cannot load 'C:\Users\Roman\AppData\Roaming\MetaQuotes\Terminal\MQL5\Libraries\sqlite3_32.dll' [193]


Both libraries 32 and 64 were in the archive. I have Win7 64. I don't understand - what do I need to do?


 
rvkstudent:
I get 2 warnings when running the script:

2017.09.26 07:39:35.569 SQLite3Test 'C:\Users\Roman\AppData\Roaming\MetaQuotes\Terminal\MQL5\Libraries\sqlite3_32.dll' is not 64-bit version
2017.09.26 07:39:35.602 SQLite3Test (GAZP,H1) Cannot load 'C:\Users\Roman\AppData\Roaming\MetaQuotes\Terminal\MQL5\Libraries\sqlite3_32.dll' [193]

Both libraries 32 and 64 were in the archive. I have Win7 64. I don't understand - what do I need to do?

nothing

this is MT's reaction to import, but the code continues to work.

There is a fix for the PrintTable function in the appendix.

Files:
sql_ft__mql5.zip  808 kb
 
MetaQuotes Software Corp.:

New article SQL and MQL5: Working with SQLite Database has been published:

Author: o_O


Do you have a 32 bits version ?

The issue is i have a lot of 32 bit customers...

 

Hello.

When I run SQLite3Test.mq5 I get error 14 (SQLITE_CANTOPEN). What am I doing wrong?

 
Serhii Shevchuk:

Hello.

When I run SQLite3Test.mq5 I get error 14 (SQLITE_CANTOPEN).

What am I doing wrong?

not debugging or logging the error location

 
o_o:

do not debug or do not print the error location to the log

1. I run the script from the archive, "as is".

2. Debug "On real data". I enter the first function:

//--- open database connection
   if(sql3.Connect("SQLite3Test.db3")!=SQLITE_OK)
      return;

3. I get to this place in the SQLite3Base.mqh file:

int CSQLite3Base::Reconnect()
  {
   Disconnect();
   uchar file[];
   StringToCharArray(m_dbfile,file);
   int res=::sqlite3_open(file,m_db);
   m_bopened=(res==SQLITE_OK && m_db);
   return(res);
  }

4. After executing the line

int res=::sqlite3_open(file,m_db);

I get res equal to 14. This is the end of the script.

Although, judging by the text of the article, it should be

"В результате работы появится файл базы данных в папке установки терминала MetaTrader 5."

What can be the reason? Which way to look?

 

Checked the downloaded script


Everything worked correctly the first time




Serhii Shevchuk:

Which direction to look in?

start here

 
o_o:

Checked the downloaded script

I checked it too:

Still error 14.

I realise it's hard to get any help from you. I'll just have to figure it out myself. Just keep in mind that your example doesn't work everywhere. I don't know why.