quickfix_ruby 1.14.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +248 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +127 -0
  6. data/ext/quickfix/AtomicCount.h +109 -0
  7. data/ext/quickfix/DOMDocument.h +74 -0
  8. data/ext/quickfix/DataDictionary.cpp +618 -0
  9. data/ext/quickfix/DataDictionary.h +539 -0
  10. data/ext/quickfix/DataDictionaryProvider.cpp +71 -0
  11. data/ext/quickfix/DataDictionaryProvider.h +70 -0
  12. data/ext/quickfix/DatabaseConnectionID.h +105 -0
  13. data/ext/quickfix/DatabaseConnectionPool.h +91 -0
  14. data/ext/quickfix/Dictionary.cpp +162 -0
  15. data/ext/quickfix/Dictionary.h +94 -0
  16. data/ext/quickfix/Event.h +95 -0
  17. data/ext/quickfix/Exceptions.h +299 -0
  18. data/ext/quickfix/Field.h +672 -0
  19. data/ext/quickfix/FieldConvertors.h +863 -0
  20. data/ext/quickfix/FieldMap.cpp +238 -0
  21. data/ext/quickfix/FieldMap.h +244 -0
  22. data/ext/quickfix/FieldNumbers.h +46 -0
  23. data/ext/quickfix/FieldTypes.cpp +64 -0
  24. data/ext/quickfix/FieldTypes.h +698 -0
  25. data/ext/quickfix/Fields.h +31 -0
  26. data/ext/quickfix/FileLog.cpp +200 -0
  27. data/ext/quickfix/FileLog.h +112 -0
  28. data/ext/quickfix/FileStore.cpp +332 -0
  29. data/ext/quickfix/FileStore.h +129 -0
  30. data/ext/quickfix/FixFieldNumbers.h +1537 -0
  31. data/ext/quickfix/FixFields.h +1538 -0
  32. data/ext/quickfix/FixValues.h +3281 -0
  33. data/ext/quickfix/FlexLexer.h +188 -0
  34. data/ext/quickfix/Group.cpp +64 -0
  35. data/ext/quickfix/Group.h +73 -0
  36. data/ext/quickfix/HtmlBuilder.h +186 -0
  37. data/ext/quickfix/HttpConnection.cpp +739 -0
  38. data/ext/quickfix/HttpConnection.h +78 -0
  39. data/ext/quickfix/HttpMessage.cpp +149 -0
  40. data/ext/quickfix/HttpMessage.h +133 -0
  41. data/ext/quickfix/HttpParser.cpp +49 -0
  42. data/ext/quickfix/HttpParser.h +54 -0
  43. data/ext/quickfix/HttpServer.cpp +169 -0
  44. data/ext/quickfix/HttpServer.h +78 -0
  45. data/ext/quickfix/Initiator.cpp +289 -0
  46. data/ext/quickfix/Initiator.h +149 -0
  47. data/ext/quickfix/Log.cpp +77 -0
  48. data/ext/quickfix/Log.h +179 -0
  49. data/ext/quickfix/Message.cpp +580 -0
  50. data/ext/quickfix/Message.h +370 -0
  51. data/ext/quickfix/MessageCracker.h +188 -0
  52. data/ext/quickfix/MessageSorters.cpp +105 -0
  53. data/ext/quickfix/MessageSorters.h +156 -0
  54. data/ext/quickfix/MessageStore.cpp +146 -0
  55. data/ext/quickfix/MessageStore.h +174 -0
  56. data/ext/quickfix/Mutex.h +131 -0
  57. data/ext/quickfix/MySQLConnection.h +194 -0
  58. data/ext/quickfix/MySQLLog.cpp +275 -0
  59. data/ext/quickfix/MySQLLog.h +145 -0
  60. data/ext/quickfix/MySQLStore.cpp +331 -0
  61. data/ext/quickfix/MySQLStore.h +142 -0
  62. data/ext/quickfix/NullStore.cpp +54 -0
  63. data/ext/quickfix/NullStore.h +99 -0
  64. data/ext/quickfix/OdbcConnection.h +266 -0
  65. data/ext/quickfix/OdbcLog.cpp +252 -0
  66. data/ext/quickfix/OdbcLog.h +117 -0
  67. data/ext/quickfix/OdbcStore.cpp +338 -0
  68. data/ext/quickfix/OdbcStore.h +113 -0
  69. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  70. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  71. data/ext/quickfix/Parser.cpp +103 -0
  72. data/ext/quickfix/Parser.h +57 -0
  73. data/ext/quickfix/PostgreSQLConnection.h +176 -0
  74. data/ext/quickfix/PostgreSQLLog.cpp +276 -0
  75. data/ext/quickfix/PostgreSQLLog.h +144 -0
  76. data/ext/quickfix/PostgreSQLStore.cpp +334 -0
  77. data/ext/quickfix/PostgreSQLStore.h +141 -0
  78. data/ext/quickfix/Queue.h +75 -0
  79. data/ext/quickfix/QuickfixRuby.cpp +252066 -0
  80. data/ext/quickfix/QuickfixRuby.h +34 -0
  81. data/ext/quickfix/Responder.h +43 -0
  82. data/ext/quickfix/Session.cpp +1487 -0
  83. data/ext/quickfix/Session.h +335 -0
  84. data/ext/quickfix/SessionFactory.cpp +274 -0
  85. data/ext/quickfix/SessionFactory.h +86 -0
  86. data/ext/quickfix/SessionID.h +170 -0
  87. data/ext/quickfix/SessionSettings.cpp +189 -0
  88. data/ext/quickfix/SessionSettings.h +171 -0
  89. data/ext/quickfix/SessionState.h +231 -0
  90. data/ext/quickfix/Settings.cpp +100 -0
  91. data/ext/quickfix/Settings.h +53 -0
  92. data/ext/quickfix/SharedArray.h +150 -0
  93. data/ext/quickfix/SocketAcceptor.cpp +222 -0
  94. data/ext/quickfix/SocketAcceptor.h +75 -0
  95. data/ext/quickfix/SocketConnection.cpp +238 -0
  96. data/ext/quickfix/SocketConnection.h +103 -0
  97. data/ext/quickfix/SocketConnector.cpp +116 -0
  98. data/ext/quickfix/SocketConnector.h +67 -0
  99. data/ext/quickfix/SocketInitiator.cpp +260 -0
  100. data/ext/quickfix/SocketInitiator.h +81 -0
  101. data/ext/quickfix/SocketMonitor.cpp +335 -0
  102. data/ext/quickfix/SocketMonitor.h +111 -0
  103. data/ext/quickfix/SocketServer.cpp +177 -0
  104. data/ext/quickfix/SocketServer.h +100 -0
  105. data/ext/quickfix/ThreadedSocketAcceptor.cpp +258 -0
  106. data/ext/quickfix/ThreadedSocketAcceptor.h +98 -0
  107. data/ext/quickfix/ThreadedSocketConnection.cpp +209 -0
  108. data/ext/quickfix/ThreadedSocketConnection.h +82 -0
  109. data/ext/quickfix/ThreadedSocketInitiator.cpp +268 -0
  110. data/ext/quickfix/ThreadedSocketInitiator.h +84 -0
  111. data/ext/quickfix/TimeRange.cpp +173 -0
  112. data/ext/quickfix/TimeRange.h +258 -0
  113. data/ext/quickfix/Utility.cpp +537 -0
  114. data/ext/quickfix/Utility.h +219 -0
  115. data/ext/quickfix/Values.h +62 -0
  116. data/ext/quickfix/config.h +0 -0
  117. data/ext/quickfix/config_windows.h +0 -0
  118. data/ext/quickfix/extconf.rb +12 -0
  119. data/ext/quickfix/index.h +37 -0
  120. data/ext/quickfix/pugiconfig.hpp +72 -0
  121. data/ext/quickfix/pugixml.cpp +10765 -0
  122. data/ext/quickfix/pugixml.hpp +1341 -0
  123. data/ext/quickfix/strptime.h +7 -0
  124. data/lib/quickfix40.rb +274 -0
  125. data/lib/quickfix41.rb +351 -0
  126. data/lib/quickfix42.rb +1184 -0
  127. data/lib/quickfix43.rb +3504 -0
  128. data/lib/quickfix44.rb +10721 -0
  129. data/lib/quickfix50.rb +13426 -0
  130. data/lib/quickfix50sp1.rb +15629 -0
  131. data/lib/quickfix50sp2.rb +17068 -0
  132. data/lib/quickfix_fields.rb +19853 -0
  133. data/lib/quickfix_ruby.rb +82 -0
  134. data/lib/quickfixt11.rb +70 -0
  135. data/spec/FIX40.xml +862 -0
  136. data/spec/FIX41.xml +1285 -0
  137. data/spec/FIX42.xml +2746 -0
  138. data/spec/FIX43.xml +4229 -0
  139. data/spec/FIX44.xml +6596 -0
  140. data/spec/FIX50.xml +8137 -0
  141. data/spec/FIX50SP1.xml +9496 -0
  142. data/spec/FIX50SP2.xml +10011 -0
  143. data/spec/FIXT11.xml +313 -0
  144. data/test/test_DataDictionaryTestCase.rb +268 -0
  145. data/test/test_DictionaryTestCase.rb +112 -0
  146. data/test/test_FieldBaseTestCase.rb +24 -0
  147. data/test/test_MessageTestCase.rb +368 -0
  148. data/test/test_SessionSettingsTestCase.rb +41 -0
  149. metadata +193 -0
