Valentina Win32 data access component like libmysql.dll?
Kenley Lamaute
klamaute at gmail.com
Sun Jan 6 20:19:23 CST 2008
I am currently using the following MQL code ('C++ / Java' like language
supplied by my broker on the MetaTrader platform) to write data to a local
MySQL database on a Vista installation.
As you can see from the import statement below, MySQL has a "libmysql" COM
component that allows one to simply read, write or call stored procs on a
MYSQL database from any high level programming language / Win32 application.
MQL code >>
//+------------------------------------------------------------------+
//| TicksInMySQL.mq4 |
//| Copyright (c) 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright (c) 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
*#import "libmysql.dll"*
int mysql_init(int db);
int mysql_errno(int TMYSQL);
int mysql_real_connect(int TMYSQL, string host, string user, string
password,
string DB,int port,int socket,int clientflag);
int mysql_real_query(int TMSQL, string query, int length);
void mysql_close(int TMSQL);
#import
int mysql;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
mysql = mysql_init(mysql);
if(mysql != 0)
Print("allocated");
string host = "localhost";
string user = "user";
string password = "pass";
string DB = "test";
int clientflag = 0;
int port = 3306;
string socket = "";
int res =
mysql_real_connect(mysql,host,user,password,DB,port,socket,clientflag);
int err = GetLastError();
if(res == mysql)
Print("connected");
else
Print("error=", mysql, " ", mysql_errno(mysql), " ");
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
mysql_close(mysql);
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
string query = "";
int length = 0;
for (int i=0; i<OrdersTotal(); i++)
// For all orders in the terminal
{
if(OrderSelect(i, SELECT_BY_POS)==true)
//If there is the next and our currency pair
{
query = StringConcatenate("insert into
ticks(margin,freemargin,date,ask,bid,symbol,equity) values(",
AccountMargin(), ",", AccountFreeMargin(),
",\"",
TimeToStr(CurTime(), TIME_DATE|TIME_SECONDS),
"\",",
NormalizeDouble(Ask, 4), ",",
NormalizeDouble(Bid, 4),
",\"", OrderSymbol(), "\",", AccountEquity(),
");");
length = StringLen(query);
mysql_real_query(mysql, query, length);
int myerr = mysql_errno(mysql);
if(myerr > 0)
Print("error=",myerr);
}
//+------------------------------------------------------------------+
}}
<<
Does Valentina embedded server db have a similar component to
libmysql.dllto read, write and call stored procedures?
If so, will someone please point me to documentation and usage examples?
Thanks,
Ken
More information about the Valentina
mailing list