Пример #1
0
/*
   SQLite dbs have no user name, passwords, hosts or ports.
   just file names.
*/
bool QSQLite2Driver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &)
{
    if (isOpen())
        close();

    if (db.isEmpty())
        return false;

    char* err = 0;
    d->access = sqlite_open(QFile::encodeName(db), 0, &err);
    if (err) {
        setLastError(QSqlError(tr("Error opening database"), QString::fromAscii(err),
                     QSqlError::ConnectionError));
        sqlite_freemem(err);
        err = 0;
    }

    if (d->access) {
        setOpen(true);
        setOpenError(false);
        return true;
    }
    setOpenError(true);
    return false;
}
Пример #2
0
/**
 * Override
 * Open a connection to the database.
 * @param db            The name of the database which is to open.
 * @param user          A username of a database role.
 * @param password      The password to the username.
 * @param host          The host name or address where the database is home.
 * @param port          The port number to the database.
 * @param connOpts      Additional and optional options.
 * @return              True if database is open. Otherwise returns false.
 */
bool KQPostgreSqlDriver::open(const QString &db, const QString &user, const QString &password, const QString &host, int port, const QString &connOpts)
{
    if (isOpen()) {
        close();
    }
    QByteArray connectionInfo;
    connectionInfo.append("host=").append(host).append(' ');
    connectionInfo.append("port=").append(QString::number(port)).append(' ');
    connectionInfo.append("dbname=").append(db).append(' ');
    connectionInfo.append("user="******"password="******"Could not open database !"), QString(PQerrorMessage(m_connection)), QSqlError::ConnectionError);
        setLastError(error);
        setOpenError(true);
        PQfinish(m_connection);
        m_connection = NULL;

        return false;
    }
    setOpen(true);
    setOpenError(false);

    return true;
}
Пример #3
0
QSymSQLDriver::QSymSQLDriver(RSqlDatabase& connection, QObject *parent)
    : QSqlDriver(parent)
{
    d = new QSymSQLDriverPrivate();
    d->access = connection;
    setOpen(true);
    setOpenError(false);
}
Пример #4
0
void QSymSQLDriver::close()
{
    if (isOpen()) {
        d->access.Close();
        setOpen(false);
        setOpenError(false);
    }
}
Пример #5
0
QSQLiteDriver::QSQLiteDriver(sqlite *connection, QObject *parent, const char *name)
    : QSqlDriver(parent, name ? name : QSQLITE_DRIVER_NAME)
{
    d = new QSQLiteDriverPrivate();
    d->access = connection;
    setOpen(TRUE);
    setOpenError(FALSE);
}
Пример #6
0
QSQLite2Driver::QSQLite2Driver(sqlite *connection, QObject *parent)
    : QSqlDriver(parent)
{
    d = new QSQLite2DriverPrivate();
    d->access = connection;
    setOpen(true);
    setOpenError(false);
}
Пример #7
0
void QMYSQLDriver::close()
{
    if ( isOpen() ) {
	mysql_close( d->mysql );
	setOpen( FALSE );
	setOpenError( FALSE );
    }
}
Пример #8
0
bool QPSQLDriver::open(const QString & db,
                        const QString & user,
                        const QString & password,
                        const QString & host,
                        int port,
                        const QString& connOpts)
{
    if (isOpen())
        close();
    QString connectString;
    if (!host.isEmpty())
        connectString.append(QLatin1String("host=")).append(qQuote(host));
    if (!db.isEmpty())
        connectString.append(QLatin1String(" dbname=")).append(qQuote(db));
    if (!user.isEmpty())
        connectString.append(QLatin1String(" user="******" password="******" port=")).append(qQuote(QString::number(port)));

    // add any connect options - the server will handle error detection
    if (!connOpts.isEmpty()) {
        QString opt = connOpts;
        opt.replace(QLatin1Char(';'), QLatin1Char(' '), Qt::CaseInsensitive);
        connectString.append(QLatin1Char(' ')).append(opt);
    }

    d->connection = PQconnectdb(connectString.toLocal8Bit().constData());
    if (PQstatus(d->connection) == CONNECTION_BAD) {
        setLastError(qMakeError(tr("Unable to connect"), QSqlError::ConnectionError, d));
        setOpenError(true);
        PQfinish(d->connection);
        d->connection = 0;
        return false;
    }

    d->pro = getPSQLVersion(d->connection);
    d->isUtf8 = setEncodingUtf8(d->connection);
    setDatestyle(d->connection);

    setOpen(true);
    setOpenError(false);
    return true;
}
Пример #9
0
/**
 * Override
 * Close an open database connection.
 */
