diff --git a/src/PreferencesDialog.cpp b/src/PreferencesDialog.cpp index b0d3be36..58d0dcea 100644 --- a/src/PreferencesDialog.cpp +++ b/src/PreferencesDialog.cpp @@ -52,6 +52,11 @@ void PreferencesDialog::encodingChanged( int which ) } } +void PreferencesDialog::foreignkeysStateChanged(int state) +{ + foreignkeys = state > 0; +} + void PreferencesDialog::chooseLocation() { QString s = QFileDialog::getExistingDirectory( @@ -76,6 +81,7 @@ void PreferencesDialog::loadSettings() defaultnewdata = settings.value( "/db/defaultnewdata", "NULL" ).toString(); defaultlocation = settings.value( "/db/defaultlocation", QDir::homePath() ).toString(); defaulttext = settings.value( "/db/defaulttext", "Plain" ).toString(); + foreignkeys = settings.value( "/db/foreignkeys", true ).toBool(); if (defaultencoding=="Latin1") { @@ -103,6 +109,8 @@ void PreferencesDialog::loadSettings() ui->defaultTextComboBox->setCurrentIndex(0) ; defaulttext = QString("Plain"); } + + ui->foreignKeysCheckBox->setChecked(foreignkeys); ui->locationEdit->setText(defaultlocation); } @@ -115,6 +123,7 @@ void PreferencesDialog::saveSettings() settings.setValue( "/db/defaultnewdata", defaultnewdata ); settings.setValue( "/db/defaultlocation", defaultlocation ); settings.setValue( "/db/defaulttext", defaulttext ); + settings.setValue( "/db/foreignkeys", foreignkeys ); settings.sync(); accept(); } diff --git a/src/PreferencesDialog.h b/src/PreferencesDialog.h index c51fad2b..264aed00 100644 --- a/src/PreferencesDialog.h +++ b/src/PreferencesDialog.h @@ -19,11 +19,13 @@ public: QString defaultlocation; QString defaultnewdata; QString defaultencoding; + bool foreignkeys; private slots: virtual void defaultDataChanged( int which ); virtual void defaultTextChanged( int which ); virtual void encodingChanged( int which ); + virtual void foreignkeysStateChanged( int state ); virtual void chooseLocation(); virtual void loadSettings(); virtual void saveSettings(); diff --git a/src/PreferencesDialog.ui b/src/PreferencesDialog.ui index 8db6c8bd..90e0add3 100644 --- a/src/PreferencesDialog.ui +++ b/src/PreferencesDialog.ui @@ -7,7 +7,7 @@ 0 0 492 - 145 + 219 @@ -85,7 +85,7 @@ - + Default location @@ -95,7 +95,7 @@ - + @@ -127,6 +127,26 @@ + + + + Open databases with foreign keys enabled. + + + Foreign keys + + + foreignKeysCheckBox + + + + + + + enabled + + + @@ -247,6 +267,22 @@ + + foreignKeysCheckBox + stateChanged(int) + PreferencesDialog + foreignkeysStateChanged(int) + + + 213 + 113 + + + 245 + 109 + + + saveSettings() @@ -254,5 +290,6 @@ encodingChanged(int) chooseLocation() defaultTextChanged(int) + foreignkeysStateChanged(int) diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 4f92930e..0f0649dc 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -6,6 +6,7 @@ #include #include #include +#include void DBBrowserObject::addField(int order, const QString& wfield,const QString& wtype) { @@ -97,6 +98,12 @@ bool DBBrowserDB::open ( const QString & db) } if (_db){ + // set preference defaults + QSettings settings(QApplication::organizationName(), QApplication::organizationName()); + settings.sync(); + bool foreignkeys = settings.value( "/db/foreignkeys", false ).toBool(); + setPragma("foreign_keys", foreignkeys ? "1" : "0"); + if (SQLITE_OK==sqlite3_exec(_db,"PRAGMA empty_result_callbacks = ON;", NULL,NULL,NULL)){ if (SQLITE_OK==sqlite3_exec(_db,"PRAGMA show_datatypes = ON;",