@@ -0,0 +1,266 @@
1
+ /* -*- C++ -*- */
2
+
3
+ /****************************************************************************
4
+ ** Copyright (c) 2001-2014
5
+ **
6
+ ** This file is part of the QuickFIX FIX Engine
7
+ **
8
+ ** This file may be distributed under the terms of the quickfixengine.org
9
+ ** license as defined by quickfixengine.org and appearing in the file
10
+ ** LICENSE included in the packaging of this file.
11
+ **
12
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14
+ **
15
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
16
+ **
17
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
18
+ ** not clear to you.
19
+ **
20
+ ****************************************************************************/
21
+
22
+ #ifndef HAVE_ODBC
23
+ #error OdbcConnection.h included, but HAVE_ODBC not defined
24
+ #endif
25
+
26
+ #ifdef HAVE_ODBC
27
+ #ifndef FIX_ODBCCONNECTION_H
28
+ #define FIX_ODBCCONNECTION_H
29
+
30
+ #ifdef _MSC_VER
31
+ #pragma warning( disable : 4503 4355 4786 4290 )
32
+ #pragma comment( lib, "Odbc32" )
33
+ #endif
34
+
35
+ #include "Utility.h"
36
+ #include <sql.h>
37
+ #include <sqlext.h>
38
+ #include <sqltypes.h>
39
+ #include <sstream>
40
+ #include "DatabaseConnectionID.h"
41
+ #include "DatabaseConnectionPool.h"
42
+ #include "Exceptions.h"
43
+ #include "Mutex.h"
44
+
45
+ namespace FIX
46
+ {
47
+
48
+ inline std::string odbcError( SQLSMALLINT statementType, SQLHANDLE handle )
49
+ {
50
+ SQLCHAR state[6];
51
+ SQLINTEGER error;
52
+ SQLCHAR text[SQL_MAX_MESSAGE_LENGTH];
53
+ SQLSMALLINT textLength;
54
+ RETCODE result = SQLGetDiagRec
55
+ ( statementType, handle, 1, state, &error, text, sizeof(text), &textLength );
56
+ if( result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO )
57
+ return std::string( (char*)text );
58
+ return "";
59
+ }
60
+
61
+ inline bool odbcSuccess( RETCODE result )
62
+ {
63
+ return result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO;
64
+ }
65
+
66
+ class OdbcQuery
67
+ {
68
+ public:
69
+ OdbcQuery( const std::string& query )
70
+ : m_statement( 0 ), m_result( 0 ), m_query( query )
71
+ {}
72
+
73
+ ~OdbcQuery()
74
+ {
75
+ close();
76
+ }
77
+
78
+ void close()
79
+ {
80
+ if( m_statement )
81
+ {
82
+ SQLFreeHandle( SQL_HANDLE_STMT, m_statement );
83
+ m_statement = 0;
84
+ m_result = 0;
85
+ }
86
+ }
87
+
88
+ bool execute( HDBC connection )
89
+ {
90
+ if( m_statement ) SQLFreeHandle( SQL_HANDLE_STMT, m_statement );
91
+ SQLAllocHandle( SQL_HANDLE_STMT, connection, &m_statement );
92
+ m_result = SQLExecDirect( m_statement, (SQLCHAR*)m_query.c_str(), m_query.size() );
93
+ if( success() || m_result == SQL_NO_DATA )
94
+ return true;
95
+ m_reason = odbcError( SQL_HANDLE_STMT, m_statement );
96
+ SQLFreeHandle( SQL_HANDLE_STMT, m_statement );
97
+ m_statement = 0;
98
+ return success();
99
+ }
100
+
101
+ bool success()
102
+ {
103
+ return odbcSuccess( m_result );
104
+ }
105
+
106
+ /*int rows()
107
+ {
108
+ return (int)mysql_num_rows( m_result );
109
+ }*/
110
+
111
+ const std::string& reason()
112
+ {
113
+ return m_reason;
114
+ }
115
+
116
+ bool fetch()
117
+ {
118
+ return odbcSuccess( SQLFetch(m_statement) );
119
+ }
120
+
121
+ /*char* getValue( int row, int column )
122
+ {
123
+ if( m_rows.empty() )
124
+ {
125
+ MYSQL_ROW row = 0;
126
+ while( row = mysql_fetch_row( m_result ) )
127
+ m_rows.push_back(row);
128
+ }
129
+ return m_rows[row][column];
130
+ }*/
131
+
132
+ HSTMT statement()
133
+ {
134
+ return m_statement;
135
+ }
136
+
137
+ void throwException() throw( IOException )
138
+ {
139
+ if( !success() )
140
+ throw IOException( "Query failed [" + m_query + "] " + reason() );
141
+ }
142
+
143
+ private:
144
+ HSTMT m_statement;
145
+ RETCODE m_result;
146
+ std::string m_query;
147
+ std::string m_reason;
148
+ };
149
+
150
+ class OdbcConnection
151
+ {
152
+ public:
153
+ OdbcConnection
154
+ ( const DatabaseConnectionID& id )
155
+ : m_connection( 0 ), m_environment( 0 ), m_connectionID( id )
156
+ {
157
+ connect();
158
+ }
159
+
160
+ OdbcConnection
161
+ ( const std::string& user, const std::string& password,
162
+ const std::string& connectionString )
163
+ : m_connection( 0 ), m_environment( 0 ), m_connectionID( "", user, password, connectionString, 0 )
164
+ {
165
+ connect();
166
+ }
167
+
168
+ ~OdbcConnection()
169
+ {
170
+ if( m_connection )
171
+ {
172
+ SQLDisconnect( m_connection );
173
+ SQLFreeHandle( SQL_HANDLE_DBC, m_connection );
174
+ SQLFreeHandle( SQL_HANDLE_ENV, m_environment );
175
+ }
176
+ }
177
+
178
+ const DatabaseConnectionID& connectionID()
179
+ {
180
+ return m_connectionID;
181
+ }
182
+
183
+ bool connected()
184
+ {
185
+ Locker locker( m_mutex );
186
+ return m_connected;
187
+ }
188
+
189
+ bool reconnect()
190
+ {
191
+ Locker locker( m_mutex );
192
+ SQLDisconnect( m_connection );
193
+ SQLFreeHandle( SQL_HANDLE_DBC, m_connection );
194
+ m_connection = 0;
195
+ connect();
196
+ return true;
197
+ }
198
+
199
+ bool execute( OdbcQuery& pQuery )
200
+ {
201
+ Locker locker( m_mutex );
202
+ if( !pQuery.execute( m_connection ) )
203
+ {
204
+ reconnect();
205
+ return pQuery.execute( m_connection );
206
+ }
207
+ return true;
208
+ }
209
+
210
+ private:
211
+ void connect()
212
+ {
213
+ m_connected = false;
214
+
215
+ RETCODE result;
216
+ if(!m_environment)
217
+ {
218
+ result = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_environment );
219
+ if( !odbcSuccess(result) )
220
+ throw ConfigError( "Unable to allocate ODBC environment" );
221
+
222
+ result = SQLSetEnvAttr(m_environment, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
223
+ if( !odbcSuccess(result) )
224
+ throw ConfigError( "Unable to find ODBC version 3.0" );
225
+ }
226
+
227
+ result = SQLAllocHandle( SQL_HANDLE_DBC, m_environment, &m_connection );
228
+ if( !odbcSuccess(result) )
229
+ throw ConfigError( "Unable to allocate ODBC connection" );
230
+
231
+ std::stringstream connectionStream;
232
+ std::string connectionString = m_connectionID.getHost();
233
+ if( m_connectionID.getHost().find("UID=") == std::string::npos )
234
+ connectionStream << "UID=" << m_connectionID.getUser() << ";";
235
+ if( m_connectionID.getHost().find("PWD=") == std::string::npos )
236
+ connectionStream << "PWD=" << m_connectionID.getPassword() << ";";
237
+ connectionStream << m_connectionID.getHost();
238
+ connectionString = connectionStream.str();
239
+
240
+ SQLCHAR connectionStringOut[255];
241
+
242
+ result = SQLDriverConnect(
243
+ m_connection, NULL,
244
+ (SQLCHAR*)connectionString.c_str(), SQL_NTS,
245
+ connectionStringOut, 255,
246
+ 0, SQL_DRIVER_NOPROMPT );
247
+
248
+ if( !odbcSuccess(result) )
249
+ {
250
+ std::string error = odbcError( SQL_HANDLE_DBC, m_connection );
251
+ throw ConfigError( error );
252
+ }
253
+
254
+ m_connected = true;
255
+ }
256
+
257
+ HENV m_environment;
258
+ HDBC m_connection;
259
+ bool m_connected;
260
+ DatabaseConnectionID m_connectionID;
261
+ Mutex m_mutex;
262
+ };
263
+ }
264
+
265
+ #endif
266
+ #endif
@@ -0,0 +1,252 @@
1
+ /****************************************************************************
2
+ ** Copyright (c) 2001-2014
3
+ **
4
+ ** This file is part of the QuickFIX FIX Engine
5
+ **
6
+ ** This file may be distributed under the terms of the quickfixengine.org
7
+ ** license as defined by quickfixengine.org and appearing in the file
8
+ ** LICENSE included in the packaging of this file.
9
+ **
10
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12
+ **
13
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
14
+ **
15
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
16
+ ** not clear to you.
17
+ **
18
+ ****************************************************************************/
19
+
20
+ #ifdef _MSC_VER
21
+ #include "stdafx.h"
22
+ #else
23
+ #include "config.h"
24
+ #endif
25
+
26
+ #ifdef HAVE_ODBC
27
+
28
+ #include "OdbcLog.h"
29
+ #include "SessionID.h"
30
+ #include "SessionSettings.h"
31
+ #include "Utility.h"
32
+ #include "strptime.h"
33
+ #include <fstream>
34
+
35
+ namespace FIX
36
+ {
37
+
38
+ const std::string OdbcLogFactory::DEFAULT_USER = "sa";
39
+ const std::string OdbcLogFactory::DEFAULT_PASSWORD = "";
40
+ const std::string OdbcLogFactory::DEFAULT_CONNECTION_STRING
41
+ = "DATABASE=quickfix;DRIVER={SQL Server};SERVER=(local);";
42
+
43
+ OdbcLog::OdbcLog
44
+ ( const SessionID& s, const std::string& user, const std::string& password,
45
+ const std::string& connectionString )
46
+ {
47
+ init();
48
+ m_pSessionID = new SessionID( s );
49
+ m_pConnection = new OdbcConnection( user, password, connectionString );
50
+ }
51
+
52
+ OdbcLog::OdbcLog
53
+ ( const std::string& user, const std::string& password,
54
+ const std::string& connectionString )
55
+ : m_pSessionID( 0 )
56
+ {
57
+ init();
58
+ m_pConnection = new OdbcConnection( user, password, connectionString );
59
+ }
60
+
61
+ void OdbcLog::init()
62
+ {
63
+ setIncomingTable( "messages_log" );
64
+ setOutgoingTable( "messages_log" );
65
+ setEventTable( "event_log" );
66
+ }
67
+
68
+ OdbcLog::~OdbcLog()
69
+ {
70
+ delete m_pSessionID;
71
+ delete m_pConnection;
72
+ }
73
+
74
+ OdbcLogFactory::OdbcLogFactory( const std::string& user, const std::string& password,
75
+ const std::string& connectionString )
76
+ : m_user( user ), m_password( password ), m_connectionString( connectionString ),
77
+ m_useSettings( false )
78
+ {
79
+ }
80
+
81
+ OdbcLogFactory::OdbcLogFactory()
82
+ : m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
83
+ m_connectionString( DEFAULT_CONNECTION_STRING ), m_useSettings( false )
84
+ {
85
+ }
86
+
87
+ OdbcLogFactory::~OdbcLogFactory()
88
+ {
89
+ }
90
+
91
+ Log* OdbcLogFactory::create()
92
+ {
93
+ std::string database;
94
+ std::string user;
95
+ std::string connectionString;
96
+
97
+ init( m_settings.get(), database, user, connectionString );
98
+ OdbcLog* result = new OdbcLog( database, user, connectionString );
99
+ initLog( m_settings.get(), *result );
100
+ return result;
101
+ }
102
+
103
+ Log* OdbcLogFactory::create( const SessionID& s )
104
+ {
105
+ std::string database;
106
+ std::string user;
107
+ std::string connectionString;
108
+
109
+ Dictionary settings;
110
+ if( m_settings.has(s) )
111
+ settings = m_settings.get( s );
112
+
113
+ init( settings, database, user, connectionString );
114
+ OdbcLog* result = new OdbcLog( s, database, user, connectionString );
115
+ initLog( settings, *result );
116
+ return result;
117
+ }
118
+
119
+ void OdbcLogFactory::init( const Dictionary& settings,
120
+ std::string& user,
121
+ std::string& password,
122
+ std::string& connectionString )
123
+ {
124
+ user = DEFAULT_USER;
125
+ password = DEFAULT_PASSWORD;
126
+ connectionString = DEFAULT_CONNECTION_STRING;
127
+
128
+ if( m_useSettings )
129
+ {
130
+ try { user = settings.getString( ODBC_LOG_USER ); }
131
+ catch( ConfigError& ) {}
132
+
133
+ try { password = settings.getString( ODBC_LOG_PASSWORD ); }
134
+ catch( ConfigError& ) {}
135
+
136
+ try { connectionString = settings.getString( ODBC_LOG_CONNECTION_STRING ); }
137
+ catch( ConfigError& ) {}
138
+ }
139
+ else
140
+ {
141
+ user = m_user;
142
+ password = m_password;
143
+ connectionString = m_connectionString;
144
+ }
145
+ }
146
+
147
+ void OdbcLogFactory::initLog( const Dictionary& settings, OdbcLog& log )
148
+ {
149
+ try { log.setIncomingTable( settings.getString( ODBC_LOG_INCOMING_TABLE ) ); }
150
+ catch( ConfigError& ) {}
151
+
152
+ try { log.setOutgoingTable( settings.getString( ODBC_LOG_OUTGOING_TABLE ) ); }
153
+ catch( ConfigError& ) {}
154
+
155
+ try { log.setEventTable( settings.getString( ODBC_LOG_EVENT_TABLE ) ); }
156
+ catch( ConfigError& ) {}
157
+ }
158
+
159
+ void OdbcLogFactory::destroy( Log* pLog )
160
+ {
161
+ delete pLog;
162
+ }
163
+
164
+ void OdbcLog::clear()
165
+ {
166
+ std::stringstream whereClause;
167
+
168
+ whereClause << "WHERE ";
169
+
170
+ if( m_pSessionID )
171
+ {
172
+ whereClause
173
+ << "BeginString = '" << m_pSessionID->getBeginString().getValue() << "' "
174
+ << "AND SenderCompID = '" << m_pSessionID->getSenderCompID().getValue() << "' "
175
+ << "AND TargetCompID = '" << m_pSessionID->getTargetCompID().getValue() << "' ";
176
+
177
+ if( m_pSessionID->getSessionQualifier().size() )
178
+ whereClause << "AND SessionQualifier = '" << m_pSessionID->getSessionQualifier() << "'";
179
+ }
180
+ else
181
+ {
182
+ whereClause << "BeginString = NULL AND SenderCompID = NULL && TargetCompID = NULL";
183
+ }
184
+
185
+ std::stringstream incomingQuery;
186
+ std::stringstream outgoingQuery;
187
+ std::stringstream eventQuery;
188
+
189
+ incomingQuery
190
+ << "DELETE FROM " << m_incomingTable << " " << whereClause.str();
191
+ outgoingQuery
192
+ << "DELETE FROM " << m_outgoingTable << " " << whereClause.str();
193
+ eventQuery
194
+ << "DELETE FROM " << m_eventTable << " " << whereClause.str();
195
+
196
+ OdbcQuery incoming( incomingQuery.str() );
197
+ OdbcQuery outgoing( outgoingQuery.str() );
198
+ OdbcQuery event( eventQuery.str() );
199
+ m_pConnection->execute( incoming );
200
+ m_pConnection->execute( outgoing );
201
+ m_pConnection->execute( event );
202
+ }
203
+
204
+ void OdbcLog::backup()
205
+ {
206
+ }
207
+
208
+ void OdbcLog::insert( const std::string& table, const std::string value )
209
+ {
210
+ UtcTimeStamp time;
211
+ int year, month, day, hour, minute, second, millis;
212
+ time.getYMD( year, month, day );
213
+ time.getHMS( hour, minute, second, millis );
214
+
215
+ char sqlTime[ 24 ];
216
+ STRING_SPRINTF( sqlTime, "%d-%02d-%02d %02d:%02d:%02d.%003d",
217
+ year, month, day, hour, minute, second, millis );
218
+
219
+ std::string valueCopy = value;
220
+ string_replace( "'", "''", valueCopy );
221
+
222
+ std::stringstream queryString;
223
+ queryString << "INSERT INTO " << table << " "
224
+ << "(time, beginstring, sendercompid, targetcompid, session_qualifier, text) "
225
+ << "VALUES ("
226
+ << "{ts '" << sqlTime << "'},";
227
+
228
+ if( m_pSessionID )
229
+ {
230
+ queryString
231
+ << "'" << m_pSessionID->getBeginString().getValue() << "',"
232
+ << "'" << m_pSessionID->getSenderCompID().getValue() << "',"
233
+ << "'" << m_pSessionID->getTargetCompID().getValue() << "',";
234
+ if( m_pSessionID->getSessionQualifier() == "" )
235
+ queryString << "NULL" << ",";
236
+ else
237
+ queryString << "'" << m_pSessionID->getSessionQualifier() << "',";
238
+ }
239
+ else
240
+ {
241
+ queryString << "NULL, NULL, NULL, NULL, ";
242
+ }
243
+
244
+ queryString << "'" << valueCopy << "')";
245
+
246
+ OdbcQuery query( queryString.str() );
247
+ m_pConnection->execute( query );
248
+ }
249
+
250
+ }
251
+
252
+ #endif
@@ -0,0 +1,117 @@
1
+ /* -*- C++ -*- */
2
+
3
+ /****************************************************************************
4
+ ** Copyright (c) 2001-2014
5
+ **
6
+ ** This file is part of the QuickFIX FIX Engine
7
+ **
8
+ ** This file may be distributed under the terms of the quickfixengine.org
9
+ ** license as defined by quickfixengine.org and appearing in the file
10
+ ** LICENSE included in the packaging of this file.
11
+ **
12
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14
+ **
15
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
16
+ **
17
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
18
+ ** not clear to you.
19
+ **
20
+ ****************************************************************************/
21
+
22
+ #ifndef HAVE_ODBC
23
+ #error OdbcLog.h included, but HAVE_ODBC not defined
24
+ #endif
25
+
26
+ #ifdef HAVE_ODBC
27
+ #ifndef FIX_ODBCLOG_H
28
+ #define FIX_ODBCLOG_H
29
+
30
+ #ifdef _MSC_VER
31
+ #pragma warning( disable : 4503 4355 4786 4290 )
32
+ #endif
33
+
34
+ #include "OdbcConnection.h"
35
+ #include "Log.h"
36
+ #include "SessionSettings.h"
37
+ #include <fstream>
38
+ #include <string>
39
+
40
+ namespace FIX
41
+ {
42
+ /// ODBC based implementation of Log.
43
+ class OdbcLog : public Log
44
+ {
45
+ public:
46
+ OdbcLog( const SessionID& s, const std::string& user, const std::string& password,
47
+ const std::string& connectionString );
48
+ OdbcLog( const std::string& user, const std::string& password,
49
+ const std::string& connectionString );
50
+
51
+ ~OdbcLog();
52
+
53
+ void clear();
54
+ void backup();
55
+ void setIncomingTable( const std::string& incomingTable )
56
+ { m_incomingTable = incomingTable; }
57
+ void setOutgoingTable( const std::string& outgoingTable )
58
+ { m_outgoingTable = outgoingTable; }
59
+ void setEventTable( const std::string& eventTable )
60
+ { m_eventTable = eventTable; }
61
+
62
+ void onIncoming( const std::string& value )
63
+ { insert( m_incomingTable, value ); }
64
+ void onOutgoing( const std::string& value )
65
+ { insert( m_outgoingTable, value ); }
66
+ void onEvent( const std::string& value )
67
+ { insert( m_eventTable, value ); }
68
+
69
+ private:
70
+ void init();
71
+ void insert( const std::string& table, const std::string value );
72
+
73
+ std::string m_incomingTable;
74
+ std::string m_outgoingTable;
75
+ std::string m_eventTable;
76
+ OdbcConnection* m_pConnection;
77
+ SessionID* m_pSessionID;
78
+ };
79
+
80
+ /// Creates a ODBC based implementation of Log.
81
+ class OdbcLogFactory : public LogFactory
82
+ {
83
+ public:
84
+ static const std::string DEFAULT_USER;
85
+ static const std::string DEFAULT_PASSWORD;
86
+ static const std::string DEFAULT_CONNECTION_STRING;
87
+
88
+ OdbcLogFactory( const SessionSettings& settings )
89
+ : m_settings( settings ), m_useSettings( true ) {}
90
+
91
+ OdbcLogFactory( const std::string& user, const std::string& password,
92
+ const std::string& connectionString );
93
+
94
+ OdbcLogFactory();
95
+
96
+ ~OdbcLogFactory();
97
+
98
+ Log* create();
99
+ Log* create( const SessionID& );
100
+ void destroy( Log* );
101
+ private:
102
+ void init( const Dictionary& settings,
103
+ std::string& user, std::string& password,
104
+ std::string& connectionString );
105
+
106
+ void initLog( const Dictionary& settings, OdbcLog& log );
107
+
108
+ SessionSettings m_settings;
109
+ std::string m_user;
110
+ std::string m_password;
111
+ std::string m_connectionString;
112
+ bool m_useSettings;
113
+ };
114
+ }
115
+
116
+ #endif
117
+ #endif