void KQPostgreSqlDriver::close()
{
    if (m_connection && isOpen()) {
        PQfinish(m_connection);
        m_connection = NULL;
        setOpen(false);
        setOpenError(false);
    }
}
Пример #10
0
void QSQLiteDriver::close()
{
    if (isOpen()) {
        sqlite_close(d->access);
        d->access = 0;
        setOpen(FALSE);
        setOpenError(FALSE);
    }
}
Пример #11
0
void QSQLite2Driver::close()
{
    if (isOpen()) {
        sqlite_close(d->access);
        d->access = 0;
        setOpen(false);
        setOpenError(false);
    }
}
Пример #12
0
bool QTDSDriver::open(const QString & db,
                       const QString & user,
                       const QString & password,
                       const QString & host,
                       int /*port*/,
                       const QString& /*connOpts*/)
{
    if (isOpen())
        close();
    if (!dbinit()) {
        setOpenError(true);
        return false;
    }
    d->login = dblogin();
    if (!d->login) {
        setOpenError(true);
        return false;
    }
    DBSETLPWD(d->login, const_cast<char*>(password.toLocal8Bit().constData()));
    DBSETLUSER(d->login, const_cast<char*>(user.toLocal8Bit().constData()));

    // Now, try to open and use the database. If this fails, return false.
    DBPROCESS* dbproc;

    dbproc = dbopen(d->login, const_cast<char*>(host.toLatin1().constData()));
    if (!dbproc) {
        setLastError(qMakeError(tr("Unable to open connection"), QSqlError::ConnectionError, -1));
        setOpenError(true);
        return false;
    }
    if (dbuse(dbproc, const_cast<char*>(db.toLatin1().constData())) == FAIL) {
        setLastError(qMakeError(tr("Unable to use database"), QSqlError::ConnectionError, -1));
        setOpenError(true);
        return false;
    }
    dbclose( dbproc );

    setOpen(true);
    setOpenError(false);
    d->hostName = host;
    d->db = db;
    return true;
}
Пример #13
0
void SqliteDriver::close()
{
  if (isOpen() && dataBase_) {
    dataBase_->disconnect();
    delete dataBase_;
    dataBase_ = 0;
  }
  setOpen(FALSE);
  setOpenError(FALSE);
}
Пример #14
0
bool SqliteDriver::open(const QString &db, const QString &, const QString &, const QString &, int)
{
  if (db.isEmpty()) {
#ifdef FL_DEBUG
    qWarning("SqliteDriver::open() : No Database name");
#endif

    return false;
  }

  if (!QFile::exists(db)) {
    QMessageBox msgBox(tr("AVISO IMPORTANTE") ,
                       tr("AbanQ puede comportarse de forma inestable con la base de datos SQLite.\n"
                          "AbanQ utilizando SQLite no tiene ningún tipo de soporte por parte de InfoSiAL S.L.,\n"
                          "esta opción sólo se ofrece para poder probar fácilmente la aplicación\n"
                          "sin necesidad de instalar un servidor de bases de datos.\n\n"
                          "Para asegurar la fiabilidad en entornos en producción utilice un sistema de gestión\n"
                          "de bases de datos como PostgreSQL o MySQL"),
                       QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton,  QMessageBox::NoButton);
    msgBox.setIconPixmap(QPixmap::fromMimeSource("bomba.png"));
    msgBox.exec();
  }

  close();
  dataBase_ = new SqliteDatabase();
  dataBase_->setDatabase(db);

  if (dataBase_->connect() != DB_CONNECTION_OK) {
#ifdef FL_DEBUG
    qWarning("SqliteDriver::open() : %s", dataBase_->getErrorMsg());
#endif

    setOpen(false);
    setOpenError(true);
    setLastError(QSqlError(dataBase_->getErrorMsg(), QString::null, QSqlError::Unknown));
    return false;
  } else {
    setOpen(true);
    setOpenError(false);
    return true;
  }
}
Пример #15
0
void SQLiteDriver::close()
{
    if (isOpen()) {
        if (sqlite3_close(d->access) != SQLITE_OK)
            setLastError(qMakeError(d->access, tr("Error closing database"),
                                    QSqlError::ConnectionError));
        d->access = 0;
        setOpen(false);
        setOpenError(false);
    }
}
Пример #16
0
QPSQLDriver::QPSQLDriver(PGconn *conn, QObject *parent)
    : QSqlDriver(parent)
{
    init();
    d->connection = conn;
    if (conn) {
        d->pro = getPSQLVersion(d->connection);
        setOpen(true);
        setOpenError(false);
    }
}
Пример #17
0
QTDSDriver::QTDSDriver(LOGINREC* rec, const QString& host, const QString &db, QObject* parent)
    : QSqlDriver(parent)
{
    init();
    d->login = rec;
    d->hostName = host;
    d->db = db;
    if (rec) {
        setOpen(true);
        setOpenError(false);
    }
}
Пример #18
0
void QTDSDriver::close()
{
    if (isOpen()) {
#ifdef Q_USE_SYBASE
        dbloginfree(d->login);
#else
        dbfreelogin(d->login);
#endif
        d->login = 0;
        setOpen(false);
        setOpenError(false);
    }
}
Пример #19
0
/*
   SQLite dbs have no user name, passwords, hosts or ports.
   just file names.
*/
bool QSpatiaLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &conOpts)
{
    if (isOpen())
        close();

    if (db.isEmpty())
        return false;

    bool sharedCache = false;
    int openMode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, timeOut=5000;
    QStringList opts=QString(conOpts).remove(QLatin1Char(' ')).split(QLatin1Char(';'));
    foreach(const QString &option, opts) {
        if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) {
            bool ok;
            int nt = option.mid(21).toInt(&ok);
            if (ok)
                timeOut = nt;
        }
        if (option == QLatin1String("QSQLITE_OPEN_READONLY"))
            openMode = SQLITE_OPEN_READONLY;
        if (option == QLatin1String("QSQLITE_ENABLE_SHARED_CACHE"))
            sharedCache = true;
    }

    sqlite3_enable_shared_cache(sharedCache);

    if (QgsSLConnect::sqlite3_open_v2(db.toUtf8().constData(), &d->access, openMode, NULL) == SQLITE_OK) {
        sqlite3_busy_timeout(d->access, timeOut);
        setOpen(true);
        setOpenError(false);
        return true;
    } else {
        setLastError(qMakeError(d->access, tr("Error opening database"),
                     QSqlError::ConnectionError));
        setOpenError(true);
        return false;
    }
}
Пример #20
0
QMYSQLDriver::QMYSQLDriver( MYSQL * con, QObject * parent, const char * name )
    : QSqlDriver( parent, name ? name : QMYSQL_DRIVER_NAME )
{
    init();
    if ( con ) {
	d->mysql = (MYSQL *) con;
	setOpen( TRUE );
	setOpenError( FALSE );
        if (qMySqlConnectionCount == 1)
            qMySqlInitHandledByUser = TRUE;
    } else {
        qServerInit();
    }
}
Пример #21
0
void QSpatiaLiteDriver::close()
{
    if (isOpen()) {
        foreach (QSpatiaLiteResult *result, d->results)
            result->d->finalize();

        if (QgsSLConnect::sqlite3_close(d->access) != SQLITE_OK)
            setLastError(qMakeError(d->access, tr("Error closing database"),
                                    QSqlError::ConnectionError));
        d->access = 0;
        setOpen(false);
        setOpenError(false);
    }
}
Пример #22
0
/*
   SQLite dbs have no user name, passwords, hosts or ports.
   just file names.
*/
bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &)
{
    if (isOpen())
        close();

    if (db.isEmpty())
	return FALSE;

    char* err = 0;
    d->access = sqlite_open(QFile::encodeName(db), 0, &err);
    if (err) {
        setLastError(QSqlError("Error to open database", err, QSqlError::Connection));
        sqlite_freemem(err);
        err = 0;
    }

    if (d->access) {
        setOpen(TRUE);
	setOpenError(FALSE);
        return TRUE;
    }
    setOpenError(TRUE);
    return FALSE;
}
Пример #23
0
/*
   SQLite dbs have no user name, passwords, hosts or ports.
   just file names.
*/
bool SQLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &)
{
    if (isOpen())
        close();

    if (db.isEmpty())
        return false;

    if (sqlite3_open16(db.utf16(), &d->access) == SQLITE_OK) {
        sqlite3_busy_timeout(d->access, 500);
#if defined(SQLITEDRIVER_DEBUG)
        sqlite3_trace(d->access, trace, NULL);
#endif
        setOpen(true);
        setOpenError(false);
        installSQLiteExtension(d->access);
        return true;
    } else {
        setLastError(qMakeError(d->access, tr("Error opening database"),
                     QSqlError::ConnectionError));
        setOpenError(true);
        return false;
    }
}
Пример #24
0
void QPSQLDriver::close()
{
    if (isOpen()) {

        d->seid.clear();
        if (d->sn) {
            disconnect(d->sn, SIGNAL(activated(int)), this, SLOT(_q_handleNotification(int)));
            delete d->sn;
            d->sn = 0;
        }

        if (d->connection)
            PQfinish(d->connection);
        d->connection = 0;
        setOpen(false);
        setOpenError(false);
    }
Пример #25
0
bool QMYSQLDriver::open( const QString& db,
			 const QString& user,
			 const QString& password,
			 const QString& host,
			 int port,
			 const QString& connOpts )
{
    if ( isOpen() )
	close();
 
    unsigned int optionFlags = 0;
    
    QStringList raw = QStringList::split( ';', connOpts );
    QStringList opts;
    QStringList::ConstIterator it;
    
    // extract the real options from the string
    for ( it = raw.begin(); it != raw.end(); ++it ) {
	QString tmp( *it );
	int idx;
	if ( (idx = tmp.find( '=' )) != -1 ) {
	    QString val( tmp.mid( idx + 1 ) );
	    val.simplifyWhiteSpace();
	    if ( val == "TRUE" || val == "1" )
		opts << tmp.left( idx );
	    else
		qWarning( "QMYSQLDriver::open: Illegal connect option value '%s'", tmp.latin1() );
	} else {
	    opts << tmp;
	}
    }
    
    for ( it = opts.begin(); it != opts.end(); ++it ) {
	QString opt( (*it).upper() );
	if ( opt == "CLIENT_COMPRESS" )
	    optionFlags |= CLIENT_COMPRESS;
	else if ( opt == "CLIENT_FOUND_ROWS" )
	    optionFlags |= CLIENT_FOUND_ROWS;
	else if ( opt == "CLIENT_IGNORE_SPACE" )
	    optionFlags |= CLIENT_IGNORE_SPACE;
	else if ( opt == "CLIENT_INTERACTIVE" )
	    optionFlags |= CLIENT_INTERACTIVE;
	else if ( opt == "CLIENT_NO_SCHEMA" )
	    optionFlags |= CLIENT_NO_SCHEMA;
	else if ( opt == "CLIENT_ODBC" )
	    optionFlags |= CLIENT_ODBC;
	else if ( opt == "CLIENT_SSL" )
	    optionFlags |= CLIENT_SSL;
	else 
	    qWarning( "QMYSQLDriver::open: Unknown connect option '%s'", (*it).latin1() );
    }

    if ( (d->mysql = mysql_init((MYSQL*) 0)) &&
	    mysql_real_connect( d->mysql,
				host,
				user,
				password,
				db.isNull() ? QString("") : db,
				(port > -1) ? port : 0,
				NULL,
				optionFlags ) )
    {
	if ( !db.isEmpty() && mysql_select_db( d->mysql, db )) {
	    setLastError( qMakeError("Unable open database '" + db + "'", QSqlError::Connection, d ) );
	    mysql_close( d->mysql );
	    setOpenError( TRUE );
	    return FALSE;
	}
    } else {
	    setLastError( qMakeError( "Unable to connect", QSqlError::Connection, d ) );
	    mysql_close( d->mysql );
	    setOpenError( TRUE );
	    return FALSE;
    }
    setOpen( TRUE );
    setOpenError( FALSE );
    return TRUE;
}
Пример #26
0
/*
   SQLite dbs have no user name, passwords, hosts or ports.
   just file names.
*/
bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &conOpts)
{
    if (isOpen())
        close();

    if (db.isEmpty())
        return false;
    bool sharedCache = false;
    int openMode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, timeOut=5000;
    QStringList opts=QString(conOpts).remove(QLatin1Char(' ')).split(QLatin1Char(';'));
    foreach(const QString &option, opts) {
        if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) {
            bool ok;
            int nt = option.mid(21).toInt(&ok);
            if (ok)
                timeOut = nt;
        }
        if (option == QLatin1String("QSQLITE_OPEN_READONLY"))
            openMode = SQLITE_OPEN_READONLY;
        if (option == QLatin1String("QSQLITE_ENABLE_SHARED_CACHE"))
            sharedCache = true;
    }

    sqlite3_enable_shared_cache(sharedCache);

