1

I have sqlite database that i want to be readonly, when it used by other gui application, so that user can't edit data, only Qt application can edit it.

Here is my code:

//open the database
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(database location);

    if(db.open())
        qDebug ()<<"opened!";
    else
        qDebug ()<<"not opened!";

//insert data
QSqlQuery qry;

qry.prepare("insert into tableName (column_1, column_2, column_3) values (:v1, :v2, :v3)");

    qry.bindValue(":v1", "data1");
    qry.bindValue(":v2", "data2");
    qry.bindValue(":v3", "data3");

    qry.exec();
abdallah allam
  • 73
  • 1
  • 13
  • 2
    There's no way to only allow one program to write to a file like that. – Colonel Thirty Two Nov 16 '16 at 00:44
  • why do you want to have that lock ? – HazemGomaa Nov 16 '16 at 01:31
  • i mean that i want to make the database read only, because say that my application deal with data for client business, so if maybe some one edit the data from any gui sqlite application it will affect his work, so i want make the only way to edit the data by use the application.(the user will have password) – abdallah allam Nov 16 '16 at 01:47
  • 1
    May be just add password or change file permission ... check http://stackoverflow.com/questions/16658880/sqlite-user-password-security. And http://stackoverflow.com/questions/5669905/sqlite-with-encryption-password-protection – HazemGomaa Nov 16 '16 at 02:54
  • set file permission make the database read only, but it also make it read only for qt program, the program can't insert new data to database. – abdallah allam Nov 16 '16 at 04:40

1 Answers1

0

Encrypt your database so only your application can access it. Provide an export function inside your application which writes out a non-encrypted version of the DB for viewing only.

zeFrenchy
  • 6,541
  • 1
  • 27
  • 36