diff options
Diffstat (limited to 'src/sql')
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.cpp | 17 | ||||
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.h | 1 | ||||
-rw-r--r-- | src/sql/drivers/tds/qsql_tds.cpp | 15 | ||||
-rw-r--r-- | src/sql/drivers/tds/qsql_tds.h | 2 |
4 files changed, 29 insertions, 6 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index 7cf5e8b..ff9458b 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -127,7 +127,7 @@ class QODBCPrivate { public: QODBCPrivate(QODBCDriverPrivate *dpp) - : hStmt(0), useSchema(false), hasSQLFetchScroll(true), driverPrivate(dpp) + : hStmt(0), useSchema(false), hasSQLFetchScroll(true), driverPrivate(dpp), userForwardOnly(false) { unicode = false; } @@ -148,6 +148,7 @@ public: int disconnectCount; bool hasSQLFetchScroll; QODBCDriverPrivate *driverPrivate; + bool userForwardOnly; bool isStmtHandleValid(const QSqlDriver *driver); void updateStmtHandleState(const QSqlDriver *driver); @@ -848,7 +849,7 @@ bool QODBCResult::reset (const QString& query) d->updateStmtHandleState(driver()); - if (isForwardOnly()) { + if (d->userForwardOnly) { r = SQLSetStmtAttr(d->hStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_FORWARD_ONLY, @@ -885,7 +886,7 @@ bool QODBCResult::reset (const QString& query) SQLINTEGER isScrollable, bufferLength; r = SQLGetStmtAttr(d->hStmt, SQL_ATTR_CURSOR_SCROLLABLE, &isScrollable, SQL_IS_INTEGER, &bufferLength); if(r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) - setForwardOnly(isScrollable==SQL_NONSCROLLABLE); + QSqlResult::setForwardOnly(isScrollable==SQL_NONSCROLLABLE); SQLSMALLINT count; SQLNumResultCols(d->hStmt, &count); @@ -1194,7 +1195,7 @@ bool QODBCResult::prepare(const QString& query) d->updateStmtHandleState(driver()); - if (isForwardOnly()) { + if (d->userForwardOnly) { r = SQLSetStmtAttr(d->hStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_FORWARD_ONLY, @@ -1508,7 +1509,7 @@ bool QODBCResult::exec() SQLINTEGER isScrollable, bufferLength; r = SQLGetStmtAttr(d->hStmt, SQL_ATTR_CURSOR_SCROLLABLE, &isScrollable, SQL_IS_INTEGER, &bufferLength); if(r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) - setForwardOnly(isScrollable==SQL_NONSCROLLABLE); + QSqlResult::setForwardOnly(isScrollable==SQL_NONSCROLLABLE); SQLSMALLINT count; SQLNumResultCols(d->hStmt, &count); @@ -1639,6 +1640,12 @@ void QODBCResult::virtual_hook(int id, void *data) } } +void QODBCResult::setForwardOnly(bool forward) +{ + d->userForwardOnly = forward; + QSqlResult::setForwardOnly(forward); +} + //////////////////////////////////////// diff --git a/src/sql/drivers/odbc/qsql_odbc.h b/src/sql/drivers/odbc/qsql_odbc.h index d8a3b69..8bd7660 100644 --- a/src/sql/drivers/odbc/qsql_odbc.h +++ b/src/sql/drivers/odbc/qsql_odbc.h @@ -100,6 +100,7 @@ public: bool exec(); QVariant handle() const; + virtual void setForwardOnly(bool forward); protected: bool fetchNext(); diff --git a/src/sql/drivers/tds/qsql_tds.cpp b/src/sql/drivers/tds/qsql_tds.cpp index 46508a0..2508833 100644 --- a/src/sql/drivers/tds/qsql_tds.cpp +++ b/src/sql/drivers/tds/qsql_tds.cpp @@ -754,7 +754,9 @@ QString QTDSDriver::formatValue(const QSqlField &field, r = QLatin1String("NULL"); else if (field.type() == QVariant::DateTime) { if (field.value().toDateTime().isValid()){ - r = field.value().toDateTime().toString(QLatin1String("'yyyyMMdd hh:mm:ss'")); + r = field.value().toDateTime().toString(QLatin1String("yyyyMMdd hh:mm:ss")); + r.prepend(QLatin1String("'")); + r.append(QLatin1String("'")); } else r = QLatin1String("NULL"); } else if (field.type() == QVariant::ByteArray) { @@ -805,4 +807,15 @@ QSqlIndex QTDSDriver::primaryIndex(const QString& tablename) const return idx; } +QString QTDSDriver::escapeIdentifier(const QString &identifier, IdentifierType type) const +{ + QString res = identifier; + if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) { + res.replace(QLatin1Char('"'), QLatin1String("\"\"")); + res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); + res.replace(QLatin1Char('.'), QLatin1String("\".\"")); + } + return res; +} + QT_END_NAMESPACE diff --git a/src/sql/drivers/tds/qsql_tds.h b/src/sql/drivers/tds/qsql_tds.h index 6001106..0ceae6d 100644 --- a/src/sql/drivers/tds/qsql_tds.h +++ b/src/sql/drivers/tds/qsql_tds.h @@ -116,6 +116,8 @@ public: bool trimStrings) const; QVariant handle() const; + QString escapeIdentifier(const QString &identifier, IdentifierType type) const; + protected: bool beginTransaction(); bool commitTransaction(); |