#ifndef QT_WEBOS
    if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, openMode, NULL) == SQLITE_OK) {
#else // QT_WEBOS
#if SQLITE_VERSION_NUMBER >= 3005000
    if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, openMode, NULL) == SQLITE_OK) {
#else
	if (sqlite3_open(db.toUtf8().constData(), &d->access) == SQLITE_OK) {
#endif
#endif // QT_WEBOS
        sqlite3_busy_timeout(d->access, timeOut);
        setOpen(true);
        setOpenError(false);
        return true;
    } else {
        setLastError(qMakeError(d->access, tr("Error opening database"),
                     QSqlError::ConnectionError));
        setOpenError(true);
        return false;
    }
}

void QSQLiteDriver::close()
{
    if (isOpen()) {
        foreach (QSQLiteResult *result, d->results)
            result->d->finalize();

        if (sqlite3_close(d->access) != SQLITE_OK)
            setLastError(qMakeError(d->access, tr("Error closing database"),
                                    QSqlError::ConnectionError));
        d->access = 0;
        setOpen(false);
        setOpenError(false);
    }
}

QSqlResult *QSQLiteDriver::createResult() const
{
    return new QSQLiteResult(this);
}

bool QSQLiteDriver::beginTransaction()
{
    if (!isOpen() || isOpenError())
        return false;

    QSqlQuery q(createResult());
    if (!q.exec(QLatin1String("BEGIN"))) {
        setLastError(QSqlError(tr("Unable to begin transaction"),
                               q.lastError().databaseText(), QSqlError::TransactionError));
        return false;
    }

    return true;
}

