Skip to content

Commit

Permalink
add a foreign key setting
Browse files Browse the repository at this point in the history
to open database with foreign keys enabled
  • Loading branch information
rp- committed Jan 29, 2013
1 parent 9c9e1a6 commit f8e51cc
Showing 4 changed files with 58 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
2 changes: 2 additions & 0 deletions src/PreferencesDialog.h
Original file line number Diff line number Diff line change
@@ -19,11 +19,13 @@ class PreferencesDialog : public QDialog
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();
43 changes: 40 additions & 3 deletions src/PreferencesDialog.ui
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>492</width>
<height>145</height>
<height>219</height>
</rect>
</property>
<property name="windowTitle">
@@ -85,7 +85,7 @@
</item>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Default location</string>
@@ -95,7 +95,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="locationEdit">
@@ -127,6 +127,26 @@
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string>Open databases with foreign keys enabled.</string>
</property>
<property name="text">
<string>Foreign keys</string>
</property>
<property name="buddy">
<cstring>foreignKeysCheckBox</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="foreignKeysCheckBox">
<property name="text">
<string>enabled</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -247,12 +267,29 @@
</hint>
</hints>
</connection>
<connection>
<sender>foreignKeysCheckBox</sender>
<signal>stateChanged(int)</signal>
<receiver>PreferencesDialog</receiver>
<slot>foreignkeysStateChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>213</x>
<y>113</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
<y>109</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>saveSettings()</slot>
<slot>defaultDataChanged(int)</slot>
<slot>encodingChanged(int)</slot>
<slot>chooseLocation()</slot>
<slot>defaultTextChanged(int)</slot>
<slot>foreignkeysStateChanged(int)</slot>
</slots>
</ui>
7 changes: 7 additions & 0 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
#include <QProgressDialog>
#include <QApplication>
#include <QTextStream>
#include <QSettings>

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;",

0 comments on commit f8e51cc

Please sign in to comment.