- Move 2 images from qtdoc.
- Add "make docs" command for qtsql
- Fix qdoc command usage errors.
Change-Id: Id2f0548d09ed8f77b2317863d443c19d1cccdd83
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
--- /dev/null
+qtPrepareTool(QDOC, qdoc)
+docs.commands += $$QDOC $$QT.sql.sources/doc/qtsql.qdocconf
+QMAKE_EXTRA_TARGETS += docs
--- /dev/null
+include(../../../doc/global/qt-cpp-ignore.qdocconf)
+
+project = QtSql
+description = Qt SQL Reference Documentation
+url = http://qt-project.org/doc/qt-5.0/qtsql
+version = 5.0.0
+
+sourceencoding = UTF-8
+outputencoding = UTF-8
+naturallanguage = en_US
+qhp.projects = QtSql
+
+qhp.QtCore.file = qtsql.qhp
+qhp.Qt.namespace = org.qt-project.qtsql.500
+qhp.Qt.virtualFolder = qdoc
+qhp.Qt.indexTitle = Qt SQL Reference Documentation
+qhp.Qt.indexRoot =
+
+qhp.Qt.filterAttributes = qtsql 5.0.0 qtrefdoc
+qhp.Qt.customFilters.Qt.name = QtSql 5.0.0
+qhp.Qt.customFilters.Qt.filterAttributes = qtsql 5.0.0
+qhp.Qt.subprojects = classes overviews examples
+qhp.Qt.subprojects.classes.title = Classes
+qhp.Qt.subprojects.classes.indexTitle = Qt SQL's Classes
+qhp.Qt.subprojects.classes.selectors = class fake:headerfile
+qhp.Qt.subprojects.classes.sortPages = true
+qhp.Qt.subprojects.overviews.title = Overviews
+qhp.Qt.subprojects.overviews.indexTitle = All Overviews and HOWTOs
+qhp.Qt.subprojects.overviews.selectors = fake:page,group,module
+qhp.Qt.subprojects.examples.title = Qt Core Tutorials and Examples
+qhp.Qt.subprojects.examples.indexTitle = Qt Core Examples
+qhp.Qt.subprojects.examples.selectors = fake:example
+
+dita.metadata.default.author = Qt Project
+dita.metadata.default.permissions = all
+dita.metadata.default.publisher = Qt Project
+dita.metadata.default.copyryear = 2012
+dita.metadata.default.copyrholder = Nokia
+dita.metadata.default.audience = programmer
+
+sources.fileextensions = "*.c++ *.cc *.cpp *.cxx *.mm *.qml *.qdoc"
+headers.fileextensions = "*.ch *.h *.h++ *.hh *.hpp *.hxx"
+
+examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml *.css"
+examples.imageextensions = "*.png"
+
+outputdir = ../../../doc/qtsql
+tagfile = ../../../doc/qtsql/qtsql.tags
+
+HTML.generatemacrefs = "true"
+HTML.nobreadcrumbs = "true"
+
+HTML.templatedir = .
+
+HTML.stylesheets = ../../../doc/global/style/offline.css
+
+HTML.headerstyles = \
+ " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n"
+
+HTML.endheader = \
+ "</head>\n" \
+
+defines = Q_QDOC \
+ QT_.*_SUPPORT \
+ QT_.*_LIB \
+ QT_COMPAT \
+ QT_KEYPAD_NAVIGATION \
+ QT_NO_EGL \
+ Q_WS_.* \
+ Q_OS_.* \
+ Q_BYTE_ORDER \
+ QT_DEPRECATED \
+ QT_DEPRECATED_* \
+ Q_NO_USING_KEYWORD \
+ __cplusplus \
+ Q_COMPILER_INITIALIZER_LISTS
+
+versionsym = QT_VERSION_STR
+
+codeindent = 1
+
+depends += qtcore
+
+headerdirs += ..
+
+sourcedirs += ..
+
+exampledirs += ../../../examples \
+ ../ \
+ snippets
+
+imagedirs += images
To include the definitions of the module's classes, use the
following directive:
- \snippet doc/src/snippets/code/doc_src_qtsql.cpp 0
+ \snippet code/doc_src_qtsql.cpp 0
To link against the module, add this line to your \l qmake \c
.pro file:
- \snippet doc/src/snippets/code/doc_src_qtsql.pro 1
+ \snippet code/doc_src_qtsql.pro 1
See the \l{SQL Programming} guide for information about using this
module in your applications.
machine. Run \c{configure -help} to see what drivers can be
built. You should get an output similar to this:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 0
+ \snippet code/doc_src_sql-driver.qdoc 0
The \c configure script cannot detect the necessary libraries
and include files if they are not in the standard paths, so it
Example stored procedure:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 1
+ \snippet code/doc_src_sql-driver.qdoc 1
Source code to access the OUT values:
- \snippet doc/src/snippets/code/doc_src_sql-driver.cpp 2
+ \snippet code/doc_src_sql-driver.cpp 2
\b{Note:} \c{@outval1} and \c{@outval2} are variables local to the current
connection and will not be affected by queries sent from another host
libraries (here it is assumed that MySQL is installed in
\c{/usr/local}) and run \c{make}:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 3
+ \snippet code/doc_src_sql-driver.qdoc 3
After installing Qt, as described in the \l{Installing Qt for X11
Platforms} document, you also need to install the plugin in the
standard location:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 4
+ \snippet code/doc_src_sql-driver.qdoc 4
\section3 How to Build the QMYSQL Plugin on Windows
Build the plugin as follows (here it is assumed that MySQL is
installed in \c{C:\MySQL}):
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 5
+ \snippet code/doc_src_sql-driver.qdoc 5
If you are not using a Microsoft compiler, replace \c nmake with \c
make in the line above.
libraries and run make:
For Oracle version 9:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 6
+ \snippet code/doc_src_sql-driver.qdoc 6
For Oracle version 10, we assume that you installed the RPM packages of the
Instant Client Package SDK (you need to adjust the version number accordingly):
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 7
+ \snippet code/doc_src_sql-driver.qdoc 7
\b{Note:} If you are using the Oracle Instant Client package,
you will need to set LD_LIBRARY_PATH when building the OCI SQL plugin
and when running an application that uses the OCI SQL plugin. You can
avoid this requirement by setting and RPATH and listing all of the
libraries to link to. Here is an example:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 32
+ \snippet code/doc_src_sql-driver.qdoc 32
If you wish to build the OCI plugin manually with this method the procedure looks like this:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 33
+ \snippet code/doc_src_sql-driver.qdoc 33
\section3 How to Build the OCI Plugin on Windows
Build the plugin as follows (here it is assumed that Oracle Client is
installed in \c{C:\oracle}):
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 8
+ \snippet code/doc_src_sql-driver.qdoc 8
If you are not using a Microsoft compiler, replace \c nmake with \c
make in the line above.
When you run your application you will also need to add the \c oci.dll
path to your \c PATH environment variable:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 9
+ \snippet code/doc_src_sql-driver.qdoc 9
\b{Note:} This database plugin is not supported for Windows CE.
sets, will be accessible only if you set the query's forward only
mode to \e forward using \l QSqlQuery::setForwardOnly().
- \snippet doc/src/snippets/code/doc_src_sql-driver.cpp 10
+ \snippet code/doc_src_sql-driver.cpp 10
\b{Note:} The value returned by the stored procedure's return statement
is discarded.
libraries (here it is assumed that unixODBC is installed in
\c{/usr/local/unixODBC}) and run \c{make}:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 11
+ \snippet code/doc_src_sql-driver.qdoc 11
\section3 How to Build the ODBC Plugin on Windows
The ODBC header and include files should already be installed in the
right directories. You just have to build the plugin as follows:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 12
+ \snippet code/doc_src_sql-driver.qdoc 12
If you are not using a Microsoft compiler, replace \c nmake with \c
make in the line above.
libraries, run \c qmake the following way (assuming that the
PostgreSQL client is installed in \c{/usr}):
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 13
+ \snippet code/doc_src_sql-driver.qdoc 13
After installing Qt, as described in the \l{Installing Qt for X11 Platforms} document,
you also need to install the plugin in the standard location:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 14
+ \snippet code/doc_src_sql-driver.qdoc 14
\section3 How to Build the QPSQL Plugin on Windows
compiler. Assuming that PostgreSQL was installed in \c{C:\psql},
build the plugin as follows:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 15
+ \snippet code/doc_src_sql-driver.qdoc 15
Users of MinGW may wish to consult the following online document:
\l{PostgreSQL MinGW/Native Windows}.
point to the directory where you installed the client library and
execute \c{qmake}:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 16
+ \snippet code/doc_src_sql-driver.qdoc 16
\section3 How to Build the QDTS Plugin on Windows
Open Client (\l{http://www.sybase.com}). You must include \c
NTWDBLIB.LIB to build the plugin:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 17
+ \snippet code/doc_src_sql-driver.qdoc 17
By default the Microsoft library is used on Windows, if you want to
force the use of the Sybase Open Client, you must define \c
\section3 How to Build the QDB2 Plugin on Unix and Mac OS X
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 18
+ \snippet code/doc_src_sql-driver.qdoc 18
After installing Qt, as described in the \l{Installing Qt for X11 Platforms} document,
you also need to install the plugin in the standard location:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 19
+ \snippet code/doc_src_sql-driver.qdoc 19
\section3 How to Build the QDB2 Plugin on Windows
The DB2 header and include files should already be installed in the
right directories. You just have to build the plugin as follows:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 20
+ \snippet code/doc_src_sql-driver.qdoc 20
If you are not using a Microsoft compiler, replace \c nmake
with \c make in the line above.
it manually (replace \c $SQLITE with the directory where
SQLite resides):
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 21
+ \snippet code/doc_src_sql-driver.qdoc 21
After installing Qt, as described in the \l{Installing Qt for X11 Platforms} document,
you also need to install the plugin in the standard location:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 22
+ \snippet code/doc_src_sql-driver.qdoc 22
On Windows:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 23
+ \snippet code/doc_src_sql-driver.qdoc 23
\section3 QSQLITE File Format Compatibility
database file, no matter whether it is stored locally or on another
server.
- \snippet doc/src/snippets/code/doc_src_sql-driver.cpp 24
+ \snippet code/doc_src_sql-driver.cpp 24
You need the InterBase/Firebird development headers and libraries
to build this plugin.
be overridden by setting the ISC_DPB_LC_CTYPE parameter with
QSqlDatabase::setConnectOptions() before opening the connection.
- \snippet doc/src/snippets/code/doc_src_sql-driver.cpp 25
+ \snippet code/doc_src_sql-driver.cpp 25
If Qt doesn't support the given text encoding the driver will issue a
warning message and connect to the database using UNICODE_FSS.
procedure, only IN values need to be bound via QSqlQuery::bindValue(). The
RETURN/OUT values can be retrieved via QSqlQuery::value(). Example:
- \snippet doc/src/snippets/code/doc_src_sql-driver.cpp 26
+ \snippet code/doc_src_sql-driver.cpp 26
\section3 How to Build the QIBASE Plugin on Unix and Mac OS X
If you are using InterBase:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 27
+ \snippet code/doc_src_sql-driver.qdoc 27
If you are using Firebird, the Firebird library has to be set explicitly:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 28
+ \snippet code/doc_src_sql-driver.qdoc 28
\section3 How to Build the QIBASE Plugin on Windows
If you are using InterBase:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 29
+ \snippet code/doc_src_sql-driver.qdoc 29
If you are using Firebird, the Firebird library has to be set explicitly:
- \snippet doc/src/snippets/code/doc_src_sql-driver.qdoc 30
+ \snippet code/doc_src_sql-driver.qdoc 30
If you are not using a Microsoft compiler, replace \c nmake
with \c make in the line above.
Make sure you have followed the guide to \l{Deploying Plugins}.
If you experience plugin load problems and see output like this:
- \snippet doc/src/snippets/code/doc_src_sql-driver.cpp 31
+ \snippet code/doc_src_sql-driver.cpp 31
the problem is usually that the plugin had the wrong \l{Deploying
Plugins#The Build Key}{build key}. This might require removing an
The following code can be used as a skeleton for a SQL driver:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 47
+ \snippet sqldatabase/sqldatabase.cpp 47
\codeline
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 48
+ \snippet sqldatabase/sqldatabase.cpp 48
*/
following snippet shows how to create a \e{default} connection
and then open it:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 26
+ \snippet sqldatabase/sqldatabase.cpp 26
The first line creates the connection object, and the last line
opens it for use. In between, we initialize some connection
connection name. For example, here we establish two MySQL database
connections named \c{"first"} and \c{"second"}:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 27
+ \snippet sqldatabase/sqldatabase.cpp 27
After these connections have been initialized, \l{QSqlDatabase::}
{open()} for each one to establish the live connections. If the
connection name, it will return the default connection. For
example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 28
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 29
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 30
+ \snippet sqldatabase/sqldatabase.cpp 28
+ \snippet sqldatabase/sqldatabase.cpp 29
+ \snippet sqldatabase/sqldatabase.cpp 30
To remove a database connection, first close the database using
QSqlDatabase::close(), then remove it using the static method
To execute an SQL statement, simply create a QSqlQuery object and
call QSqlQuery::exec() like this:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 31
+ \snippet sqldatabase/sqldatabase.cpp 31
The QSqlQuery constructor accepts an optional QSqlDatabase object
that specifies which database connection to use. In the example
to access the other records, until it returns false. Here's a
typical loop that iterates over all the records in order:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 32
+ \snippet sqldatabase/sqldatabase.cpp 32
The QSqlQuery::value() function returns the value of a field in
the current record. Fields are specified as zero-based indexes.
navigate to the last record and use the query's position to tell
us how many records there are.
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 33
+ \snippet sqldatabase/sqldatabase.cpp 33
If you iterate through a result set only using next() and seek()
with positive values, you can call
\c{SELECT}s. The following example inserts a record into a table
using \c{INSERT}:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 34
+ \snippet sqldatabase/sqldatabase.cpp 34
If you want to insert many records at the same time, it is often
more efficient to separate the query from the actual values being
placeholder syntaxes: named binding and positional binding.
Here's an example of named binding:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 35
+ \snippet sqldatabase/sqldatabase.cpp 35
Here's an example of positional binding:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 36
+ \snippet sqldatabase/sqldatabase.cpp 36
Both syntaxes work with all database drivers provided by Qt. If
the database supports the syntax natively, Qt simply forwards the
Updating a record is similar to inserting it into a table:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 37
+ \snippet sqldatabase/sqldatabase.cpp 37
You can also use named or positional binding to associate
parameters to actual values.
Finally, here's an example of a \c DELETE statement:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 38
+ \snippet sqldatabase/sqldatabase.cpp 38
\section2 Transactions
Example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 39
+ \snippet sqldatabase/sqldatabase.cpp 39
Transactions can be used to ensure that a complex operation is
atomic (for example, looking up a foreign key and creating a
Example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 40
+ \snippet sqldatabase/sqldatabase.cpp 40
After setting the query using QSqlQueryModel::setQuery(), you can
use QSqlQueryModel::record(int) to access the individual records.
Example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 41
+ \snippet sqldatabase/sqldatabase.cpp 41
QSqlTableModel is a high-level alternative to QSqlQuery for
navigating and modifying individual SQL tables. It typically
following code will increase every employee's salary by 10 per
cent:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 42
+ \snippet sqldatabase/sqldatabase.cpp 42
You can also use QSqlTableModel::data() and
QSqlTableModel::setData(), which are inherited from
to update a record using
\l{QSqlTableModel::setData()}{setData()}:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 43
+ \snippet sqldatabase/sqldatabase.cpp 43
Here's how to insert a row and populate it:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 44
+ \snippet sqldatabase/sqldatabase.cpp 44
Here's how to delete five consecutive rows:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 45
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 46
+ \snippet sqldatabase/sqldatabase.cpp 45
+ \snippet sqldatabase/sqldatabase.cpp 46
The first argument to QSqlTableModel::removeRows() is the index
of the first row to delete.
The following code snippet shows how the QSqlRelationalTableModel
was set up:
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 0
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 0
\codeline
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 1
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 2
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 1
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 2
See the QSqlRelationalTableModel documentation for details.
*/
The following example creates a view based on an SQL data model:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 17
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 18
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 19
+ \snippet sqldatabase/sqldatabase.cpp 17
+ \snippet sqldatabase/sqldatabase.cpp 18
+ \snippet sqldatabase/sqldatabase.cpp 19
If the model is a read-write model (e.g., QSqlTableModel), the
view lets the user edit the fields. You can disable this by
calling
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 20
+ \snippet sqldatabase/sqldatabase.cpp 20
You can use the same model as a data source for multiple views.
If the user edits the model through one of the views, the other
model. The header's labels default to the table's field names.
For example:
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 3
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 3
QTableView also has a vertical header on the left with numbers
identifying the rows. If you insert rows programmatically using
read-write. The following two functions make fields 1 and 2 of a
query model editable:
- \snippet examples/sql/querymodel/editablesqlmodel.cpp 0
+ \snippet sql/querymodel/editablesqlmodel.cpp 0
\codeline
- \snippet examples/sql/querymodel/editablesqlmodel.cpp 1
+ \snippet sql/querymodel/editablesqlmodel.cpp 1
The setFirstName() helper function is defined as follows:
- \snippet examples/sql/querymodel/editablesqlmodel.cpp 2
+ \snippet sql/querymodel/editablesqlmodel.cpp 2
The setLastName() function is similar. See the
\l{sql/querymodel}{Query Model} example for the complete source code.
\ingroup database
- \sa {QtSql Module}
+ \sa {Qt SQL Module}
*/
/*!
snippet shows how to create and open a default connection to a
PostgreSQL database:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 0
+ \snippet sqldatabase/sqldatabase.cpp 0
Once the QSqlDatabase object has been created, set the connection
parameters with setDatabaseName(), setUserName(), setPassword(),
{addDatabase()}. Subsequently, you can get the default connection
by calling database() without the connection name argument:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 1
+ \snippet sqldatabase/sqldatabase.cpp 1
QSqlDatabase is a value class. Changes made to a database
connection via one instance of QSqlDatabase will affect other
If you have created your own custom driver, you must register it
with registerSqlDriver().
- \sa QSqlDriver, QSqlQuery, {QtSql Module}, {Threads and the SQL Module}
+ \sa QSqlDriver, QSqlQuery, {Qt SQL Module}, {Threads and the SQL Module}
*/
/*! \fn QSqlDatabase QSqlDatabase::addDatabase(const QString &type, const QString &connectionName)
setHostName(), setPort(), and setConnectOptions(), and, finally,
open().
- \sa database() removeDatabase() {Threads and the SQL Module}
+ \sa database(), removeDatabase(), {Threads and the SQL Module}
*/
QSqlDatabase QSqlDatabase::addDatabase(const QString &type, const QString &connectionName)
{
connectionName does not exist in the list of databases, an invalid
connection is returned.
- \sa isOpen() {Threads and the SQL Module}
+ \sa isOpen(), {Threads and the SQL Module}
*/
QSqlDatabase QSqlDatabase::database(const QString& connectionName, bool open)
Example:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 0
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 0
The correct way to do it:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 1
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 1
To remove the default connection, which may have been created with a
call to addDatabase() not specifying a connection name, you can
the database returned by database(). Note that if a default database
hasn't been created an invalid database will be returned.
- \sa database() connectionName() {Threads and the SQL Module}
+ \sa database(), connectionName(), {Threads and the SQL Module}
*/
void QSqlDatabase::removeDatabase(const QString& connectionName)
and don't want to compile it as a plugin.
Example:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 2
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 2
QSqlDatabase takes ownership of the \a creator pointer, so you
mustn't delete it yourself.
values. Returns true on success; otherwise returns false. Error
information can be retrieved using lastError().
- \sa lastError() setDatabaseName() setUserName() setPassword()
- \sa setHostName() setPort() setConnectOptions()
+ \sa lastError(), setDatabaseName(), setUserName(), setPassword(),
+ setHostName(), setPort(), setConnectOptions()
*/
bool QSqlDatabase::open()
Call lastError() to get information about errors.
- \sa QSqlQuery::isActive() QSqlDriver::hasFeature() rollback()
+ \sa QSqlQuery::isActive(), QSqlDriver::hasFeature(), rollback()
*/
bool QSqlDatabase::commit()
{
Call lastError() to get information about errors.
- \sa QSqlQuery::isActive() QSqlDriver::hasFeature() commit()
+ \sa QSqlQuery::isActive(), QSqlDriver::hasFeature(), commit()
*/
bool QSqlDatabase::rollback()
{
connection string to open an \c .mdb file directly, instead of
having to create a DSN entry in the ODBC manager:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 3
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 3
There is no default value.
- \sa databaseName() setUserName() setPassword() setHostName()
- \sa setPort() setConnectOptions() open()
+ \sa databaseName(), setUserName(), setPassword(), setHostName(),
+ setPort(), setConnectOptions(), open()
*/
void QSqlDatabase::setDatabaseName(const QString& name)
There is no default value.
- \sa userName() setDatabaseName() setPassword() setHostName()
- \sa setPort() setConnectOptions() open()
+ \sa userName(), setDatabaseName(), setPassword(), setHostName(),
+ setPort(), setConnectOptions(), open()
*/
void QSqlDatabase::setUserName(const QString& name)
Qt. Use the open() call that takes a password as parameter to
avoid this behavior.
- \sa password() setUserName() setDatabaseName() setHostName()
- \sa setPort() setConnectOptions() open()
+ \sa password(), setUserName(), setDatabaseName(), setHostName(),
+ setPort(), setConnectOptions(), open()
*/
void QSqlDatabase::setPassword(const QString& password)
There is no default value.
- \sa hostName() setUserName() setPassword() setDatabaseName()
- \sa setPort() setConnectOptions() open()
+ \sa hostName(), setUserName(), setPassword(), setDatabaseName(),
+ setPort(), setConnectOptions(), open()
*/
void QSqlDatabase::setHostName(const QString& host)
There is no default value.
- \sa port() setUserName() setPassword() setHostName()
- \sa setDatabaseName() setConnectOptions() open()
+ \sa port(), setUserName(), setPassword(), setHostName(),
+ setDatabaseName(), setConnectOptions(), open()
*/
void QSqlDatabase::setPort(int port)
Returns the database driver used to access the database
connection.
- \sa addDatabase() drivers()
+ \sa addDatabase(), drivers()
*/
QSqlDriver* QSqlDatabase::driver() const
\endtable
Examples:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 4
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 4
Refer to the client library documentation for more information
about the different options.
application. For example, you can create a PostgreSQL connection
with your own QPSQL driver like this:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 5
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 5
\codeline
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 6
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 6
The above code sets up a PostgreSQL connection and instantiates a
QPSQLDriver object. Next, addDatabase() is called to add the
client library. Make sure the client library is in your linker's
search path, and add lines like these to your \c{.pro} file:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 7
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 7
The method described works for all the supplied drivers. The only
difference will be in the driver constructor arguments. Here is a
Returns true if the QSqlDatabase has a valid driver.
Example:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp 8
+ \snippet code/src_sql_kernel_qsqldatabase.cpp 8
*/
bool QSqlDatabase::isValid() const
{
/*!
\since 5.0
- \fn QSqlDriver::notification(const QString &name, NotificationSource source, const QString & payload)
+ \fn QSqlDriver::notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant & payload)
This signal is emitted when the database posts an event notification
that the driver subscribes to. \a name identifies the event notification, \a source indicates the signal source,
This example retrieves the handle for a connection to sqlite:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp 0
+ \snippet code/src_sql_kernel_qsqldriver.cpp 0
This snippet returns the handle for PostgreSQL or MySQL:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp 1
+ \snippet code/src_sql_kernel_qsqldriver.cpp 1
\sa QSqlResult::handle()
*/
}
/*!
- \fn QSqlRecord QSqlDriver::record(const QSqlQuery& query) const
-
- Use query.record() instead.
-*/
-
-/*!
- \fn QSqlRecord QSqlDriver::recordInfo(const QString& tablename) const
-
- Use record() instead.
-*/
-
-/*!
- \fn QSqlRecord QSqlDriver::recordInfo(const QSqlQuery& query) const
-
- Use query.record() instead.
-*/
-
-/*!
- \fn QString QSqlDriver::nullText() const
-
- sqlStatement() is now used to generate SQL. Use tr("NULL") for example, instead.
-*/
-
-/*!
- \fn QString QSqlDriver::formatValue(const QSqlField *field, bool trimStrings) const
-
- Use the other formatValue() overload instead.
-*/
-
-/*!
This function is called to subscribe to event notifications from the database.
\a name identifies the event notification.
own QSqlDriver subclass,
\since 4.4
- \sa unsubscribeFromNotification() subscribedToNotifications() QSqlDriver::hasFeature()
+ \sa unsubscribeFromNotification(), subscribedToNotifications(), QSqlDriver::hasFeature()
*/
bool QSqlDriver::subscribeToNotification(const QString &name)
{
own QSqlDriver subclass,
\since 4.4
- \sa subscribeToNotification() subscribedToNotifications()
+ \sa subscribeToNotification(), subscribedToNotifications()
*/
bool QSqlDriver::unsubscribeFromNotification(const QString &name)
{
own QSqlDriver subclass,
\since 4.4
- \sa subscribeToNotification() unsubscribeFromNotification()
+ \sa subscribeToNotification(), unsubscribeFromNotification()
*/
QStringList QSqlDriver::subscribedToNotifications() const
{
Returns the text of the error as reported by the driver. This may
contain database-specific descriptions. It may also be empty.
- \sa setDriverText() databaseText() text()
+ \sa setDriverText(), databaseText(), text()
*/
QString QSqlError::driverText() const
{
/*!
Sets the driver error text to the value of \a driverText.
- \sa driverText() setDatabaseText() text()
+ \sa driverText(), setDatabaseText(), text()
*/
void QSqlError::setDriverText(const QString& driverText)
Returns the text of the error as reported by the database. This
may contain database-specific descriptions; it may be empty.
- \sa setDatabaseText() driverText() text()
+ \sa setDatabaseText(), driverText(), text()
*/
QString QSqlError::databaseText() const
/*!
Sets the database error text to the value of \a databaseText.
- \sa databaseText() setDriverText() text()
+ \sa databaseText(), setDriverText(), text()
*/
void QSqlError::setDatabaseText(const QString& databaseText)
This is a convenience function that returns databaseText() and
driverText() concatenated into a single string.
- \sa driverText() databaseText()
+ \sa driverText(), databaseText()
*/
QString QSqlError::text() const
Returns true if an error is set, otherwise false.
Example:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqlerror.cpp 0
+ \snippet code/src_sql_kernel_qsqlerror.cpp 0
\sa type()
*/
Field data values are stored as QVariants. Using an incompatible
type is not permitted. For example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 2
+ \snippet sqldatabase/sqldatabase.cpp 2
However, the field will attempt to cast certain data types to the
field data type where possible:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 3
+ \snippet sqldatabase/sqldatabase.cpp 3
QSqlField objects are rarely created explicitly in application
code. They are usually accessed indirectly through \l{QSqlRecord}s
that already contain a list of fields. For example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 4
+ \snippet sqldatabase/sqldatabase.cpp 4
\dots
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 5
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 6
+ \snippet sqldatabase/sqldatabase.cpp 5
+ \snippet sqldatabase/sqldatabase.cpp 6
A QSqlField object can provide some meta-data about the field, for
example, its name(), variant type(), length(), precision(),
Constructs an empty field called \a fieldName of variant type \a
type.
- \sa setRequiredStatus() setLength() setPrecision() setDefaultValue() setGenerated() setReadOnly()
+ \sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(),
+ setGenerated(), setReadOnly()
*/
QSqlField::QSqlField(const QString& fieldName, QVariant::Type type)
{
/*!
Sets the required status of this field to \a required.
- \sa requiredStatus() setType() setLength() setPrecision() setDefaultValue() setGenerated() setReadOnly()
+ \sa requiredStatus(), setType(), setLength(), setPrecision(),
+ setDefaultValue(), setGenerated(), setReadOnly()
*/
void QSqlField::setRequiredStatus(RequiredStatus required)
{
maximum number of characters the string can hold; the meaning
varies for other types.
- \sa length() setType() setRequiredStatus() setPrecision() setDefaultValue() setGenerated() setReadOnly()
+ \sa length(), setType(), setRequiredStatus(), setPrecision(),
+ setDefaultValue(), setGenerated(), setReadOnly()
*/
void QSqlField::setLength(int fieldLength)
{
/*!
Sets the field's \a precision. This only affects numeric fields.
- \sa precision() setType() setRequiredStatus() setLength() setDefaultValue() setGenerated() setReadOnly()
+ \sa precision(), setType(), setRequiredStatus(), setLength(),
+ setDefaultValue(), setGenerated(), setReadOnly()
*/
void QSqlField::setPrecision(int precision)
{
/*!
Sets the default value used for this field to \a value.
- \sa defaultValue() value() setType() setRequiredStatus() setLength() setPrecision() setGenerated() setReadOnly()
+ \sa defaultValue(), value(), setType(), setRequiredStatus(),
+ setLength(), setPrecision(), setGenerated(), setReadOnly()
*/
void QSqlField::setDefaultValue(const QVariant &value)
{
QSqlQueryModel and QSqlTableModel will generate SQL for this
field.
- \sa isGenerated() setType() setRequiredStatus() setLength() setPrecision() setDefaultValue() setReadOnly()
+ \sa isGenerated(), setType(), setRequiredStatus(), setLength(),
+ setPrecision(), setDefaultValue(), setReadOnly()
*/
void QSqlField::setGenerated(bool gen)
{
To set the value to NULL, use clear().
- \sa value() isReadOnly() defaultValue()
+ \sa value(), isReadOnly(), defaultValue()
*/
void QSqlField::setValue(const QVariant& value)
Clears the value of the field and sets it to NULL.
If the field is read-only, nothing happens.
- \sa setValue() isReadOnly() requiredStatus()
+ \sa setValue(), isReadOnly(), requiredStatus()
*/
void QSqlField::clear()
/*!
Set's the field's variant type to \a type.
- \sa type() setRequiredStatus() setLength() setPrecision() setDefaultValue() setGenerated() setReadOnly()
+ \sa type(), setRequiredStatus(), setLength(), setPrecision(),
+ setDefaultValue(), setGenerated(), setReadOnly()
*/
void QSqlField::setType(QVariant::Type type)
{
Returns true if the field's value is read-only; otherwise returns
false.
- \sa setReadOnly() type() requiredStatus() length() precision() defaultValue() isGenerated()
+ \sa setReadOnly(), type(), requiredStatus(), length(), precision(),
+ defaultValue(), isGenerated()
*/
bool QSqlField::isReadOnly() const
{ return d->ro; }
Returns true if this is a required field; otherwise returns false.
An \c INSERT will fail if a required field does not have a value.
- \sa setRequiredStatus() type() length() precision() defaultValue() isGenerated()
+ \sa setRequiredStatus(), type(), length(), precision(), defaultValue(),
+ isGenerated()
*/
QSqlField::RequiredStatus QSqlField::requiredStatus() const
{
If the returned value is negative, it means that the information
is not available from the database.
- \sa setLength() type() requiredStatus() precision() defaultValue() isGenerated()
+ \sa setLength(), type(), requiredStatus(), precision(), defaultValue(),
+ isGenerated()
*/
int QSqlField::length() const
{
If the returned value is negative, it means that the information
is not available from the database.
- \sa setPrecision() type() requiredStatus() length() defaultValue() isGenerated()
+ \sa setPrecision(), type(), requiredStatus(), length(), defaultValue(),
+ isGenerated()
*/
int QSqlField::precision() const
{
/*!
Returns the field's default value (which may be NULL).
- \sa setDefaultValue() type() requiredStatus() length() precision() isGenerated()
+ \sa setDefaultValue(), type(), requiredStatus(), length(), precision(),
+ isGenerated()
*/
QVariant QSqlField::defaultValue() const
{
Returns true if the field is generated; otherwise returns
false.
- \sa setGenerated() type() requiredStatus() length() precision() defaultValue()
+ \sa setGenerated(), type(), requiredStatus(), length(), precision(),
+ defaultValue()
*/
bool QSqlField::isGenerated() const
{
#endif
/*!
- \fn void QSqlField::setNull()
-
- Use clear() instead.
-*/
-
-/*!
Returns true if the value is auto-generated by the database,
for example auto-increment primary key values.
For example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 7
+ \snippet sqldatabase/sqldatabase.cpp 7
To access the data returned by a query, use value(int). Each
field in the data returned by a \c SELECT statement is accessed
explained below). To convert a field name into an index, use
record().\l{QSqlRecord::indexOf()}{indexOf()}, for example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 8
+ \snippet sqldatabase/sqldatabase.cpp 8
QSqlQuery supports prepared query execution and the binding of
parameter values to placeholders. Some databases don't support
\b{Named binding using named placeholders:}
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 9
+ \snippet sqldatabase/sqldatabase.cpp 9
\b{Positional binding using named placeholders:}
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 10
+ \snippet sqldatabase/sqldatabase.cpp 10
\b{Binding values using positional placeholders (version 1):}
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 11
+ \snippet sqldatabase/sqldatabase.cpp 11
\b{Binding values using positional placeholders (version 2):}
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 12
+ \snippet sqldatabase/sqldatabase.cpp 12
\b{Binding values to a stored procedure:}
it a character through its in parameter, and taking its result in
the out parameter.
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 13
+ \snippet sqldatabase/sqldatabase.cpp 13
Note that unbound parameters will retain their values.
Example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 34
+ \snippet sqldatabase/sqldatabase.cpp 34
\sa isActive(), isValid(), next(), previous(), first(), last(),
seek()
The fields are numbered from left to right using the text of the
\c SELECT statement, e.g. in
- \snippet doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp 0
+ \snippet code/src_sql_kernel_qsqlquery.cpp 0
field 0 is \c forename and field 1 is \c
surname. Using \c{SELECT *} is not recommended because the order
exist, if the query is inactive, or if the query is positioned on
an invalid record.
- \sa previous() next() first() last() seek() isActive() isValid()
+ \sa previous(), next(), first(), last(), seek(), isActive(), isValid()
*/
QVariant QSqlQuery::value(int index) const
function returns QSql::BeforeFirstRow or
QSql::AfterLastRow, which are special negative values.
- \sa previous() next() first() last() seek() isActive() isValid()
+ \sa previous(), next(), first(), last(), seek(), isActive(), isValid()
*/
int QSqlQuery::at() const
\endlist
- \sa next() previous() first() last() at() isActive() isValid()
+ \sa next(), previous(), first(), last(), at(), isActive(), isValid()
*/
bool QSqlQuery::seek(int index, bool relative)
{
the last record and false is returned. If the record is successfully
retrieved, true is returned.
- \sa previous() first() last() seek() at() isActive() isValid()
+ \sa previous(), first(), last(), seek(), at(), isActive(), isValid()
*/
bool QSqlQuery::next()
{
before the first record and false is returned. If the record is
successfully retrieved, true is returned.
- \sa next() first() last() seek() at() isActive() isValid()
+ \sa next(), first(), last(), seek(), at(), isActive(), isValid()
*/
bool QSqlQuery::previous()
{
return false. Returns true if successful. If unsuccessful the query
position is set to an invalid position and false is returned.
- \sa next() previous() last() seek() at() isActive() isValid()
+ \sa next(), previous(), last(), seek(), at(), isActive(), isValid()
*/
bool QSqlQuery::first()
{
Returns true if successful. If unsuccessful the query position is
set to an invalid position and false is returned.
- \sa next() previous() first() seek() at() isActive() isValid()
+ \sa next(), previous(), first(), seek(), at(), isActive(), isValid()
*/
bool QSqlQuery::last()
To determine the number of rows affected by a non-\c SELECT
statement, use numRowsAffected().
- \sa isActive() numRowsAffected() QSqlDriver::hasFeature()
+ \sa isActive(), numRowsAffected(), QSqlDriver::hasFeature()
*/
int QSqlQuery::size() const
{
statements, the value is undefined; use size() instead. If the query
is not \l{isActive()}{active}, -1 is returned.
- \sa size() QSqlDriver::hasFeature()
+ \sa size(), QSqlDriver::hasFeature()
*/
int QSqlQuery::numRowsAffected() const
Since the order of the columns is not defined, QSqlRecord::indexOf()
is used to obtain the index of a column.
- \snippet doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp 1
+ \snippet code/src_sql_kernel_qsqlquery.cpp 1
\sa value()
*/
Example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 9
+ \snippet sqldatabase/sqldatabase.cpp 9
\sa exec(), bindValue(), addBindValue()
*/
Note that the last error for this query is reset when exec() is
called.
- \sa prepare() bindValue() addBindValue() boundValue() boundValues()
+ \sa prepare(), bindValue(), addBindValue(), boundValue(), boundValues()
*/
bool QSqlQuery::exec()
{
Example:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp 2
+ \snippet code/src_sql_kernel_qsqlquery.cpp 2
The example above inserts four new rows into \c myTable:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp 3
+ \snippet code/src_sql_kernel_qsqlquery.cpp 3
To bind NULL values, a null QVariant of the relevant type has to be
added to the bound QVariantList; for example, \c
\endcode
Binding to name will bind to the first :name, but not the second.
- \sa addBindValue(), prepare(), exec(), boundValue() boundValues()
+ \sa addBindValue(), prepare(), exec(), boundValue(), boundValues()
*/
void QSqlQuery::bindValue(const QString& placeholder, const QVariant& val,
QSql::ParamType paramType
To bind a NULL value, use a null QVariant; for example, use \c
{QVariant(QVariant::String)} if you are binding a string.
- \sa bindValue(), prepare(), exec(), boundValue() boundValues()
+ \sa bindValue(), prepare(), exec(), boundValue(), boundValues()
*/
void QSqlQuery::addBindValue(const QVariant& val, QSql::ParamType paramType)
{
/*!
Returns the value for the \a placeholder.
- \sa boundValues() bindValue() addBindValue()
+ \sa boundValues(), bindValue(), addBindValue()
*/
QVariant QSqlQuery::boundValue(const QString& placeholder) const
{
With named binding, the bound values can be examined in the
following ways:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 14
+ \snippet sqldatabase/sqldatabase.cpp 14
With positional binding, the code becomes:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 15
+ \snippet sqldatabase/sqldatabase.cpp 15
- \sa boundValue() bindValue() addBindValue()
+ \sa boundValue(), bindValue(), addBindValue()
*/
QMap<QString,QVariant> QSqlQuery::boundValues() const
{
}
/*!
- \fn bool QSqlQuery::prev()
-
- Use previous() instead.
-*/
-
-/*!
Returns the object ID of the most recent inserted row if the
database supports it. An invalid QVariant will be returned if the
query did not insert any value or if the database does not report
Sets the query to inactive. Bound values retain their values.
- \sa prepare() exec() isActive()
+ \sa prepare(), exec(), isActive()
*/
void QSqlQuery::finish()
{
databases may have restrictions on which statements are allowed to
be used in a SQL batch.
- \sa QSqlDriver::hasFeature() setForwardOnly() next() isSelect() numRowsAffected() isActive() lastError()
+ \sa QSqlDriver::hasFeature(), setForwardOnly(), next(), isSelect(),
+ numRowsAffected(), isActive(), lastError()
*/
bool QSqlQuery::nextResult()
{
the record. If \a index is out of bounds, an invalid QVariant
is returned.
- \sa fieldName() isNull()
+ \sa fieldName(), isNull()
*/
QVariant QSqlRecord::value(int index) const
/*!
Append a copy of field \a field to the end of the record.
- \sa insert() replace() remove()
+ \sa insert(), replace(), remove()
*/
void QSqlRecord::append(const QSqlField& field)
/*!
Inserts the field \a field at position \a pos in the record.
- \sa append() replace() remove()
+ \sa append(), replace(), remove()
*/
void QSqlRecord::insert(int pos, const QSqlField& field)
{
Replaces the field at position \a pos with the given \a field. If
\a pos is out of range, nothing happens.
- \sa append() insert() remove()
+ \sa append(), insert(), remove()
*/
void QSqlRecord::replace(int pos, const QSqlField& field)
Removes the field at position \a pos. If \a pos is out of range,
nothing happens.
- \sa append() insert() replace()
+ \sa append(), insert(), replace()
*/
void QSqlRecord::remove(int pos)
/*!
Removes all the record's fields.
- \sa clearValues() isEmpty()
+ \sa clearValues(), isEmpty()
*/
void QSqlRecord::clear()
Returns true if there are no fields in the record; otherwise
returns false.
- \sa append() insert() clear()
+ \sa append(), insert(), clear()
*/
bool QSqlRecord::isEmpty() const
}
#endif
-/*!
- \fn int QSqlRecord::position(const QString& name) const
-
- Use indexOf() instead.
-*/
-
QT_END_NAMESPACE
Example:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp 0
+ \snippet code/src_sql_kernel_qsqlresult.cpp 0
Here, we insert two rows into a SQL table, with each row containing three values.
This example retrieves the handle for a sqlite result:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp 1
+ \snippet code/src_sql_kernel_qsqlresult.cpp 1
This snippet returns the handle for PostgreSQL or MySQL:
- \snippet doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp 2
+ \snippet code/src_sql_kernel_qsqlresult.cpp 2
\sa QSqlDriver::handle()
*/
the lower-level QSqlQuery and can be used to provide data to
view classes such as QTableView. For example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 16
+ \snippet sqldatabase/sqldatabase.cpp 16
We set the model's query, then we set up the labels displayed in
the view header.
QSqlQueryModel can also be used to access a database
programmatically, without binding it to a view:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 21
+ \snippet sqldatabase/sqldatabase.cpp 21
The code snippet above extracts the \c salary field from record 4 in
the result set of the query \c{SELECT * from employee}. Assuming
that \c salary is column 2, we can rewrite the last line as follows:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 22
+ \snippet sqldatabase/sqldatabase.cpp 22
The model is read-only by default. To make it read-write, you
must subclass it and reimplement setData() and flags(). Another
To force fetching of the entire result set, you can use the following:
- \snippet doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp 0
+ \snippet code/src_sql_models_qsqlquerymodel.cpp 0
\a parent should always be an invalid QModelIndex.
was an error setting the query.
Example:
- \snippet doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp 1
+ \snippet code/src_sql_models_qsqlquerymodel.cpp 1
\sa query(), queryChange(), lastError()
*/
By default, inserted columns are empty. To fill them with data,
reimplement data() and handle any inserted column separately:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 23
+ \snippet sqldatabase/sqldatabase.cpp 23
\sa removeColumns()
*/
use the class, simply call QAbstractItemView::setItemDelegate()
on the view with an instance of QSqlRelationalDelegate:
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 4
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 4
The \l{sql/relationaltablemodel}{Relational Table Model} example
(shown below) illustrates how to use QSqlRelationalDelegate in
The following code snippet shows how the QSqlRelationalTableModel
was set up:
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 0
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 0
\codeline
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 1
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 2
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 1
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 2
The setRelation() function calls establish a relationship between
two tables. The first call specifies that column 2 in table \c
call QAbstractItemView::setItemDelegate() on the view with an
instance of QSqlRelationalDelegate:
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 4
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 4
The \l{sql/relationaltablemodel} example illustrates how to use
QSqlRelationalTableModel in conjunction with
Example:
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 0
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 0
\codeline
- \snippet examples/sql/relationaltablemodel/relationaltablemodel.cpp 1
+ \snippet sql/relationaltablemodel/relationaltablemodel.cpp 1
The setRelation() call specifies that column 2 in table \c
employee is a foreign key that maps with field \c id of table \c
lower-level QSqlQuery and can be used to provide data to view
classes such as QTableView. For example:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 24
+ \snippet sqldatabase/sqldatabase.cpp 24
We set the SQL table's name and the edit strategy, then we set up
the labels displayed in the view header. The edit strategy
QSqlTableModel can also be used to access a database
programmatically, without binding it to a view:
- \snippet doc/src/snippets/sqldatabase/sqldatabase.cpp 21
+ \snippet sqldatabase/sqldatabase.cpp 21
The code snippet above extracts the \c salary field from record 4 in
the result set of the query \c{SELECT * from employee}.
PRECOMPILED_HEADER = ../corelib/global/qt_pch.h
SQL_P = sql
+include(doc/doc.pri)
include(kernel/kernel.pri)
include(drivers/drivers.pri)
include(models/models.pri)