bool QSQLiteDriver::commitTransaction()
{
    if (!isOpen() || isOpenError())
        return false;

    QSqlQuery q(createResult());
    if (!q.exec(QLatin1String("COMMIT"))) {
        setLastError(QSqlError(tr("Unable to commit transaction"),
                               q.lastError().databaseText(), QSqlError::TransactionError));
        return false;
    }

    return true;
}

bool QSQLiteDriver::rollbackTransaction()
{
    if (!isOpen() || isOpenError())
        return false;

    QSqlQuery q(createResult());
    if (!q.exec(QLatin1String("ROLLBACK"))) {
        setLastError(QSqlError(tr("Unable to rollback transaction"),
                               q.lastError().databaseText(), QSqlError::TransactionError));
        return false;
    }

    return true;
}

QStringList QSQLiteDriver::tables(QSql::TableType type) const
{
    QStringList res;
    if (!isOpen())
        return res;

    QSqlQuery q(createResult());
    q.setForwardOnly(true);

    QString sql = QLatin1String("SELECT name FROM sqlite_master WHERE %1 "
                                "UNION ALL SELECT name FROM sqlite_temp_master WHERE %1");
    if ((type & QSql::Tables) && (type & QSql::Views))
        sql = sql.arg(QLatin1String("type='table' OR type='view'"));
    else if (type & QSql::Tables)
        sql = sql.arg(QLatin1String("type='table'"));
    else if (type & QSql::Views)
        sql = sql.arg(QLatin1String("type='view'"));
    else
        sql.clear();

    if (!sql.isEmpty() && q.exec(sql)) {
        while(q.next())
            res.append(q.value(0).toString());
    }

    if (type & QSql::SystemTables) {
        // there are no internal tables beside this one:
        res.append(QLatin1String("sqlite_master"));
    }

    return res;
}

