Skip to content

Commit

Permalink
Changed function name from db_write to db_execute
Browse files Browse the repository at this point in the history
  • Loading branch information
vdemydiuk committed Mar 3, 2016
1 parent 6c76eb9 commit d288272
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion MqlDbAdapter/DbConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace DB
{
public:
virtual bool init() abstract;
virtual bool writeRecord(System::String^ sqlStr) abstract;
virtual int execute(System::String^ sqlStr) abstract;
virtual bool close() abstract;
};
}
10 changes: 5 additions & 5 deletions MqlDbAdapter/MqlAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ extern "C"
return MqlAdapter::Instance->Close(connection_id) == true ? 1 : 0;
}

__declspec(dllexport) int db_write(int connection_id, wchar_t* sqlstr)
__declspec(dllexport) int db_execute(int connection_id, wchar_t* sqlstr)
{
return MqlAdapter::Instance->Write(connection_id, gcnew String(sqlstr)) == true ? 1 : 0;
return MqlAdapter::Instance->Execute(connection_id, gcnew String(sqlstr));
}
}

Expand Down Expand Up @@ -75,13 +75,13 @@ int MqlAdapter::Init(String^ connectionString, int dbType)
return connectionId;
}

bool MqlAdapter::Write(int connectionId, String^ sqlStr)
int MqlAdapter::Execute(int connectionId, String^ sqlStr)
{
bool res = false;
int res = -1;
if (m_connectors.ContainsKey(connectionId))
{
DbConnector^ connector = m_connectors[connectionId];
res = connector->writeRecord(sqlStr);
res = connector->execute(sqlStr);
}

return res;
Expand Down
2 changes: 1 addition & 1 deletion MqlDbAdapter/MqlAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ref class MqlAdapter
public:
static property MqlAdapter^ Instance { MqlAdapter^ get() { return %m_instance; } }
int Init(System::String^ connectionString, int dbType);
bool Write(int connectionId, System::String^ sqlStr);
int Execute(int connectionId, System::String^ sqlStr);
bool Close(int connectionId);

private:
Expand Down
9 changes: 6 additions & 3 deletions MqlDbAdapter/MsSqlConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,26 @@ void MsSqlConnector::readRecords()
}
}

bool MsSqlConnector::writeRecord(String^ sqlStr)
int MsSqlConnector::execute(String^ sqlStr)
{
int res = -1;

try
{
SqlCommand^ cmd = gcnew SqlCommand();
cmd->CommandType = Data::CommandType::Text;
cmd->CommandText = sqlStr;
cmd->Connection = m_sqlConnection;

cmd->ExecuteNonQuery();
res = cmd->ExecuteNonQuery();
}
catch (Exception^ e)
{
Console::Write(e->ToString());
return false;
}
return true;

return res;
}

bool MsSqlConnector::close()
Expand Down
2 changes: 1 addition & 1 deletion MqlDbAdapter/MsSqlConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace DB
~MsSqlConnector();

virtual bool init() override;
virtual bool writeRecord(System::String^ sqlStr) override;
virtual int execute(System::String^ sqlStr) override;
void readRecords();
virtual bool close() override;

Expand Down
4 changes: 2 additions & 2 deletions MqlDbAdapter/StubDbConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ bool DB::StubDbConnector::init()
return false;
}

bool DB::StubDbConnector::writeRecord(System::String^ sqlStr)
int DB::StubDbConnector::execute(System::String^ sqlStr)
{
return true;
return 0;
}

bool DB::StubDbConnector::close()
Expand Down
2 changes: 1 addition & 1 deletion MqlDbAdapter/StubDbConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace DB
~StubDbConnector();

virtual bool init() override;
virtual bool writeRecord(System::String^ sqlStr) override;
virtual int execute(System::String^ sqlStr) override;
virtual bool close() override;

private:
Expand Down
9 changes: 3 additions & 6 deletions TestLibrary/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ class Program
public static extern int db_close(int connection_id);

[DllImport("MqlDbAdapter.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern int db_write(int connection_id,
[MarshalAsAttribute(UnmanagedType.LPWStr)] string sqlstr);
public static extern int db_execute(int connection_id, [MarshalAsAttribute(UnmanagedType.LPWStr)] string sqlstr);
#endregion

private static IntPtr _message = IntPtr.Zero;

static void Main(string[] args)
{
if (!TestStubDb())
Expand Down Expand Up @@ -51,7 +48,7 @@ private static bool TestStubDb()
return false;
}

if (db_write(connId, null) < 0)
if (db_execute(connId, null) < 0)
{
Console.WriteLine("StubDb: Write error!");
return false;
Expand All @@ -78,7 +75,7 @@ private static bool TestMsSql()
}

string sql = string.Format("INSERT INTO Pattern (Symbol, Time) VALUES ('{0}', {1})", "EURUSD", 1);
if (db_write(connId, sql) == 0)
if (db_execute(connId, sql) <= 0)
{
Console.WriteLine("Write error: ");
return false;
Expand Down

0 comments on commit d288272

Please sign in to comment.