22 #ifndef DBALLE_DB_ODBC_INTERNALS_H 23 #define DBALLE_DB_ODBC_INTERNALS_H 33 #include <dballe/db/sql.h> 39 #define DBA_DB_QUIRK_NO_ROWCOUNT_IN_DIAG (1 << 0) 60 error_odbc(SQLSMALLINT handleType, SQLHANDLE handle,
const std::string& msg);
63 wreport::ErrorCode code()
const throw () {
return wreport::WR_ERR_ODBC; }
65 virtual const char* what()
const throw () {
return msg.c_str(); }
67 static void throwf(SQLSMALLINT handleType, SQLHANDLE handle,
const char* fmt, ...) WREPORT_THROWF_ATTRS(3, 4);
110 void connect(
const char* dsn,
const char* user,
const char* password);
111 void connect_url(
const char* url);
114 void driver_connect(
const char* config);
115 std::string driver_name();
116 std::string driver_version();
117 void get_info(SQLUSMALLINT info_type, SQLINTEGER& res);
118 void set_autocommit(
bool val);
120 void exec(
const std::string& query);
122 std::unique_ptr<Transaction> transaction()
override;
123 std::unique_ptr<ODBCStatement> odbcstatement(
const std::string& query);
126 bool has_table(
const std::string& name)
override;
133 std::string get_setting(
const std::string& key)
override;
140 void set_setting(
const std::string& key,
const std::string& value)
override;
143 void drop_settings()
override;
148 void drop_table_if_exists(
const char* name);
153 void drop_sequence_if_exists(
const char* name);
161 int get_last_insert_id();
166 void init_after_connect();
173 SQLHSTMT stm =
nullptr;
175 const char* ignore_error =
nullptr;
176 #ifdef DEBUG_WARN_OPEN_TRANSACTIONS 177 std::string debug_query;
179 bool debug_reached_completion =
false;
188 void bind_in(
int idx,
const int& val);
189 void bind_in(
int idx,
const int& val,
const SQLLEN& ind);
190 void bind_in(
int idx,
const unsigned& val);
191 void bind_in(
int idx,
const unsigned& val,
const SQLLEN& ind);
192 void bind_in(
int idx,
const unsigned short& val);
193 void bind_in(
int idx,
const unsigned short& val,
const SQLLEN& ind);
194 void bind_in(
int idx,
const char* val);
195 void bind_in(
int idx,
const char* val,
const SQLLEN& ind);
196 void bind_in(
int idx,
const std::string& val);
197 void bind_in(
int idx,
const SQL_TIMESTAMP_STRUCT& val);
199 void bind_out(
int idx,
int& val);
200 void bind_out(
int idx,
int& val, SQLLEN& ind);
201 void bind_out(
int idx,
unsigned& val);
202 void bind_out(
int idx,
unsigned& val, SQLLEN& ind);
203 void bind_out(
int idx,
unsigned short& val);
204 void bind_out(
int idx,
unsigned short& val, SQLLEN& ind);
205 void bind_out(
int idx,
char* val, SQLLEN buflen);
206 void bind_out(
int idx,
char* val, SQLLEN buflen, SQLLEN& ind);
207 void bind_out(
int idx, SQL_TIMESTAMP_STRUCT& val);
208 void bind_out(
int idx, SQL_TIMESTAMP_STRUCT& val, SQLLEN& ind);
210 void prepare(
const char* query);
211 void prepare(
const char* query,
int qlen);
212 void prepare(
const std::string& query);
218 int execute_and_close();
220 int exec_direct_and_close(
const char* query,
int qlen);
222 void execute_ignoring_results();
230 bool fetch_expecting_one();
232 void close_cursor_if_needed();
234 size_t select_rowcount();
238 void set_cursor_forward_only();
239 void set_cursor_static();
242 bool error_is_ignored();
243 bool is_error(
int sqlres);
263 static inline bool operator!=(
const SQL_TIMESTAMP_STRUCT& a,
const SQL_TIMESTAMP_STRUCT& b)
265 return a.year != b.year || a.month != b.month || a.day != b.day || a.hour != b.hour || a.minute != b.minute || a.second != b.second || a.fraction != b.fraction;
268 std::ostream& operator<<(std::ostream& o,
const SQL_TIMESTAMP_STRUCT& t);
270 static inline SQL_TIMESTAMP_STRUCT make_sql_timestamp(
int year,
int month,
int day,
int hour,
int minute,
int second)
272 SQL_TIMESTAMP_STRUCT res;
Report an ODBC error, using informations from the ODBC diagnostic record.
Definition: odbc/internals.h:52
error_odbc(SQLSMALLINT handleType, SQLHANDLE handle, const std::string &msg)
Copy informations from the ODBC diagnostic record to the dba error report.
ODBC statement.
Definition: odbc/internals.h:170
Base exception for database errors.
Definition: db/defs.h:54
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
unsigned server_quirks
Bitfield of quirks we should be aware of when using ODBC.
Definition: odbc/internals.h:94
SQLHDBC od_conn
ODBC database connection.
Definition: odbc/internals.h:90
String buffer for composing database queries.
Definition: querybuf.h:37
bool connected
True if the connection is open.
Definition: odbc/internals.h:92
Functions used to connect to DB-All.e and insert, query and delete data.
Implementation of an efficient string buffer for composing database queries.
ODBC environment.
Definition: odbc/internals.h:71
int m_last_insert_id
ID of the last autogenerated primary key.
Definition: odbc/internals.h:100
Date and time.
Definition: types.h:147
ODBC statement to read a sequence.
Definition: odbc/internals.h:247
ODBCStatement * stm_last_insert_id
Precompiled LAST_INSERT_ID (or equivalent) SQL statement.
Definition: odbc/internals.h:98
Database connection.
Definition: odbc/internals.h:87