static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool onlyPIndex = false)
{
    QString schema;
    QString table(tableName);
    int indexOfSeparator = tableName.indexOf(QLatin1Char('.'));
    if (indexOfSeparator > -1) {
        schema = tableName.left(indexOfSeparator).append(QLatin1Char('.'));
        table = tableName.mid(indexOfSeparator + 1);
    }
    q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info (") + _q_escapeIdentifier(table) + QLatin1String(")"));

    QSqlIndex ind;
    while (q.next()) {
        bool isPk = q.value(5).toInt();
        if (onlyPIndex && !isPk)
            continue;
        QString typeName = q.value(2).toString().toLower();
        QSqlField fld(q.value(1).toString(), qGetColumnType(typeName));
        if (isPk && (typeName == QLatin1String("integer")))
            // INTEGER PRIMARY KEY fields are auto-generated in sqlite
            // INT PRIMARY KEY is not the same as INTEGER PRIMARY KEY!
            fld.setAutoValue(true);
        fld.setRequired(q.value(3).toInt() != 0);
        fld.setDefaultValue(q.value(4));
        ind.append(fld);
    }
    return ind;
}
Пример #27
0
/*!   
    Opens the database connection using the given connection options. Returns true on success; otherwise returns false.
    Error information can be retrieved using the lastError() function. Symbian SQL dbs have no \a user, \a password, \a host
    or \a port just file names.
    
    \a connOpts Connection options hold definition for security policies and all parameters that does not contain "POLICY_" will be
    passed to RSqlDatabase. Policy will be filled according to parsed values.

    Value in database wide parameters starts by definition which can be vendorId or secureId. These come directly from TSecurityPolicy class in Symbian. 
    
    POLICY_DB_DEFAULT
    Default security policy which will be used for the database and all database objects. POLICY_DB_DEFAULT must be 
    defined before any other policy definitions can be used.    
    POLICY_DB_READ
    Read database security policy. An application with read database security policy can read from database.    
    POLICY_DB_WRITE:
    Write database security policy. An application with write database security policy can write to database. 
    POLICY_DB_SCHEMA:
    Schema database security policy. An application with schema database security policy can modify
    the database schema, write to database, read from database.   
    
    Format:
    POLICY_DB_DEFAULT=cap1,cap2,cap3,cap4,cap5,cap6,cap7    (Up to 7 capabilities) 
    POLICY_DB_READ=cap1,cap2,cap3,cap4,cap5,cap6,cap7       (Up to 7 capabilities)
    POLICY_DB_WRITE=vendorid,cap1,cap2,cap3                 (Vendor ID and up to 3 capabilities)
    POLICY_DB_SCHEMA=secureid,cap1,cap2,cap3                (Secure ID and up to 3 capabilities)  
    
    Table policies does not support schema policy as database level does.
    
    Table specific parameters would be as:    
    POLICY_TABLE_WRITE=tablename,cap1,cap2,cap3,cap4,cap5,cap6,cap7
    POLICY_TABLE_READ=tablename,cap1,cap2,cap3,cap4,cap5,cap6,cap7    
    
    Vendor Id and Secure id format:    
    vid[0x12345678]                              (Hex)    
    sid[0x12345678]                              (Hex)                        
    
    Example:   
    \code   
    QSqlDatabase database = QSqlDatabase::addDatabase("QSYMSQL", "MyConnection");
    database.setConnectOptions("POLICY_DB_DEFAULT=ReadDeviceData");
    database.setDatabaseName("[12345678]myDatabase");
    bool ok = database.open();   
    \encode    
    
    \code   
    QSqlDatabase database = QSqlDatabase::addDatabase("QSYMSQL", "MyConnection");
    database.setConnectOptions("POLICY_DB_DEFAULT=None; POLICY_DB_WRITE=sid[0x12345678], WriteDeviceData");
    database.setDatabaseName("[12345678]myDatabase");
    bool ok = database.open();   
    \encode    
    
    FOREIGN KEY:  
    Enabling foreign key support from underlying SQLite
    add: "foreign_keys = ON" to your connection options string. This will be passes to SQLite.
   
    Foreign key Example:   
    \code
    QSqlDatabase database = QSqlDatabase::addDatabase("QSYMSQL", "MyConnection");
    database.setDatabaseName("[12345678]myDatabase");
    database.setConnectOptions("foreign_keys = ON");
    bool ok = database.open();
    \encode
    
   More information about Symbian Security Policy can be found from Symbian documentation.
    
*/
bool QSymSQLDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &conOpts)
{                                
    if (isOpen())
        close();
    if (db.isEmpty())
        return false;
    
    //Separating our parameters from Symbian ones and construct new connection options
    const QString itemSeparator(QLatin1String(";"));
    QRegExp isOurOption(QLatin1String("POLICY_*"), Qt::CaseInsensitive, QRegExp::Wildcard); 
    
    QStringList optionList = conOpts.split(itemSeparator, QString::SkipEmptyParts);
    QStringList symbianList;
    
    for (int i = optionList.count() - 1; i >= 0; i--) {
        if (!optionList[i].contains(isOurOption)) {
            symbianList.append(optionList[i]);
            optionList.removeAt(i);
        } else {
            //Removing whitespace
            QString formatted = optionList[i];
            formatted = formatted.remove(QLatin1Char(' '));
            formatted = formatted.remove(QLatin1Char('\t'));
            formatted = formatted.remove(QLatin1Char('\n'));
            formatted = formatted.remove(QLatin1Char('\r'));
            optionList[i] = formatted;
        }
    }
    
    QString symbianOpt;
    
    for (int i = 0; i < symbianList.count(); i++) {
        symbianOpt += symbianList[i];
        symbianOpt += itemSeparator;
    }

    TPtrC dbName(qt_QString2TPtrC(db));
    QByteArray conOpts8 = symbianOpt.toUtf8();    
    const TPtrC8 config(reinterpret_cast<const TUint8*>(conOpts8.constData()), (conOpts8.length()));
    
    TInt res = d->access.Open(dbName, &config);
    
    if (res == KErrNotFound) {

        QRegExp findDefault(QLatin1String("POLICY_DB_DEFAULT=*"), Qt::CaseInsensitive, QRegExp::Wildcard);
        QRegExp findRead(QLatin1String("POLICY_DB_READ=*"), Qt::CaseInsensitive, QRegExp::Wildcard);
        QRegExp findWrite(QLatin1String("POLICY_DB_WRITE=*"), Qt::CaseInsensitive, QRegExp::Wildcard);
        QRegExp findSchema(QLatin1String("POLICY_DB_SCHEMA=*"), Qt::CaseInsensitive, QRegExp::Wildcard);
        QRegExp findTableRead(QLatin1String("POLICY_TABLE_READ=*"), Qt::CaseInsensitive, QRegExp::Wildcard);
        QRegExp findTableWrite(QLatin1String("POLICY_TABLE_WRITE=*"), Qt::CaseInsensitive, QRegExp::Wildcard);
               
        int policyIndex = optionList.indexOf(findDefault);
        
        if (policyIndex != -1) {
            QString defaultPolicyString = optionList[policyIndex];
            optionList.removeAt(policyIndex);
            
            TSecurityPolicy policyItem;
            
            if (qExtractSecurityPolicyFromString(defaultPolicyString, policyItem)) {
                RSqlSecurityPolicy policy;
                res = policy.Create(policyItem);
                
                if (res == KErrNone) {
                    for (int i = 0; i < optionList.count(); i++) {
                        QString option = optionList[i];
                        
                        if (option.contains(findRead)) {
                            if (qExtractSecurityPolicyFromString(option, policyItem)) {
                                res = policy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, policyItem);
                            } else {
                                res = KErrArgument;
                            }
                        } else if (option.contains(findWrite)) {
                            if (qExtractSecurityPolicyFromString(option, policyItem)) {
                                res = policy.SetDbPolicy(RSqlSecurityPolicy::EWritePolicy, policyItem);
                            } else {
                                res = KErrArgument;
                            }
                        } else if (option.contains(findSchema)) {
                            if (qExtractSecurityPolicyFromString(option, policyItem)) {
                                res = policy.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, policyItem);
                            } else {
                                res = KErrArgument;
                            }
                        } else if (option.contains(findTableWrite)) {
                            QString tableOption = option.mid(option.indexOf(QLatin1Char('=')) + 1);
                            int firstComma = tableOption.indexOf(QLatin1Char(','));
                            
                            if (firstComma != -1) {
                                QString tableName = tableOption.left(firstComma);
                                tableOption = tableOption.mid(firstComma + 1);
                                
                                if (qExtractSecurityPolicyFromString(tableOption, policyItem)) {
                                    TPtrC symTableName(qt_QString2TPtrC(tableName));
                                                                
                                    res = policy.SetPolicy(RSqlSecurityPolicy::ETable, symTableName,
                                                        RSqlSecurityPolicy::EWritePolicy, policyItem);
                                } else {
                                    res = KErrArgument;
                                }
                            } else {
                                res = KErrArgument;
                            }
                        } else if (option.contains(findTableRead)) {
                            QString tableOption = option.mid(option.indexOf(QLatin1Char('=')) + 1);
                            int firstComma = tableOption.indexOf(QLatin1Char(','));
                            
                            if (firstComma != -1) {
                                QString tableName = tableOption.left(firstComma);
                                tableOption = tableOption.mid(firstComma + 1);
                                
                                if (qExtractSecurityPolicyFromString(tableOption, policyItem)) {
                                    TPtrC symTableName(qt_QString2TPtrC(tableName));
                                                                
                                    res = policy.SetPolicy(RSqlSecurityPolicy::ETable, symTableName,
                                                        RSqlSecurityPolicy::EReadPolicy, policyItem);
                                } else {
                                    res = KErrArgument;
                                }
                            } else {
                                res = KErrArgument;
                            }
                        } else {
                            res = KErrArgument;
                        }
                        
                        if (res != KErrNone) {
                            setLastError(gMakeErrorOpen(tr("Invalid option: ") + option, QSqlError::ConnectionError, res));
                            break;
                        }
                    }
                    
                    if (res == KErrNone) {
                        res = d->access.Create(dbName, policy, &config);
                        policy.Close();
                        
                        if (res != KErrNone) 
                            setLastError(gMakeErrorOpen(tr("Error opening database"), QSqlError::ConnectionError, res));
                    }
                }
                
            } else {
                res = KErrArgument;
                setLastError(gMakeErrorOpen(tr("Invalid option: ") + defaultPolicyString, QSqlError::ConnectionError, res));
            }
            
        } else {
            //Check whether there is some of our options, fail if so.
            policyIndex = optionList.indexOf(isOurOption);
            
            if (policyIndex == -1) {
                res = d->access.Create(dbName, &config);
            
                if (res != KErrNone) 
                    setLastError(gMakeErrorOpen(tr("Error opening database"), QSqlError::ConnectionError, res));
            } else {
                res = KErrArgument;
                setLastError(gMakeErrorOpen(tr("POLICY_DB_DEFAULT must be defined before any other POLICY definitions can be used"), QSqlError::ConnectionError, res));
            }
        }
    }
    
    if (res == KErrNone) {
        setOpen(true);
        setOpenError(false);
        return true;
    } else {
        setOpenError(true);
        return false;
    }
}