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