Esempio n. 1
0
static QSqlError qMakeError(RSqlDatabase& access, 
    const QString &descr, 
    QSqlError::ErrorType type,
    int errorCode = -1)
{
    return QSqlError(descr,
                     QString::fromUtf16(static_cast<const ushort *>(access.LastErrorMessage().Ptr())),
                     type, 
                     errorCode);
}
//This functnion is called while there is an open secure connection.
//The function will create a new, non-secure connection and check that the non-secure database schema can be modified,
//while there is another alive, secure database connection.
void NonSecureDbTest()
    {
    (void)RSqlDatabase::Delete(KTestDbName2);
    RSqlDatabase db;
    TInt err = db.Create(KTestDbName2);
    TEST2(err, KErrNone);
    
    err = db.Exec(_L("CREATE TABLE A(I1 INTEGER, I2 INTEGER)"));
    TEST(err >= 0);
    err = db.Exec(_L("CREATE TEMP TABLE B(I1 INTEGER, I2 INTEGER)"));
    TEST(err >= 0);

    //"CREATE VIRTUAL TABLE" statement not supported
    err = db.Exec(_L("CREATE VIRTUAL TABLE V1 USING FTS3(ColOne TEXT, ColTwo DATETIME)"));
    TPtrC msg = db.LastErrorMessage();
    TheTest.Printf(_L("*** \"CREATE VIRTUAL TABLE\" expected failure, msg=\"%S\", err=%d\r\n"), &msg, err);
    TEST(err != KErrNone);
    
    err = db.Exec(_L("CREATE TRIGGER T1 AFTER INSERT ON A BEGIN INSERT INTO B VALUES(new.I1, new.I2); END;"));
    TEST(err >= 0);
    err = db.Exec(_L("DROP TRIGGER T1"));
    TEST(err >= 0);
    err = db.Exec(_L("CREATE TEMP TRIGGER T2 AFTER UPDATE OF I1 ON A BEGIN UPDATE B SET I1 = new.I1; END;"));
    TEST(err >= 0);
    err = db.Exec(_L("DROP TRIGGER T2"));
    TEST(err >= 0);

    err = db.Exec(_L("CREATE VIEW V1 AS SELECT * FROM A"));
    TEST(err >= 0);
    err = db.Exec(_L("DROP VIEW V1"));
    TEST(err >= 0);
    err = db.Exec(_L("CREATE TEMP VIEW V2 AS SELECT * FROM A"));
    TEST(err >= 0);
    err = db.Exec(_L("DROP VIEW V2"));
    TEST(err >= 0);

    err = db.Exec(_L("CREATE INDEX Idx1 ON A(I1)"));
    TEST(err >= 0);
    err = db.Exec(_L("ANALYZE A"));
    TEST(err >= 0);
    err = db.Exec(_L("DROP INDEX Idx1"));
    TEST(err >= 0);
    err = db.Exec(_L("CREATE INDEX Idx2 ON B(I1)"));
    TEST(err >= 0);
    err = db.Exec(_L("DROP INDEX Idx2"));
    TEST(err >= 0);
        
    err = db.Exec(_L("DROP TABLE B"));
    TEST(err >= 0);
    err = db.Exec(_L("DROP TABLE A"));
    TEST(err >= 0);
    
    db.Close();
    (void)RSqlDatabase::Delete(KTestDbName2);
    }