zoukankan      html  css  js  c++  java
  • qt 与mysql建立交互式连接

    void QSqlDatabase::setConnectOptions(const QString & options = QString())
    Sets database-specific options. This must be done before the connection is opened or it has no effect (or you can close() the connection, call this function and open() the connection again).

    The format of the options string is a semicolon separated list of option names or option=value pairs. The options depend on the database client used:

    ODBC MySQL PostgreSQL
    SQL_ATTR_ACCESS_MODE
    SQL_ATTR_LOGIN_TIMEOUT
    SQL_ATTR_CONNECTION_TIMEOUT
    SQL_ATTR_CURRENT_CATALOG
    SQL_ATTR_METADATA_ID
    SQL_ATTR_PACKET_SIZE
    SQL_ATTR_TRACEFILE
    SQL_ATTR_TRACE
    SQL_ATTR_CONNECTION_POOLING
    SQL_ATTR_ODBC_VERSION
    CLIENT_COMPRESS
    CLIENT_FOUND_ROWS
    CLIENT_IGNORE_SPACE
    CLIENT_SSL
    CLIENT_ODBC
    CLIENT_NO_SCHEMA
    CLIENT_INTERACTIVE
    UNIX_SOCKET
    MYSQL_OPT_RECONNECT
    connect_timeout
    options
    tty
    requiressl
    service
    DB2 OCI TDS
    SQL_ATTR_ACCESS_MODE
    SQL_ATTR_LOGIN_TIMEOUT
    OCI_ATTR_PREFETCH_ROWS
    OCI_ATTR_PREFETCH_MEMORY
    none
    SQLite Interbase
    QSQLITE_BUSY_TIMEOUT
    QSQLITE_OPEN_READONLY
    QSQLITE_OPEN_URI
    QSQLITE_ENABLE_SHARED_CACHE
    ISC_DPB_LC_CTYPE
    ISC_DPB_SQL_ROLE_NAME
    Examples:

    ...
    // MySQL connection
    db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1"); // use an SSL connection to the server
    if (!db.open()) {
    db.setConnectOptions(); // clears the connect option string
    ...
    }
    ...
    // PostgreSQL connection
    db.setConnectOptions("requiressl=1"); // enable PostgreSQL SSL connections
    if (!db.open()) {
    db.setConnectOptions(); // clear options
    ...
    }
    ...
    // ODBC connection
    db.setConnectOptions("SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON"); // set ODBC options
    if (!db.open()) {
    db.setConnectOptions(); // don't try to set this option
    ...
    }

  • 相关阅读:
    SQL Server中游标的使用
    SQL Server之内连接 左连接 右连接 全连接 交叉连接
    C#后台格式化JSON字符串显示
    使用反射、特性简化代码
    JQuery方法扩展
    .NET强制进行即时垃圾回收
    .NET中的Queue和Stack
    如何解决firefox下window.event的问题
    【JS对象、JSON字符串】之间的相互转换
    Javascript模块化编程(一):模块的写法
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/4831445.html
Copyright © 2011-2022 走看看