int openCnn=OpenConnection(StringConnection,adUseClient,0); Sleep(10);
return(0); }
//job example:
int start() { //this is just in case a connection is closed or "gone bad" - there are enough reasons if (createCnn<=0 || IsOpenConnection()==0) { createCnn=0; openCnn=0;
CloseConnection(); Sleep(10);
DestroyConnection(); Sleep(10);
createCnn=CreateConnection(); Sleep(30); }
if (createCnn>0 &&(openCnn<=0 || IsOpenConnection()==0 || Insert==0)) { openCnn=0;
//insertion code works /* string CommandText="INSERT INTO Rates (TimeCurrent,AccountCompany,Symb,DateTimeRate,Ask,Bid) "+ "VALUES("+TimeCurrent()+",'"+Company+"','"+Symb+"','"+DateTimeRate+"',"+Ask+","+Bid+")"; Execute(CommandText,adAsyncFetch); Sleep(15); */ //I want to receive data from the database
string CommandText="select ask from test where ask='1.4560'"; string text=Execute(CommandText,adAsyncFetch); Comment(text);
Sleep(15);
//returns 1; }
//+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { CloseConnection(); DestroyConnection();
//+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators string row; connect(); string query="Select ask from calendar WHERE ask = '1.4567'"; int length=StringLen(query); mysql_real_query(mysql,query,length); int result = mysql_store_result(mysql); int numOfRows = mysql_num_rows(result); for (int i=0;i<numOfRows;i++) { row = mysql_fetch_row(result); Print(row);
Comment(row);
//returns a normal value but at the beginning of the load
#import "ADOLib.dll". int CreateConnection(); int DestroyConnection(); int OpenConnection(string ConnectionString,int CursorLocation,int CommandTimeout); int CloseConnection(); int IsOpenConnection(); int Execute(string CommandText,int ExecuteOption); int BeginTrans(); int CommitTrans(); int RollbackTrans(); int OpenTable(string Qry,int CursorLocation,int CursorType,int LockType,int Options); int CloseTable(); int Requery(); int Update(); int UpdateBatch(); int Cancel(); int CancelBatch(); int CancelUpdate(); int Find(string Criteria,int SearchDirection,int Start); int Filter(string Criteria); int BOF(); int EOF(); int MoveFirst(); int MoveLast(); int MoveNext(); string TableStatus(); int FieldsCount(); string FieldName(int I); string FieldType(int Name); string FieldTypeByPos(int I); string GetFieldValue(string Name); string GetFieldValueByPos(int I); int SetFieldValue(string Name);
intFieldValueByPos(int I);
in ADOLib.mqh
there are methods:
GetFieldValue
GetFieldValueByPos
after successful opening of the table "SELECT * FROM NameTable"
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
А что вы конкретно имеете в наработке по данному вопросу MS SQL?
приведите код и покажите где у вас не работает. будем разбираться.
//TheVilkas example
#include <ADOLib.mqh>
int createCnn=0;
int openCnn=0;
int Insert=0;
string StringConnection="DSN=dbForex;UID=sa;PWD=;";
int init()
{
CloseConnection();
DestroyConnection();
int createCnn=CreateConnection();
Sleep(10);
int openCnn=OpenConnection(StringConnection,adUseClient,0);
Sleep(10);
return(0);
}
//job example:
int start()
{
//this is just in case a connection is closed or "gone bad" - there are enough reasons
if (createCnn<=0 || IsOpenConnection()==0)
{
createCnn=0;
openCnn=0;
CloseConnection();
Sleep(10);
DestroyConnection();
Sleep(10);
createCnn=CreateConnection();
Sleep(30);
}
if (createCnn>0 &&(openCnn<=0 || IsOpenConnection()==0 || Insert==0))
{
openCnn=0;
CloseConnection();
Sleep(10);
openCnn=OpenConnection(StringConnection,adUseClient,0);
Sleep(30);
}
//and then write ticks into the database
string Company=AccountCompany();
string Symb=Symbol();
//insertion code works
/*
string CommandText="INSERT INTO Rates (TimeCurrent,AccountCompany,Symb,DateTimeRate,Ask,Bid) "+
"VALUES("+TimeCurrent()+",'"+Company+"','"+Symb+"','"+DateTimeRate+"',"+Ask+","+Bid+")";
Execute(CommandText,adAsyncFetch);
Sleep(15);
*/
//I want to receive data from the database
string CommandText="select ask from test where ask='1.4560'";
string text=Execute(CommandText,adAsyncFetch);
Comment(text);
Sleep(15);
//returns 1;
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
CloseConnection();
DestroyConnection();
return(0);
}
А что вы конкретно имеете в наработке по данному вопросу MS SQL?
приведите код и покажите где у вас не работает. будем разбираться.
//Sample Graff.
//+------------------------------------------------------------------+
//| news001.mq4 |
//| Copyright © 2009, Graff |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Graff"
#property link ""
#property indicator_chart_window
#define DELIM ";"
//#include <mysql.mqh>
#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);
int mysql_store_result(int TMSQL);
string mysql_fetch_row(int result);
int mysql_num_rows(int result);
void mysql_free_result(int result);
//#import
int mysql;
int mTicket, mType;
string mSymbol;
double mLots, mOpen, mClose, mStopLoss, mTakeProfit;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
string row;
connect();
string query="Select ask from calendar WHERE ask = '1.4567'";
int length=StringLen(query);
mysql_real_query(mysql,query,length);
int result = mysql_store_result(mysql);
int numOfRows = mysql_num_rows(result);
for (int i=0;i<numOfRows;i++) {
row = mysql_fetch_row(result);
Print(row);
Comment(row);
//returns a normal value but at the beginning of the load
IMHO - you need to write your own dll. Too many language constructs are missing in MQL4 - MQL5 promises more.
IMHO is not helpful here.
What about the documentation. What does Execute return?
I think it returns a boolean value. Your text says 1. It means that it was executed correctly.
You have to search through the recordings.
Here' s a demonstration of how to work through ADO - might come in handy - quick and easy to do
А как осуществить чтение из БД?ADOLib.mqh looks like this:
// Constants for enum CursorTypeEnum#define adOpenUnspecified 4294967295 //$FFFFFFFFFF;
#define adOpenForwardOnly 0 //$000000000000;
#define adOpenKeyset 1 //$00000001;
#define adOpenDynamic 2 //$00000002;
#define adOpenStatic 3 //$00000003;
// Constants for enum LockTypeEnum
#define adLockUnspecified 4294967295 //$FFFFFFFFFF;
#define adLockReadOnly 1 //$00000001
#define adLockPessimistic 2 //$00000002;
#define adLockOptimistic 3 //$$00000003;
#define adLockBatchOptimistic 4 //$00000004;
// Constants for enum ExecuteOptionEnum
#define adOptionUnspecified 4294967295 //$FFFFFFFFFF;
#define adAsyncExecute 16 //$00000010;
#define adAsyncFetch 32 //$00000020;
#define adAsyncFetchNonBlocking 64 //$00000040;
#define adExecuteNoRecords 128 //$00000080;
#define adExecuteStream 296 //$00000400;
#define adExecuteRecord 2048 //$00000800;
// Constants for enum CursorLocationEnum
#define adUseNone 1 //$00000001;
#define adUseServer 2 //$00000002;
#define adUseClient 3 //$00000003;
#define adUseClientBatch 3 //$00000003;
// Constants for enum CommandTypeEnum
#define adCmdUnspecified 4294967295 //$FFFFFFFFFF;
#define adCmdUnknown 8 //$00000008;
#define adCmdText 1 //$00000001;
#define adCmdTable 2 //$00000002;
#define adCmdStoredProc 4 //$00000004;
#define adCmdFile 256 //$00000100;
#define adCmdTableDirect 512 //$00000200;
#import "ADOLib.dll".
int CreateConnection();
int DestroyConnection();
int OpenConnection(string ConnectionString,int CursorLocation,int CommandTimeout);
int CloseConnection();
int IsOpenConnection();
int Execute(string CommandText,int ExecuteOption);
int BeginTrans();
int CommitTrans();
int RollbackTrans();
int OpenTable(string Qry,int CursorLocation,int CursorType,int LockType,int Options);
int CloseTable();
int Requery();
int Update();
int UpdateBatch();
int Cancel();
int CancelBatch();
int CancelUpdate();
int Find(string Criteria,int SearchDirection,int Start);
int Filter(string Criteria);
int BOF();
int EOF();
int MoveFirst();
int MoveLast();
int MoveNext();
string TableStatus();
int FieldsCount();
string FieldName(int I);
string FieldType(int Name);
string FieldTypeByPos(int I);
string GetFieldValue(string Name);
string GetFieldValueByPos(int I);
int SetFieldValue(string Name);
intFieldValueByPos(int I);
in ADOLib.mqh
there are methods:
GetFieldValue
GetFieldValueByPos
after successful opening of the table "SELECT * FROM NameTable"
set to the right record with
int is_succ=MoveFirst();
and if successful, read:
string FieldVal=";
if(is_succ=1)
FieldVal=GetFieldValue("NameField");
or read by the numeric handler of the field:
int hbdFld=0;
if(is_succ=1)
FieldVal=GetFieldValueByPos(hndFld);
the MoveFirst() method which sets to the FIRST entry,
the ones you want are either overridden by MoveNext(),
and the ones you don't want are either searched and/or filtered.
see. Find(),Filter() or WHERE in SELECT....
and also the GetFieldValueXXXX data reading methods convert field values to
string type, so if necessary the
to the required type