⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsqldatabase.3qt

📁 qt专门用于嵌入式的图形开发GUI
💻 3QT
📖 第 1 页 / 共 2 页
字号:
Returns information about the last error that occurred on the database. See QSqlError for more information..PPExamples:.)l sql/overview/connection.cpp and sql/sqltable/main.cpp..SH "bool QSqlDatabase::open ()"Opens the database connection using the current connection values. Returns TRUE on success; otherwise returns FALSE. Error information can be retrieved using the lastError() function..PPSee also lastError()..PPExamples:.)l sql/overview/connect1/main.cpp, sql/overview/connection.cpp, and sql/sqltable/main.cpp..SH "bool QSqlDatabase::open ( const QString & user, const QString & password )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPOpens the database connection using the given \fIuser\fR name and \fIpassword\fR. Returns TRUE on success; otherwise returns FALSE. Error information can be retrieved using the lastError() function..PPThis function does not store the password it is given. Instead, the password is passed directly to the driver for opening a connection and is then discarded..PPSee also lastError()..SH "QString QSqlDatabase::password () const"Returns the password used to connect to the database. See the "password" property for details..SH "int QSqlDatabase::port () const"Returns the port used to connect to the database. See the "port" property for details..SH "QSqlIndex QSqlDatabase::primaryIndex ( const QString & tablename ) const"Returns the primary index for table \fItablename\fR. If no primary index exists an empty QSqlIndex will be returned..SH "QSqlRecord QSqlDatabase::record ( const QString & tablename ) const"Returns a QSqlRecord populated with the names of all the fields in the table (or view) called \fItablename\fR. The order in which the fields appear in the record is undefined. If no such table (or view) exists, an empty record is returned..PPSee also recordInfo()..SH "QSqlRecord QSqlDatabase::record ( const QSqlQuery & query ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns a QSqlRecord populated with the names of all the fields used in the SQL \fIquery\fR. If the query is a "SELECT *" the order in which fields appear in the record is undefined..PPSee also recordInfo()..SH "QSqlRecordInfo QSqlDatabase::recordInfo ( const QString & tablename ) const"Returns a QSqlRecordInfo populated with meta data about the table or view \fItablename\fR. If no such table (or view) exists, an empty record is returned..PPSee also QSqlRecordInfo, QSqlFieldInfo, and record()..SH "QSqlRecordInfo QSqlDatabase::recordInfo ( const QSqlQuery & query ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns a QSqlRecordInfo object with meta data for the QSqlQuery \fIquery\fR. Note that this overloaded function may return less information than the recordInfo() function which takes the name of a table as parameter..PPSee also QSqlRecordInfo, QSqlFieldInfo, and record()..SH "void QSqlDatabase::registerSqlDriver ( const QString & name, const QSqlDriverCreatorBase * creator )\fC [static]\fR"This function registers a new SQL driver called \fIname\fR, within the SQL framework. This is useful if you have a custom SQL driver and don't want to compile it as a plugin..PPExample usage:.PP.nf.br    QSqlDatabase::registerSqlDriver( "MYDRIVER", new QSqlDriverCreator<MyDatabaseDriver> );.br    QSqlDatabase* db = QSqlDatabase::addDatabase( "MYDRIVER" );.br    ....br.fi.PP\fBWarning:\fR The framework takes ownership of the \fIcreator\fR pointer, so it should not be deleted..SH "void QSqlDatabase::removeDatabase ( const QString & connectionName )\fC [static]\fR"Removes the database connection \fIconnectionName\fR from the list of database connections..PP\fBWarning:\fR There should be no open queries on the database connection when this function is called, otherwise a resource leak will occur..SH "void QSqlDatabase::removeDatabase ( QSqlDatabase * db )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPRemoves the database connection \fIdb\fR from the list of database connections. The QSqlDatabase object is destroyed when it is removed from the list..PP\fBWarning:\fR The \fIdb\fR pointer is not valid after this function has been called. There should be no open queries on the database connection when this function is called, otherwise a resource leak will occur..SH "bool QSqlDatabase::rollback ()"Rolls a transaction back on the database if the driver supports transactions. Returns TRUE if the operation succeeded; otherwise returns FALSE..PPSee also QSqlDriver::hasFeature(), commit(), and transaction()..SH "void QSqlDatabase::setConnectOptions ( const QString & options = QString::null )"Sets the database connect options to \fIoptions\fR. See the "connectOptions" property for details..SH "void QSqlDatabase::setDatabaseName ( const QString & name )\fC [virtual]\fR"Sets the name of the database to \fIname\fR. See the "databaseName" property for details..SH "void QSqlDatabase::setHostName ( const QString & host )\fC [virtual]\fR"Sets the host name where the database resides to \fIhost\fR. See the "hostName" property for details..SH "void QSqlDatabase::setPassword ( const QString & password )\fC [virtual]\fR"Sets the password used to connect to the database to \fIpassword\fR. See the "password" property for details..SH "void QSqlDatabase::setPort ( int p )\fC [virtual]\fR"Sets the port used to connect to the database to \fIp\fR. See the "port" property for details..SH "void QSqlDatabase::setUserName ( const QString & name )\fC [virtual]\fR"Sets the user name connected to the database to \fIname\fR. See the "userName" property for details..SH "QStringList QSqlDatabase::tables ( QSql::TableType type ) const"Returns a list of the database's tables, system tables and views, as specified by the parameter \fItype\fR..PPNote that if you want to iterate over the list, you should iterate over a copy, e.g..PP.nf.br    QStringList list = myDatabase.tables( QSql::Tables | QSql::Views );.br    QStringList::Iterator it = list.begin();.br    while( it != list.end() ) {.br        myProcessing( *it );.br        ++it;.br    }.br.fi.PPExample: sql/sqltable/main.cpp..SH "QStringList QSqlDatabase::tables () const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns a list of the database's tables that are visible to the user. To include views or system tables, use the version of this function that takes a table \fCtype\fR parameter..PPNote that if you want to iterate over the list, you should iterate over a copy, e.g..PP.nf.br    QStringList list = myDatabase.tables();.br    QStringList::Iterator it = list.begin();.br    while( it != list.end() ) {.br        myProcessing( *it );.br        ++it;.br    }.br.fi.SH "bool QSqlDatabase::transaction ()"Begins a transaction on the database if the driver supports transactions. Returns TRUE if the operation succeeded; otherwise returns FALSE..PPSee also QSqlDriver::hasFeature(), commit(), and rollback()..SH "QString QSqlDatabase::userName () const"Returns the user name connected to the database. See the "userName" property for details..SS "Property Documentation".SH "QString connectOptions"This property holds the database connect options..PPThe format of the options string is a semi-colon separated list of option names or option = value pairs. The options depend on the database client used:.PP<center>.nf.TSl - l. ODBC MySQL PostgreSQL.TPSQL_ATTR_ACCESS_MODE.TPSQL_ATTR_LOGIN_TIMEOUT.TPSQL_ATTR_CONNECTION_TIMEOUT.TPSQL_ATTR_CURRENT_CATALOG.TPSQL_ATTR_METADATA_ID.TPSQL_ATTR_PACKET_SIZE.TPSQL_ATTR_TRACEFILE.TPSQL_ATTR_TRACE.PP	.TPCLIENT_COMPRESS.TPCLIENT_FOUND_ROWS.TPCLIENT_IGNORE_SPACE.TPCLIENT_SSL.TPCLIENT_ODBC.TPCLIENT_NO_SCHEMA.TPCLIENT_INTERACTIVE.PP	.TPconnect_timeout.TPoptions.TPtty.TPrequiressl.TPservice DB2 OCI TDS.TPSQL_ATTR_ACCESS_MODE.TPSQL_ATTR_LOGIN_TIMEOUT.PP	\fInone\fR.PP.TE.fi</center>.PPExample of usage:.PP.nf.br    ....br    // MySQL connection.br    db->setConnectOptions( "CLIENT_SSL;CLIENT_IGNORE_SPACE" ); // use an SSL connection to the server.br    if ( !db->open() ) {.br        db->setConnectOptions(); // clears the connect option string.br        ....br    }.br    ....br    // PostgreSQL connection.br    db->setConnectOptions( "requiressl=1" ); // enable PostgreSQL SSL connections.br    if ( !db->open() ) {.br        db->setConnectOptions(); // clear options.br        ....br    }.br    ....br    // ODBC connection.br    db->setConnectOptions( "SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON" ); // set ODBC options.br    if ( !db->open() ) {.br        db->setConnectOptions(); // don't try to set this option.br        ....br    }.br.fi.PPPlease refer to the client library documentation for more information about the different options. The options will be set prior to opening the database connection. Setting new options without re-opening the connection does nothing..PPSee also.PPSet this property's value with setConnectOptions() and get this property's value with connectOptions()..SH "QString databaseName"This property holds the name of the database..PPNote that the database name is the TNS Service Name for the QOCI8 (Oracle) driver..PPFor the QODBC3 driver it can either be a DSN, a DSN filename (the file must have a \fC.dsn\fR extension), or a connection string. MS Access users can for example use the following connection string to open a \fC.mdb\fR file directly, instead of having to create a DSN entry in the ODBC manager:.PP.nf.br    ....br    db = QSqlDatabase::addDatabase( "QODBC3" );.br    db->setDatabaseName( "DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb" );.br    if ( db->open() ) {.br        // success!.br    }.br    ....br.fi("FIL" is the required spelling in Microsoft's API.).PPThere is no default value..PPSet this property's value with setDatabaseName() and get this property's value with databaseName()..SH "QString hostName"This property holds the host name where the database resides..PPThere is no default value..PPSet this property's value with setHostName() and get this property's value with hostName()..SH "QString password"This property holds the password used to connect to the database..PPThere is no default value..PP\fBWarning:\fR This function stores the password in plain text within Qt. Use the open() call that takes a password as parameter to avoid this behaviour..PPSee also open()..PPSet this property's value with setPassword() and get this property's value with password()..SH "int port"This property holds the port used to connect to the database..PPThere is no default value..PPSet this property's value with setPort() and get this property's value with port()..SH "QString userName"This property holds the user name connected to the database..PPThere is no default value..PPSet this property's value with setUserName() and get this property's value with userName()..SH "SEE ALSO".BR http://doc.trolltech.com/qsqldatabase.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com.  See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qsqldatabase.3qt) and the Qtversion (3.3.5).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -