Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qsql_odbc.cpp File Reference
#include "qsql_odbc_p.h"
#include <qsqlrecord.h>
#include <qcoreapplication.h>
#include <qdatetime.h>
#include <qlist.h>
#include <qmath.h>
#include <qsqlerror.h>
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qstringconverter.h>
#include <qstringlist.h>
#include <qvariant.h>
#include <qvarlengtharray.h>
#include <QDebug>
#include <QSqlQuery>
#include <QtSql/private/qsqldriver_p.h>
#include <QtSql/private/qsqlresult_p.h>
#include "private/qtools_p.h"
#include "moc_qsql_odbc_p.cpp"
+ Include dependency graph for qsql_odbc.cpp:

Go to the source code of this file.

Classes

class  QODBCDriverPrivate
 
class  QODBCResult
 
class  QODBCResultPrivate
 
struct  DiagRecord
 

Macros

#define SQL_SS_TIME2   (-154)
 
#define ODBC_CHECK_DRIVER
 

Functions

template<typename C , int SIZE = sizeof(SQLTCHAR)>
static QString fromSQLTCHAR (const C &input, qsizetype size=-1)
 
template<int SIZE = sizeof(SQLTCHAR)>
QStringConverter::Encoding encodingForSqlTChar ()
 
static QVarLengthArray< SQLTCHAR > toSQLTCHAR (const QString &input)
 
static QList< DiagRecordqWarnODBCHandle (int handleType, SQLHANDLE handle)
 
static QList< DiagRecordqODBCWarn (const SQLHANDLE hStmt, const SQLHANDLE envHandle=nullptr, const SQLHANDLE pDbC=nullptr)
 
static QList< DiagRecordqODBCWarn (const QODBCResultPrivate *odbc)
 
static QList< DiagRecordqODBCWarn (const QODBCDriverPrivate *odbc)
 
static DiagRecord combineRecords (const QList< DiagRecord > &records)
 
static QSqlError errorFromDiagRecords (const QString &err, QSqlError::ErrorType type, const QList< DiagRecord > &records)
 
static QString errorStringFromDiagRecords (const QList< DiagRecord > &records)
 
template<class T >
static void qSqlWarning (const QString &message, T &&val)
 
static QSqlError qMakeError (const QString &err, QSqlError::ErrorType type, const QODBCResultPrivate *p)
 
static QSqlError qMakeError (const QString &err, QSqlError::ErrorType type, const QODBCDriverPrivate *p)
 
static QMetaType qDecodeODBCType (SQLSMALLINT sqltype, bool isSigned=true)
 
template<typename CT >
static QVariant getStringDataImpl (SQLHANDLE hStmt, SQLUSMALLINT column, qsizetype colSize, SQLSMALLINT targetType)
 
static QVariant qGetStringData (SQLHANDLE hStmt, SQLUSMALLINT column, int colSize, bool unicode)
 
static QVariant qGetBinaryData (SQLHANDLE hStmt, int column)
 
static QVariant qGetIntData (SQLHANDLE hStmt, int column, bool isSigned=true)
 
static QVariant qGetDoubleData (SQLHANDLE hStmt, int column)
 
static QVariant qGetBigIntData (SQLHANDLE hStmt, int column, bool isSigned=true)
 
static bool isAutoValue (const SQLHANDLE hStmt, int column)
 
static QSqlField qMakeFieldInfo (const SQLHANDLE hStmt, int i, QString *errorMessage)
 
static QSqlField qMakeFieldInfo (const SQLHANDLE hStmt, const QODBCDriverPrivate *p)
 
static QSqlField qMakeFieldInfo (const QODBCResultPrivate *p, int i)
 
static size_t qGetODBCVersion (const QString &connOpts)
 
static SQLRETURN qt_string_SQLSetConnectAttr (SQLHDBC handle, SQLINTEGER attr, const QString &val)
 

Variables

static constexpr int COLNAMESIZE = 256
 
