SQL/ODBC: cache return value of SQLGetInfo(SQL_IDENTIFIER_CASE)
This value does not change over time so no need to retrieve it from the driver for every call. As a drive-by change the enum to an enum class. Change-Id: I25292d724f5173fef7054bb5e7e82e82992e41c6 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
parent
000d462bf9
commit
97bbf37f42
@ -111,7 +111,7 @@ class QODBCDriverPrivate : public QSqlDriverPrivate
|
|||||||
Q_DECLARE_PUBLIC(QODBCDriver)
|
Q_DECLARE_PUBLIC(QODBCDriver)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum DefaultCase {Lower, Mixed, Upper, Sensitive};
|
enum class DefaultCase {Lower, Mixed, Upper, Sensitive};
|
||||||
using QSqlDriverPrivate::QSqlDriverPrivate;
|
using QSqlDriverPrivate::QSqlDriverPrivate;
|
||||||
|
|
||||||
SQLHANDLE hEnv = nullptr;
|
SQLHANDLE hEnv = nullptr;
|
||||||
@ -132,10 +132,10 @@ public:
|
|||||||
void checkHasMultiResults();
|
void checkHasMultiResults();
|
||||||
void checkSchemaUsage();
|
void checkSchemaUsage();
|
||||||
void checkDateTimePrecision();
|
void checkDateTimePrecision();
|
||||||
|
void checkDefaultCase();
|
||||||
bool setConnectionOptions(const QString& connOpts);
|
bool setConnectionOptions(const QString& connOpts);
|
||||||
void splitTableQualifier(const QString &qualifier, QString &catalog,
|
void splitTableQualifier(const QString &qualifier, QString &catalog,
|
||||||
QString &schema, QString &table) const;
|
QString &schema, QString &table) const;
|
||||||
DefaultCase defaultCase() const;
|
|
||||||
QString adjustCase(const QString&) const;
|
QString adjustCase(const QString&) const;
|
||||||
QChar quoteChar();
|
QChar quoteChar();
|
||||||
SQLRETURN sqlFetchNext(const SqlStmtHandle &hStmt) const;
|
SQLRETURN sqlFetchNext(const SqlStmtHandle &hStmt) const;
|
||||||
@ -143,6 +143,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool isQuoteInitialized = false;
|
bool isQuoteInitialized = false;
|
||||||
QChar quote = u'"';
|
QChar quote = u'"';
|
||||||
|
DefaultCase m_defaultCase = DefaultCase::Mixed;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QODBCResultPrivate;
|
class QODBCResultPrivate;
|
||||||
@ -860,35 +861,31 @@ void QODBCDriverPrivate::splitTableQualifier(const QString &qualifier, QString &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QODBCDriverPrivate::DefaultCase QODBCDriverPrivate::defaultCase() const
|
void QODBCDriverPrivate::checkDefaultCase()
|
||||||
{
|
{
|
||||||
DefaultCase ret;
|
m_defaultCase = DefaultCase::Mixed; //arbitrary case if driver cannot be queried
|
||||||
SQLUSMALLINT casing;
|
SQLUSMALLINT casing;
|
||||||
int r = SQLGetInfo(hDbc,
|
SQLRETURN r = SQLGetInfo(hDbc,
|
||||||
SQL_IDENTIFIER_CASE,
|
SQL_IDENTIFIER_CASE,
|
||||||
&casing,
|
&casing,
|
||||||
sizeof(casing),
|
sizeof(casing),
|
||||||
NULL);
|
NULL);
|
||||||
if ( r != SQL_SUCCESS)
|
if (r == SQL_SUCCESS) {
|
||||||
ret = Mixed;//arbitrary case if driver cannot be queried
|
|
||||||
else {
|
|
||||||
switch (casing) {
|
switch (casing) {
|
||||||
case (SQL_IC_UPPER):
|
case SQL_IC_UPPER:
|
||||||
ret = Upper;
|
m_defaultCase = DefaultCase::Upper;
|
||||||
break;
|
break;
|
||||||
case (SQL_IC_LOWER):
|
case SQL_IC_LOWER:
|
||||||
ret = Lower;
|
m_defaultCase = DefaultCase::Lower;
|
||||||
break;
|
break;
|
||||||
case (SQL_IC_SENSITIVE):
|
case SQL_IC_SENSITIVE:
|
||||||
ret = Sensitive;
|
m_defaultCase = DefaultCase::Sensitive;
|
||||||
break;
|
break;
|
||||||
case (SQL_IC_MIXED):
|
case SQL_IC_MIXED:
|
||||||
default:
|
m_defaultCase = DefaultCase::Mixed;
|
||||||
ret = Mixed;
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -897,20 +894,16 @@ QODBCDriverPrivate::DefaultCase QODBCDriverPrivate::defaultCase() const
|
|||||||
*/
|
*/
|
||||||
QString QODBCDriverPrivate::adjustCase(const QString &identifier) const
|
QString QODBCDriverPrivate::adjustCase(const QString &identifier) const
|
||||||
{
|
{
|
||||||
QString ret = identifier;
|
switch (m_defaultCase) {
|
||||||
switch(defaultCase()) {
|
case DefaultCase::Lower:
|
||||||
case (Lower):
|
return identifier.toLower();
|
||||||
ret = identifier.toLower();
|
case DefaultCase::Upper:
|
||||||
break;
|
return identifier.toUpper();
|
||||||
case (Upper):
|
case DefaultCase::Mixed:
|
||||||
ret = identifier.toUpper();
|
case DefaultCase::Sensitive:
|
||||||
break;
|
break;
|
||||||
case(Mixed):
|
|
||||||
case(Sensitive):
|
|
||||||
default:
|
|
||||||
ret = identifier;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
@ -2010,6 +2003,7 @@ bool QODBCDriver::open(const QString & db,
|
|||||||
d->checkHasSQLFetchScroll();
|
d->checkHasSQLFetchScroll();
|
||||||
d->checkHasMultiResults();
|
d->checkHasMultiResults();
|
||||||
d->checkDateTimePrecision();
|
d->checkDateTimePrecision();
|
||||||
|
d->checkDefaultCase();
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
setOpenError(false);
|
setOpenError(false);
|
||||||
if (d->dbmsType == MSSqlServer) {
|
if (d->dbmsType == MSSqlServer) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user