SQL: more documentation and test cleanups

Remove some stuff no longer supported and refine others.

Pick-to: 6.5
Change-Id: I29730d5acfcf4a7ef3f569f101d3a4f72dd8b3aa
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Christian Ehrlicher 2022-12-31 17:51:32 +01:00
parent 2b2065bf35
commit 65a5efae69
4 changed files with 20 additions and 104 deletions

View File

@ -35,14 +35,6 @@ QSqlDatabase db;
db.setHostName("MyServer");
db.setDatabaseName("C:\\test.gdb");
//! [24]
//! [25]
// connect to database using the Latin-1 character set
db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1");
if (db.open())
qDebug("The database connection is open.");
//! [25]
}
void exProc()
@ -87,18 +79,3 @@ while (query1.next()) {
}
//! [37]
}
void setConnString()
{
//! [39]
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
QString connectString = QStringLiteral(
"DRIVER=/path/to/installation/libodbcHDB.so;"
"SERVERNODE=hostname:port;"
"UID=USER;"
"PWD=PASSWORD;"
"SCROLLABLERESULT=true");
db.setDatabaseName(connectString);
//! [39]
}

View File

@ -27,8 +27,7 @@ END
//! [3]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.<so|dylib>"
qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.<so|dylib>"
cmake --build .
cmake --install .
//! [3]
@ -37,7 +36,6 @@ cmake --install .
//! [5]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib"
cmake --build .
cmake --install .
@ -47,8 +45,7 @@ cmake --install .
//! [7]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DOracle_INCLUDE_DIR="/usr/include/oracle/21/client64" -DOracle_LIBRARY="/usr/lib/oracle/21/client64/lib/libclntsh.<so|dylib>"
qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DOracle_INCLUDE_DIR="/usr/include/oracle/21/client64" -DOracle_LIBRARY="/usr/lib/oracle/21/client64/lib/libclntsh.<so|dylib>"
cmake --build .
cmake --install .
//! [7]
@ -71,8 +68,7 @@ set PATH=%PATH%;C:\oracle
//! [11]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DODBC_INCLUDE_DIR="/usr/local/unixODBC/include" -DODBC_LIBRARY="/usr/local/unixODBC/lib/libodbc.<so|dylib>"
qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DODBC_INCLUDE_DIR="/usr/local/unixODBC/include" -DODBC_LIBRARY="/usr/local/unixODBC/lib/libodbc.<so|dylib>"
cmake --build .
cmake --install .
//! [11]
@ -81,7 +77,6 @@ cmake --install .
//! [12]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform>
cmake --build .
cmake --install .
@ -92,7 +87,7 @@ cmake --install .
mkdir build-psql-driver
cd build-psql-driver
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers-DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DCMAKE_INCLUDE_PATH="/usr/local/pgsql/include" -DCMAKE_LIBRARY_PATH="/usr/local/pgsql/lib"
qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers-DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DCMAKE_INCLUDE_PATH="/usr/local/pgsql/include" -DCMAKE_LIBRARY_PATH="/usr/local/pgsql/lib"
cmake --build .
cmake --install .
//! [13]
@ -101,7 +96,6 @@ cmake --install .
//! [15]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DCMAKE_INCLUDE_PATH="C:\pgsql\include" -DCMAKE_LIBRARY_PATH="C:\pgsql\lib"
cmake --build .
cmake --install .
@ -111,8 +105,7 @@ cmake --install .
//! [18]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DDB2_INCLUDE_DIR="/usr/local/db2/include" -DDB2_LIBRARY="/usr/local/db2/lib/libdb2.<so|dylib>"
qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DDB2_INCLUDE_DIR="/usr/local/db2/include" -DDB2_LIBRARY="/usr/local/db2/lib/libdb2.<so|dylib>"
cmake --build .
cmake --install .
//! [18]
@ -121,7 +114,6 @@ cmake --install .
//! [20]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DDB2_INCLUDE_DIR="C:\db2\include" -DDB2_LIBRARY="C:\db2\lib\db2.lib"
cmake --build .
cmake --install .
@ -131,8 +123,7 @@ cmake --install .
//! [21]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DFEATURE_system_sqlite=ON -DCMAKE_INCLUDE_PATH="$SQLITE/include" -DCMAKE_LIBRARY_PATH="$SQLITE/lib"
qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DFEATURE_system_sqlite=ON -DCMAKE_INCLUDE_PATH="$SQLITE/include" -DCMAKE_LIBRARY_PATH="$SQLITE/lib"
cmake --build .
cmake --install .
//! [21]
@ -141,7 +132,6 @@ cmake --install .
//! [23]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DFEATURE_system_sqlite=ON -DCMAKE_INCLUDE_PATH="C:\SQLITE\include" -DCMAKE_LIBRARY_PATH="C:\SQLITE\lib"
cmake --build .
cmake --install .
@ -151,8 +141,7 @@ cmake --install .
//! [27]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DInterbase_INCLUDE_DIR="/opt/interbase/include" -DInterbase_LIBRARY="/opt/interbase/lib/libgds.<so|dylib>"
qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DInterbase_INCLUDE_DIR="/opt/interbase/include" -DInterbase_LIBRARY="/opt/interbase/lib/libgds.<so|dylib>"
cmake --build .
cmake --install .
//! [27]
@ -161,8 +150,7 @@ cmake --install .
//! [28]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DInterbase_INCLUDE_DIR="/opt/interbase/include" -DInterbase_LIBRARY="/opt/interbase/lib/libfbclient.<so|dylib>"
qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DInterbase_INCLUDE_DIR="/opt/interbase/include" -DInterbase_LIBRARY="/opt/interbase/lib/libfbclient.<so|dylib>"
cmake --build .
cmake --install .
//! [28]
@ -171,7 +159,6 @@ cmake --install .
//! [29]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DInterbase_INCLUDE_DIR="C:\interbase\include" -DInterbase_LIBRARY="C:\interbase\gds.lib"
cmake --build .
cmake --install .
@ -181,7 +168,6 @@ cmake --install .
//! [30]
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DInterbase_INCLUDE_DIR="C:\interbase\include" -DInterbase_LIBRARY="C:\interbase\lib\fbclient_ms.lib"
cmake --build .
cmake --install .

