ODBC: improve detection of DBMS

Change-Id: Ia93c3adb54fd28e290ff6fc85cb98138514885f1
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
Israel Lins 2013-02-15 19:40:35 -03:00 committed by The Qt Project
parent 4da840f230
commit bc5170f274

View File

@ -115,9 +115,10 @@ class QODBCDriverPrivate
{
public:
enum DefaultCase{Lower, Mixed, Upper, Sensitive};
enum DBMSType {UnknownDB, MSSqlServer, MySqlServer, PostgreSQL, Oracle, Sybase};
QODBCDriverPrivate()
: hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), datetime_precision(19), isMySqlServer(false),
isMSSqlServer(false), isFreeTDSDriver(false), hasSQLFetchScroll(true),
: hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), datetime_precision(19),
dbmsType(UnknownDB), isFreeTDSDriver(false), hasSQLFetchScroll(true),
hasMultiResultSets(false), isQuoteInitialized(false), quote(QLatin1Char('"'))
{
}
@ -129,15 +130,14 @@ public:
bool useSchema;
int disconnectCount;
int datetime_precision;
bool isMySqlServer;
bool isMSSqlServer;
DBMSType dbmsType;
bool isFreeTDSDriver;
bool hasSQLFetchScroll;
bool hasMultiResultSets;
bool checkDriver() const;
void checkUnicode();
void checkSqlServer();
void checkDBMS();
void checkHasSQLFetchScroll();
void checkHasMultiResults();
void checkSchemaUsage();
@ -1806,7 +1806,7 @@ bool QODBCDriver::hasFeature(DriverFeature f) const
case MultipleResultSets:
return d->hasMultiResultSets;
case BLOB: {
if(d->isMySqlServer)
if (d->dbmsType == QODBCDriverPrivate::MySqlServer)
return true;
else
return false;
@ -1896,13 +1896,13 @@ bool QODBCDriver::open(const QString & db,
d->checkUnicode();
d->checkSchemaUsage();
d->checkSqlServer();
d->checkDBMS();
d->checkHasSQLFetchScroll();
d->checkHasMultiResults();
d->checkDateTimePrecision();
setOpen(true);
setOpenError(false);
if(d->isMSSqlServer) {
if (d->dbmsType == QODBCDriverPrivate::MSSqlServer) {
QSqlQuery i(createResult());
i.exec(QLatin1String("SET QUOTED_IDENTIFIER ON"));
}
@ -2069,7 +2069,7 @@ void QODBCDriverPrivate::checkSchemaUsage()
useSchema = (val != 0);
}
void QODBCDriverPrivate::checkSqlServer()
void QODBCDriverPrivate::checkDBMS()
{
SQLRETURN r;
QVarLengthArray<SQLTCHAR> serverString(200);
@ -2088,8 +2088,16 @@ void QODBCDriverPrivate::checkSqlServer()
#else
serverType = QString::fromUtf8((const char *)serverString.constData(), t);
#endif
isMySqlServer = serverType.contains(QLatin1String("mysql"), Qt::CaseInsensitive);
isMSSqlServer = serverType.contains(QLatin1String("Microsoft SQL Server"), Qt::CaseInsensitive);
if (serverType.contains(QLatin1String("PostgreSQL"), Qt::CaseInsensitive))
dbmsType = PostgreSQL;
else if (serverType.contains(QLatin1String("Oracle"), Qt::CaseInsensitive))
dbmsType = Oracle;
else if (serverType.contains(QLatin1String("MySql"), Qt::CaseInsensitive))
dbmsType = MySqlServer;
else if (serverType.contains(QLatin1String("Microsoft SQL Server"), Qt::CaseInsensitive))
dbmsType = MSSqlServer;
else if (serverType.contains(QLatin1String("Sybase"), Qt::CaseInsensitive))
dbmsType = Sybase;
}
r = SQLGetInfo(hDbc,
SQL_DRIVER_NAME,