Database Wrapper – library MetaTrader 5

Introduction

SQLite locks are coarse-grained file locks. If multiple tables share a database, you need to pay attention to synchronization issues.
a. It is not recommended to define global variables for the classes in this class, otherwise 5605 errors will easily occur
b. After the query, the data should be retrieved and released as soon as possible to prevent other connections from being unable to obtain the reserved lock

c. Try to Execute in the transaction to avoid some 5605 errors


This is an encapsulation library of DatabaseXXX series functions, which realizes the automatic release of resources

//Open

CDatabase db( "test.db" );   //对象生命周期结束时,自动调用DatabaseClose

Print ( "db IsAvaliable=" , db.IsAvaliable());

// have table

  MV_OBV - indicator MetaTrader 5
 Print ( "table" ,db.HasTable( "tab" ) ? "exist" : "不存在" );

//implement

db.Execute("创建表tab(aa integer, bb double , cc string );");

for ( int i= 1 ;i< 10 ;i++)
{

db.Execute( StringFormat ("插入 (aa, bb, cc) 值(%d, %G, %s);", i, rand ()/ 100 , SQLiteTimeStr( TimeCurrent ())));

}

//read

CDatabaseRequest req = db.Query( "select * from tab" ); //对象生命周期结束时,自动调用DatabaseFinalize

int v;

req.GetInteger( 0 , v);

int v2 = req.GetIntegerOrDefault( "aa" );
 int v;

double d;

string  s;

bool rc = db.QueryFirst< int , double , string >(v, d, s, "select * from tab" );
 int v[];

double d[];

string s[];

bool rc = db.Query< int , double , string >(v, d, s, "select * from tab" );
📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks