SQLRETURN SQLConnect(SQLHDBC conn, SQLCHAR* serverName, SQLSMALLINT serverNameLen, SQLCHAR* userName, SQLSMALLINT userNameLen, SQLCHAR* auth, SQLSMALLINT authLen) { using odbc::Connection; using odbc::config::Configuration; using utility::SqlStringToString; LOG_MSG("SQLConnect called\n"); Connection *connection = reinterpret_cast<Connection*>(conn); if (!connection) return SQL_INVALID_HANDLE; odbc::config::Configuration config; std::string dsn = SqlStringToString(serverName, serverNameLen); LOG_MSG("DSN: " << dsn); odbc::ReadDsnConfiguration(dsn.c_str(), config); connection->Establish(config); return connection->GetDiagnosticRecords().GetReturnCode(); }
SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND windowHandle, SQLCHAR* inConnectionString, SQLSMALLINT inConnectionStringLen, SQLCHAR* outConnectionString, SQLSMALLINT outConnectionStringBufferLen, SQLSMALLINT* outConnectionStringLen, SQLUSMALLINT driverCompletion) { using odbc::Connection; using odbc::diagnostic::DiagnosticRecordStorage; using utility::SqlStringToString; using utility::CopyStringToBuffer; UNREFERENCED_PARAMETER(windowHandle); LOG_MSG("SQLDriverConnect called"); if (inConnectionString) LOG_MSG("Connection String: [" << inConnectionString << "]"); Connection *connection = reinterpret_cast<Connection*>(conn); if (!connection) return SQL_INVALID_HANDLE; std::string connectStr = SqlStringToString(inConnectionString, inConnectionStringLen); odbc::config::Configuration config; config.FillFromConnectString(connectStr); std::string dsn = config.GetDsn(); if (!dsn.empty()) odbc::ReadDsnConfiguration(dsn.c_str(), config); connection->Establish(config); const DiagnosticRecordStorage& diag = connection->GetDiagnosticRecords(); if (!diag.IsSuccessful()) return diag.GetReturnCode(); size_t reslen = CopyStringToBuffer(connectStr, reinterpret_cast<char*>(outConnectionString), static_cast<size_t>(outConnectionStringBufferLen)); if (outConnectionStringLen) *outConnectionStringLen = static_cast<SQLSMALLINT>(reslen); if (outConnectionString) LOG_MSG(outConnectionString); return diag.GetReturnCode(); }
SQLRETURN SQLEndTran(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT completionType) { using namespace odbc; LOG_MSG("SQLEndTran called"); SQLRETURN result; switch (handleType) { case SQL_HANDLE_ENV: { Environment *env = reinterpret_cast<Environment*>(handle); if (!env) return SQL_INVALID_HANDLE; if (completionType == SQL_COMMIT) env->TransactionCommit(); else env->TransactionRollback(); result = env->GetDiagnosticRecords().GetReturnCode(); break; } case SQL_HANDLE_DBC: { Connection *conn = reinterpret_cast<Connection*>(handle); if (!conn) return SQL_INVALID_HANDLE; if (completionType == SQL_COMMIT) conn->TransactionCommit(); else conn->TransactionRollback(); result = conn->GetDiagnosticRecords().GetReturnCode(); break; } default: { result = SQL_INVALID_HANDLE; break; } } return result; }
SQLRETURN SQLDisconnect(SQLHDBC conn) { using odbc::Connection; LOG_MSG("SQLDisconnect called"); Connection *connection = reinterpret_cast<Connection*>(conn); if (!connection) return SQL_INVALID_HANDLE; connection->Release(); return connection->GetDiagnosticRecords().GetReturnCode(); }
SQLRETURN SQL_API SQLSetConnectAttr(SQLHDBC conn, SQLINTEGER attr, SQLPOINTER value, SQLINTEGER valueLen) { using odbc::Connection; LOG_MSG("SQLSetConnectAttr called"); Connection *connection = reinterpret_cast<Connection*>(conn); if (!connection) return SQL_INVALID_HANDLE; connection->SetAttribute(attr, value, valueLen); return connection->GetDiagnosticRecords().GetReturnCode(); }
SQLRETURN SQLAllocStmt(SQLHDBC conn, SQLHSTMT* stmt) { using odbc::Connection; using odbc::Statement; LOG_MSG("SQLAllocStmt called"); *stmt = SQL_NULL_HDBC; Connection *connection = reinterpret_cast<Connection*>(conn); if (!connection) return SQL_INVALID_HANDLE; Statement *statement = connection->CreateStatement(); *stmt = reinterpret_cast<SQLHSTMT>(statement); return connection->GetDiagnosticRecords().GetReturnCode(); }
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result) { //LOG_MSG("SQLAllocHandle called"); switch (type) { case SQL_HANDLE_ENV: return SQLAllocEnv(result); case SQL_HANDLE_DBC: return SQLAllocConnect(parent, result); case SQL_HANDLE_STMT: return SQLAllocStmt(parent, result); case SQL_HANDLE_DESC: { using odbc::Connection; Connection *connection = reinterpret_cast<Connection*>(parent); if (!connection) return SQL_INVALID_HANDLE; if (result) *result = 0; connection->GetDiagnosticRecords().Reset(); connection->AddStatusRecord(odbc::SqlState::SIM001_FUNCTION_NOT_SUPPORTED, "The HandleType argument was SQL_HANDLE_DESC, and " "the driver does not support allocating a descriptor handle"); return SQL_ERROR; } default: break; } *result = 0; return SQL_ERROR; }
SQLRETURN SQL_API SQLGetConnectAttr(SQLHDBC conn, SQLINTEGER attr, SQLPOINTER valueBuf, SQLINTEGER valueBufLen, SQLINTEGER* valueResLen) { using namespace odbc; using namespace type_traits; using app::ApplicationDataBuffer; LOG_MSG("SQLGetConnectAttr called"); Connection *connection = reinterpret_cast<Connection*>(conn); if (!connection) return SQL_INVALID_HANDLE; connection->GetAttribute(attr, valueBuf, valueBufLen, valueResLen); return connection->GetDiagnosticRecords().GetReturnCode(); }
SQLRETURN SQLGetInfo(SQLHDBC conn, SQLUSMALLINT infoType, SQLPOINTER infoValue, SQLSMALLINT infoValueMax, SQLSMALLINT* length) { using odbc::Connection; using odbc::config::ConnectionInfo; LOG_MSG("SQLGetInfo called: " << infoType << " (" << ConnectionInfo::InfoTypeToString(infoType) << "), " << std::hex << reinterpret_cast<size_t>(infoValue) << ", " << infoValueMax << ", " << std::hex << reinterpret_cast<size_t>(length)); Connection *connection = reinterpret_cast<Connection*>(conn); if (!connection) return SQL_INVALID_HANDLE; connection->GetInfo(infoType, infoValue, infoValueMax, length); return connection->GetDiagnosticRecords().GetReturnCode(); }