static constexpr SQLSMALLINT TABLENAMESIZE = 128
 
static constexpr SQLSMALLINT qParamType [4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT }
 

Macro Definition Documentation

◆ ODBC_CHECK_DRIVER

#define ODBC_CHECK_DRIVER

Definition at line 37 of file qsql_odbc.cpp.

◆ SQL_SS_TIME2

#define SQL_SS_TIME2   (-154)

Definition at line 33 of file qsql_odbc.cpp.

Function Documentation

◆ combineRecords()

static DiagRecord combineRecords ( const QList< DiagRecord > &  records)
static

Definition at line 264 of file qsql_odbc.cpp.

References add(), QList< T >::begin(), DiagRecord::description, QList< T >::end(), and QList< T >::front().

Referenced by errorFromDiagRecords(), and errorStringFromDiagRecords().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodingForSqlTChar()

template<int SIZE = sizeof(SQLTCHAR)>
QStringConverter::Encoding encodingForSqlTChar ( )

Definition at line 63 of file qsql_odbc.cpp.

References SIZE, QStringConverter::Utf16, QStringConverter::Utf32, and QStringConverter::Utf8.

Referenced by toSQLTCHAR().

+ Here is the caller graph for this function:

◆ errorFromDiagRecords()

static QSqlError errorFromDiagRecords ( const QString err,
QSqlError::ErrorType  type,
const QList< DiagRecord > &  records 
)
static

Definition at line 274 of file qsql_odbc.cpp.

References combineRecords(), and QList< T >::empty().

Referenced by qMakeError(), and qMakeError().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorStringFromDiagRecords()

static QString errorStringFromDiagRecords ( const QList< DiagRecord > &  records)
static

Definition at line 285 of file qsql_odbc.cpp.

References combineRecords().

Referenced by QODBCResult::nextResult(), and qSqlWarning().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromSQLTCHAR()

template<typename C , int SIZE = sizeof(SQLTCHAR)>
static QString fromSQLTCHAR ( const C &  input,
qsizetype  size = -1 
)
inlinestatic

Definition at line 45 of file qsql_odbc.cpp.

References QString::fromUcs4(), QString::fromUtf16(), QString::fromUtf8(), qMin(), and SIZE.

Referenced by QODBCDriverPrivate::checkDBMS(), QODBCDriverPrivate::checkHasMultiResults(), QODBCDriverPrivate::checkUnicode(), QODBCResult::exec(), qMakeFieldInfo(), and qWarnODBCHandle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStringDataImpl()

template<typename CT >
static QVariant getStringDataImpl ( SQLHANDLE  hStmt,
SQLUSMALLINT  column,
qsizetype  colSize,
SQLSMALLINT  targetType 
)
static

Definition at line 376 of file qsql_odbc.cpp.

References qSqlWarning(), and QString::size().

+ Here is the call graph for this function:

◆ isAutoValue()

static bool isAutoValue ( const SQLHANDLE  hStmt,
int  column 
)
static

Definition at line 555 of file qsql_odbc.cpp.

References QString::number(), qSqlWarning(), and QStringLiteral.

Referenced by qMakeFieldInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qDecodeODBCType()

static QMetaType qDecodeODBCType ( SQLSMALLINT  sqltype,
bool  isSigned = true 
)
static

Definition at line 311 of file qsql_odbc.cpp.

References SQL_SS_TIME2, and QMetaType::UnknownType.

Referenced by qMakeFieldInfo(), and qMakeFieldInfo().

+ Here is the caller graph for this function:

◆ qGetBigIntData()

static QVariant qGetBigIntData ( SQLHANDLE  hStmt,
int  column,
bool  isSigned = true 
)
static

Definition at line 534 of file qsql_odbc.cpp.

Referenced by QODBCResult::data().

+ Here is the caller graph for this function:

◆ qGetBinaryData()

static QVariant qGetBinaryData ( SQLHANDLE  hStmt,
int  column 
)
static

