SQL/ODBC: Remove code duplication - merge SQLFetch/SQLFetchScroll
... into an own function instead doing the check if fetchScroll is available in every function. Change-Id: I8c8a1c8693f667ddf89a660b733e31505427073a Reviewed-by: Andy Shaw <andy.shaw@qt.io> (cherry picked from commit 16c27a83f0c9c6f53578dd56024719a709cafcb0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
0c4dfd15b9
commit
e068750afd
@ -115,6 +115,7 @@ public:
|
|||||||
DefaultCase defaultCase() const;
|
DefaultCase defaultCase() const;
|
||||||
QString adjustCase(const QString&) const;
|
QString adjustCase(const QString&) const;
|
||||||
QChar quoteChar();
|
QChar quoteChar();
|
||||||
|
SQLRETURN sqlFetchNext(SQLHANDLE hStmt) const;
|
||||||
private:
|
private:
|
||||||
bool isQuoteInitialized = false;
|
bool isQuoteInitialized = false;
|
||||||
QChar quote = u'"';
|
QChar quote = u'"';
|
||||||
@ -688,6 +689,13 @@ QChar QODBCDriverPrivate::quoteChar()
|
|||||||
return quote;
|
return quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SQLRETURN QODBCDriverPrivate::sqlFetchNext(SQLHANDLE hStmt) const
|
||||||
|
{
|
||||||
|
if (hasSQLFetchScroll)
|
||||||
|
return SQLFetchScroll(hStmt, SQL_FETCH_NEXT, 0);
|
||||||
|
return SQLFetch(hStmt);
|
||||||
|
}
|
||||||
|
|
||||||
static SQLRETURN qt_string_SQLSetConnectAttr(SQLHDBC handle, SQLINTEGER attr, const QString &val)
|
static SQLRETURN qt_string_SQLSetConnectAttr(SQLHDBC handle, SQLINTEGER attr, const QString &val)
|
||||||
{
|
{
|
||||||
auto encoded = toSQLTCHAR(val);
|
auto encoded = toSQLTCHAR(val);
|
||||||
@ -2352,13 +2360,7 @@ QStringList QODBCDriver::tables(QSql::TableType type) const
|
|||||||
if (r != SQL_SUCCESS)
|
if (r != SQL_SUCCESS)
|
||||||
qSqlWarning("QODBCDriver::tables Unable to execute table list"_L1, d);
|
qSqlWarning("QODBCDriver::tables Unable to execute table list"_L1, d);
|
||||||
|
|
||||||
if (d->hasSQLFetchScroll)
|
r = d->sqlFetchNext(hStmt);
|
||||||
r = SQLFetchScroll(hStmt,
|
|
||||||
SQL_FETCH_NEXT,
|
|
||||||
0);
|
|
||||||
else
|
|
||||||
r = SQLFetch(hStmt);
|
|
||||||
|
|
||||||
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO && r != SQL_NO_DATA) {
|
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO && r != SQL_NO_DATA) {
|
||||||
qSqlWarning("QODBCDriver::tables failed to retrieve table/view list: ("_L1
|
qSqlWarning("QODBCDriver::tables failed to retrieve table/view list: ("_L1
|
||||||
+ QString::number(r) + u':',
|
+ QString::number(r) + u':',
|
||||||
@ -2368,13 +2370,7 @@ QStringList QODBCDriver::tables(QSql::TableType type) const
|
|||||||
|
|
||||||
while (r == SQL_SUCCESS) {
|
while (r == SQL_SUCCESS) {
|
||||||
tl.append(qGetStringData(hStmt, 2, -1, d->unicode).toString());
|
tl.append(qGetStringData(hStmt, 2, -1, d->unicode).toString());
|
||||||
|
r = d->sqlFetchNext(hStmt);
|
||||||
if (d->hasSQLFetchScroll)
|
|
||||||
r = SQLFetchScroll(hStmt,
|
|
||||||
SQL_FETCH_NEXT,
|
|
||||||
0);
|
|
||||||
else
|
|
||||||
r = SQLFetch(hStmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
|
r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
|
||||||
@ -2439,12 +2435,7 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->hasSQLFetchScroll)
|
r = d->sqlFetchNext(hStmt);
|
||||||
r = SQLFetchScroll(hStmt,
|
|
||||||
SQL_FETCH_NEXT,
|
|
||||||
0);
|
|
||||||
else
|
|
||||||
r = SQLFetch(hStmt);
|
|
||||||
|
|
||||||
int fakeId = 0;
|
int fakeId = 0;
|
||||||
QString cName, idxName;
|
QString cName, idxName;
|
||||||
@ -2460,13 +2451,7 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const
|
|||||||
index.append(rec.field(cName));
|
index.append(rec.field(cName));
|
||||||
index.setName(idxName);
|
index.setName(idxName);
|
||||||
|
|
||||||
if (d->hasSQLFetchScroll)
|
r = d->sqlFetchNext(hStmt);
|
||||||
r = SQLFetchScroll(hStmt,
|
|
||||||
SQL_FETCH_NEXT,
|
|
||||||
0);
|
|
||||||
else
|
|
||||||
r = SQLFetch(hStmt);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
|
r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
|
||||||
if (r!= SQL_SUCCESS)
|
if (r!= SQL_SUCCESS)
|
||||||
@ -2511,24 +2496,12 @@ QSqlRecord QODBCDriver::record(const QString& tablename) const
|
|||||||
if (r != SQL_SUCCESS)
|
if (r != SQL_SUCCESS)
|
||||||
qSqlWarning("QODBCDriver::record: Unable to execute column list"_L1, d);
|
qSqlWarning("QODBCDriver::record: Unable to execute column list"_L1, d);
|
||||||
|
|
||||||
if (d->hasSQLFetchScroll)
|
r = d->sqlFetchNext(hStmt);
|
||||||
r = SQLFetchScroll(hStmt,
|
|
||||||
SQL_FETCH_NEXT,
|
|
||||||
0);
|
|
||||||
else
|
|
||||||
r = SQLFetch(hStmt);
|
|
||||||
|
|
||||||
// Store all fields in a StringList because some drivers can't detail fields in this FETCH loop
|
// Store all fields in a StringList because some drivers can't detail fields in this FETCH loop
|
||||||
while (r == SQL_SUCCESS) {
|
while (r == SQL_SUCCESS) {
|
||||||
|
|
||||||
fil.append(qMakeFieldInfo(hStmt, d));
|
fil.append(qMakeFieldInfo(hStmt, d));
|
||||||
|
r = d->sqlFetchNext(hStmt);
|
||||||
if (d->hasSQLFetchScroll)
|
|
||||||
r = SQLFetchScroll(hStmt,
|
|
||||||
SQL_FETCH_NEXT,
|
|
||||||
0);
|
|
||||||
else
|
|
||||||
r = SQLFetch(hStmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
|
r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user