View File

@ -125,7 +125,7 @@
\section3 QMYSQL Stored Procedure Support
MySQL 5 has stored procedure support at the SQL level, but no
MySQL has stored procedure support at the SQL level, but no
API to control IN, OUT, and INOUT parameters. Therefore, parameters
have to be set and read using SQL commands instead of QSqlQuery::bindValue().
@ -239,8 +239,8 @@
\section3 How to Build the QMYSQL Plugin on Windows
You need to get the MySQL installation files (e.g.
\l {https://dev.mysql.com/downloads/installer/}{mysql-installer-web-community-8.0.22.0.msi} or
\l {https://downloads.mariadb.com/Connectors/c/connector-c-3.1.11/}{mariadb-connector-c-3.1.11-win64.msi}).
\l {https://dev.mysql.com/downloads/installer/}{MySQL web installer} or
\l {https://downloads.mariadb.com/Connectors/c/}{MariaDB C Connector}).
Run the installer,
select custom installation and install the MySQL C Connector
which matches your Qt installation (x86 or x64).
@ -362,7 +362,7 @@
\snippet code/doc_src_sql-driver.qdoc 8
When you run your application, you will also need to add the \c oci.lib
When you run your application, you will also need to add the \c oci.dll
path to your \c PATH environment variable:
\snippet code/doc_src_sql-driver.qdoc 9
@ -413,17 +413,11 @@
e.g., the SQLSTATEs. Before setting this connect option, consult
your ODBC documentation about behavior differences you can expect.
When using the SAP HANA database, the connection has to be
established using the option "SCROLLABLERESULT=TRUE", as the
HANA ODBC driver does not provide scrollable results by default, e.g.:
\snippet code/doc_src_sql-driver.cpp 39
If you experience very slow access of the ODBC datasource, make sure
that ODBC call tracing is turned off in the ODBC datasource manager.
Some drivers do not support scrollable cursors. In that case, only
queries in forwardOnly mode can be used successfully.
queries in \l QSqlQuery::setForwardOnly() mode can be used successfully.
\section3 ODBC Stored Procedure Support
@ -440,12 +434,12 @@
\section3 ODBC Unicode Support
The QODBC Plugin will use the Unicode API if UNICODE is defined. On
Windows NT based systems, this is the default. Note that the ODBC
Windows based systems, this is the default. Note that the ODBC
driver and the DBMS must also support Unicode.
For the Oracle 9 ODBC driver (Windows), it is necessary to check
"SQL_WCHAR support" in the ODBC driver manager otherwise Oracle
will convert all Unicode strings to local 8-bit.
will convert all Unicode strings to local 8-bit representation.
\section3 Connection options
The Qt ODBC plugin honors the following connection options:
@ -491,7 +485,7 @@
\row
\li SQL_ATTR_ODBC_VERSION
\li SQL_OV_ODBC3: The driver should act as a ODBC 3.x driver\br
SQL_OV_ODBC2: The driver should act as a ODBC 2.x driver
SQL_OV_ODBC2: The driver should act as a ODBC 2.x driver (default)
\endtable
For more detailed information about the connect options please refer
to the \l {https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetconnectattr-function}
@ -517,7 +511,7 @@
\snippet code/doc_src_sql-driver.qdoc 12
\target QPSQL
\section2 QPSQL for PostgreSQL (Version 7.3 and Above)
\section2 QPSQL for PostgreSQL (Version 7.3 and above)
The QPSQL driver supports version 7.3 and higher of the PostgreSQL server.
@ -625,7 +619,7 @@
as the application executable.
\target QDB2
\section2 QDB2 for IBM DB2 (Version 7.1 and Above)
\section2 QDB2 for IBM DB2 (Version 7.1 and above)
The Qt DB2 plugin makes it possible to access IBM DB2 databases. It
has been tested with IBM DB2 v7.1 and 7.2. You must install the IBM
@ -664,7 +658,7 @@
\snippet code/doc_src_sql-driver.qdoc 20
\target QSQLITE
\section2 QSQLITE for SQLite (Version 3 and Above)
\section2 QSQLITE for SQLite (Version 3 and above)
The Qt SQLite plugin makes it possible to access SQLite
databases. SQLite is an in-process database, which means that it
@ -819,20 +813,6 @@
Edition are not allowed to link this plugin to the commercial editions of
InterBase. Please use Firebird or the free edition of InterBase.
\section3 QIBASE Unicode Support and Text Encoding
By default the driver connects to the database using UNICODE_FSS. This can
be overridden by setting the ISC_DPB_LC_CTYPE parameter with
QSqlDatabase::setConnectOptions() before opening the connection.
\snippet code/doc_src_sql-driver.cpp 25
If Qt does not support the given text encoding the driver will issue a
warning message and connect to the database using UNICODE_FSS.
Note that if the text encoding set when connecting to the database is
not the same as in the database, problems with transliteration might arise.
\section3 QIBASE Stored procedures
InterBase/Firebird return OUT values as result set, so when calling stored
@ -895,7 +875,7 @@
Qt Creator, you can update the \c PATH environment variable in the
\gui Run section of the \gui Project panel to include the path to
the folder containing the client libraries.
\li Compile Qt with \c{QT_DEBUG_COMPONENT} defined to get very verbose
\li Compile Qt with \c{QT_DEBUG_PLUGINS} defined to get very verbose
debug output when loading plugins.
\endlist

View File

@ -137,8 +137,6 @@ private slots:
void ibase_numericFields(); // For task 125053
void ibase_fetchBlobs_data() { generic_data("QIBASE"); }
void ibase_fetchBlobs(); // For task 143471
void ibase_useCustomCharset_data() { generic_data("QIBASE"); }
void ibase_useCustomCharset(); // For task 134608
void ibase_procWithoutReturnValues_data() { generic_data("QIBASE"); } // For task 165423
void ibase_procWithoutReturnValues();
void ibase_procWithReturnValues_data() { generic_data("QIBASE"); } // For task 177530
@ -1906,31 +1904,6 @@ void tst_QSqlDatabase::mysql_multiselect()
QVERIFY_SQL(q, exec("SELECT * FROM " + qtest));
}
void tst_QSqlDatabase::ibase_useCustomCharset()
{
QFETCH(QString, dbName);
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
QString nonlatin1string("<EFBFBD><EFBFBD>");
db.close();
db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1");
db.open();
const QString tableName(qTableName("latin1table", __FILE__, db));
QSqlQuery q(db);
QEXPECT_FAIL("", "Currently fails, potentially due to invalid test - needs further "
"investigation - QTBUG-85828", Abort);
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(text VARCHAR(6) CHARACTER SET Latin1)").arg(tableName)));
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES(?)").arg(tableName)));
q.addBindValue(nonlatin1string);
QVERIFY_SQL(q, exec());
QVERIFY_SQL(q, exec(QString("SELECT text FROM %1").arg(tableName)));
QVERIFY_SQL(q, next());
QCOMPARE(toHex(q.value(0).toString()), toHex(nonlatin1string));
}
void tst_QSqlDatabase::oci_serverDetach()
{
QFETCH(QString, dbName);