Definition at line 438 of file qsql_odbc.cpp.

References COLNAMESIZE, QByteArray::constData(), QVarLengthArray< T, Prealloc >::data(), qWarning, read(), QByteArray::resize(), QByteArray::size(), and QVLABaseBase::size().

Referenced by QODBCResult::data().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qGetDoubleData()

static QVariant qGetDoubleData ( SQLHANDLE  hStmt,
int  column 
)
static

Definition at line 514 of file qsql_odbc.cpp.

Referenced by QODBCResult::data().

+ Here is the caller graph for this function:

◆ qGetIntData()

static QVariant qGetIntData ( SQLHANDLE  hStmt,
int  column,
bool  isSigned = true 
)
static

Definition at line 494 of file qsql_odbc.cpp.

Referenced by QODBCResult::data(), and qMakeFieldInfo().

+ Here is the caller graph for this function:

◆ qGetODBCVersion()

static size_t qGetODBCVersion ( const QString connOpts)
static

Definition at line 665 of file qsql_odbc.cpp.

References Qt::CaseInsensitive, and QString::contains().

Referenced by QODBCDriver::open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qGetStringData()

static QVariant qGetStringData ( SQLHANDLE  hStmt,
SQLUSMALLINT  column,
int  colSize,
bool  unicode 
)
static

Definition at line 425 of file qsql_odbc.cpp.

Referenced by QODBCResult::data(), and qMakeFieldInfo().

+ Here is the caller graph for this function:

◆ qMakeError() [1/2]

static QSqlError qMakeError ( const QString err,
QSqlError::ErrorType  type,
const QODBCDriverPrivate p 
)
static

Definition at line 304 of file qsql_odbc.cpp.

References errorFromDiagRecords(), and qODBCWarn().

+ Here is the call graph for this function:

◆ qMakeError() [2/2]

static QSqlError qMakeError ( const QString err,
QSqlError::ErrorType  type,
const QODBCResultPrivate p 
)
static

Definition at line 297 of file qsql_odbc.cpp.

References errorFromDiagRecords(), and qODBCWarn().

Referenced by QODBCResult::exec(), QODBCResult::fetch(), QODBCResult::fetchFirst(), QODBCResult::fetchLast(), QODBCResult::fetchNext(), QODBCResult::fetchPrevious(), QODBCResult::nextResult(), QODBCResult::prepare(), and QODBCResult::reset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qMakeFieldInfo() [1/3]

static QSqlField qMakeFieldInfo ( const QODBCResultPrivate p,
int  i 
)
static

Definition at line 592 of file qsql_odbc.cpp.

References errorMessage(), i, QString::isEmpty(), qMakeFieldInfo(), and qSqlWarning().

+ Here is the call graph for this function:

◆ qMakeFieldInfo() [2/3]

static QSqlField qMakeFieldInfo ( const SQLHANDLE  hStmt,
const QODBCDriverPrivate p 
)
static

Definition at line 572 of file qsql_odbc.cpp.

References QVariant::isNull(), qDecodeODBCType(), qGetIntData(), qGetStringData(), QVariant::toInt(), QVariant::toString(), and var.

+ Here is the call graph for this function:

◆ qMakeFieldInfo() [3/3]

static QSqlField qMakeFieldInfo ( const SQLHANDLE  hStmt,
int  i,
QString errorMessage 
)
static

Definition at line 601 of file qsql_odbc.cpp.

References QString::clear(), COLNAMESIZE, QVarLengthArray< T, Prealloc >::data(), errorMessage(), fromSQLTCHAR(), i, isAutoValue(), QString::number(), qDecodeODBCType(), qSqlWarning(), QStringLiteral, QVLABaseBase::size(), and TABLENAMESIZE.

Referenced by QODBCResult::exec(), QODBCResult::nextResult(), qMakeFieldInfo(), and QODBCResult::reset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qODBCWarn() [1/3]

static QList< DiagRecord > qODBCWarn ( const QODBCDriverPrivate odbc)
static

