Results 1 to 5 of 5

Thread: sql cipher query is not working with Qt

  1. #1
    Join Date
    Jan 2018
    Posts
    8
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Unhappy sql cipher query is not working with Qt

    Decrypt the database to a plaintext database

    $ sqlcipher u.db

    sqlite> PRAGMA key = '234ii';
    sqlite> PRAGMA cipher_use_hmac = OFF;
    sqlite> ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';
    sqlite> SELECT sqlcipher_export('plaintext');
    sqlite> DETACH DATABASE plaintext;
    sqlite> .q

    This is working fine, but while coming to Qt Code we are trying to execute the same queries by using QSqlQuery.

    This is the code flow how we are following in Qt-4.7.4,

    QSqlDatabase db1 = QSqlDatabase::addDatabase("SQLITECIPHER");
    db1.setDatabaseName("Qt.db");
    qDebug() << QSqlDatabase::drivers();

    db1.open();

    QSqlQuery qry;
    qry.exec("PRAGMA key = 'test123';");
    qry.exec("PRAGMA cipher_use_hmac = OFF");
    qry.exec("ATTACH DATABASE 'plaintext.db' AS plaintext KEY ''; ");
    qry.exec("SELECT sqlcipher_export('plaintext');");
    qry.exec("DETACH DATABASE plaintext; ");
    qry.exec(".q");

    db1.close();

    In This case qry.exec("SELECT sqlcipher_export('plaintext');"); is not executing.

    Please help me to sort out this issue.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: sql cipher query is not working with Qt

    In This case qry.exec("SELECT sqlcipher_export('plaintext');"); is not executing.
    How do you know that -any- of the Qt code is working? Your code doesn't check for errors anywhere (and with the typos it won't even compile). The key is different between the sqlite command line code and the Qt code as well.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2018
    Posts
    8
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Red face Re: sql cipher query is not working with Qt

    can u please tell me if der is any other procedure to encrypt and decrypt data by using sqlcipher in QT 4.7.4.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: sql cipher query is not working with Qt

    QSqlDatabase db1 = QSqlDatabase::addDatabase("SQLITECIPHER");
    SQLITECIPHER is not one of the database drivers supplied with Qt. Do you have a Qt driver for it? Was it compiled using your compiler toolchain and your version of Qt? Have you installed it in the correct place for a db plugin?

    See the QSqlDatabase docs.

    And as I said in my original answer to your post: You do not appear to be checking any of the return values for the Qt SQL methods you are calling. My guess is that the addDatabase() call is failing, and because of that nothing else that follows works either. You can't simply write code and assume it will work. So go back, add error checking, and run your code in a debugger to determine where it fails.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jan 2018
    Posts
    8
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: sql cipher query is not working with Qt

    Hi,
    Please just tell me what are the database drivers available/supported in Qt for encryption and decryption of database. It will be very helpful for me to compile/build Qt.

    Actually we were already checking the error handling, but i had typed here simple way to explain, how i am doing ? sorry for that.

    Any how now i am posting actual code content from my sample code.

    Qt Code:
    1. QSqlDatabase db1 = QSqlDatabase::addDatabase("SQLITECIPHER");
    2.  
    3. db1.setDatabaseName("Qt.db");
    4. qDebug() << QSqlDatabase::drivers();
    5.  
    6. db1.open();
    7.  
    8. QSqlQuery qry;
    9. bool ret = qry.exec("PRAGMA key = 'test123';");
    10. qDebug()<<"Pragma key exec ret:::"<<ret;
    11. ret = qry.exec("PRAGMA cipher_use_hmac = OFF");
    12. qDebug()<<"Pragma cipher exec ret:::"<<ret;
    13.  
    14. ret = qry.exec("create table employee(sno INTEGER,empname varchar(100)); ");
    15. qDebug()<<"create table exec ret:::"<<ret;
    16. if(ret == false)
    17. {
    18. QMessageBox::warning(this,"Error-msg","Table already created",QMessageBox::Ok);
    19. }
    20.  
    21. ret = qry.exec("insert into employee(sno,empname)values(46,'abc');");
    22. qDebug()<<"insert into table exec ret:::"<<ret;
    23. ret = qry.exec("insert into employee(sno,empname)values(11,'xyz');");
    24. qDebug()<<"insert into table exec ret:::"<<ret;
    25.  
    26. db1.close();
    27. if(ret == true)
    28. QMessageBox::information(this,"Info","Encrypted Successfully",QMessageBox::Ok);
    29. else
    30. QMessageBox::warning(this,"Error-msg","Encryption Failed",QMessageBox::Ok);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 7
    Last Post: 16th April 2015, 17:11
  2. QSqlQuery update query not working using SQLite
    By Cyrebo in forum Qt Programming
    Replies: 2
    Last Post: 29th March 2013, 00:33
  3. Replies: 7
    Last Post: 24th September 2012, 07:17
  4. QSslSocket and cipher problem
    By maggu2810 in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2011, 07:08
  5. Parameterized query not working.
    By pnunn in forum Newbie
    Replies: 5
    Last Post: 4th March 2009, 09:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.