Definition at line 259 of file qsql_odbc.cpp.

References QODBCDriverPrivate::hDbc, QODBCDriverPrivate::hEnv, and qODBCWarn().

+ Here is the call graph for this function:

◆ qODBCWarn() [2/3]

static QList< DiagRecord > qODBCWarn ( const QODBCResultPrivate odbc)
static

Definition at line 254 of file qsql_odbc.cpp.

References QODBCResultPrivate::dpDbc(), QODBCResultPrivate::dpEnv(), QODBCResultPrivate::hStmt, and qODBCWarn().

+ Here is the call graph for this function:

◆ qODBCWarn() [3/3]

static QList< DiagRecord > qODBCWarn ( const SQLHANDLE  hStmt,
const SQLHANDLE  envHandle = nullptr,
const SQLHANDLE  pDbC = nullptr 
)
static

Definition at line 243 of file qsql_odbc.cpp.

References qWarnODBCHandle().

Referenced by QODBCResult::nextResult(), qMakeError(), qMakeError(), qODBCWarn(), qODBCWarn(), and qSqlWarning().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qSqlWarning()

template<class T >
static void qSqlWarning ( const QString message,
T &&  val 
)
static

Definition at line 292 of file qsql_odbc.cpp.

References errorStringFromDiagRecords(), qODBCWarn(), and qWarning.

Referenced by QODBCResult::~QODBCResult(), QODBCDriverPrivate::checkDriver(), QODBCResult::exec(), getStringDataImpl(), isAutoValue(), QODBCResult::lastInsertId(), QODBCResult::numRowsAffected(), QODBCResult::prepare(), qMakeFieldInfo(), qMakeFieldInfo(), QODBCResult::reset(), QODBCDriverPrivate::setConnectionOptions(), and QODBCDriverPrivate::splitTableQualifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qt_string_SQLSetConnectAttr()

static SQLRETURN qt_string_SQLSetConnectAttr ( SQLHDBC  handle,
SQLINTEGER  attr,
const QString val 
)
static

Definition at line 691 of file qsql_odbc.cpp.

References QByteArray::data(), encoded, QByteArray::size(), and toSQLTCHAR().

Referenced by QODBCDriverPrivate::setConnectionOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qWarnODBCHandle()

static QList< DiagRecord > qWarnODBCHandle ( int  handleType,
SQLHANDLE  handle 
)
static

Definition at line 206 of file qsql_odbc.cpp.

References QVarLengthArray< T, Prealloc >::data(), fromSQLTCHAR(), i, QString::number(), QVarLengthArray< T, Prealloc >::resize(), QVLABaseBase::size(), and state.

Referenced by qODBCWarn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toSQLTCHAR()

static QVarLengthArray< SQLTCHAR > toSQLTCHAR ( const QString input)
inlinestatic

Definition at line 76 of file qsql_odbc.cpp.

References QStringEncoder::appendToBuffer(), encodingForSqlTChar(), and QStringEncoder::requiredSpace().

Referenced by QODBCDriverPrivate::checkUnicode(), QODBCResult::exec(), QODBCDriver::open(), QODBCResult::prepare(), QODBCDriver::primaryIndex(), qt_string_SQLSetConnectAttr(), QODBCDriver::record(), QODBCResult::reset(), and QODBCDriver::tables().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ COLNAMESIZE

constexpr int COLNAMESIZE = 256
staticconstexpr

Definition at line 39 of file qsql_odbc.cpp.

Referenced by qGetBinaryData(), and qMakeFieldInfo().

◆ qParamType

constexpr SQLSMALLINT qParamType[4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT }
staticconstexpr

Definition at line 42 of file qsql_odbc.cpp.

Referenced by QODBCResult::exec().

◆ TABLENAMESIZE

constexpr SQLSMALLINT TABLENAMESIZE = 128
staticconstexpr

Definition at line 40 of file qsql_odbc.cpp.

Referenced by qMakeFieldInfo().