This commit is contained in:
Peinthor Rene
2013-01-21 20:12:18 +01:00
99 changed files with 7166 additions and 153594 deletions

View File

@@ -4,23 +4,47 @@ sqlitebrowser
This is a fork from the SF project which seems to be stagnant.
Website:
http://sqlitebrowser.sourceforge.net
Old Project
-----------
- http://sqlitebrowser.sourceforge.net
- https://sourceforge.net/projects/sqlitebrowser/
Project:
https://sourceforge.net/projects/sqlitebrowser/
What it is
----------
Status
------
(taken from the website linked to above; it's still true - now even more)
SQLite Database Browser is a freeware, public domain, open source visual tool
used to create, design and edit database files compatible with SQLite. It is
meant to be used for users and developers that want to create databases, edit
and search data using a familiar spreadsheet-like interface, without the need
to learn complicated SQL commands.
What's been done since then
---------------------------
- Qt3Support was removed
- Recent files menu added
- Improved UI, making it more modern, replacing some dialogs etc.
- Syntax highlighting for SQL code
- Cleaned up the code, reducing the SLOC quite a bit
- Added basic support for triggers and views
- Added pragma editing
- Fixed a ton of bugs
- Probably more
Todo
----
All in all a fair amount of the code has been rewritten in order to regain
maintainability. Based on this quite a few bugs could be fixed and some
features added.
- UI cleanup
- Code cleanup (a lot)
For recent issues look at: https://github.com/rp-/sqlitebrowser/issues
What's still to do
------------------
- Even more code cleanup
- Further improvement of the UI, adding more features and making it easier to
use
- Inline editing of records instead of having to use a special dialog for it
- Avoid loading all records of a table to avoid problems when opening a very
big table
- Add proper support for BLOBs
- Feel free to add more issues at
https://github.com/mkleusberg/sqlitebrowser/issues

View File

@@ -1,10 +1,10 @@
#include "dialogabout.h"
#include "ui_dialogabout.h"
#include "sqlite_source/sqlite3.h"
#include "AboutDialog.h"
#include "ui_AboutDialog.h"
#include <sqlite3.h>
DialogAbout::DialogAbout(QWidget *parent) :
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogAbout)
ui(new Ui::AboutDialog)
{
ui->setupUi(this);
this->setFixedSize(669, 306);
@@ -14,7 +14,7 @@ DialogAbout::DialogAbout(QWidget *parent) :
ui->label_versionsqlite->setText(ui->label_versionsqlite->text() + " " + SQLITE_VERSION);
}
DialogAbout::~DialogAbout()
AboutDialog::~AboutDialog()
{
delete ui;
}

22
src/AboutDialog.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef __ABOUTDIALOG_H__
#define __ABOUTDIALOG_H__
#include <QDialog>
namespace Ui {
class AboutDialog;
}
class AboutDialog : public QDialog
{
Q_OBJECT
public:
explicit AboutDialog(QWidget *parent = 0);
~AboutDialog();
private:
Ui::AboutDialog *ui;
};
#endif

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogAbout</class>
<widget class="QDialog" name="DialogAbout">
<class>AboutDialog</class>
<widget class="QDialog" name="AboutDialog">
<property name="geometry">
<rect>
<x>0</x>
@@ -124,7 +124,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogAbout</receiver>
<receiver>AboutDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@@ -140,7 +140,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogAbout</receiver>
<receiver>AboutDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

95
src/CreateIndexDialog.cpp Normal file
View File

@@ -0,0 +1,95 @@
#include "CreateIndexDialog.h"
#include "ui_CreateIndexDialog.h"
#include "sqlitedb.h"
#include <QMessageBox>
#include <QPushButton>
CreateIndexDialog::CreateIndexDialog(DBBrowserDB* db, QWidget* parent)
: QDialog(parent),
pdb(db),
ui(new Ui::CreateIndexDialog)
{
// Create UI
ui->setupUi(this);
// Fill table combobox
QList<DBBrowserObject> tables = pdb->objMap.values("table");
for(int i=0;i<tables.count();i++)
ui->comboTableName->addItem(tables.at(i).getname());
}
CreateIndexDialog::~CreateIndexDialog()
{
delete ui;
}
void CreateIndexDialog::tableChanged(QString new_table)
{
// And fill the table again
QStringList fields = pdb->getTableFields(new_table);
ui->tableIndexColumns->setRowCount(fields.size());
for(int i=0;i<fields.size();i++)
{
// Put the name of the field in the first column
QTableWidgetItem* name = new QTableWidgetItem(fields.at(i));
name->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->tableIndexColumns->setItem(i, 0, name);
// Put a checkbox to enable usage in the index of this field in the second column
QTableWidgetItem* enabled = new QTableWidgetItem("");
enabled->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
enabled->setCheckState(Qt::Unchecked);
ui->tableIndexColumns->setItem(i, 1, enabled);
// And put a combobox to select the order in which to index the field in the last column
QComboBox* order = new QComboBox(this);
order->addItem("ASC");
order->addItem("DESC");
ui->tableIndexColumns->setCellWidget(i, 2, order);
}
}
void CreateIndexDialog::checkInput()
{
ui->editIndexName->setText(ui->editIndexName->text().trimmed());
bool valid = true;
if(ui->editIndexName->text().isEmpty() || ui->editIndexName->text().contains(" "))
valid = false;
int num_columns = 0;
for(int i=0;i<ui->tableIndexColumns->rowCount();i++)
{
if(ui->tableIndexColumns->item(i, 1) && ui->tableIndexColumns->item(i, 1)->data(Qt::CheckStateRole) == Qt::Checked)
num_columns++;
}
if(num_columns == 0)
valid = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}
void CreateIndexDialog::accept()
{
QString sql = QString("CREATE %1 INDEX `%2` ON `%3` (")
.arg(ui->checkIndexUnique->isChecked() ? "UNIQUE" : "")
.arg(ui->editIndexName->text())
.arg(ui->comboTableName->currentText());
for(int i=0;i<ui->tableIndexColumns->rowCount();i++)
{
if(ui->tableIndexColumns->item(i, 1)->data(Qt::CheckStateRole) == Qt::Checked)
{
sql.append(QString("`%1` %2,")
.arg(ui->tableIndexColumns->item(i, 0)->text())
.arg(qobject_cast<QComboBox*>(ui->tableIndexColumns->cellWidget(i, 2))->currentText()));
}
}
sql.remove(sql.count() - 1, 1); // Remove last comma
sql.append(");");
if(pdb->executeSQL(sql))
QDialog::accept();
else
QMessageBox::warning(this, QApplication::applicationName(), tr("Creating the index failed:\n%1").arg(pdb->lastErrorMessage));
}

29
src/CreateIndexDialog.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef __CREATEINDEXDIALOG_H__
#define __CREATEINDEXDIALOG_H__
#include <QDialog>
class DBBrowserDB;
namespace Ui {
class CreateIndexDialog;
}
class CreateIndexDialog : public QDialog
{
Q_OBJECT
public:
explicit CreateIndexDialog(DBBrowserDB* db, QWidget* parent = 0);
~CreateIndexDialog();
private slots:
void accept();
void tableChanged(QString new_table);
void checkInput();
private:
DBBrowserDB* pdb;
Ui::CreateIndexDialog* ui;
};
#endif

226
src/CreateIndexDialog.ui Normal file
View File

@@ -0,0 +1,226 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreateIndexDialog</class>
<widget class="QDialog" name="CreateIndexDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>610</width>
<height>342</height>
</rect>
</property>
<property name="windowTitle">
<string>Create New Index</string>
</property>
<property name="windowIcon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/index_create</normaloff>:/icons/index_create</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelIndexName">
<property name="text">
<string>&amp;Name</string>
</property>
<property name="buddy">
<cstring>editIndexName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="editIndexName"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelIndexColumns">
<property name="text">
<string>&amp;Columns</string>
</property>
<property name="buddy">
<cstring>tableIndexColumns</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QTableWidget" name="tableIndexColumns">
<property name="minimumSize">
<size>
<width>0</width>
<height>250</height>
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Column</string>
</property>
</column>
<column>
<property name="text">
<string>Use in Index</string>
</property>
</column>
<column>
<property name="text">
<string>Order</string>
</property>
</column>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelTableName">
<property name="text">
<string>&amp;Table</string>
</property>
<property name="buddy">
<cstring>comboTableName</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboTableName"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelIndexUnique">
<property name="text">
<string>&amp;Unique</string>
</property>
<property name="buddy">
<cstring>checkIndexUnique</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkIndexUnique">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>editIndexName</tabstop>
<tabstop>comboTableName</tabstop>
<tabstop>checkIndexUnique</tabstop>
<tabstop>tableIndexColumns</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="icons/icons.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CreateIndexDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>252</x>
<y>337</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CreateIndexDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>337</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>comboTableName</sender>
<signal>currentIndexChanged(QString)</signal>
<receiver>CreateIndexDialog</receiver>
<slot>tableChanged(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>91</x>
<y>43</y>
</hint>
<hint type="destinationlabel">
<x>236</x>
<y>31</y>
</hint>
</hints>
</connection>
<connection>
<sender>editIndexName</sender>
<signal>textChanged(QString)</signal>
<receiver>CreateIndexDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>429</x>
<y>14</y>
</hint>
<hint type="destinationlabel">
<x>443</x>
<y>39</y>
</hint>
</hints>
</connection>
<connection>
<sender>tableIndexColumns</sender>
<signal>cellChanged(int,int)</signal>
<receiver>CreateIndexDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>443</x>
<y>170</y>
</hint>
<hint type="destinationlabel">
<x>566</x>
<y>40</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>tableChanged(QString)</slot>
<slot>checkInput()</slot>
</slots>
</ui>

157
src/EditDialog.cpp Normal file
View File

@@ -0,0 +1,157 @@
#include "EditDialog.h"
#include "ui_EditDialog.h"
#include <QTextStream>
#include <QMessageBox>
#include <QFileDialog>
#include "sqlitedb.h"
EditDialog::EditDialog(QWidget* parent)
: QDialog(parent),
ui(new Ui::EditDialog)
{
ui->setupUi(this);
reset();
}
EditDialog::~EditDialog()
{
delete ui;
}
void EditDialog::reset()
{
curRow = -1;
curCol = -1;
ui->editData->setPlainText("");
ui->editData->setFocus();
setDataType(kSQLiteMediaType_Void, 0);
}
void EditDialog::enableExport(bool enabled)
{
ui->buttonExport->setEnabled(enabled);
}
void EditDialog::setDataType(int type, int size)
{
dataType = type;
dataSize = size;
QString charstr;
switch(dataType)
{
case kSQLiteMediaType_String:
ui->labelType->setText(tr("Type of data currently in cell: Text / Numeric"));
ui->labelSize->setText(tr("%n char(s)", "", ui->editData->toPlainText().length()));
enableExport(true);
break;
case kSQLiteMediaType_Void:
ui->labelType->setText(tr("Type of data currently in cell: Empty"));
ui->labelSize->setText(tr(""));
enableExport(false);
break;
}
}
void EditDialog::closeEvent(QCloseEvent*)
{
emit goingAway();
}
void EditDialog::loadText(QString text, int row, int col)
{
ui->editData->setPlainText(text);
ui->editData->setFocus();
ui->editData->selectAll();
curRow = row;
curCol = col;
if(ui->editData->toPlainText().length() > 0)
setDataType(kSQLiteMediaType_String, 0);
else
setDataType(kSQLiteMediaType_Void, 0);
}
void EditDialog::importData()
{
int type = kSQLiteMediaType_Void;
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Choose a file"),
defaultlocation,
tr("Text files(*.txt);;All files(*)"));
if(QFile::exists(fileName))
{
type = kSQLiteMediaType_String;
QFile file(fileName);
if(file.open(QIODevice::ReadOnly))
{
QTextStream stream(&file);
ui->editData->setPlainText(stream.readAll());
file.close();
}
setDataType(type, ui->editData->toPlainText().length());
}
}
void EditDialog::exportData()
{
QString filter;
switch (dataType)
{
case kSQLiteMediaType_String:
filter = tr("Text files(*.txt)");
break;
default:
return;
}
QString fileName = QFileDialog::getSaveFileName(
this,
tr("Choose a filename to export data"),
defaultlocation,
filter);
if(fileName.size() > 0)
{
switch (dataType)
{
case kSQLiteMediaType_String:
{
QFile file(fileName);
if(file.open(QIODevice::WriteOnly))
{
QTextStream stream(&file);
stream << ui->editData->toPlainText();
file.close();
}
}
break;
default:
return;
}
}
}
void EditDialog::clearData()
{
ui->editData->setPlainText("");
setDataType(kSQLiteMediaType_Void, 0);
}
void EditDialog::accept()
{
if(dataType == kSQLiteMediaType_String)
emit updateRecordText(curRow, curCol, ui->editData->toPlainText());
if (dataType == kSQLiteMediaType_Void)
emit updateRecordText(curRow, curCol, "");
emit goingAway();
}
void EditDialog::editTextChanged()
{
int newtype = kSQLiteMediaType_String;
if(ui->editData->toPlainText().length() == 0)
newtype = kSQLiteMediaType_Void;
setDataType(newtype, ui->editData->toPlainText().length());
}

50
src/EditDialog.h Normal file
View File

@@ -0,0 +1,50 @@
#ifndef __EDITDIALOG_H__
#define __EDITDIALOG_H__
#include <QDialog>
namespace Ui {
class EditDialog;
}
class EditDialog : public QDialog
{
Q_OBJECT
public:
explicit EditDialog(QWidget* parent = 0);
~EditDialog();
QString defaultlocation;
public:
int getCurrentCol() { return curCol; }
int getCurrentRow() { return curRow; }
public slots:
virtual void reset();
virtual void loadText(QString text, int row, int col);
private slots:
virtual void enableExport(bool enabled);
virtual void setDataType(int type, int size);
virtual void closeEvent(QCloseEvent*);
virtual void importData();
virtual void exportData();
virtual void clearData();
virtual void accept();
virtual void editTextChanged();
signals:
void goingAway();
void updateRecordText(int, int, QString);
private:
Ui::EditDialog* ui;
int dataType;
int dataSize;
int curCol;
int curRow;
};
#endif

218
src/EditDialog.ui Normal file
View File

@@ -0,0 +1,218 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditDialog</class>
<widget class="QDialog" name="EditDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>372</width>
<height>375</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit database cell</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="buttomImport">
<property name="toolTip">
<string>Import text</string>
</property>
<property name="whatsThis">
<string>Opens a file dialog used to import text to this database cell.</string>
</property>
<property name="text">
<string>&amp;Import</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonExport">
<property name="toolTip">
<string>Export text</string>
</property>
<property name="whatsThis">
<string>Opens a file dialog used to export the contents of this database cell to a text file.</string>
</property>
<property name="text">
<string>&amp;Export</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonClear">
<property name="toolTip">
<string>Clear cell data</string>
</property>
<property name="whatsThis">
<string>Erases the contents of the cell</string>
</property>
<property name="text">
<string>&amp;Clear</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="editData">
<property name="whatsThis">
<string>This area displays information about the data present in this database cell</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelType">
<property name="text">
<string>Type of data currently in cell</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelSize">
<property name="text">
<string>Size of data currently in table</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>buttomImport</tabstop>
<tabstop>buttonExport</tabstop>
<tabstop>buttonClear</tabstop>
<tabstop>editData</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>EditDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>262</x>
<y>370</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EditDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>326</x>
<y>350</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttomImport</sender>
<signal>clicked()</signal>
<receiver>EditDialog</receiver>
<slot>importData()</slot>
<hints>
<hint type="sourcelabel">
<x>41</x>
<y>16</y>
</hint>
<hint type="destinationlabel">
<x>60</x>
<y>0</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonExport</sender>
<signal>clicked()</signal>
<receiver>EditDialog</receiver>
<slot>exportData()</slot>
<hints>
<hint type="sourcelabel">
<x>100</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>162</x>
<y>17</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonClear</sender>
<signal>clicked()</signal>
<receiver>EditDialog</receiver>
<slot>clearData()</slot>
<hints>
<hint type="sourcelabel">
<x>321</x>
<y>13</y>
</hint>
<hint type="destinationlabel">
<x>290</x>
<y>12</y>
</hint>
</hints>
</connection>
<connection>
<sender>editData</sender>
<signal>textChanged()</signal>
<receiver>EditDialog</receiver>
<slot>editTextChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>234</x>
<y>218</y>
</hint>
<hint type="destinationlabel">
<x>362</x>
<y>309</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>importData()</slot>
<slot>exportData()</slot>
<slot>clearData()</slot>
<slot>editTextChanged()</slot>
</slots>
</ui>

90
src/EditFieldDialog.cpp Normal file
View File

@@ -0,0 +1,90 @@
#include "EditFieldDialog.h"
#include "ui_EditFieldDialog.h"
#include "sqlitedb.h"
#include <QPushButton>
#include <QMessageBox>
EditFieldDialog::EditFieldDialog(DBBrowserDB* db, bool new_field, QString table, QString fld_name, QString fld_type, QWidget* parent)
: QDialog(parent),
ui(new Ui::EditFieldDialog),
pdb(db),
original_field_name(fld_name),
table_name(table),
is_new(new_field)
{
// Create window and set its properties
ui->setupUi(this);
setWindowIcon(QIcon(is_new ? ":/icons/field_add" : ":/icons/field_edit"));
if(table == "")
setWindowTitle(tr("Add new field to new table"));
else
setWindowTitle(is_new ? tr("New Field in '%1'").arg(table_name) : tr("Change Field in '%1'").arg(table_name));
// Associate the radio buttons with their relative SQL data type
ui->radioTEXT->setProperty("field_type", "TEXT");
ui->radioNUMERIC->setProperty("field_type", "NUMERIC");
ui->radioBLOB->setProperty("field_type", "BLOB");
ui->radioINTPRIMARY->setProperty("field_type", "INTEGER PRIMARY KEY");
ui->radioCustom->setProperty("field_type", "__custom__");
// Set the current settings
ui->nameLineEdit->setText(fld_name);
QList<QAbstractButton *> buttons = ui->groupRadioTypes->buttons();
bool custom = true;
for(int i = 0; i < buttons.size(); ++i){
if( buttons.at(i)->property("field_type").toString() == fld_type.toUpper()){
buttons.at(i)->setChecked(true);
custom = false;
break;
}
}
if(custom)
{
ui->radioCustom->setChecked(true);
ui->txtCustomType->setText(fld_type);
}
// Check the current input values
checkInput();
}
EditFieldDialog::~EditFieldDialog()
{
delete ui;
}
void EditFieldDialog::accept()
{
field_name = ui->nameLineEdit->text();
field_type = ui->groupRadioTypes->checkedButton()->property("field_type").toString();
if(field_type == "__custom__")
field_type = ui->txtCustomType->text();
// Only change DB when dialog was not opened for a newly created table, i.e. table name is ""
if(table_name != "")
{
bool ok;
if(is_new)
ok = pdb->createColumn(table_name, field_name, field_type);
else
ok = pdb->renameColumn(table_name, original_field_name, field_name, field_type);
if(!ok){
QMessageBox::warning(this, QApplication::applicationName(), pdb->lastErrorMessage);
qDebug(pdb->lastErrorMessage.toUtf8());
return;
}
}
QDialog::accept();
}
void EditFieldDialog::checkInput()
{
ui->nameLineEdit->setText(ui->nameLineEdit->text().trimmed());
bool valid = true;
if(ui->nameLineEdit->text().isEmpty() || ui->nameLineEdit->text().contains(" "))
valid = false;
if(ui->radioCustom->isChecked() && ui->txtCustomType->text().isEmpty())
valid = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}

37
src/EditFieldDialog.h Normal file
View File

@@ -0,0 +1,37 @@
#ifndef __EDITFIELDDIALOG_H__
#define __EDITFIELDDIALOG_H__
#include <QDialog>
class DBBrowserDB;
namespace Ui {
class EditFieldDialog;
}
class EditFieldDialog : public QDialog
{
Q_OBJECT
public:
explicit EditFieldDialog(DBBrowserDB* db, bool new_field, QString table, QString fld_name, QString fld_type, QWidget* parent = 0);
~EditFieldDialog();
QString getFieldName() { return field_name; }
QString getFieldType() { return field_type; }
private slots:
virtual void accept();
virtual void checkInput();
private:
Ui::EditFieldDialog* ui;
DBBrowserDB* pdb;
QString original_field_name;
QString table_name;
bool is_new;
QString field_name;
QString field_type;
};
#endif

234
src/EditFieldDialog.ui Normal file
View File

@@ -0,0 +1,234 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditFieldDialog</class>
<widget class="QDialog" name="EditFieldDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<height>214</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Field name:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="buddy">
<cstring>nameLineEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Field type:</string>
</property>
<property name="buddy">
<cstring>radioTEXT</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioTEXT">
<property name="text">
<string>TEXT</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioNUMERIC">
<property name="text">
<string>NUMERIC</string>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioBLOB">
<property name="text">
<string>BLOB</string>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioINTPRIMARY">
<property name="text">
<string>INTEGER PRIMARY KEY</string>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioCustom">
<property name="text">
<string>Custom</string>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtCustomType">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>nameLineEdit</tabstop>
<tabstop>radioTEXT</tabstop>
<tabstop>radioNUMERIC</tabstop>
<tabstop>radioBLOB</tabstop>
<tabstop>radioINTPRIMARY</tabstop>
<tabstop>radioCustom</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>EditFieldDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>243</x>
<y>209</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>213</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EditFieldDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>311</x>
<y>209</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>213</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioCustom</sender>
<signal>toggled(bool)</signal>
<receiver>txtCustomType</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>137</x>
<y>142</y>
</hint>
<hint type="destinationlabel">
<x>138</x>
<y>167</y>
</hint>
</hints>
</connection>
<connection>
<sender>nameLineEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>EditFieldDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>354</x>
<y>24</y>
</hint>
<hint type="destinationlabel">
<x>446</x>
<y>33</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtCustomType</sender>
<signal>textChanged(QString)</signal>
<receiver>EditFieldDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>215</x>
<y>162</y>
</hint>
<hint type="destinationlabel">
<x>29</x>
<y>154</y>
</hint>
</hints>
</connection>
<connection>
<sender>groupRadioTypes</sender>
<signal>buttonClicked(int)</signal>
<receiver>EditFieldDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>224</x>
<y>106</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>checkInput()</slot>
</slots>
<buttongroups>
<buttongroup name="groupRadioTypes"/>
</buttongroups>
</ui>

185
src/EditTableDialog.cpp Normal file
View File

@@ -0,0 +1,185 @@
#include "EditTableDialog.h"
#include "ui_EditTableDialog.h"
#include "EditFieldDialog.h"
#include <QMessageBox>
#include <QPushButton>
#include "sqlitedb.h"
EditTableDialog::EditTableDialog(DBBrowserDB* db, QString tableName, QWidget* parent)
: QDialog(parent),
ui(new Ui::EditTableDialog),
pdb(db),
curTable(tableName)
{
// Create UI
ui->setupUi(this);
// Editing an existing table?
if(curTable != "")
{
// Existing table, so load and set the current layout
populateFields();
// And create a savepoint
pdb->executeSQL(QString("SAVEPOINT edittable_%1_save;").arg(curTable));
}
// Update UI
ui->editTableName->setText(curTable);
checkInput();
}
EditTableDialog::~EditTableDialog()
{
delete ui;
}
void EditTableDialog::populateFields()
{
//make sure we are not using cached information
pdb->updateSchema();
fields= pdb->getTableFields(curTable);
types= pdb->getTableTypes(curTable);
ui->treeWidget->model()->removeRows(0, ui->treeWidget->model()->rowCount());
QStringList::Iterator tt = types.begin();
for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) {
QTreeWidgetItem *fldItem = new QTreeWidgetItem();
fldItem->setText( 0, *ct );
fldItem->setText( 1, *tt );
ui->treeWidget->addTopLevelItem(fldItem);
++tt;
}
}
void EditTableDialog::accept()
{
// Are we editing an already existing table or designing a new one? In the first case there is a table name set,
// in the latter the current table name is empty
if(curTable == "")
{
// Creation of new table
// Prepare creation of the table
QList<DBBrowserField> tbl_structure;
for(int i=0;i<ui->treeWidget->topLevelItemCount();i++)
tbl_structure.push_back(DBBrowserField(ui->treeWidget->topLevelItem(i)->text(0), ui->treeWidget->topLevelItem(i)->text(1)));
// Create table
if(!pdb->createTable(ui->editTableName->text(), tbl_structure))
{
QMessageBox::warning(this, QApplication::applicationName(), tr("Error creating table. Message from database engine:\n%1").arg(pdb->lastErrorMessage));
return;
}
} else {
// Editing of old table
// Rename table if necessary
if(ui->editTableName->text() != curTable)
{
QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time
if(!pdb->renameTable(curTable, ui->editTableName->text()))
{
QApplication::restoreOverrideCursor();
QMessageBox::warning(this, QApplication::applicationName(), pdb->lastErrorMessage);
return;
} else {
QApplication::restoreOverrideCursor();
}
}
// Release the savepoint
pdb->executeSQL(QString("RELEASE SAVEPOINT edittable_%1_save;").arg(curTable));
}
QDialog::accept();
}
void EditTableDialog::reject()
{
// Have we been in the process of editing an old table?
if(curTable != "")
{
// Then rollback to our savepoint
pdb->executeSQL(QString("ROLLBACK TO SAVEPOINT edittable_%1_save;").arg(curTable));
}
QDialog::reject();
}
void EditTableDialog::checkInput()
{
ui->editTableName->setText(ui->editTableName->text().trimmed());
bool valid = true;
if(ui->editTableName->text().isEmpty() || ui->editTableName->text().contains(" "))
valid = false;
if(ui->treeWidget->topLevelItemCount() == 0)
valid = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}
void EditTableDialog::editField()
{
if(!ui->treeWidget->currentItem())
return;
// Show the edit dialog
QTreeWidgetItem *item = ui->treeWidget->currentItem();
EditFieldDialog dialog(pdb, curTable == "", curTable, item->text(0), item->text(1), this);
if(dialog.exec())
{
item->setText(0, dialog.getFieldName());
item->setText(1, dialog.getFieldType());
}
}
void EditTableDialog::addField()
{
EditFieldDialog dialog(pdb, true, curTable, "", "", this);
if(dialog.exec())
{
QTreeWidgetItem *tbitem = new QTreeWidgetItem(ui->treeWidget);
tbitem->setText(0, dialog.getFieldName());
tbitem->setText(1, dialog.getFieldType());
ui->treeWidget->addTopLevelItem(tbitem);
checkInput();
}
}
void EditTableDialog::removeField()
{
// Is there any item selected to delete?
if(!ui->treeWidget->currentItem())
return;
// Are we creating a new table or editing an old one?
if(curTable == "")
{
// Creating a new one
// Just delete that item. At this point there is no DB table to edit or data to be lost anyway
delete ui->treeWidget->currentItem();
} else {
// Editing an old one
// Ask user wether he really wants to delete that column
QString msg = tr("Are you sure you want to delete the field '%1'?\nAll data currently stored in this field will be lost.").arg(ui->treeWidget->currentItem()->text(0));
if(QMessageBox::warning(this, QApplication::applicationName(), msg, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes)
{
if(!pdb->dropColumn(curTable, ui->treeWidget->currentItem()->text(0)))
{
QMessageBox::warning(0, QApplication::applicationName(), pdb->lastErrorMessage);
} else {
delete ui->treeWidget->currentItem();
}
}
}
checkInput();
}
void EditTableDialog::fieldSelectionChanged()
{
ui->renameFieldButton->setEnabled(ui->treeWidget->selectionModel()->hasSelection());
ui->removeFieldButton->setEnabled(ui->treeWidget->selectionModel()->hasSelection());
}

37
src/EditTableDialog.h Normal file
View File

@@ -0,0 +1,37 @@
#ifndef __EDITTABLEDIALOG_H__
#define __EDITTABLEDIALOG_H__
#include <QDialog>
class DBBrowserDB;
namespace Ui {
class EditTableDialog;
}
class EditTableDialog : public QDialog
{
Q_OBJECT
public:
explicit EditTableDialog(DBBrowserDB* pdb, QString tableName, QWidget* parent = 0);
~EditTableDialog();
private slots:
virtual void populateFields();
virtual void editField();
virtual void addField();
virtual void removeField();
virtual void fieldSelectionChanged();
virtual void accept();
virtual void reject();
virtual void checkInput();
private:
Ui::EditTableDialog* ui;
DBBrowserDB* pdb;
QString curTable;
QStringList types;
QStringList fields;
};
#endif

297
src/EditTableDialog.ui Normal file
View File

@@ -0,0 +1,297 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditTableDialog</class>
<widget class="QDialog" name="EditTableDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>414</width>
<height>405</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit table definition</string>
</property>
<property name="windowIcon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/table</normaloff>:/icons/table</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupTable">
<property name="title">
<string>Table</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLineEdit" name="editTableName">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupFields">
<property name="title">
<string>Fields</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="addFieldButton">
<property name="text">
<string>Add field</string>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/field_add</normaloff>:/icons/field_add</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="renameFieldButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit field</string>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/field_edit</normaloff>:/icons/field_edit</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="removeFieldButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Remove field</string>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/field_delete</normaloff>:/icons/field_delete</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTreeWidget" name="treeWidget">
<column>
<property name="text">
<string>Field name</string>
</property>
</column>
<column>
<property name="text">
<string>Field type</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>editTableName</tabstop>
<tabstop>addFieldButton</tabstop>
<tabstop>renameFieldButton</tabstop>
<tabstop>removeFieldButton</tabstop>
<tabstop>treeWidget</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="icons/icons.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>EditTableDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>252</x>
<y>400</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EditTableDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>400</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>treeWidget</sender>
<signal>itemSelectionChanged()</signal>
<receiver>EditTableDialog</receiver>
<slot>fieldSelectionChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>116</x>
<y>193</y>
</hint>
<hint type="destinationlabel">
<x>411</x>
<y>181</y>
</hint>
</hints>
</connection>
<connection>
<sender>addFieldButton</sender>
<signal>clicked()</signal>
<receiver>EditTableDialog</receiver>
<slot>addField()</slot>
<hints>
<hint type="sourcelabel">
<x>57</x>
<y>106</y>
</hint>
<hint type="destinationlabel">
<x>79</x>
<y>65</y>
</hint>
</hints>
</connection>
<connection>
<sender>renameFieldButton</sender>
<signal>clicked()</signal>
<receiver>EditTableDialog</receiver>
<slot>editField()</slot>
<hints>
<hint type="sourcelabel">
<x>136</x>
<y>108</y>
</hint>
<hint type="destinationlabel">
<x>161</x>
<y>65</y>
</hint>
</hints>
</connection>
<connection>
<sender>removeFieldButton</sender>
<signal>clicked()</signal>
<receiver>EditTableDialog</receiver>
<slot>removeField()</slot>
<hints>
<hint type="sourcelabel">
<x>276</x>
<y>111</y>
</hint>
<hint type="destinationlabel">
<x>249</x>
<y>63</y>
</hint>
</hints>
</connection>
<connection>
<sender>editTableName</sender>
<signal>textChanged(QString)</signal>
<receiver>EditTableDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>62</x>
<y>48</y>
</hint>
<hint type="destinationlabel">
<x>115</x>
<y>3</y>
</hint>
</hints>
</connection>
<connection>
<sender>treeWidget</sender>
<signal>itemChanged(QTreeWidgetItem*,int)</signal>
<receiver>EditTableDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>138</x>
<y>197</y>
</hint>
<hint type="destinationlabel">
<x>412</x>
<y>135</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>fieldSelectionChanged()</slot>
<slot>addField()</slot>
<slot>editField()</slot>
<slot>removeField()</slot>
<slot>checkInput()</slot>
</slots>
</ui>

96
src/ExportCsvDialog.cpp Normal file
View File

@@ -0,0 +1,96 @@
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <QFileDialog>
#include "ExportCsvDialog.h"
#include "ui_ExportCsvDialog.h"
#include "sqlitedb.h"
ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, QString deflocation, QWidget* parent)
: QDialog(parent),
ui(new Ui::ExportCsvDialog),
pdb(db),
defaultLocation(deflocation)
{
// Create UI
ui->setupUi(this);
// Get list of tables to export
objectMap objects = pdb->getBrowsableObjects();
for(objectMap::ConstIterator i=objects.begin();i!=objects.end();++i)
ui->comboTable->addItem(QIcon(QString(":icons/%1").arg(i.value().gettype())), i.value().getname());
}
ExportCsvDialog::~ExportCsvDialog()
{
delete ui;
}
void ExportCsvDialog::accept()
{
// Get filename
QString fileName = QFileDialog::getSaveFileName(
this,
tr("Choose a filename to export data"),
defaultLocation,
tr("Text files(*.csv *.txt)"));
// Only if the user hasn't clicked the cancel button
if(fileName.size() > 0)
{
// Get data from selected table
pdb->browseTable(ui->comboTable->currentText());
// Prepare the quote and separating characters
QString quoteChar = ui->comboQuoteCharacter->currentText();
QString quotequoteChar = quoteChar + quoteChar;
QString sepChar = ui->comboFieldSeparator->currentText();
if(sepChar == tr("Tab")) sepChar = "\t";
QString newlineChar = "\n";
// Open file
QFile file(fileName);
if(file.open(QIODevice::WriteOnly))
{
// Open text stream to the file
QTextStream stream(&file);
// Put field names in first row if user wants to have them
if(ui->checkHeader->isChecked())
{
QStringList fields = pdb->browseFields;
for(int i=0;i<fields.count();i++)
{
stream << quoteChar << fields.at(i) << quoteChar;
if(i < fields.count() - 1)
stream << sepChar;
else
stream << newlineChar;
}
}
// Get and write actual data
rowList data = pdb->browseRecs;
for(int i=0;i<data.size();i++)
{
QStringList& row = data[i];
for(int j=1;j<row.size();j++)
{
QString content = row[j];
stream << quoteChar << content.replace(quoteChar, quotequoteChar) << quoteChar;
if(j < row.count() - 1)
stream << sepChar;
else
stream << newlineChar;
}
}
// Done writing the file
file.close();
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));
QDialog::accept();
} else {
QMessageBox::warning(this, QApplication::applicationName(), tr("Could not open output file."));
}
}
}

28
src/ExportCsvDialog.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef __EXPORTCSVDIALOG_H__
#define __EXPORTCSVDIALOG_H__
#include <QDialog>
class DBBrowserDB;
namespace Ui {
class ExportCsvDialog;
}
class ExportCsvDialog : public QDialog
{
Q_OBJECT
public:
explicit ExportCsvDialog(DBBrowserDB* db, QString deflocation, QWidget* parent = 0);
~ExportCsvDialog();
private slots:
virtual void accept();
private:
Ui::ExportCsvDialog* ui;
DBBrowserDB* pdb;
QString defaultLocation;
};
#endif

166
src/ExportCsvDialog.ui Normal file
View File

@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExportCsvDialog</class>
<widget class="QDialog" name="ExportCsvDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>141</height>
</rect>
</property>
<property name="windowTitle">
<string>Export table to CSV</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelTable">
<property name="text">
<string>&amp;Table</string>
</property>
<property name="buddy">
<cstring>comboTable</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboTable"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelHeader">
<property name="text">
<string>&amp;Column names in first line</string>
</property>
<property name="buddy">
<cstring>checkHeader</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkHeader">
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelFieldSeparator">
<property name="text">
<string>Field &amp;separator</string>
</property>
<property name="buddy">
<cstring>comboFieldSeparator</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboFieldSeparator">
<item>
<property name="text">
<string>,</string>
</property>
</item>
<item>
<property name="text">
<string>;</string>
</property>
</item>
<item>
<property name="text">
<string>Tab</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelQuoteCharacter">
<property name="text">
<string>&amp;Quote character</string>
</property>
<property name="buddy">
<cstring>comboQuoteCharacter</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboQuoteCharacter">
<item>
<property name="text">
<string>&quot;</string>
</property>
</item>
<item>
<property name="text">
<string>'</string>
</property>
</item>
<item>
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>comboTable</tabstop>
<tabstop>checkHeader</tabstop>
<tabstop>comboFieldSeparator</tabstop>
<tabstop>comboQuoteCharacter</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ExportCsvDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>252</x>
<y>136</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>140</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ExportCsvDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>136</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>140</y>
</hint>
</hints>
</connection>
</connections>
</ui>

61
src/FindDialog.cpp Normal file
View File

@@ -0,0 +1,61 @@
#include "FindDialog.h"
#include "ui_FindDialog.h"
FindDialog::FindDialog(QWidget* parent)
: QDialog(parent),
ui(new Ui::FindDialog)
{
ui->setupUi(this);
}
FindDialog::~FindDialog()
{
delete ui;
}
void FindDialog::showResults(resultMap rmap)
{
ui->tableResults->setSortingEnabled(false);
ui->tableResults->clearContents();
resultMap::Iterator it;
int rowNum;
ui->tableResults->setRowCount(rmap.size());
for(it=rmap.begin(),rowNum=0;it!=rmap.end();++it,rowNum++)
{
QString firstline = it.value().section('\n', 0, 0);
ui->tableResults->setItem(rowNum, 0, new QTableWidgetItem(QString::number(it.key() + 1)));
ui->tableResults->setItem(rowNum, 1, new QTableWidgetItem(firstline));
}
QString results = tr("Found: %1").arg(ui->tableResults->rowCount());
ui->labelNumberResults->setText(results);
ui->tableResults->setSortingEnabled(true);
}
void FindDialog::find()
{
emit lookfor(ui->comboColumn->currentText(), ui->comboOperator->currentText(), ui->editSearchString->text());
}
void FindDialog::resetFields(QStringList fieldlist)
{
ui->comboColumn->clear();
ui->comboColumn->addItems(fieldlist);
ui->editSearchString->setText("");
ui->comboOperator->setCurrentIndex(0);
ui->tableResults->clearContents();
ui->labelNumberResults->setText(tr("Found: 0"));
}
void FindDialog::recordSelected(QTableWidgetItem* witem)
{
if(witem)
{
int recNum = ui->tableResults->item(witem->row(), 0)->text().toInt();
emit showrecord(recNum - 1);
}
}
void FindDialog::closeEvent(QCloseEvent*)
{
emit goingAway();
}

38
src/FindDialog.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef __FINDDIALOG_H__
#define __FINDDIALOG_H__
#include <QDialog>
#include "sqlitedb.h"
class QTableWidgetItem;
namespace Ui {
class FindDialog;
}
class FindDialog : public QDialog
{
Q_OBJECT
public:
explicit FindDialog(QWidget* parent = 0);
~FindDialog();
public slots:
virtual void showResults(resultMap rmap);
virtual void resetFields(QStringList fieldlist = QStringList());
private slots:
virtual void find();
virtual void recordSelected(QTableWidgetItem* witem);
virtual void closeEvent(QCloseEvent*);
signals:
void lookfor(const QString&, const QString&, const QString&);
void showrecord(int);
void goingAway();
private:
Ui::FindDialog* ui;
};
#endif

190
src/FindDialog.ui Normal file
View File

@@ -0,0 +1,190 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FindDialog</class>
<widget class="QDialog" name="FindDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>288</width>
<height>351</height>
</rect>
</property>
<property name="windowTitle">
<string>Find</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="comboColumn">
<property name="toolTip">
<string>Field to be searched</string>
</property>
<property name="whatsThis">
<string>Use this control to select the field to be searched in the current table</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboOperator">
<property name="toolTip">
<string>Search criteria: use 'contains' for partial matches</string>
</property>
<property name="whatsThis">
<string>This control is used to select the search criteria used to look for the search term in the database. Use '=' or 'contains' to find words, and the comparison symbols to filter numeric data.</string>
</property>
<item>
<property name="text">
<string>=</string>
</property>
</item>
<item>
<property name="text">
<string>contains</string>
</property>
</item>
<item>
<property name="text">
<string>&gt;</string>
</property>
</item>
<item>
<property name="text">
<string>&gt;=</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;=</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;&gt;</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="editSearchString">
<property name="toolTip">
<string>Enter values or words to search</string>
</property>
<property name="whatsThis">
<string>This is a place to enter the word or number to be searched in the database</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonSearch">
<property name="toolTip">
<string>Perform the search</string>
</property>
<property name="whatsThis">
<string>This button starts the search process</string>
</property>
<property name="text">
<string>&amp;Search</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tableResults">
<property name="whatsThis">
<string>Results of the search will appear in this area. Click on a result to select the corresponding record in the database</string>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<column>
<property name="text">
<string>Records</string>
</property>
</column>
<column>
<property name="text">
<string>Data</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QLabel" name="labelNumberResults">
<property name="text">
<string>Found: 0</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>comboColumn</tabstop>
<tabstop>comboOperator</tabstop>
<tabstop>editSearchString</tabstop>
<tabstop>buttonSearch</tabstop>
<tabstop>tableResults</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonSearch</sender>
<signal>clicked()</signal>
<receiver>FindDialog</receiver>
<slot>find()</slot>
<hints>
<hint type="sourcelabel">
<x>233</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>267</x>
<y>30</y>
</hint>
</hints>
</connection>
<connection>
<sender>tableResults</sender>
<signal>itemClicked(QTableWidgetItem*)</signal>
<receiver>FindDialog</receiver>
<slot>recordSelected(QTableWidgetItem*)</slot>
<hints>
<hint type="sourcelabel">
<x>100</x>
<y>176</y>
</hint>
<hint type="destinationlabel">
<x>86</x>
<y>58</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>find()</slot>
<slot>recordSelected(QTableWidgetItem*)</slot>
</slots>
</ui>

191
src/ImportCsvDialog.cpp Normal file
View File

@@ -0,0 +1,191 @@
#include "ImportCsvDialog.h"
#include "ui_ImportCsvDialog.h"
#include <QMessageBox>
#include <QProgressDialog>
#include <QPushButton>
#include "sqlitedb.h"
ImportCsvDialog::ImportCsvDialog(QString filename, DBBrowserDB* db, QWidget* parent)
: QDialog(parent),
ui(new Ui::ImportCsvDialog),
csvFilename(filename),
pdb(db)
{
ui->setupUi(this);
checkInput();
updatePreview();
}
ImportCsvDialog::~ImportCsvDialog()
{
delete ui;
}
void ImportCsvDialog::accept()
{
QString sql;
// Parse all csv data
int numfields;
QStringList curList = pdb->decodeCSV(csvFilename, currentSeparatorChar(), currentQuoteChar(), -1, &numfields);
// Can not operate on an empty result
if(numfields == 0)
return;
// Generate field names. These are either taken from the first CSV row or are generated in the format of "fieldXY" depending on the user input
QList<DBBrowserField> fieldList;
if(ui->checkboxHeader->isChecked())
{
int cfieldnum = 0;
while(!curList.empty() && cfieldnum != numfields)
{
// Remove invalid characters
QString thisfield = curList.front();
thisfield.replace(" ", "");
thisfield.replace('"', "");
thisfield.replace("'","");
thisfield.replace(",","");
thisfield.replace(";","");
// Avoid empty field names
if(thisfield.isEmpty())
thisfield = QString("field%1").arg(cfieldnum+1);
fieldList.push_back(DBBrowserField(thisfield, ""));
cfieldnum++;
curList.pop_front();
}
} else {
for(int i=0;i<numfields;i++)
fieldList.push_back(DBBrowserField(QString("field%1").arg(i+1), ""));
}
// Show progress dialog
QProgressDialog progress(tr("Inserting data..."), tr("Cancel"), 0, curList.size());
progress.setWindowModality(Qt::ApplicationModal);
// declare local variables we will need before the rollback jump
int colNum = 0;
// Create a savepoint, so we can rollback in case of any errors during importing
// db needs to be saved or an error will occur
if(!pdb->executeSQL("SAVEPOINT CSVIMPORT;", false))
goto rollback;
// Create table
if(!pdb->createTable(ui->editName->text(), fieldList))
goto rollback;
{ // avoid error on MSVC due to rollback label
// now lets import all data, one row at a time
for(int i=0;i<curList.size();++i)
{
if(colNum == 0)
sql = QString("INSERT INTO `%1` VALUES(").arg(ui->editName->text());
// need to mprintf here
char* formSQL = sqlite3_mprintf("%Q", (const char*)curList[i].toUtf8());
sql.append(formSQL);
if(formSQL)
sqlite3_free(formSQL);
colNum++;
if(colNum < numfields)
{
sql.append(",");
} else {
colNum = 0;
sql.append(");");
if(!pdb->executeSQL(sql, false, false))
goto rollback;
}
progress.setValue(i);
if(progress.wasCanceled())
goto rollback;
}
}
// Everything ok, release the savepoint
if(!pdb->executeSQL("RELEASE SAVEPOINT CSVIMPORT;"))
goto rollback;
pdb->setDirtyDirect(true);
QApplication::restoreOverrideCursor(); // restore original cursor
QDialog::accept();
return;
rollback:
progress.hide();
QApplication::restoreOverrideCursor(); // restore original cursor
QString error = tr("Error importing data. Message from database engine: %1").arg(pdb->lastErrorMessage);
QMessageBox::warning(this, QApplication::applicationName(), error);
pdb->executeSQL("ROLLBACK TO SAVEPOINT CSVIMPORT;", false);
}
void ImportCsvDialog::updatePreview()
{
// Get preview data
int numfields;
int maxrecs = 20;
QStringList curList = pdb->decodeCSV(csvFilename, currentSeparatorChar(), currentQuoteChar(), maxrecs, &numfields);
// Reset preview widget
ui->tablePreview->clear();
ui->tablePreview->setColumnCount(numfields);
// Exit if there are no lines to preview at all
if(numfields == 0)
return;
// Use first row as header if necessary
if(ui->checkboxHeader->isChecked())
{
ui->tablePreview->setHorizontalHeaderLabels(curList);
// Remove this row to not show it in the data section
for(int e=0;e<numfields;e++)
curList.pop_front();
}
// Fill data section
ui->tablePreview->setRowCount(curList.count() / numfields);
int rowNum = 0;
int colNum = 0;
for(QStringList::Iterator ct=curList.begin();ct!=curList.end();++ct)
{
if(colNum == 0)
ui->tablePreview->setVerticalHeaderItem(rowNum, new QTableWidgetItem(QString::number(rowNum + 1)));
ui->tablePreview->setItem(rowNum, colNum, new QTableWidgetItem(*ct));
colNum++;
if(colNum == numfields)
{
colNum = 0;
rowNum++;
}
}
}
void ImportCsvDialog::checkInput()
{
ui->editName->setText(ui->editName->text().trimmed());
bool valid = true;
if(ui->editName->text().isEmpty() || ui->editName->text().contains(" "))
valid = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}
char ImportCsvDialog::currentQuoteChar()
{
if(ui->comboQuote->currentText().length())
return ui->comboQuote->currentText().at(0).toAscii();
else
return 0;
}
char ImportCsvDialog::currentSeparatorChar()
{
return ui->comboSeparator->currentText() == tr("Tab") ? '\t' : ui->comboSeparator->currentText().at(0).toAscii();
}

33
src/ImportCsvDialog.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef __IMPORTCSVDIALOG_H__
#define __IMPORTCSVDIALOG_H__
#include <QDialog>
class DBBrowserDB;
namespace Ui {
class ImportCsvDialog;
}
class ImportCsvDialog : public QDialog
{
Q_OBJECT
public:
explicit ImportCsvDialog(QString filename, DBBrowserDB* db, QWidget* parent = 0);
~ImportCsvDialog();
private slots:
virtual void accept();
virtual void updatePreview();
virtual void checkInput();
private:
Ui::ImportCsvDialog* ui;
QString csvFilename;
DBBrowserDB* pdb;
char currentQuoteChar();
char currentSeparatorChar();
};
#endif

235
src/ImportCsvDialog.ui Normal file
View File

@@ -0,0 +1,235 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportCsvDialog</class>
<widget class="QDialog" name="ImportCsvDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>738</width>
<height>490</height>
</rect>
</property>
<property name="windowTitle">
<string>Import CSV file</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>&amp;Table name</string>
</property>
<property name="buddy">
<cstring>editName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="editName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelHeader">
<property name="text">
<string>&amp;Column names in first line</string>
</property>
<property name="buddy">
<cstring>checkboxHeader</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkboxHeader">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelSeparator">
<property name="text">
<string>Field &amp;separator</string>
</property>
<property name="buddy">
<cstring>comboSeparator</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboSeparator">
<item>
<property name="text">
<string>,</string>
</property>
</item>
<item>
<property name="text">
<string>;</string>
</property>
</item>
<item>
<property name="text">
<string>Tab</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelQuote">
<property name="text">
<string>&amp;Quote character</string>
</property>
<property name="buddy">
<cstring>comboQuote</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboQuote">
<item>
<property name="text">
<string>&quot;</string>
</property>
</item>
<item>
<property name="text">
<string>'</string>
</property>
</item>
<item>
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tablePreview"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>editName</tabstop>
<tabstop>checkboxHeader</tabstop>
<tabstop>comboSeparator</tabstop>
<tabstop>comboQuote</tabstop>
<tabstop>tablePreview</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ImportCsvDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>252</x>
<y>485</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImportCsvDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>485</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkboxHeader</sender>
<signal>toggled(bool)</signal>
<receiver>ImportCsvDialog</receiver>
<slot>updatePreview()</slot>
<hints>
<hint type="sourcelabel">
<x>187</x>
<y>46</y>
</hint>
<hint type="destinationlabel">
<x>354</x>
<y>45</y>
</hint>
</hints>
</connection>
<connection>
<sender>comboSeparator</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>ImportCsvDialog</receiver>
<slot>updatePreview()</slot>
<hints>
<hint type="sourcelabel">
<x>216</x>
<y>71</y>
</hint>
<hint type="destinationlabel">
<x>445</x>
<y>64</y>
</hint>
</hints>
</connection>
<connection>
<sender>comboQuote</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>ImportCsvDialog</receiver>
<slot>updatePreview()</slot>
<hints>
<hint type="sourcelabel">
<x>224</x>
<y>100</y>
</hint>
<hint type="destinationlabel">
<x>350</x>
<y>88</y>
</hint>
</hints>
</connection>
<connection>
<sender>editName</sender>
<signal>textChanged(QString)</signal>
<receiver>ImportCsvDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>609</x>
<y>13</y>
</hint>
<hint type="destinationlabel">
<x>631</x>
<y>45</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>updatePreview()</slot>
<slot>checkInput()</slot>
</slots>
</ui>

View File

@@ -36,5 +36,7 @@ To comply with the terms of the LGPL, sources for Qt 4.6.0 can be obtained from
the same site where you downloaded this software:
http://sourceforge.net/projects/sqlitebrowser/files/
----
The Icons are licensed under a Creative Commons Attribution 2.5 and 3.0 license.
They were made by Mark James, also see http://www.famfamfam.com/lab/icons/silk/

1153
src/MainWindow.cpp Normal file

File diff suppressed because it is too large Load Diff

124
src/MainWindow.h Normal file
View File

@@ -0,0 +1,124 @@
#ifndef MAINFORM_H
#define MAINFORM_H
#include <QMainWindow>
#include "sqlitedb.h"
#define ORDERMODE_ASC 0
#define ORDERMODE_DESC 1
class QDragEnterEvent;
class SQLLogDock;
class EditDialog;
class FindDialog;
class SQLiteSyntaxHighlighter;
class QStandardItemModel;
class QIntValidator;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget* parent = 0);
~MainWindow();
private:
Ui::MainWindow* ui;
SQLLogDock * logWin;
QStandardItemModel *queryResultListModel;
QMenu *popupTableMenu;
QMenu *popupFieldMenu;
QMenu *recentFilesMenu;
SQLiteSyntaxHighlighter* sqliteHighlighter;
enum { MaxRecentFiles = 5 };
QAction *recentFileActs[MaxRecentFiles];
QAction *recentSeparatorAct;
int curBrowseOrderByIndex;
int curBrowseOrderByMode;
EditDialog* editWin;
FindDialog* findWin;
QIntValidator* gotoValidator;
QString defaultlocation;
DBBrowserDB db;
void init();
void updateRecentFileActions();
void setCurrentFile(const QString& fileName);
void activateFields(bool enable = true);
protected:
void closeEvent(QCloseEvent *);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void resizeEvent(QResizeEvent *event);
public slots:
virtual void fileOpen( const QString & fileName );
private slots:
virtual void createTreeContextMenu(const QPoint & qPoint);
virtual void changeTreeSelection();
virtual void addField();
virtual void editField();
virtual void deleteField();
virtual void fileOpen();
virtual void fileNew();
virtual void populateStructure();
virtual void populateTable(const QString & tablename , bool keepColumnWidths = false);
virtual void resetBrowser();
virtual void fileClose();
virtual void fileExit();
virtual void addRecord();
virtual void deleteRecord();
virtual void updateTableView(int lineToSelect , bool keepColumnWidths = false);
virtual void selectTableLine( int lineToSelect );
virtual void navigatePrevious();
virtual void navigateNext();
virtual void navigateGoto();
virtual void setRecordsetLabel();
virtual void browseFind( bool open );
virtual void browseFindAway();
virtual void browseRefresh();
virtual void lookfor( const QString & wfield, const QString & woperator, const QString & wsearchterm );
virtual void createTable();
virtual void createIndex();
virtual void compact();
virtual void deleteObject();
virtual void editTable();
virtual void helpWhatsThis();
virtual void helpAbout();
virtual void updateRecordText( int row, int col, QString newtext );
virtual void logWinAway();
virtual void editWinAway();
virtual void editText( int row, int col );
virtual void doubleClickTable( int row, int col );
virtual void executeQuery();
virtual void importTableFromCSV();
virtual void exportTableToCSV();
virtual void dbState( bool dirty );
virtual void fileSave();
virtual void fileRevert();
virtual void exportDatabaseToSQL();
virtual void importDatabaseFromSQL();
virtual void openPreferences();
virtual void updatePreferences();
virtual void openRecentFile();
virtual void loadPragmas();
virtual void savePragmas();
virtual void mainTabSelected( int tabindex );
virtual void browseTableHeaderClicked(int logicalindex);
};
#endif

2073
src/MainWindow.ui Normal file

File diff suppressed because it is too large Load Diff

120
src/PreferencesDialog.cpp Normal file
View File

@@ -0,0 +1,120 @@
#include "PreferencesDialog.h"
#include "ui_PreferencesDialog.h"
#include <QDir>
#include <QSettings>
#include <QFileDialog>
#include "sqlitedb.h"
PreferencesDialog::PreferencesDialog(QWidget* parent)
: QDialog(parent),
ui(new Ui::PreferencesDialog)
{
ui->setupUi(this);
loadSettings();
}
/*
* Destroys the object and frees any allocated resources
*/
PreferencesDialog::~PreferencesDialog()
{
delete ui;
}
void PreferencesDialog::defaultDataChanged( int which )
{
if (which==2) {
defaultnewdata = QString("\'\'");
} else if (which==1) {
defaultnewdata = QString("0");
} else {
defaultnewdata = QString("NULL");
}
}
void PreferencesDialog::defaultTextChanged( int which )
{
if (which==1) {
defaulttext = QString("Auto");
} else {
defaulttext = QString("Plain");
}
}
void PreferencesDialog::encodingChanged( int which )
{
if (which==1) {
defaultencoding = QString("Latin1");
} else {
defaultencoding = QString("UTF8");
}
}
void PreferencesDialog::chooseLocation()
{
QString s = QFileDialog::getExistingDirectory(
this,
tr("Choose a directory"),
defaultlocation,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if(!s.isEmpty())
{
defaultlocation = s;
ui->locationEdit->setText(defaultlocation);
}
}
void PreferencesDialog::loadSettings()
{
QSettings settings(QApplication::organizationName(), QApplication::organizationName());
settings.sync();
defaultencoding = settings.value( "/db/defaultencoding", "UTF8" ).toString();
defaultnewdata = settings.value( "/db/defaultnewdata", "NULL" ).toString();
defaultlocation = settings.value( "/db/defaultlocation", QDir::homePath() ).toString();
defaulttext = settings.value( "/db/defaulttext", "Plain" ).toString();
if (defaultencoding=="Latin1")
{
ui->encodingComboBox->setCurrentIndex(1);
} else {
ui->encodingComboBox->setCurrentIndex(0) ;
defaultencoding = QString("UTF8");
}
if (defaultnewdata=="\'\'")
{
ui->defaultdataComboBox->setCurrentIndex(2) ;
} else if (defaultnewdata=="0")
{
ui->defaultdataComboBox->setCurrentIndex(1) ;
} else {
ui->defaultdataComboBox->setCurrentIndex(0) ;
defaultnewdata = QString("NULL");
}
if (defaulttext=="Auto")
{
ui->defaultTextComboBox->setCurrentIndex(1) ;
} else {
ui->defaultTextComboBox->setCurrentIndex(0) ;
defaulttext = QString("Plain");
}
ui->locationEdit->setText(defaultlocation);
}
void PreferencesDialog::saveSettings()
{
QSettings settings(QApplication::organizationName(), QApplication::organizationName());
settings.setValue( "/db/defaultencoding", defaultencoding );
settings.setValue( "/db/defaultnewdata", defaultnewdata );
settings.setValue( "/db/defaultlocation", defaultlocation );
settings.setValue( "/db/defaulttext", defaulttext );
settings.sync();
accept();
}

35
src/PreferencesDialog.h Normal file
View File

@@ -0,0 +1,35 @@
#ifndef __PREFERENCESDIALOG_H__
#define __PREFERENCESDIALOG_H__
#include <QDialog>
namespace Ui {
class PreferencesDialog;
}
class PreferencesDialog : public QDialog
{
Q_OBJECT
public:
explicit PreferencesDialog(QWidget* parent = 0);
~PreferencesDialog();
QString defaulttext;
QString defaultlocation;
QString defaultnewdata;
QString defaultencoding;
private slots:
virtual void defaultDataChanged( int which );
virtual void defaultTextChanged( int which );
virtual void encodingChanged( int which );
virtual void chooseLocation();
virtual void loadSettings();
virtual void saveSettings();
private:
Ui::PreferencesDialog *ui;
};
#endif

258
src/PreferencesDialog.ui Normal file
View File

@@ -0,0 +1,258 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PreferencesDialog</class>
<widget class="QDialog" name="PreferencesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>492</width>
<height>145</height>
</rect>
</property>
<property name="windowTitle">
<string>Preferences</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Database Encoding</string>
</property>
<property name="buddy">
<cstring>encodingComboBox</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Default data for new records</string>
</property>
<property name="buddy">
<cstring>defaultdataComboBox</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="defaultdataComboBox">
<item>
<property name="text">
<string>NULL</string>
</property>
</item>
<item>
<property name="text">
<string>0</string>
</property>
</item>
<item>
<property name="text">
<string>Empty string</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Default text editor format</string>
</property>
<property name="buddy">
<cstring>defaultTextComboBox</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="defaultTextComboBox">
<item>
<property name="text">
<string>Plain</string>
</property>
</item>
<item>
<property name="text">
<string>Auto</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Default location</string>
</property>
<property name="buddy">
<cstring>locationEdit</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="locationEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="setLocationButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="encodingComboBox">
<item>
<property name="text">
<string>UTF8 (Unicode)</string>
</property>
</item>
<item>
<property name="text">
<string>Latin1 (8bit)</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>buttonBox</tabstop>
<tabstop>encodingComboBox</tabstop>
<tabstop>defaultdataComboBox</tabstop>
<tabstop>defaultTextComboBox</tabstop>
<tabstop>locationEdit</tabstop>
<tabstop>setLocationButton</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PreferencesDialog</receiver>
<slot>saveSettings()</slot>
<hints>
<hint type="sourcelabel">
<x>252</x>
<y>140</y>
</hint>
<hint type="destinationlabel">
<x>155</x>
<y>143</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PreferencesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>140</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>144</y>
</hint>
</hints>
</connection>
<connection>
<sender>encodingComboBox</sender>
<signal>activated(int)</signal>
<receiver>PreferencesDialog</receiver>
<slot>encodingChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>265</x>
<y>15</y>
</hint>
<hint type="destinationlabel">
<x>339</x>
<y>8</y>
</hint>
</hints>
</connection>
<connection>
<sender>defaultdataComboBox</sender>
<signal>activated(int)</signal>
<receiver>PreferencesDialog</receiver>
<slot>defaultDataChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>239</x>
<y>40</y>
</hint>
<hint type="destinationlabel">
<x>350</x>
<y>43</y>
</hint>
</hints>
</connection>
<connection>
<sender>setLocationButton</sender>
<signal>clicked()</signal>
<receiver>PreferencesDialog</receiver>
<slot>chooseLocation()</slot>
<hints>
<hint type="sourcelabel">
<x>468</x>
<y>98</y>
</hint>
<hint type="destinationlabel">
<x>459</x>
<y>62</y>
</hint>
</hints>
</connection>
<connection>
<sender>defaultTextComboBox</sender>
<signal>activated(int)</signal>
<receiver>PreferencesDialog</receiver>
<slot>defaultTextChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>215</x>
<y>72</y>
</hint>
<hint type="destinationlabel">
<x>297</x>
<y>64</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>saveSettings()</slot>
<slot>defaultDataChanged(int)</slot>
<slot>encodingChanged(int)</slot>
<slot>chooseLocation()</slot>
<slot>defaultTextChanged(int)</slot>
</slots>
</ui>

View File

@@ -1,9 +1,8 @@
#include "SQLLogDock.h"
#include <QScrollBar>
#include "sqlitedb.h"
#include "sqlitesyntaxhighlighter.h"
#include "SQLiteSyntaxHighlighter.h"
/*
* Constructs a sqlLogForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
@@ -12,7 +11,7 @@
* true to construct a modal dialog.
*/
SQLLogDock::SQLLogDock(QWidget* parent)
: QDockWidget("SQL Log", parent)
: QDockWidget(tr("SQL Log"), parent)
{
setupUi();
}

View File

@@ -3,7 +3,6 @@
#include <QTextEdit>
#include <QStackedWidget>
#include <QtGui/QAction>
#include <QtGui/QComboBox>
#include <QtGui/QDockWidget>
#include <QtGui/QHBoxLayout>

View File

@@ -1,4 +1,4 @@
#include "sqlitesyntaxhighlighter.h"
#include "SQLiteSyntaxHighlighter.h"
SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) :
QSyntaxHighlighter(parent)
@@ -61,14 +61,17 @@ SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) :
highlightingRules.append(rule);
}
quotationFormat.setForeground(Qt::darkRed);
singleLineCommentFormat.setForeground(Qt::darkGreen);
rule.pattern = QRegExp("--[^\n]*");
rule.format = singleLineCommentFormat;
highlightingRules.append(rule);
quotationFormat.setForeground(Qt::red);
rule.pattern = QRegExp("\".*\"");
rule.pattern.setMinimal(true);
rule.format = quotationFormat;
highlightingRules.append(rule);
rule.pattern = QRegExp("'.*'");
rule.pattern.setMinimal(true);
rule.format = quotationFormat;
highlightingRules.append(rule);
}

View File

@@ -25,12 +25,8 @@ private:
QVector<HighlightingRule> highlightingRules;
QVector<HighlightingRule> tableNameRules;
QRegExp commentStartExpression;
QRegExp commentEndExpression;
QTextCharFormat keywordFormat;
QTextCharFormat singleLineCommentFormat;
QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat;
QTextCharFormat tableFormat;
};

View File

@@ -1,84 +0,0 @@
#include "addfieldform.h"
#include <qvariant.h>
#include <qmessagebox.h>
#include <qimage.h>
#include <qpixmap.h>
#include "sqlitedb.h"
#include "addfieldtypeform.h"
/*
* Constructs a addFieldForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
addFieldForm::addFieldForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
addFieldForm::~addFieldForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void addFieldForm::languageChange()
{
retranslateUi(this);
}
void addFieldForm::setInitialValues(QString name, QString type)
{
nameLineEdit->setText(name);
typeBox->clear();
typeBox->addItem(type);
QString tString = "";
if (type.compare(tString)!=0) typeBox->addItem(tString);
tString = "TEXT";
if (type.compare(tString)!=0) typeBox->addItem(tString);
tString = "NUMERIC";
if (type.compare(tString)!=0) typeBox->addItem(tString);
tString = "BLOB";
if (type.compare(tString)!=0) typeBox->addItem(tString);
tString = "INTEGER PRIMARY KEY";
if (type.compare(tString)!=0) typeBox->addItem(tString);
}
void addFieldForm::confirmAddField()
{
QString fieldname = nameLineEdit->text();
if (fieldname.isEmpty()) {
QMessageBox::information( this, QApplication::applicationName(), "Field name can not be empty" );
return;
}
if (fieldname.contains(" ")>0) {
QMessageBox::warning( this, QApplication::applicationName(), "Spaces are not allowed in the field name" );
return;
}
fname = fieldname;
ftype = typeBox->currentText();
accept();
}
void addFieldForm::getCustomType()
{
addFieldTypeForm * addForm = new addFieldTypeForm( this );
addForm->setModal(true);
if (addForm->exec())
{
//QString nospaces = addForm->typeNameEdit->text().remove(" ");
QString nospaces = addForm->typeNameEdit->text();
setInitialValues(nameLineEdit->text(),nospaces );
}
}

View File

@@ -1,230 +0,0 @@
#ifndef ADDFIELDFORM_H
#define ADDFIELDFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtCore/QStringList>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QRadioButton>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QToolButton>
#include <QtGui/QVBoxLayout>
QT_BEGIN_NAMESPACE
class Ui_addFieldForm
{
public:
QGridLayout *gridLayout;
QSpacerItem *spacer17;
QHBoxLayout *hboxLayout;
QSpacerItem *spacer15;
QPushButton *cancelButton;
QPushButton *createButton;
QVBoxLayout *vboxLayout;
QLabel *textLabel1;
QLabel *textLabel2;
QVBoxLayout *vboxLayout1;
QLineEdit *nameLineEdit;
QHBoxLayout *hboxLayout1;
QComboBox *typeBox;
QToolButton *typeButton;
void setupUi(QDialog *addFieldForm)
{
if (addFieldForm->objectName().isEmpty()){
addFieldForm->setObjectName(QString::fromUtf8("addFieldForm"));
}
addFieldForm->resize(338, 136);
gridLayout = new QGridLayout(addFieldForm);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
spacer17 = new QSpacerItem(20, 16, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(spacer17, 1, 1, 1, 1);
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
spacer15 = new QSpacerItem(41, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacer15);
//** Cancel Button
cancelButton = new QPushButton(addFieldForm);
cancelButton->setIcon(QIcon(":/icons/cancel"));
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
hboxLayout->addWidget(cancelButton);
//** Create Button
createButton = new QPushButton(addFieldForm);
createButton->setObjectName(QString::fromUtf8("createButton"));
createButton->setDefault(true);
createButton->setIcon(QIcon(":/icons/save"));
hboxLayout->addWidget(createButton);
gridLayout->addLayout(hboxLayout, 2, 0, 1, 2);
vboxLayout = new QVBoxLayout();
vboxLayout->setSpacing(6);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
textLabel1 = new QLabel(addFieldForm);
textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
textLabel1->setWordWrap(false);
vboxLayout->addWidget(textLabel1);
textLabel2 = new QLabel(addFieldForm);
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
textLabel2->setWordWrap(false);
vboxLayout->addWidget(textLabel2);
gridLayout->addLayout(vboxLayout, 0, 0, 1, 1);
vboxLayout1 = new QVBoxLayout();
vboxLayout1->setSpacing(6);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
nameLineEdit = new QLineEdit(addFieldForm);
nameLineEdit->setObjectName(QString::fromUtf8("nameLineEdit"));
vboxLayout1->addWidget(nameLineEdit);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
typeBox = new QComboBox(addFieldForm);
typeBox->setObjectName(QString::fromUtf8("typeBox"));
hboxLayout1->addWidget(typeBox);
//**** Field Types Radios
QVBoxLayout *radioLayout = new QVBoxLayout();
vboxLayout1->addLayout(radioLayout);
QRadioButton *radioTEXT = new QRadioButton();
radioTEXT->setText(QApplication::translate("addFieldForm", "TEXT", 0, QApplication::UnicodeUTF8));
radioLayout->addWidget(radioTEXT);
QRadioButton *radioNUMERIC = new QRadioButton();
radioNUMERIC->setText(QApplication::translate("addFieldForm", "NUMERIC", 0, QApplication::UnicodeUTF8));
radioLayout->addWidget(radioNUMERIC);
QRadioButton *radioBLOB = new QRadioButton();
radioBLOB->setText(QApplication::translate("addFieldForm", "BLOB", 0, QApplication::UnicodeUTF8));
radioLayout->addWidget(radioBLOB);
QRadioButton *radioINTPRIMARY = new QRadioButton();
radioINTPRIMARY->setText(QApplication::translate("addFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8));
radioLayout->addWidget(radioINTPRIMARY);
QRadioButton *radioCustom = new QRadioButton();
radioCustom->setText(QApplication::translate("addFieldForm", "Custom", 0, QApplication::UnicodeUTF8));
radioLayout->addWidget(radioCustom);
typeButton = new QToolButton(addFieldForm);
typeButton->setObjectName(QString::fromUtf8("typeButton"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(typeButton->sizePolicy().hasHeightForWidth());
typeButton->setSizePolicy(sizePolicy);
hboxLayout1->addWidget(typeButton);
vboxLayout1->addLayout(hboxLayout1);
gridLayout->addLayout(vboxLayout1, 0, 1, 1, 1);
retranslateUi(addFieldForm);
QObject::connect(cancelButton, SIGNAL(clicked()), addFieldForm, SLOT(reject()));
QObject::connect(createButton, SIGNAL(clicked()), addFieldForm, SLOT(confirmAddField()));
QObject::connect(typeButton, SIGNAL(clicked()), addFieldForm, SLOT(getCustomType()));
QMetaObject::connectSlotsByName(addFieldForm);
} // setupUi
void retranslateUi(QDialog *addFieldForm)
{
addFieldForm->setWindowTitle(QApplication::translate("addFieldForm", "Add database field", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("addFieldForm", "Cancel", 0, QApplication::UnicodeUTF8));
createButton->setText(QApplication::translate("addFieldForm", "Create", 0, QApplication::UnicodeUTF8));
textLabel1->setText(QApplication::translate("addFieldForm", "Field name:", 0, QApplication::UnicodeUTF8));
textLabel2->setText(QApplication::translate("addFieldForm", "Field type:", 0, QApplication::UnicodeUTF8));
typeBox->clear();
typeBox->insertItems(0, QStringList()
<< QString()
<< QApplication::translate("addFieldForm", "TEXT", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "NUMERIC", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "BLOB", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8)
);
typeButton->setText(QApplication::translate("addFieldForm", "...", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
typeButton->setProperty("toolTip", QVariant(QApplication::translate("addFieldForm", "Custom type", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
typeButton->setProperty("whatsThis", QVariant(QApplication::translate("addFieldForm", "Click this button to enter a new type for the field", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
} // retranslateUi
};
namespace Ui {
class addFieldForm: public Ui_addFieldForm {};
} // namespace Ui
QT_END_NAMESPACE
class addFieldForm : public QDialog, public Ui::addFieldForm
{
Q_OBJECT
public:
addFieldForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~addFieldForm();
QString fname;
QString ftype;
public slots:
virtual void setInitialValues( QString name, QString type );
virtual void confirmAddField();
virtual void getCustomType();
protected slots:
virtual void languageChange();
};
#endif // ADDFIELDFORM_H

View File

@@ -1,39 +0,0 @@
#include "addfieldtypeform.h"
#include <qvariant.h>
#include <qmessagebox.h>
#include <qimage.h>
#include <qpixmap.h>
#include "sqlitedb.h"
/*
* Constructs a addFieldTypeForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
addFieldTypeForm::addFieldTypeForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
addFieldTypeForm::~addFieldTypeForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void addFieldTypeForm::languageChange()
{
retranslateUi(this);
}

View File

@@ -1,110 +0,0 @@
#ifndef ADDFIELDTYPEFORM_H
#define ADDFIELDTYPEFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
QT_BEGIN_NAMESPACE
class Ui_addFieldTypeForm
{
public:
QGridLayout *gridLayout;
QLineEdit *typeNameEdit;
QHBoxLayout *hboxLayout;
QSpacerItem *spacer5;
QPushButton *cancelButton;
QPushButton *okButton;
void setupUi(QDialog *addFieldTypeForm)
{
if (addFieldTypeForm->objectName().isEmpty())
addFieldTypeForm->setObjectName(QString::fromUtf8("addFieldTypeForm"));
addFieldTypeForm->resize(294, 98);
gridLayout = new QGridLayout(addFieldTypeForm);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
typeNameEdit = new QLineEdit(addFieldTypeForm);
typeNameEdit->setObjectName(QString::fromUtf8("typeNameEdit"));
gridLayout->addWidget(typeNameEdit, 0, 0, 1, 1);
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
spacer5 = new QSpacerItem(31, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacer5);
cancelButton = new QPushButton(addFieldTypeForm);
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
hboxLayout->addWidget(cancelButton);
okButton = new QPushButton(addFieldTypeForm);
okButton->setObjectName(QString::fromUtf8("okButton"));
okButton->setDefault(true);
hboxLayout->addWidget(okButton);
gridLayout->addLayout(hboxLayout, 1, 0, 1, 1);
retranslateUi(addFieldTypeForm);
QObject::connect(okButton, SIGNAL(clicked()), addFieldTypeForm, SLOT(accept()));
QObject::connect(cancelButton, SIGNAL(clicked()), addFieldTypeForm, SLOT(reject()));
QMetaObject::connectSlotsByName(addFieldTypeForm);
} // setupUi
void retranslateUi(QDialog *addFieldTypeForm)
{
addFieldTypeForm->setWindowTitle(QApplication::translate("addFieldTypeForm", "Enter field type", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("addFieldTypeForm", "Cancel", 0, QApplication::UnicodeUTF8));
okButton->setText(QApplication::translate("addFieldTypeForm", "OK", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class addFieldTypeForm: public Ui_addFieldTypeForm {};
} // namespace Ui
QT_END_NAMESPACE
class addFieldTypeForm : public QDialog, public Ui::addFieldTypeForm
{
Q_OBJECT
public:
addFieldTypeForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~addFieldTypeForm();
protected slots:
virtual void languageChange();
};
#endif // ADDFIELDTYPEFORM_H

View File

@@ -1,49 +0,0 @@
#include "choosetableform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
/*
* Constructs a chooseTableForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
chooseTableForm::chooseTableForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
chooseTableForm::~chooseTableForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void chooseTableForm::languageChange()
{
retranslateUi(this);
}
void chooseTableForm::editPressed()
{
option = comboOptions->currentText();
accept();
}
void chooseTableForm::populateOptions(QStringList entries)
{
comboOptions->clear();
comboOptions->addItems(entries);
}

View File

@@ -1,149 +0,0 @@
#ifndef CHOOSETABLEFORM_H
#define CHOOSETABLEFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
QT_BEGIN_NAMESPACE
class Ui_chooseTableForm
{
public:
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;
QLabel *textLabel2;
QComboBox *comboOptions;
QSpacerItem *spacer13;
QHBoxLayout *hboxLayout1;
QSpacerItem *spacer11;
QPushButton *buttonEdit;
QPushButton *buttonCancel;
void setupUi(QDialog *chooseTableForm)
{
if (chooseTableForm->objectName().isEmpty())
chooseTableForm->setObjectName(QString::fromUtf8("chooseTableForm"));
chooseTableForm->resize(256, 163);
vboxLayout = new QVBoxLayout(chooseTableForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
textLabel2 = new QLabel(chooseTableForm);
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
textLabel2->setWordWrap(false);
hboxLayout->addWidget(textLabel2);
comboOptions = new QComboBox(chooseTableForm);
comboOptions->setObjectName(QString::fromUtf8("comboOptions"));
hboxLayout->addWidget(comboOptions);
vboxLayout->addLayout(hboxLayout);
spacer13 = new QSpacerItem(20, 41, QSizePolicy::Minimum, QSizePolicy::Expanding);
vboxLayout->addItem(spacer13);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
spacer11 = new QSpacerItem(31, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout1->addItem(spacer11);
buttonEdit = new QPushButton(chooseTableForm);
buttonEdit->setObjectName(QString::fromUtf8("buttonEdit"));
hboxLayout1->addWidget(buttonEdit);
buttonCancel = new QPushButton(chooseTableForm);
buttonCancel->setObjectName(QString::fromUtf8("buttonCancel"));
buttonCancel->setDefault(true);
hboxLayout1->addWidget(buttonCancel);
vboxLayout->addLayout(hboxLayout1);
retranslateUi(chooseTableForm);
QObject::connect(buttonCancel, SIGNAL(clicked()), chooseTableForm, SLOT(reject()));
QObject::connect(buttonEdit, SIGNAL(clicked()), chooseTableForm, SLOT(editPressed()));
QMetaObject::connectSlotsByName(chooseTableForm);
} // setupUi
void retranslateUi(QDialog *chooseTableForm)
{
chooseTableForm->setWindowTitle(QApplication::translate("chooseTableForm", "Select table to edit", 0, QApplication::UnicodeUTF8));
textLabel2->setText(QApplication::translate("chooseTableForm", "Table name:", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
comboOptions->setProperty("toolTip", QVariant(QApplication::translate("chooseTableForm", "Choose the table to delete", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
comboOptions->setProperty("whatsThis", QVariant(QApplication::translate("chooseTableForm", "Use this control to select the name of the table to be edited", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
buttonEdit->setText(QApplication::translate("chooseTableForm", "Edit", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonEdit->setProperty("toolTip", QVariant(QApplication::translate("chooseTableForm", "Edit table", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
buttonCancel->setText(QApplication::translate("chooseTableForm", "Cancel", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("chooseTableForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
} // retranslateUi
};
namespace Ui {
class chooseTableForm: public Ui_chooseTableForm {};
} // namespace Ui
QT_END_NAMESPACE
class chooseTableForm : public QDialog, public Ui::chooseTableForm
{
Q_OBJECT
public:
chooseTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~chooseTableForm();
QString option;
public slots:
virtual void editPressed();
virtual void populateOptions( QStringList entries );
protected slots:
virtual void languageChange();
};
#endif // CHOOSETABLEFORM_H

View File

@@ -1,111 +0,0 @@
#include "createindexform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
#include "qmessagebox.h"
/*
* Constructs a createIndexForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
createIndexForm::createIndexForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
createIndexForm::~createIndexForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void createIndexForm::languageChange()
{
retranslateUi(this);
}
void createIndexForm::tableSelected( const QString & entry )
{
tableMap::Iterator it;
for ( it = mtablemap.begin(); it != mtablemap.end(); ++it ) {
QString tname = it.value().getname() ;
//populate the fields with first table name
if ((tname.compare(entry)==0)){
comboFields->clear();
fieldMap::Iterator fit;
fieldMap fmap = it.value().fldmap;
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
comboFields->addItem( fit.value().getname() );
}
}
}
}
void createIndexForm::confirmCreate()
{
bool ok = true;
QString idxname = indexLineEdit->text();
if (idxname.isEmpty()) {
ok = false;
QMessageBox::information( this, QApplication::applicationName(), "Please select a name for the index" );
return;
}
if (idxname.contains(" ")>0) {
ok = false;
QMessageBox::warning( this, QApplication::applicationName(), "Spaces are not allowed in the index name" );
return;
}
if (ok){
createStatement = "CREATE ";
if (comboUnique->currentIndex()==1){
createStatement.append("UNIQUE ");
}
createStatement.append("INDEX ");
createStatement.append(indexLineEdit->text());
createStatement.append(" ON ");
createStatement.append(comboTables->currentText());
createStatement.append("(");
createStatement.append(comboFields->currentText());
createStatement.append(" ");
if (comboOrder->currentIndex()==0){
createStatement.append("ASC");
} else {
createStatement.append("DESC");
}
createStatement.append(");");
accept();
}
}
void createIndexForm::populateTable(const tableMap& rmap)
{
tableMap::ConstIterator it;
for ( it = rmap.begin(); it != rmap.end(); ++it ) {
comboTables->addItem( it.value().getname() );
//populate the fields with first table name
if (it==mtablemap.begin()){
fieldMap::Iterator fit;
fieldMap fmap = it.value().fldmap;
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
comboFields->addItem( fit.value().getname() );
}
}
}
}

View File

@@ -1,276 +0,0 @@
#ifndef CREATEINDEXFORM_H
#define CREATEINDEXFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QGroupBox>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
#include "sqlitedb.h"
QT_BEGIN_NAMESPACE
class Ui_createIndexForm
{
public:
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;
QLabel *textLabel2;
QLineEdit *indexLineEdit;
QGroupBox *groupBox2;
QGridLayout *gridLayout;
QVBoxLayout *vboxLayout1;
QComboBox *comboTables;
QComboBox *comboFields;
QComboBox *comboOrder;
QComboBox *comboUnique;
QVBoxLayout *vboxLayout2;
QLabel *textLabel3;
QLabel *textLabel4;
QLabel *textLabel5;
QLabel *textLabel6;
QHBoxLayout *hboxLayout1;
QSpacerItem *spacer8;
QPushButton *buttonCreate;
QPushButton *buttonCancel;
void setupUi(QDialog *createIndexForm)
{
if (createIndexForm->objectName().isEmpty())
createIndexForm->setObjectName(QString::fromUtf8("createIndexForm"));
createIndexForm->resize(300, 258);
vboxLayout = new QVBoxLayout(createIndexForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
textLabel2 = new QLabel(createIndexForm);
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
textLabel2->setWordWrap(false);
hboxLayout->addWidget(textLabel2);
indexLineEdit = new QLineEdit(createIndexForm);
indexLineEdit->setObjectName(QString::fromUtf8("indexLineEdit"));
hboxLayout->addWidget(indexLineEdit);
vboxLayout->addLayout(hboxLayout);
groupBox2 = new QGroupBox(createIndexForm);
groupBox2->setObjectName(QString::fromUtf8("groupBox2"));
gridLayout = new QGridLayout();
groupBox2->setLayout(gridLayout);
groupBox2->layout()->setSpacing(6);
groupBox2->layout()->setContentsMargins(11, 11, 11, 11);
gridLayout->setAlignment(Qt::AlignTop);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
vboxLayout1 = new QVBoxLayout();
vboxLayout1->setSpacing(6);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
comboTables = new QComboBox(groupBox2);
comboTables->setObjectName(QString::fromUtf8("comboTables"));
vboxLayout1->addWidget(comboTables);
comboFields = new QComboBox(groupBox2);
comboFields->setObjectName(QString::fromUtf8("comboFields"));
vboxLayout1->addWidget(comboFields);
comboOrder = new QComboBox(groupBox2);
comboOrder->setObjectName(QString::fromUtf8("comboOrder"));
vboxLayout1->addWidget(comboOrder);
comboUnique = new QComboBox(groupBox2);
comboUnique->setObjectName(QString::fromUtf8("comboUnique"));
vboxLayout1->addWidget(comboUnique);
gridLayout->addLayout(vboxLayout1, 0, 1, 1, 1);
vboxLayout2 = new QVBoxLayout();
vboxLayout2->setSpacing(6);
vboxLayout2->setObjectName(QString::fromUtf8("vboxLayout2"));
textLabel3 = new QLabel(groupBox2);
textLabel3->setObjectName(QString::fromUtf8("textLabel3"));
textLabel3->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
textLabel3->setWordWrap(false);
vboxLayout2->addWidget(textLabel3);
textLabel4 = new QLabel(groupBox2);
textLabel4->setObjectName(QString::fromUtf8("textLabel4"));
textLabel4->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
textLabel4->setWordWrap(false);
vboxLayout2->addWidget(textLabel4);
textLabel5 = new QLabel(groupBox2);
textLabel5->setObjectName(QString::fromUtf8("textLabel5"));
textLabel5->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
textLabel5->setWordWrap(false);
vboxLayout2->addWidget(textLabel5);
textLabel6 = new QLabel(groupBox2);
textLabel6->setObjectName(QString::fromUtf8("textLabel6"));
textLabel6->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
textLabel6->setWordWrap(false);
vboxLayout2->addWidget(textLabel6);
gridLayout->addLayout(vboxLayout2, 0, 0, 1, 1);
vboxLayout->addWidget(groupBox2);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
spacer8 = new QSpacerItem(51, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout1->addItem(spacer8);
buttonCreate = new QPushButton(createIndexForm);
buttonCreate->setObjectName(QString::fromUtf8("buttonCreate"));
hboxLayout1->addWidget(buttonCreate);
buttonCancel = new QPushButton(createIndexForm);
buttonCancel->setObjectName(QString::fromUtf8("buttonCancel"));
buttonCancel->setDefault(true);
hboxLayout1->addWidget(buttonCancel);
vboxLayout->addLayout(hboxLayout1);
retranslateUi(createIndexForm);
QObject::connect(buttonCreate, SIGNAL(clicked()), createIndexForm, SLOT(confirmCreate()));
QObject::connect(buttonCancel, SIGNAL(clicked()), createIndexForm, SLOT(reject()));
QObject::connect(comboTables, SIGNAL(activated(QString)), createIndexForm, SLOT(tableSelected(QString)));
QMetaObject::connectSlotsByName(createIndexForm);
} // setupUi
void retranslateUi(QDialog *createIndexForm)
{
createIndexForm->setWindowTitle(QApplication::translate("createIndexForm", "Create Index", 0, QApplication::UnicodeUTF8));
textLabel2->setText(QApplication::translate("createIndexForm", "Index name:", 0, QApplication::UnicodeUTF8));
indexLineEdit->setText(QString());
#ifndef QT_NO_TOOLTIP
indexLineEdit->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Enter the name for the new index", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
indexLineEdit->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This area contains the name of the index to be created", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
groupBox2->setTitle(QApplication::translate("createIndexForm", "Define properties:", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
comboTables->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Choose the table to index", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
comboTables->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This control is used to select the table to be indexed. Changing the selected table will automatically update the fields available in the control below", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
#ifndef QT_NO_TOOLTIP
comboFields->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Choose the field to be indexed", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
comboFields->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This control specifies the field to be used as an index", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
comboOrder->clear();
comboOrder->insertItems(0, QStringList()
<< QApplication::translate("createIndexForm", "Ascending", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("createIndexForm", "Descending", 0, QApplication::UnicodeUTF8)
);
#ifndef QT_NO_TOOLTIP
comboOrder->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Choose the index order", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
comboOrder->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This option controls the ordering of the index. Ascending is the recommended ordering", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
comboUnique->clear();
comboUnique->insertItems(0, QStringList()
<< QApplication::translate("createIndexForm", "Allowed", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("createIndexForm", "Not allowed", 0, QApplication::UnicodeUTF8)
);
#ifndef QT_NO_TOOLTIP
comboUnique->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Allow duplicate values in the index field", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
comboUnique->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This control determines if the indexed field allows duplicate values to be inserted into the database. Attempting to insert a duplicate value in an indexed fiield that does not allow this option will generate an error", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
textLabel3->setText(QApplication::translate("createIndexForm", "Table to index:", 0, QApplication::UnicodeUTF8));
textLabel4->setText(QApplication::translate("createIndexForm", "Field to index:", 0, QApplication::UnicodeUTF8));
textLabel5->setText(QApplication::translate("createIndexForm", "Indexing order:", 0, QApplication::UnicodeUTF8));
textLabel6->setText(QApplication::translate("createIndexForm", "Duplicate values:", 0, QApplication::UnicodeUTF8));
buttonCreate->setText(QApplication::translate("createIndexForm", "Create", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonCreate->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Create Index", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
buttonCancel->setText(QApplication::translate("createIndexForm", "Cancel", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
} // retranslateUi
};
namespace Ui {
class createIndexForm: public Ui_createIndexForm {};
} // namespace Ui
QT_END_NAMESPACE
class createIndexForm : public QDialog, public Ui::createIndexForm
{
Q_OBJECT
public:
createIndexForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~createIndexForm();
tableMap mtablemap;
QString createStatement;
public slots:
virtual void tableSelected( const QString & entry );
virtual void confirmCreate();
virtual void populateTable( const tableMap& rmap );
protected slots:
virtual void languageChange();
};
#endif // CREATEINDEXFORM_H

View File

@@ -1,14 +0,0 @@
#include "createtabledialog.h"
#include "ui_createtabledialog.h"
CreateTableDialog::CreateTableDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CreateTableDialog)
{
ui->setupUi(this);
}
CreateTableDialog::~CreateTableDialog()
{
delete ui;
}

View File

@@ -1,22 +0,0 @@
#ifndef CREATETABLEDIALOG_H
#define CREATETABLEDIALOG_H
#include <QDialog>
namespace Ui {
class CreateTableDialog;
}
class CreateTableDialog : public QDialog
{
Q_OBJECT
public:
explicit CreateTableDialog(QWidget *parent = 0);
~CreateTableDialog();
private:
Ui::CreateTableDialog *ui;
};
#endif // CREATETABLEDIALOG_H

View File

@@ -1,183 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreateTableDialog</class>
<widget class="QDialog" name="CreateTableDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>466</width>
<height>364</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labelTableName">
<property name="text">
<string>Table name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditTableName"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget"/>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelFieldName">
<property name="text">
<string>Field name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="ButAddField">
<property name="maximumSize">
<size>
<width>35</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/add</normaloff>:/icons/add</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="labelDataType">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Data type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxDataType">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>INTEGER</string>
</property>
</item>
<item>
<property name="text">
<string>TEXT</string>
</property>
</item>
<item>
<property name="text">
<string>REAL</string>
</property>
</item>
<item>
<property name="text">
<string>BLOB</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxNotNull">
<property name="text">
<string>Not NULL</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="icons/icons.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CreateTableDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CreateTableDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -1,142 +0,0 @@
#include "createtableform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
#include "qmessagebox.h"
#include "addfieldform.h"
/*
* Constructs a createTableForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
createTableForm::createTableForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
init();
}
/*
* Destroys the object and frees any allocated resources
*/
createTableForm::~createTableForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void createTableForm::languageChange()
{
retranslateUi(this);
}
void createTableForm::init()
{
}
//** Create The Table
void createTableForm::confirmCreate()
{
bool ok = true;
QString tabname = tablenameLineEdit->text();
if (tabname.isEmpty()) {
ok = false;
statusBar->showMessage("Please enter a name for the table", 4000);
tablenameLineEdit->setFocus();
return;
}
if (tabname.contains(" ")>0) {
ok = false;
statusBar->showMessage("Spaces are not allowed in the table name", 4000);
tablenameLineEdit->setFocus();
return;
}
if (treeWidget->invisibleRootItem()->childCount() == 0) {
ok = false;
statusBar->showMessage("No fields defined", 4000);
return;
}
/*check field names for empty or illegal names
TODO: move to add
for (int r=0; r<fieldsTable->numRows();r++){
QString rowname = fieldsTable->text(r, 0);
if (rowname.isEmpty()) {
ok = false;
QMessageBox::warning( this, applicationName, "Empty field names are not allowed" );
break;
}
if (rowname.contains(" ")>0) {
ok = false;
QMessageBox::warning( this, applicationName, "Spaces are not allowed in the field names" );
break;
}
}*/
if (!ok){
return;
}
if (ok){
//QString esc("\"");
// #TODO The colnames need to be escaped eg create table 'group'
createStatement = "CREATE TABLE ";
//createStatement.append(esc).append(tabname).append(esc);
createStatement.append(tabname);
createStatement.append(" (");
for(int i = 0; i < treeWidget->invisibleRootItem()->childCount(); i++){
QTreeWidgetItem *item = treeWidget->invisibleRootItem()->child(i);
//createStatement.append(esc).append(item->text(0)).append(esc);
createStatement.append( item->text(0) );
createStatement.append(" ");
createStatement.append(item->text(1));
if(i < treeWidget->invisibleRootItem()->childCount() -1){
createStatement.append(", ");
}
}
createStatement.append(");");
accept();
}
}
void createTableForm::addField()
{
//TODO maybe embedd locally
addFieldForm * addForm = new addFieldForm( this );
addForm->setModal(true);
addForm->setInitialValues(QString(""),QString(""));
if (addForm->exec())
{
QTreeWidgetItem *newItem = new QTreeWidgetItem();
newItem->setText(0, addForm->fname);
newItem->setText(1, addForm->ftype);
newItem->setIcon(0, QIcon(":/icons/field"));
treeWidget->addTopLevelItem(newItem);
}
}
void createTableForm::deleteField()
{
if( !treeWidget->currentItem() ){
return;
}
treeWidget->invisibleRootItem()->removeChild(treeWidget->currentItem());
}
void createTableForm::fieldSelectionChanged()
{
buttonDeleteField->setEnabled( treeWidget->selectionModel()->hasSelection() );
}

View File

@@ -1,237 +0,0 @@
#ifndef CREATETABLEFORM_H
#define CREATETABLEFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QGroupBox>
#include <QtGui/QTreeWidget>
#include <QtGui/QTreeWidgetItem>
#include <QtGui/QHeaderView>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
//#include <QtGui/QSpacerItem>
#include <QtGui/QStatusBar>
#include <QtGui/QVBoxLayout>
#include "sqlitedb.h"
QT_BEGIN_NAMESPACE
class Ui_createTableForm
{
public:
QVBoxLayout *mainVBoxLayout;
QHBoxLayout *topTableLayout;
QGroupBox *groupBoxFields;
QVBoxLayout *groupBoxLayout;
QLabel *textLabel1;
QLineEdit *tablenameLineEdit;
QTreeWidget *treeWidget;
QHBoxLayout *fieldActionsButtonLayout;
QPushButton *buttonAddField;
QPushButton *buttonDeleteField;
QHBoxLayout *bottomButtonLayout;
QPushButton *buttonCreate;
QPushButton *buttonCancel;
QStatusBar *statusBar;
void setupUi(QDialog *createTableForm)
{
if (createTableForm->objectName().isEmpty()){
createTableForm->setObjectName(QString::fromUtf8("createTableForm"));
}
createTableForm->setWindowIcon(QIcon(":/icons/db_new"));
createTableForm->resize(309, 320);
//** Main Layout
mainVBoxLayout = new QVBoxLayout(createTableForm);
mainVBoxLayout->setSpacing(10);
mainVBoxLayout->setContentsMargins(0, 0, 0, 0);
mainVBoxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
//**** Top Table Box ****
topTableLayout = new QHBoxLayout();
topTableLayout->setSpacing(10);
topTableLayout->setContentsMargins(10,10,10,10);
//topTableLayout->setObjectName(QString::fromUtf8("hboxLayout"));
textLabel1 = new QLabel(createTableForm);
//textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
textLabel1->setWordWrap(false);
topTableLayout->addWidget(textLabel1);
tablenameLineEdit = new QLineEdit(createTableForm);
//tablenameLineEdit->setObjectName(QString::fromUtf8("tablenameLineEdit"));
topTableLayout->addWidget(tablenameLineEdit);
mainVBoxLayout->addLayout(topTableLayout);
//**** Fields GroupBox
groupBoxFields = new QGroupBox(createTableForm);
groupBoxFields->setObjectName(QString::fromUtf8("groupBox1"));
groupBoxLayout = new QVBoxLayout();
groupBoxFields->setLayout(groupBoxLayout);
treeWidget = new QTreeWidget();
groupBoxLayout->addWidget(treeWidget);
treeWidget->headerItem()->setText(0, QApplication::translate("createTableForm", "Field name", 0, QApplication::UnicodeUTF8));
treeWidget->headerItem()->setText(1, QApplication::translate("createTableForm", "Field type", 0, QApplication::UnicodeUTF8));
treeWidget->setRootIsDecorated(false);
treeWidget->setAlternatingRowColors(true);
//** Field Action Buttons Box
fieldActionsButtonLayout = new QHBoxLayout();
fieldActionsButtonLayout->setSpacing(6);
fieldActionsButtonLayout->setObjectName(QString::fromUtf8("hboxLayout1"));
fieldActionsButtonLayout->addStretch(10); // force right
//*** Delete Field Button
buttonDeleteField = new QPushButton(groupBoxFields);
buttonDeleteField->setObjectName(QString::fromUtf8("buttonDeleteField"));
buttonDeleteField->setEnabled(false);
buttonDeleteField->setIcon(QIcon(":/icons/field_delete"));
fieldActionsButtonLayout->addWidget(buttonDeleteField);
//*** Add Field Button
buttonAddField = new QPushButton(groupBoxFields);
buttonAddField->setObjectName(QString::fromUtf8("buttonAddField"));
buttonAddField->setIcon(QIcon(":/icons/field_add"));
fieldActionsButtonLayout->addWidget(buttonAddField);
groupBoxLayout->addLayout(fieldActionsButtonLayout);
mainVBoxLayout->addWidget(groupBoxFields);
//***************************************
//*** Bottom Dialog action Buttons
bottomButtonLayout = new QHBoxLayout();
bottomButtonLayout->setSpacing(6);
//bottomButtonLayout->setObjectName(QString::fromUtf8("hboxLayout2"));
bottomButtonLayout->addStretch(10); // force right
//** Cancel Button
buttonCancel = new QPushButton(createTableForm);
//buttonCancel->setObjectName(QString::fromUtf8("buttonCancel"));
buttonCancel->setIcon(QIcon(":/icons/cancel"));
bottomButtonLayout->addWidget(buttonCancel);
//** Create Button
buttonCreate = new QPushButton(createTableForm);
//buttonCreate->setObjectName(QString::fromUtf8("buttonCreate"));
buttonCreate->setIcon(QIcon(":/icons/save"));
bottomButtonLayout->addWidget(buttonCreate);
mainVBoxLayout->addLayout(bottomButtonLayout);
statusBar = new QStatusBar();
mainVBoxLayout->addWidget(statusBar);
//** Setup
retranslateUi(createTableForm);
QObject::connect(buttonCancel, SIGNAL(clicked()), createTableForm, SLOT(reject()));
QObject::connect(buttonCreate, SIGNAL(clicked()), createTableForm, SLOT(confirmCreate()));
QObject::connect(buttonAddField, SIGNAL(clicked()), createTableForm, SLOT(addField()));
QObject::connect(buttonDeleteField, SIGNAL(clicked()), createTableForm, SLOT(deleteField()));
QObject::connect(treeWidget, SIGNAL(itemSelectionChanged()), createTableForm, SLOT(fieldSelectionChanged()));
QMetaObject::connectSlotsByName(createTableForm);
} // setupUi
void retranslateUi(QDialog *createTableForm)
{
createTableForm->setWindowTitle(QApplication::translate("createTableForm", "Create Table", 0, QApplication::UnicodeUTF8));
textLabel1->setText(QApplication::translate("createTableForm", "Table name:", 0, QApplication::UnicodeUTF8));
tablenameLineEdit->setText(QString());
#ifndef QT_NO_TOOLTIP
tablenameLineEdit->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Enter the name for the new table", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
tablenameLineEdit->setProperty("whatsThis", QVariant(QApplication::translate("createTableForm", "Use this control to enter the name of the table to be created.", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
groupBoxFields->setTitle(QApplication::translate("createTableForm", "Define fields:", 0, QApplication::UnicodeUTF8));
buttonAddField->setText(QApplication::translate("createTableForm", "Add", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonAddField->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Add a new field definition", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
buttonAddField->setProperty("whatsThis", QVariant(QApplication::translate("createTableForm", "This button is used to add a new field definition to your table", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
buttonDeleteField->setText(QApplication::translate("createTableForm", "Delete", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonDeleteField->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Delete current field definition", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
buttonDeleteField->setProperty("whatsThis", QVariant(QApplication::translate("createTableForm", "This button is used to delete the currently selected field definition from your table", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
buttonCreate->setText(QApplication::translate("createTableForm", "Create", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonCreate->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Create the table", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
buttonCancel->setText(QApplication::translate("createTableForm", "Cancel", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
} // retranslateUi
};
namespace Ui {
class createTableForm: public Ui_createTableForm {};
} // namespace Ui
QT_END_NAMESPACE
class createTableForm : public QDialog, public Ui::createTableForm
{
Q_OBJECT
public:
createTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~createTableForm();
QString createStatement;
public slots:
virtual void confirmCreate();
virtual void addField();
virtual void deleteField();
virtual void fieldSelectionChanged();
protected slots:
virtual void languageChange();
private:
void init();
};
#endif // CREATETABLEFORM_H

View File

@@ -1,61 +0,0 @@
#include "deleteindexform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
#include "qmessagebox.h"
/*
* Constructs a deleteIndexForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
deleteIndexForm::deleteIndexForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
deleteIndexForm::~deleteIndexForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void deleteIndexForm::languageChange()
{
retranslateUi(this);
}
void deleteIndexForm::confirmDelete()
{
QString msg = "Are you sure you want to delete index ";
msg.append(comboOptions->currentText());
msg.append("?");
if (QMessageBox::warning( this, QApplication::applicationName(),
msg,
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape )
== QMessageBox::Yes ){
option = comboOptions->currentText();
accept();
}
}
void deleteIndexForm::populateOptions(QStringList entries)
{
comboOptions->clear();
comboOptions->addItems(entries);
}

View File

@@ -1,152 +0,0 @@
#ifndef DELETEINDEXFORM_H
#define DELETEINDEXFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
#include "QtCore/QStringRef"
#include "QtCore/QStringList"
#include "sqlitedb.h"
QT_BEGIN_NAMESPACE
class Ui_deleteIndexForm
{
public:
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;
QLabel *textLabel2;
QComboBox *comboOptions;
QSpacerItem *spacer13;
QHBoxLayout *hboxLayout1;
QSpacerItem *spacer11;
QPushButton *buttonDelete;
QPushButton *buttonCancel;
void setupUi(QDialog *deleteIndexForm)
{
if (deleteIndexForm->objectName().isEmpty())
deleteIndexForm->setObjectName(QString::fromUtf8("deleteIndexForm"));
deleteIndexForm->resize(236, 137);
vboxLayout = new QVBoxLayout(deleteIndexForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
textLabel2 = new QLabel(deleteIndexForm);
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
textLabel2->setWordWrap(false);
hboxLayout->addWidget(textLabel2);
comboOptions = new QComboBox(deleteIndexForm);
comboOptions->setObjectName(QString::fromUtf8("comboOptions"));
hboxLayout->addWidget(comboOptions);
vboxLayout->addLayout(hboxLayout);
spacer13 = new QSpacerItem(20, 41, QSizePolicy::Minimum, QSizePolicy::Expanding);
vboxLayout->addItem(spacer13);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
spacer11 = new QSpacerItem(31, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout1->addItem(spacer11);
buttonDelete = new QPushButton(deleteIndexForm);
buttonDelete->setObjectName(QString::fromUtf8("buttonDelete"));
hboxLayout1->addWidget(buttonDelete);
buttonCancel = new QPushButton(deleteIndexForm);
buttonCancel->setObjectName(QString::fromUtf8("buttonCancel"));
buttonCancel->setDefault(true);
hboxLayout1->addWidget(buttonCancel);
vboxLayout->addLayout(hboxLayout1);
retranslateUi(deleteIndexForm);
QObject::connect(buttonDelete, SIGNAL(clicked()), deleteIndexForm, SLOT(confirmDelete()));
QObject::connect(buttonCancel, SIGNAL(clicked()), deleteIndexForm, SLOT(reject()));
QMetaObject::connectSlotsByName(deleteIndexForm);
} // setupUi
void retranslateUi(QDialog *deleteIndexForm)
{
deleteIndexForm->setWindowTitle(QApplication::translate("deleteIndexForm", "Delete Index", 0, QApplication::UnicodeUTF8));
textLabel2->setText(QApplication::translate("deleteIndexForm", "Index name:", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
comboOptions->setProperty("toolTip", QVariant(QApplication::translate("deleteIndexForm", "Choose the index to delete", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
comboOptions->setProperty("whatsThis", QVariant(QApplication::translate("deleteIndexForm", "Use this control to select the name of the index to be deleted", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
buttonDelete->setText(QApplication::translate("deleteIndexForm", "Delete", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonDelete->setProperty("toolTip", QVariant(QApplication::translate("deleteIndexForm", "Delete the selected index", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
buttonCancel->setText(QApplication::translate("deleteIndexForm", "Cancel", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("deleteIndexForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
} // retranslateUi
};
namespace Ui {
class deleteIndexForm: public Ui_deleteIndexForm {};
} // namespace Ui
QT_END_NAMESPACE
class deleteIndexForm : public QDialog, public Ui::deleteIndexForm
{
Q_OBJECT
public:
deleteIndexForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~deleteIndexForm();
QString option;
public slots:
virtual void confirmDelete();
virtual void populateOptions( QStringList entries );
protected slots:
virtual void languageChange();
};
#endif // DELETEINDEXFORM_H

View File

@@ -1,61 +0,0 @@
#include "deletetableform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
#include "qmessagebox.h"
/*
* Constructs a deleteTableForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
deleteTableForm::deleteTableForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
deleteTableForm::~deleteTableForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void deleteTableForm::languageChange()
{
retranslateUi(this);
}
void deleteTableForm::confirmDelete()
{
QString msg = "Are you sure you want to delete table ";
msg.append(comboOptions->currentText());
msg.append("? \n All data in the table will be lost");
if (QMessageBox::warning( this, QApplication::applicationName(),
msg,
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape )
== QMessageBox::Yes ){
option = comboOptions->currentText();
accept();
}
}
void deleteTableForm::populateOptions(QStringList entries)
{
comboOptions->clear();
comboOptions->addItems(entries);
}

View File

@@ -1,152 +0,0 @@
#ifndef DELETETABLEFORM_H
#define DELETETABLEFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
#include "QtCore/QStringRef"
#include "QtCore/QStringList"
#include "sqlitedb.h"
QT_BEGIN_NAMESPACE
class Ui_deleteTableForm
{
public:
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;
QLabel *textLabel2;
QComboBox *comboOptions;
QSpacerItem *spacer13;
QHBoxLayout *hboxLayout1;
QSpacerItem *spacer11;
QPushButton *buttonDelete;
QPushButton *buttonCancel;
void setupUi(QDialog *deleteTableForm)
{
if (deleteTableForm->objectName().isEmpty())
deleteTableForm->setObjectName(QString::fromUtf8("deleteTableForm"));
deleteTableForm->resize(236, 137);
vboxLayout = new QVBoxLayout(deleteTableForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
textLabel2 = new QLabel(deleteTableForm);
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
textLabel2->setWordWrap(false);
hboxLayout->addWidget(textLabel2);
comboOptions = new QComboBox(deleteTableForm);
comboOptions->setObjectName(QString::fromUtf8("comboOptions"));
hboxLayout->addWidget(comboOptions);
vboxLayout->addLayout(hboxLayout);
spacer13 = new QSpacerItem(20, 41, QSizePolicy::Minimum, QSizePolicy::Expanding);
vboxLayout->addItem(spacer13);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
spacer11 = new QSpacerItem(31, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout1->addItem(spacer11);
buttonDelete = new QPushButton(deleteTableForm);
buttonDelete->setObjectName(QString::fromUtf8("buttonDelete"));
hboxLayout1->addWidget(buttonDelete);
buttonCancel = new QPushButton(deleteTableForm);
buttonCancel->setObjectName(QString::fromUtf8("buttonCancel"));
buttonCancel->setDefault(true);
hboxLayout1->addWidget(buttonCancel);
vboxLayout->addLayout(hboxLayout1);
retranslateUi(deleteTableForm);
QObject::connect(buttonCancel, SIGNAL(clicked()), deleteTableForm, SLOT(reject()));
QObject::connect(buttonDelete, SIGNAL(clicked()), deleteTableForm, SLOT(confirmDelete()));
QMetaObject::connectSlotsByName(deleteTableForm);
} // setupUi
void retranslateUi(QDialog *deleteTableForm)
{
deleteTableForm->setWindowTitle(QApplication::translate("deleteTableForm", "Delete Table", 0, QApplication::UnicodeUTF8));
textLabel2->setText(QApplication::translate("deleteTableForm", "Table name:", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
comboOptions->setProperty("toolTip", QVariant(QApplication::translate("deleteTableForm", "Choose the table to delete", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
comboOptions->setProperty("whatsThis", QVariant(QApplication::translate("deleteTableForm", "Use this control to select the name of the table to be deleted", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
buttonDelete->setText(QApplication::translate("deleteTableForm", "Delete", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonDelete->setProperty("toolTip", QVariant(QApplication::translate("deleteTableForm", "Delete the selected table", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
buttonCancel->setText(QApplication::translate("deleteTableForm", "Cancel", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("deleteTableForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
} // retranslateUi
};
namespace Ui {
class deleteTableForm: public Ui_deleteTableForm {};
} // namespace Ui
QT_END_NAMESPACE
class deleteTableForm : public QDialog, public Ui::deleteTableForm
{
Q_OBJECT
public:
deleteTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~deleteTableForm();
QString option;
public slots:
virtual void confirmDelete();
virtual void populateOptions( QStringList entries );
protected slots:
virtual void languageChange();
};
#endif // DELETETABLEFORM_H

View File

@@ -1,22 +0,0 @@
#ifndef DIALOGABOUT_H
#define DIALOGABOUT_H
#include <QDialog>
namespace Ui {
class DialogAbout;
}
class DialogAbout : public QDialog
{
Q_OBJECT
public:
explicit DialogAbout(QWidget *parent = 0);
~DialogAbout();
private:
Ui::DialogAbout *ui;
};
#endif // DIALOGABOUT_H

View File

@@ -1,123 +0,0 @@
#include "editfieldform.h"
#include <qvariant.h>
#include <qmessagebox.h>
#include <qimage.h>
#include <qpixmap.h>
#include "sqlitedb.h"
#include "addfieldtypeform.h"
/*
* Constructs a editFieldForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
editFieldForm::editFieldForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
editFieldForm::~editFieldForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void editFieldForm::languageChange()
{
retranslateUi(this);
}
void editFieldForm::setDB(DBBrowserDB &db)
{
this->pdb = db;
}
void editFieldForm::setInitialValues(bool is_new, QString table, QString fld_name, QString fld_type)
{
original_field_name = QString(fld_name);
table_name = table;
nameLineEdit->setText(fld_name);
this->is_new = is_new;
saveButton->setText(is_new ? "Create Field" : "Change Field");
setWindowIcon(QIcon(is_new ? ":/icons/field_add" : ":/icons/field_edit"));
setWindowTitle(is_new
? QString( "New Field in '%1'").arg(table_name)
: QString("Change Field in '%1'").arg(table_name)
);
QList<QAbstractButton *> buttons = groupRadioTypes->buttons();
for(int i = 0; i < buttons.size(); ++i){
if( buttons.at(i)->property("field_type").toString() == fld_type){
buttons.at(i)->setChecked(true);
return;
}
}
//TODO enable custom
}
void editFieldForm::confirmEdit()
{
nameLineEdit->setText(nameLineEdit->text().trimmed());
QString fieldname = nameLineEdit->text();
if (fieldname.isEmpty()) {
statusBar->showMessage("Field name can not be empty", 4000);
nameLineEdit->setFocus();
return;
}
if (fieldname.contains(" ") > 0) {
statusBar->showMessage("Spaces are not allowed in the field name", 4000);
nameLineEdit->setFocus();
return;
}
field_name = fieldname;
field_type = groupRadioTypes->checkedButton()->property("field_type").toString();
bool ok = pdb.createColumn(table_name, field_name, field_type);
if(!ok){
qDebug(pdb.lastErrorMessage.toUtf8());
return;
}
//qDebug("");
// if(!pdb.executeSQL(sql)){
// qDebug(pdb.lastErrorMessage);
// return;
// }
accept();
}
void editFieldForm::enableSave()
{
saveButton->setEnabled(true);
}
void editFieldForm::getCustomType()
{
addFieldTypeForm * addForm = new addFieldTypeForm( this );
if (addForm->exec())
{
//QString nospaces = addForm->typeNameEdit->text().remove(" ");
QString nospaces = addForm->typeNameEdit->text();
//setInitialValues( nameLineEdit->text(), nospaces );
enableSave();
}
}
void editFieldForm::on_radio_button_clicked(QAbstractButton *button){
qDebug("YES");
//qDebug(button->property("field_type").toString());
}

View File

@@ -1,223 +0,0 @@
#ifndef EDITFIELDFORM_H
#define EDITFIELDFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QRadioButton>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QToolButton>
#include <QtGui/QVBoxLayout>
#include <QtGui/QStatusBar>
#include "sqlitedb.h"
QT_BEGIN_NAMESPACE
class Ui_editFieldForm
{
public:
DBBrowserDB pdb;
QGridLayout *gridLayout;
QVBoxLayout *vboxLayout;
QLabel *lblFieldName;
QLineEdit *nameLineEdit;
QLabel *lblFieldType;
QButtonGroup *groupRadioTypes;
QPushButton *cancelButton;
QPushButton *saveButton;
QStatusBar *statusBar;
void setupUi(QDialog *editFieldForm)
{
if (editFieldForm->objectName().isEmpty()){
editFieldForm->setObjectName(QString::fromUtf8("editFieldForm"));
}
editFieldForm->resize(352, 140);
QVBoxLayout *outerContainerLayout = new QVBoxLayout();
outerContainerLayout->setContentsMargins(0,0,0,0);
editFieldForm->setLayout(outerContainerLayout);
QVBoxLayout *mainVBoxLayout = new QVBoxLayout();
mainVBoxLayout->setContentsMargins(20,20,20,20);
outerContainerLayout->addLayout(mainVBoxLayout);
//** Field Name lbl
lblFieldName = new QLabel(editFieldForm);
lblFieldName->setObjectName(QString::fromUtf8("textLabel1"));
lblFieldName->setWordWrap(false);
mainVBoxLayout->addWidget(lblFieldName);
//** Fiel Name EDIT
nameLineEdit = new QLineEdit(editFieldForm);
nameLineEdit->setObjectName(QString::fromUtf8("nameLineEdit"));
mainVBoxLayout->addWidget(nameLineEdit);
mainVBoxLayout->addSpacing(20);
//** Field Type lbl
lblFieldType = new QLabel(editFieldForm);
lblFieldType->setObjectName(QString::fromUtf8("textLabel2"));
lblFieldType->setWordWrap(false);
mainVBoxLayout->addWidget(lblFieldType);
//**** Field Types Radios
QVBoxLayout *radioLayout = new QVBoxLayout();
mainVBoxLayout->addLayout(radioLayout);
radioLayout->setContentsMargins(20, 0 ,10 ,0);
groupRadioTypes = new QButtonGroup();
groupRadioTypes->setExclusive(true);
QRadioButton *radioTEXT = new QRadioButton();
radioTEXT->setText(QApplication::translate("addFieldForm", "TEXT", 0, QApplication::UnicodeUTF8));
radioTEXT->setProperty("field_type", QVariant("TEXT"));
radioLayout->addWidget(radioTEXT);
groupRadioTypes->addButton(radioTEXT);
QRadioButton *radioNUMERIC = new QRadioButton();
radioNUMERIC->setText(QApplication::translate("addFieldForm", "NUMERIC", 0, QApplication::UnicodeUTF8));
radioNUMERIC->setProperty("field_type", QVariant("NUMERIC"));
radioLayout->addWidget(radioNUMERIC);
groupRadioTypes->addButton(radioNUMERIC);
QRadioButton *radioBLOB = new QRadioButton();
radioBLOB->setText(QApplication::translate("addFieldForm", "BLOB", 0, QApplication::UnicodeUTF8));
radioBLOB->setProperty("field_type", QVariant("BLOB"));
radioLayout->addWidget(radioBLOB);
groupRadioTypes->addButton(radioBLOB);
QRadioButton *radioINTPRIMARY = new QRadioButton();
radioINTPRIMARY->setText(QApplication::translate("addFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8));
radioINTPRIMARY->setProperty("field_type", QVariant("INTEGER PRIMARY KEY"));
radioLayout->addWidget(radioINTPRIMARY);
groupRadioTypes->addButton(radioINTPRIMARY);
QRadioButton *radioCustom = new QRadioButton();
radioCustom->setText(QApplication::translate("addFieldForm", "Custom", 0, QApplication::UnicodeUTF8));
radioCustom->setProperty("field_type", QVariant("__custom__"));
radioLayout->addWidget(radioCustom);
groupRadioTypes->addButton(radioCustom);
QLineEdit *txtCustomType = new QLineEdit();
radioLayout->addWidget(txtCustomType);
txtCustomType->setDisabled(true);
mainVBoxLayout->addSpacing(20);
//*** Bottom Button Layout
QHBoxLayout *bottomButtonBox = new QHBoxLayout();
mainVBoxLayout->addLayout(bottomButtonBox);
bottomButtonBox->setSpacing(6);
bottomButtonBox->addStretch(10);
//** Cancel Button
cancelButton = new QPushButton(editFieldForm);
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
cancelButton->setIcon(QIcon(":/icons/cancel"));
bottomButtonBox->addWidget(cancelButton);
//** Save Button
saveButton = new QPushButton(editFieldForm);
saveButton->setObjectName(QString::fromUtf8("saveButton"));
saveButton->setEnabled(false);
saveButton->setIcon(QIcon(":/icons/save"));
bottomButtonBox->addWidget(saveButton);
statusBar = new QStatusBar();
outerContainerLayout->addWidget(statusBar);
nameLineEdit->setFocus();
retranslateUi(editFieldForm);
QObject::connect(cancelButton, SIGNAL(clicked()), editFieldForm, SLOT(reject()));
QObject::connect(saveButton, SIGNAL(clicked()), editFieldForm, SLOT(confirmEdit()));
QObject::connect(nameLineEdit, SIGNAL(textChanged(QString)), editFieldForm, SLOT(enableSave()));
QObject::connect(groupRadioTypes, SIGNAL(buttonClicked(QAbstractButton*)), editFieldForm, SLOT(on_radio_button_clicked(QAbstractButton*)));
QMetaObject::connectSlotsByName(editFieldForm);
} // setupUi
void retranslateUi(QDialog *editFieldForm)
{
editFieldForm->setWindowTitle(QApplication::translate("editFieldForm", "Edit field name and type", 0, QApplication::UnicodeUTF8));
lblFieldName->setText(QApplication::translate("editFieldForm", "Field name:", 0, QApplication::UnicodeUTF8));
lblFieldType->setText(QApplication::translate("editFieldForm", "Field type:", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("editFieldForm", "Cancel", 0, QApplication::UnicodeUTF8));
saveButton->setText(QApplication::translate("editFieldForm", "Apply Changes", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class editFieldForm: public Ui_editFieldForm {};
} // namespace Ui
QT_END_NAMESPACE
class editFieldForm : public QDialog, public Ui::editFieldForm
{
Q_OBJECT
public:
editFieldForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~editFieldForm();
void setDB(DBBrowserDB &db);
QString table_name;
QString field_name;
QString field_type;
QString original_field_name;
bool is_new;
public slots:
virtual void setInitialValues( bool is_new, QString table, QString fld_name, QString fld_type );
virtual void confirmEdit();
virtual void enableSave();
virtual void getCustomType();
virtual void on_radio_button_clicked(QAbstractButton*);
protected slots:
virtual void languageChange();
};
#endif // EDITFIELDFORM_H

View File

@@ -1,239 +0,0 @@
#include "editform.h"
#include <QTextStream>
#include <qvariant.h>
#include <qmessagebox.h>
#include <qimage.h>
#include <qpixmap.h>
#include <QFileDialog>
#include "sqlitedb.h"
/*
* Constructs a editForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
editForm::editForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
init();
}
/*
* Destroys the object and frees any allocated resources
*/
editForm::~editForm()
{
destroy();
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void editForm::languageChange()
{
retranslateUi(this);
}
void editForm::init()
{
setModified(false);
dataType = kSQLiteMediaType_Void;
dataSize = 0;
dataDepth = 0;
curRow = -1;
curCol = -1;
textEditor->setPlainText("");
textEditor->setFocus();
setDataType(kSQLiteMediaType_Void, 0);
}
void editForm::destroy()
{
}
void editForm::reset()
{
init();
}
void editForm::setModified(bool modifiedstate)
{
modified = modifiedstate;
saveChangesButton->setEnabled(modified);
}
void editForm::enableExport(bool enabled)
{
exportButton->setEnabled(enabled);
}
void editForm::enableTextEditor(bool enabled)
{
textEditor->setReadOnly(!enabled);
}
void editForm::setTextFormat(QString format)
{
// if (format=="Auto")
// {
// textEditor->setTextFormat(Qt::AutoText);
// } else {
// textEditor->setTextFormat(Qt::PlainText);
// }
}
void editForm::setDataType(int type, int size)
{
dataType = type;
dataSize = size;
QString charstr;
switch (dataType ) {
case kSQLiteMediaType_String:
currentTypeLabel->setText("Type of data currently in cell: Text / Numeric");
if (textEditor->toPlainText().length()>1) charstr = QString("chars"); else charstr = QString("char");
currentDataInfo->setText(QString("%1 %2").arg(textEditor->toPlainText().length()).arg(charstr));
editWidgetStack->setCurrentIndex(0);
enableExport(true);
enableTextEditor(true);
break;
case kSQLiteMediaType_Void:
currentTypeLabel->setText("Type of data currently in cell: Empty");
currentDataInfo->setText("");
editWidgetStack->setCurrentIndex(0);
enableExport(false);
enableTextEditor(true);
break;
}
}
void editForm::closeEvent( QCloseEvent * )
{
emit goingAway();
}
void editForm::loadText(QString text, int row, int col)
{
textEditor->setPlainText(text);
textEditor->setFocus();
textEditor->selectAll();
curRow = row;
curCol = col;
if (textEditor->toPlainText().length() > 0)
{
setDataType(kSQLiteMediaType_String, 0);
} else {
setDataType(kSQLiteMediaType_Void, 0);
}
setModified(false);
}
void editForm::importData()
{
int type = kSQLiteMediaType_Void;
QString fileName = QFileDialog::getOpenFileName(
this,
"Choose an image file",
QString(),
QString( "Text files (*.txt);;All files (*.*);;"));
if (QFile::exists(fileName) )
{
type = kSQLiteMediaType_String;
QFile file( fileName );
if ( file.open( QIODevice::ReadOnly ) ) {
QTextStream stream( &file );
textEditor->setPlainText(stream.readAll());
file.close();
}
setModified(true);
}
}
void editForm::exportData()
{
QString filter;
switch (dataType)
{
case kSQLiteMediaType_String:
filter = "Text files (*.txt)";
break;
default:
return;
}
QString fileName = QFileDialog::getSaveFileName(
this,
"Choose a filename to export data",
defaultlocation,
filter);
if (fileName.size() > 0)
{
switch (dataType)
{
case kSQLiteMediaType_String:
{
QFile file(fileName);
if ( file.open( QIODevice::WriteOnly ) ) {
QTextStream stream( &file );
stream << textEditor->toPlainText();
file.close();
}
}
break;
default:
return;
}
}
}
void editForm::clearData()
{
textEditor->setPlainText("");
setDataType(kSQLiteMediaType_Void, 0);
setModified(true);
}
void editForm::saveChanges()
{
if (dataType==kSQLiteMediaType_String)
emit updateRecordText(curRow, curCol, textEditor->toPlainText());
if (dataType==kSQLiteMediaType_Void)
emit updateRecordText(curRow, curCol, QString(""));
setModified(false);
emit goingAway();
}
void editForm::editTextChanged()
{
int newtype = kSQLiteMediaType_String;
if (textEditor->toPlainText().length() == 0)
{
newtype = kSQLiteMediaType_Void;
}
if (newtype!=dataType)
{
setDataType(newtype, 0);
}
setModified(true);
}

View File

@@ -1,306 +0,0 @@
#ifndef EDITFORM_H
#define EDITFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QFrame>
#include <QTextEdit>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QToolButton>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
#include <QtGui/QApplication>
#include <QtCore/QFile>
#include <QtGui/QImage>
#include <QtGui/QStackedWidget>
#include <stdlib.h>
QT_BEGIN_NAMESPACE
class Ui_editForm
{
public:
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;
QToolButton *importButton;
QToolButton *exportButton;
QSpacerItem *spacer11_2;
QToolButton *clearButton;
QStackedWidget *editWidgetStack;
QWidget *WStackPage;
QGridLayout *gridLayout;
QTextEdit *textEditor;
QWidget *WStackPage1;
QGridLayout *gridLayout1;
QLabel *editPixmap;
QFrame *frame9;
QVBoxLayout *vboxLayout1;
QLabel *currentTypeLabel;
QLabel *currentDataInfo;
QHBoxLayout *hboxLayout1;
QSpacerItem *spacer11;
QPushButton *closeButton;
QPushButton *saveChangesButton;
void setupUi(QDialog *editForm)
{
if (editForm->objectName().isEmpty())
editForm->setObjectName(QString::fromUtf8("editForm"));
editForm->resize(366, 431);
editForm->setModal(true);
vboxLayout = new QVBoxLayout(editForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
importButton = new QToolButton(editForm);
importButton->setObjectName(QString::fromUtf8("importButton"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(1), static_cast<QSizePolicy::Policy>(0));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(importButton->sizePolicy().hasHeightForWidth());
importButton->setSizePolicy(sizePolicy);
hboxLayout->addWidget(importButton);
exportButton = new QToolButton(editForm);
exportButton->setObjectName(QString::fromUtf8("exportButton"));
sizePolicy.setHeightForWidth(exportButton->sizePolicy().hasHeightForWidth());
exportButton->setSizePolicy(sizePolicy);
hboxLayout->addWidget(exportButton);
spacer11_2 = new QSpacerItem(81, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacer11_2);
clearButton = new QToolButton(editForm);
clearButton->setObjectName(QString::fromUtf8("clearButton"));
sizePolicy.setHeightForWidth(clearButton->sizePolicy().hasHeightForWidth());
clearButton->setSizePolicy(sizePolicy);
hboxLayout->addWidget(clearButton);
vboxLayout->addLayout(hboxLayout);
editWidgetStack = new QStackedWidget(editForm);
editWidgetStack->setObjectName(QString::fromUtf8("editWidgetStack"));
WStackPage = new QWidget(editWidgetStack);
WStackPage->setObjectName(QString::fromUtf8("WStackPage"));
gridLayout = new QGridLayout(WStackPage);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setContentsMargins(0, 0, 0, 0);
textEditor = new QTextEdit(WStackPage);
textEditor->setObjectName(QString::fromUtf8("textEditor"));
gridLayout->addWidget(textEditor, 0, 0, 1, 1);
editWidgetStack->addWidget(WStackPage);
WStackPage1 = new QWidget(editWidgetStack);
WStackPage1->setObjectName(QString::fromUtf8("WStackPage1"));
gridLayout1 = new QGridLayout(WStackPage1);
gridLayout1->setSpacing(6);
gridLayout1->setContentsMargins(11, 11, 11, 11);
gridLayout1->setObjectName(QString::fromUtf8("gridLayout1"));
gridLayout1->setContentsMargins(0, 0, 0, 0);
editPixmap = new QLabel(WStackPage1);
editPixmap->setObjectName(QString::fromUtf8("editPixmap"));
editPixmap->setMaximumSize(QSize(320, 240));
editPixmap->setScaledContents(true);
editPixmap->setAlignment(Qt::AlignCenter);
editPixmap->setWordWrap(false);
gridLayout1->addWidget(editPixmap, 0, 0, 1, 1);
editWidgetStack->addWidget(WStackPage1);
vboxLayout->addWidget(editWidgetStack);
frame9 = new QFrame(editForm);
frame9->setObjectName(QString::fromUtf8("frame9"));
frame9->setFrameShape(QFrame::Box);
frame9->setFrameShadow(QFrame::Sunken);
vboxLayout1 = new QVBoxLayout(frame9);
vboxLayout1->setSpacing(6);
vboxLayout1->setMargin(11);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
currentTypeLabel = new QLabel(frame9);
currentTypeLabel->setObjectName(QString::fromUtf8("currentTypeLabel"));
currentTypeLabel->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
currentTypeLabel->setWordWrap(false);
vboxLayout1->addWidget(currentTypeLabel);
currentDataInfo = new QLabel(frame9);
currentDataInfo->setObjectName(QString::fromUtf8("currentDataInfo"));
currentDataInfo->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
currentDataInfo->setWordWrap(true);
vboxLayout1->addWidget(currentDataInfo);
vboxLayout->addWidget(frame9);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
spacer11 = new QSpacerItem(90, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout1->addItem(spacer11);
closeButton = new QPushButton(editForm);
closeButton->setObjectName(QString::fromUtf8("closeButton"));
closeButton->setDefault(true);
hboxLayout1->addWidget(closeButton);
saveChangesButton = new QPushButton(editForm);
saveChangesButton->setObjectName(QString::fromUtf8("saveChangesButton"));
saveChangesButton->setEnabled(false);
saveChangesButton->setDefault(false);
hboxLayout1->addWidget(saveChangesButton);
vboxLayout->addLayout(hboxLayout1);
retranslateUi(editForm);
QObject::connect(importButton, SIGNAL(clicked()), editForm, SLOT(importData()));
QObject::connect(exportButton, SIGNAL(clicked()), editForm, SLOT(exportData()));
QObject::connect(saveChangesButton, SIGNAL(clicked()), editForm, SLOT(saveChanges()));
QObject::connect(clearButton, SIGNAL(clicked()), editForm, SLOT(clearData()));
QObject::connect(textEditor, SIGNAL(textChanged()), editForm, SLOT(editTextChanged()));
QObject::connect(closeButton, SIGNAL(clicked()), editForm, SLOT(close()));
QMetaObject::connectSlotsByName(editForm);
} // setupUi
void retranslateUi(QDialog *editForm)
{
editForm->setWindowTitle(QApplication::translate("editForm", "Edit database cell", 0, QApplication::UnicodeUTF8));
importButton->setText(QApplication::translate("editForm", "Import", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
importButton->setProperty("toolTip", QVariant(QApplication::translate("editForm", "Import text", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
importButton->setProperty("whatsThis", QVariant(QApplication::translate("editForm", "Opens a file dialog used to import text to this database cell.", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
exportButton->setText(QApplication::translate("editForm", "Export", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
exportButton->setProperty("toolTip", QVariant(QApplication::translate("editForm", "Export text", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
exportButton->setProperty("whatsThis", QVariant(QApplication::translate("editForm", "Opens a file dialog used to export the contents of this database cell to a text file.", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
clearButton->setText(QApplication::translate("editForm", "Clear", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
clearButton->setProperty("toolTip", QVariant(QApplication::translate("editForm", "Clear cell data", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
clearButton->setProperty("whatsThis", QVariant(QApplication::translate("editForm", "Erases the contents of the cell", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
#ifndef QT_NO_TOOLTIP
frame9->setProperty("toolTip", QVariant(QString()));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
frame9->setProperty("whatsThis", QVariant(QApplication::translate("editForm", "This area displays information about the data present in this database cell", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
currentTypeLabel->setText(QApplication::translate("editForm", "Type of data currently in cell: Empty", 0, QApplication::UnicodeUTF8));
currentDataInfo->setText(QApplication::translate("editForm", "Data information", 0, QApplication::UnicodeUTF8));
closeButton->setText(QApplication::translate("editForm", "Close", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
closeButton->setProperty("toolTip", QVariant(QApplication::translate("editForm", "Close", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
closeButton->setProperty("whatsThis", QVariant(QApplication::translate("editForm", "Close the window without saving changes", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
saveChangesButton->setText(QApplication::translate("editForm", "Apply Changes", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
saveChangesButton->setProperty("toolTip", QVariant(QApplication::translate("editForm", "Save changes to database", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
saveChangesButton->setProperty("whatsThis", QVariant(QApplication::translate("editForm", "Close this window saving changes to the database", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
} // retranslateUi
};
namespace Ui {
class editForm: public Ui_editForm {};
} // namespace Ui
QT_END_NAMESPACE
class editForm : public QDialog, public Ui::editForm
{
Q_OBJECT
public:
editForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~editForm();
int curCol;
int curRow;
QString defaultlocation;
public slots:
virtual void reset();
virtual void setModified( bool modifiedstate );
virtual void enableExport( bool enabled );
virtual void enableTextEditor( bool enabled );
virtual void setTextFormat( QString format );
virtual void setDataType( int type, int size );
virtual void closeEvent( QCloseEvent * );
virtual void loadText( QString text, int row, int col );
virtual void importData();
virtual void exportData();
virtual void clearData();
virtual void saveChanges();
virtual void editTextChanged();
signals:
void goingAway();
void updateRecordText(int, int, QString);
void updateRecordBinary(int, int, unsigned char *);
protected:
bool modified;
int dataType;
int dataSize;
int dataDepth;
protected slots:
virtual void languageChange();
private:
void init();
void destroy();
};
#endif // EDITFORM_H

View File

@@ -1,695 +0,0 @@
#include "edittableform.h"
#include <qvariant.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include <qimage.h>
#include <qpixmap.h>
#include "renametableform.h"
#include "addfieldform.h"
#include "editfieldform.h"
/*
* Constructs a editTableForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
editTableForm::editTableForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
init();
}
/*
* Destroys the object and frees any allocated resources
*/
editTableForm::~editTableForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void editTableForm::languageChange()
{
retranslateUi(this);
}
void editTableForm::init()
{
pdb = NULL;
modified = false;
}
void editTableForm::setActiveTable(DBBrowserDB * thedb, QString tableName)
{
pdb = thedb;
curTable = tableName;
populateFields();
tableLine->setText(curTable);
}
void editTableForm::populateFields()
{
if (!pdb) return;
//make sure we are not using cached information
pdb->updateSchema();
fields= pdb->getTableFields(curTable);
types= pdb->getTableTypes(curTable);
treeWidget->model()->removeRows(0, treeWidget->model()->rowCount());
QStringList::Iterator tt = types.begin();
for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) {
QTreeWidgetItem *fldItem = new QTreeWidgetItem();
//Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView, lasttbitem);
fldItem->setText( 0, *ct );
fldItem->setText( 1, *tt );
//lasttbitem = tbitem;
treeWidget->addTopLevelItem(fldItem);
++tt;
}
}
void editTableForm::renameTable()
{
renameTableForm * renTableForm = new renameTableForm( this );
renTableForm->setModal(true);
renTableForm->setTableName(curTable);
if (renTableForm->exec())
{
QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time
modified = true;
QString newName = renTableForm->getTableName();
//qDebug(newName);
//QString sql;
//do the sql rename here
//if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))){
// goto rollback;
//}
QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(curTable, newName);
//qDebug(sql);
if (!pdb->executeSQL(sql)){
//qDebug("OOPS");
//qDebug( pdb->lastErrorMessage);
QApplication::restoreOverrideCursor();
statusBar->showMessage(pdb->lastErrorMessage, 5000);
QString error("Error renaming table. Message from database engine:\n");
error.append(pdb->lastErrorMessage).append("\n\n").append(sql);
//error.append("").arg(pdb->lastErrorMessage).arg(sql);
//error.append(pdb->lastErrorMessage);
QMessageBox::warning( this, QApplication::applicationName(), error );
return;
}
QApplication::restoreOverrideCursor();
statusBar->showMessage(QString("Renamed %1 to %2").arg(curTable, newName), 5000);
//}
//sQApplication::restoreOverrideCursor(); // restore original cursor
//QString error = "Error renaming table. Message from database engine: ";
//error.append(pdb->lastErrorMessage);
// QMessageBox::warning( this, applicationName, error );
// pdb->executeSQ(QString("DROP TABLE TEMP_TABLE;"));
// //pdb->executeSQL(QString("ROLLBACK;"));
setActiveTable(pdb, curTable);
tableLine->setText(newName);
return;
// WTF is below ???
}
// sql = "CREATE TEMPORARY TABLE TEMP_TABLE(";
// Q3ListViewItemIterator it( fieldListView );
// Q3ListViewItem * item;
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// sql.append(" ");
// sql.append(item->text(1));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "INSERT INTO TEMP_TABLE SELECT ";
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(" FROM ");
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "DROP TABLE ";
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "CREATE TABLE ";
// sql.append(newName);
// sql.append(" (");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// sql.append(" ");
// sql.append(item->text(1));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "INSERT INTO ";
// sql.append(newName);
// sql.append(" SELECT ");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(" FROM TEMP_TABLE;");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback;
// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback;
//
// setActiveTable(pdb, newName);
// }
//
// //everything ok, just return
// QApplication::restoreOverrideCursor(); // restore original cursor
// return;
//
// rollback:
// QApplication::restoreOverrideCursor(); // restore original cursor
//QString error = "Error renaming table. Message from database engine: ";
//error.append(pdb->lastErrorMessage);
// QMessageBox::warning( this, applicationName, error );
// pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"));
// //pdb->executeSQL(QString("ROLLBACK;"));
// setActiveTable(pdb, curTable);
}
void editTableForm::editField()
{
//Q3ListViewItem * item = fieldListView->selectedItem();
if( !treeWidget->currentItem()){
return;
}
QTreeWidgetItem *item = treeWidget->currentItem();
//if (item==0) {
//should never happen, the button would not be active, but...
// return;
// } else {
editFieldForm * fieldForm = new editFieldForm( this );
fieldForm->setModal(true);
fieldForm->setInitialValues(false, "TABLE_NAME", item->text(0), item->text(1));
if (fieldForm->exec())
{
modified = true;
//do the sql rename here
//qDebug(fieldForm->name + fieldForm->type);
item->setText(0,fieldForm->field_name);
item->setText(1,fieldForm->field_name);
}
//not until nested transaction are supported
//if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback;
// QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE(";
// Q3ListViewItemIterator it( fieldListView );
// Q3ListViewItem * item;
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// sql.append(" ");
// sql.append(item->text(1));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "INSERT INTO TEMP_TABLE SELECT ";
// for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) {
// sql.append( *ct );
// if (*ct != fields.last())
// {
// sql.append(", ");
// }
// }
//
// sql.append(" FROM ");
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "DROP TABLE ";
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "CREATE TABLE ";
// sql.append(curTable);
// sql.append(" (");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// sql.append(" ");
// sql.append(item->text(1));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "INSERT INTO ";
// sql.append(curTable);
// sql.append(" SELECT ");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(" FROM TEMP_TABLE;");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback;
// //not until nested transaction are supported
// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback;
//
// setActiveTable(pdb, curTable);
// }
// //everything ok, just return
// QApplication::restoreOverrideCursor(); // restore original cursor
// return;
//
// rollback:
// QApplication::restoreOverrideCursor(); // restore original cursor
// QString error = "Error editing field. Message from database engine: ";
// error.append(pdb->lastErrorMessage);
// QMessageBox::warning( this, applicationName, error );
// //not until nested transaction are supported
// //pdb->executeSQL(QString("ROLLBACK;"));
// setActiveTable(pdb, curTable);
//}
}
void editTableForm::addField()
{
addFieldForm * addForm = new addFieldForm( this );
addForm->setModal(true);
addForm->setInitialValues(QString(""),QString(""));
if (addForm->exec())
{
modified = true;
//Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView);
QTreeWidgetItem *tbitem = new QTreeWidgetItem();
tbitem->setText( 0, addForm->fname);
tbitem->setText( 1, addForm->ftype);
//do the sql creation here
modified = true;
//do the sql rename here
//qDebug(fieldForm->name + fieldForm->type);
QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE(";
}
// Q3ListViewItemIterator it( fieldListView );
// Q3ListViewItem * item;
//not until nested transaction are supported
//if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback;
// {//nest for MSVC support
// for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) {
// sql.append( *ct );
// if (*ct != fields.last())
// {
// sql.append(", ");
// }
// }
// sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "INSERT INTO TEMP_TABLE SELECT ";
// for ( QStringList::Iterator ct1 = fields.begin(); ct1 != fields.end(); ++ct1 ) {
// sql.append( *ct1 );
// if (*ct1 != fields.last())
// {
// sql.append(", ");
// }
// }
// }
//
// sql.append(" FROM ");
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "DROP TABLE ";
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "CREATE TABLE ";
// sql.append(curTable);
// sql.append(" (");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// sql.append(" ");
// sql.append(item->text(1));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
// {//nest for MSVC support
//
// sql = "INSERT INTO ";
// sql.append(curT for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) {
//sql.append( *ct );
//if (*ct != fields.last())
// {
// sql.append(", ");
// }
//}
//sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
// sql = "INSERT INTO TEMP_TABLE SELECT ";
// for ( QStringList::Iterator ct1 = fields.begin(); ct1 != fields.end(); ++ct1 ) {
// sql.append( *ct1 );
// if (*ct1 != fields.last())
// {
// sql.append(", ");
// }
// }
//}
// sql.append(" FROM ");
// sql.append(";");
//if (!pdb->executeSQL(sql)) goto rollback;
//// sql = "DROP TABLE ";
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
// sql = "CREATE TABLE ";
// sql.append(curTable);
// sql.append(" (");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
/// sql.append(" ");
// sql.append(item->text(1));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
//sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
//{//nest for MSVC support
//
// sql = "INSERT INTO ";
// sql.append(curTable);
// sql.append("(");
// for ( QStringList::Iterator ct2 = fields.begin(); ct2 != fields.end(); ++ct2 ) {
// sql.append( *ct2 );
// if (*ct2 != fields.last())
// {
// sql.append(", ");
// }
// }
//}
//{//nest for MSVC support
//
// sql.append(") SELECT ");
// for ( QStringList::Iterator ct3 = fields.begin(); ct3 != fields.end(); ++ct3 ) {
// sql.append( *ct3 );
// if (*ct3 != fields.last())
// {
// sql.append(", ");
// }
// }
//}
//
// sql.append(" FROM TEMP_TABLE;");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback;
// //not until nested transaction are supported
// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback;
//
// setActiveTable(pdb, curTable);
//
// QApplication::restoreOverrideCursor(); // restore original cursor
//return;
//
//rollback:
// QApplication::restoreOverrideCursor(); // restore original cursor
// QString error = "Error adding field. Message from database engine: ";
// error.append(pdb->lastErrorMessage);
// QMessageBox::warning( this, applicationName, error );
//
// //not until nested transaction are supported
// //pdb->executeSQL(QString("ROLLBACK;"));
// setActiveTable(pdb, curTable);able);
// sql.append("(");
// for ( QStringList::Iterator ct2 = fields.begin(); ct2 != fields.end(); ++ct2 ) {
// sql.append( *ct2 );
// if (*ct2 != fields.last())
// {
// sql.append(", ");
// }
// }
// }
// {//nest for MSVC support
//
// sql.append(") SELECT ");
// for ( QStringList::Iterator ct3 = fields.begin(); ct3 != fields.end(); ++ct3 ) {
// sql.append( *ct3 );
// if (*ct3 != fields.last())
// {
// sql.append(", ");
// }
// }
// }
//
// sql.append(" FROM TEMP_TABLE;");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback;
// //not until nested transaction are supported
// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback;
//
// setActiveTable(pdb, curTable);
//
// QApplication::restoreOverrideCursor(); // restore original cursor
// return;
//
// rollback:
// QApplication::restoreOverrideCursor(); // restore original cursor
// QString error = "Error adding field. Message from database engine: ";
// error.append(pdb->lastErrorMessage);
// QMessageBox::warning( this, applicationName, error );
//
// //not until nested transaction are supported
// //pdb->executeSQL(QString("ROLLBACK;"));
// setActiveTable(pdb, curTable);
//s}
}
void editTableForm::removeField()
{
if(!treeWidget->currentItem()){
return;
}
//remItem =
//Q3ListViewItem * remitem = fieldListView->selectedItem();
// if (remitem==0) {
//should never happen, the button would not be active, but...
// return;
//} else {
QString msg = "Are you sure you want to delete field ";
msg.append(treeWidget->currentItem()->text(0));
msg.append("? \n All data currently stored in this field will be lost");
if (QMessageBox::warning( this, QApplication::applicationName(),
msg,
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape )
== QMessageBox::Yes ){
//delete field here
}
/*fields= pdb->getTableFields(curTable);
types= pdb->getTableTypes(curTable);*/
//modified = true;
// delete remitem;
// QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE(";
// Q3ListViewItemIterator it( fieldListView );
// Q3ListViewItem * item;
//
// //not until nested transaction are supported
// // if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback;
//
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// sql.append(" ");
// sql.append(item->text(1));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "INSERT INTO TEMP_TABLE SELECT ";
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
//
// sql.append(" FROM ");
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "DROP TABLE ";
// sql.append(curTable);
// sql.append(";");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "CREATE TABLE ";
// sql.append(curTable);
// sql.append(" (");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// sql.append(" ");
// sql.append(item->text(1));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(");");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// sql = "INSERT INTO ";
// sql.append(curTable);
// sql.append("(");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(") SELECT ");
// it = Q3ListViewItemIterator( fieldListView );
// while ( it.current() ) {
// item = it.current();
// sql.append(item->text(0));
// if (item->nextSibling() != 0)
// {
// sql.append(", ");
// }
// ++it;
// }
// sql.append(" FROM TEMP_TABLE;");
// if (!pdb->executeSQL(sql)) goto rollback;
//
// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback;
// //not until nested transaction are supported
// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback;
//
// setActiveTable(pdb, curTable);
//
// QApplication::restoreOverrideCursor(); // restore original cursor
// return;
//
// rollback:
// QApplication::restoreOverrideCursor(); // restore original cursor
// QString error = "Error removing field. Message from database engine: ";
// error.append(pdb->lastErrorMessage);
// QMessageBox::warning( this, applicationName, error );
//
// //not until nested transaction are supported
// //pdb->executeSQL(QString("ROLLBACK;"));
// setActiveTable(pdb, curTable);
// }
// //}
}
void editTableForm::fieldSelectionChanged()
{
renameFieldButton->setEnabled(treeWidget->selectionModel()->hasSelection());
removeFieldButton->setEnabled(treeWidget->selectionModel()->hasSelection());
}

View File

@@ -1,209 +0,0 @@
#ifndef EDITTABLEFORM_H
#define EDITTABLEFORM_H
#include <qvariant.h>
#include <QtGui/QTreeWidget>
#include <QtGui/QTreeWidgetItem>
#include <QtGui/QToolBar>
#include <QtGui/QToolButton>
#include <QtGui/QGroupBox>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QStatusBar>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
#include <QLabel>
#include "sqlitedb.h"
QT_BEGIN_NAMESPACE
class Ui_editTableForm
{
public:
// QGridLayout *gridLayout;
//QVBoxLayout *vboxLayout;
QLabel *tableLine;
QTreeWidget *treeWidget;
QToolButton *renameTableButton;
QToolButton *renameFieldButton;
QToolButton *removeFieldButton;
QToolButton *addFieldButton;
QPushButton *closeButton;
QStatusBar *statusBar;
void setupUi(QDialog *editTableForm)
{
if (editTableForm->objectName().isEmpty()){
editTableForm->setObjectName(QString::fromUtf8("editTableForm"));
}
editTableForm->setWindowIcon(QIcon(":/icons/table"));
//TODO remember sizes
editTableForm->resize(500, 500);
QVBoxLayout *mainVBoxLayout = new QVBoxLayout();
editTableForm->setLayout(mainVBoxLayout);
mainVBoxLayout->setSpacing(10);
int m = 10;
mainVBoxLayout->setContentsMargins(m,m,m,m);
//******************************************
//** Table Group Box
QGroupBox *grpTable = new QGroupBox();
mainVBoxLayout->addWidget(grpTable);
grpTable->setTitle("Table");
QHBoxLayout *grpTableLayout = new QHBoxLayout();
grpTable->setLayout(grpTableLayout);
grpTableLayout->setSpacing(0);
//** Table Text
tableLine = new QLabel(editTableForm);
tableLine->setObjectName(QString::fromUtf8("tableLine"));
tableLine->setStyleSheet("font-weight: bold; border: 1px solid #dddddd; background-color: white;");
grpTableLayout->addWidget(tableLine);
//** Rename Table
renameTableButton = new QToolButton(editTableForm);
renameTableButton->setObjectName(QString::fromUtf8("renameTableButton"));
renameTableButton->setIcon(QIcon(":/icons/table_modify"));
renameTableButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
grpTableLayout->addWidget(renameTableButton);
//******************************************
//** Fields Group Box
QGroupBox *grpFields = new QGroupBox();
mainVBoxLayout->addWidget(grpFields);
grpFields->setTitle("Fields");
QVBoxLayout *grpFieldsLayout = new QVBoxLayout();
grpFields->setLayout(grpFieldsLayout);
grpFieldsLayout->setSpacing(0);
//** Fields Toolbar **
QToolBar *toolBar = new QToolBar();
grpFieldsLayout->addWidget(toolBar);
//** Add Field
addFieldButton = new QToolButton(editTableForm);
addFieldButton->setObjectName(QString::fromUtf8("addFieldButton"));
addFieldButton->setIcon(QIcon(":/icons/field_add"));
addFieldButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolBar->addWidget(addFieldButton);
//** Rename Field
renameFieldButton = new QToolButton(editTableForm);
renameFieldButton->setObjectName(QString::fromUtf8("renameFieldButton"));
renameFieldButton->setEnabled(false);
renameFieldButton->setIcon(QIcon(":/icons/field_edit"));
renameFieldButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolBar->addWidget(renameFieldButton);
//** Remove Field
removeFieldButton = new QToolButton(editTableForm);
removeFieldButton->setObjectName(QString::fromUtf8("removeFieldButton"));
removeFieldButton->setEnabled(false);
removeFieldButton->setIcon(QIcon(":/icons/field_delete"));
removeFieldButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolBar->addWidget(removeFieldButton);
//**** Tree Widget
treeWidget = new QTreeWidget();
grpFieldsLayout->addWidget(treeWidget);
treeWidget->headerItem()->setText(0, QApplication::translate("createTableForm", "Field name", 0, QApplication::UnicodeUTF8));
treeWidget->headerItem()->setText(1, QApplication::translate("createTableForm", "Field type", 0, QApplication::UnicodeUTF8));
treeWidget->setRootIsDecorated(false);
treeWidget->setAlternatingRowColors(true);
//*** Bottom button box
QHBoxLayout *bottomButtonBox = new QHBoxLayout();
mainVBoxLayout->addLayout(bottomButtonBox);
bottomButtonBox->addStretch(10);
closeButton = new QPushButton(editTableForm);
closeButton->setObjectName(QString::fromUtf8("closeButton"));
bottomButtonBox->addWidget(closeButton);
statusBar = new QStatusBar();
mainVBoxLayout->addWidget(statusBar);
retranslateUi(editTableForm);
QObject::connect(closeButton, SIGNAL(clicked()), editTableForm, SLOT(accept()));
QObject::connect(renameTableButton, SIGNAL(clicked()), editTableForm, SLOT(renameTable()));
QObject::connect(removeFieldButton, SIGNAL(clicked()), editTableForm, SLOT(removeField()));
QObject::connect(addFieldButton, SIGNAL(clicked()), editTableForm, SLOT(addField()));
QObject::connect(renameFieldButton, SIGNAL(clicked()), editTableForm, SLOT(editField()));
QObject::connect(treeWidget, SIGNAL(itemSelectionChanged()), editTableForm, SLOT(fieldSelectionChanged()));
QMetaObject::connectSlotsByName(editTableForm);
} // setupUi
void retranslateUi(QDialog *editTableForm)
{
editTableForm->setWindowTitle(QApplication::translate("editTableForm", "Edit table definition", 0, QApplication::UnicodeUTF8));
treeWidget->headerItem()->setText(0, QApplication::translate("editTableForm", "Field name", 0, QApplication::UnicodeUTF8));
treeWidget->headerItem()->setText(1, QApplication::translate("editTableForm", "Field type", 0, QApplication::UnicodeUTF8));
renameTableButton->setText(QApplication::translate("editTableForm", "Rename table", 0, QApplication::UnicodeUTF8));
renameFieldButton->setText(QApplication::translate("editTableForm", "Edit field", 0, QApplication::UnicodeUTF8));
removeFieldButton->setText(QApplication::translate("editTableForm", "Remove field", 0, QApplication::UnicodeUTF8));
addFieldButton->setText(QApplication::translate("editTableForm", "Add field", 0, QApplication::UnicodeUTF8));
closeButton->setText(QApplication::translate("editTableForm", "Close", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class editTableForm: public Ui_editTableForm {};
} // namespace Ui
QT_END_NAMESPACE
class editTableForm : public QDialog, public Ui::editTableForm
{
Q_OBJECT
public:
editTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~editTableForm();
bool modified;
QString curTable;
public slots:
virtual void setActiveTable( DBBrowserDB * thedb, QString tableName );
virtual void populateFields();
virtual void renameTable();
virtual void editField();
virtual void addField();
virtual void removeField();
virtual void fieldSelectionChanged();
protected:
QStringList types;
QStringList fields;
DBBrowserDB * pdb;
protected slots:
virtual void languageChange();
private:
void init();
};
#endif // EDITTABLEFORM_H

View File

@@ -1,48 +0,0 @@
#include "exporttablecsvform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
/*
* Constructs a exportTableCSVForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
exportTableCSVForm::exportTableCSVForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
exportTableCSVForm::~exportTableCSVForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void exportTableCSVForm::languageChange()
{
retranslateUi(this);
}
void exportTableCSVForm::exportPressed()
{
option = comboOptions->currentText();
accept();
}
void exportTableCSVForm::populateOptions(QStringList entries)
{
comboOptions->clear();
comboOptions->addItems(entries);
}

View File

@@ -1,149 +0,0 @@
#ifndef EXPORTTABLECSVFORM_H
#define EXPORTTABLECSVFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
QT_BEGIN_NAMESPACE
class Ui_exportTableCSVForm
{
public:
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;
QLabel *textLabel2;
QComboBox *comboOptions;
QSpacerItem *spacer13;
QHBoxLayout *hboxLayout1;
QSpacerItem *spacer11;
QPushButton *buttonCancel;
QPushButton *buttonExport;
void setupUi(QDialog *exportTableCSVForm)
{
if (exportTableCSVForm->objectName().isEmpty())
exportTableCSVForm->setObjectName(QString::fromUtf8("exportTableCSVForm"));
exportTableCSVForm->resize(365, 150);
vboxLayout = new QVBoxLayout(exportTableCSVForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
textLabel2 = new QLabel(exportTableCSVForm);
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
textLabel2->setWordWrap(false);
hboxLayout->addWidget(textLabel2);
comboOptions = new QComboBox(exportTableCSVForm);
comboOptions->setObjectName(QString::fromUtf8("comboOptions"));
hboxLayout->addWidget(comboOptions);
vboxLayout->addLayout(hboxLayout);
spacer13 = new QSpacerItem(20, 41, QSizePolicy::Minimum, QSizePolicy::Expanding);
vboxLayout->addItem(spacer13);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
spacer11 = new QSpacerItem(29, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout1->addItem(spacer11);
buttonCancel = new QPushButton(exportTableCSVForm);
buttonCancel->setObjectName(QString::fromUtf8("buttonCancel"));
buttonCancel->setDefault(false);
hboxLayout1->addWidget(buttonCancel);
buttonExport = new QPushButton(exportTableCSVForm);
buttonExport->setObjectName(QString::fromUtf8("buttonExport"));
hboxLayout1->addWidget(buttonExport);
vboxLayout->addLayout(hboxLayout1);
retranslateUi(exportTableCSVForm);
QObject::connect(buttonExport, SIGNAL(clicked()), exportTableCSVForm, SLOT(exportPressed()));
QObject::connect(buttonCancel, SIGNAL(clicked()), exportTableCSVForm, SLOT(reject()));
QMetaObject::connectSlotsByName(exportTableCSVForm);
} // setupUi
void retranslateUi(QDialog *exportTableCSVForm)
{
exportTableCSVForm->setWindowTitle(QApplication::translate("exportTableCSVForm", "Choose table to export as CSV text", 0, QApplication::UnicodeUTF8));
textLabel2->setText(QApplication::translate("exportTableCSVForm", "Table name:", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
comboOptions->setProperty("toolTip", QVariant(QApplication::translate("exportTableCSVForm", "Choose the table to delete", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
comboOptions->setProperty("whatsThis", QVariant(QApplication::translate("exportTableCSVForm", "Use this control to select the name of the table to be deleted", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
buttonCancel->setText(QApplication::translate("exportTableCSVForm", "Cancel", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("exportTableCSVForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
buttonExport->setText(QApplication::translate("exportTableCSVForm", "Export", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
buttonExport->setProperty("toolTip", QVariant(QApplication::translate("exportTableCSVForm", "Delete the selected table", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
} // retranslateUi
};
namespace Ui {
class exportTableCSVForm: public Ui_exportTableCSVForm {};
} // namespace Ui
QT_END_NAMESPACE
class exportTableCSVForm : public QDialog, public Ui::exportTableCSVForm
{
Q_OBJECT
public:
exportTableCSVForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~exportTableCSVForm();
QString option;
public slots:
virtual void exportPressed();
virtual void populateOptions( QStringList entries );
protected slots:
virtual void languageChange();
};
#endif // EXPORTTABLECSVFORM_H

View File

@@ -1,87 +0,0 @@
#include "findform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
/*
* Constructs a findForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
findForm::findForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
findForm::~findForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void findForm::languageChange()
{
retranslateUi(this);
}
void findForm::showResults(resultMap rmap)
{
findTableWidget->clearContents();
findTableWidget->setSortingEnabled(false);
resultMap::Iterator it;
findTableWidget->setRowCount(rmap.size());
for ( it = rmap.begin(); it != rmap.end(); ++it ) {
QString firstline = it.value().section( '\n', 0,0 );
findTableWidget->setItem( it.key(), 0, new QTableWidgetItem( QString::number(it.key() + 1) ) );
findTableWidget->setItem( it.key(), 1, new QTableWidgetItem( firstline) );
}
QString results = "Found: ";
results.append(QString::number(findTableWidget->rowCount()));
resultsLabel->setText(results);
findTableWidget->setSortingEnabled(true);
}
void findForm::find()
{
emit lookfor( findFieldCombobox->currentText(), findOperatorComboBox->currentText(),searchLine->text() );
}
void findForm::resetFields(QStringList fieldlist)
{
findFieldCombobox->clear();
findFieldCombobox->addItems(fieldlist);
}
void findForm::resetResults()
{
findTableWidget->clearContents();
resultsLabel->setText("Found: 0");
}
void findForm::recordSelected( QTableWidgetItem * witem)
{
if (witem) {
int recNum = witem->text().toInt();
emit showrecord(recNum);
}
}
void findForm::closeEvent( QCloseEvent * )
{
emit goingAway();
}

View File

@@ -1,193 +0,0 @@
#ifndef FINDFORM_H
#define FINDFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QTableWidget>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
#include "sqlitedb.h"
QT_BEGIN_NAMESPACE
class Ui_findForm
{
public:
QVBoxLayout *vboxLayout;
QGridLayout *gridLayout;
QPushButton *searchButton;
QComboBox *findFieldCombobox;
QLineEdit *searchLine;
QComboBox *findOperatorComboBox;
QTableWidget *findTableWidget;
QHBoxLayout *hboxLayout;
QLabel *resultsLabel;
QSpacerItem *spacer10;
void setupUi(QDialog *findForm)
{
if (findForm->objectName().isEmpty())
findForm->setObjectName(QString::fromUtf8("findForm"));
findForm->resize(239, 319);
vboxLayout = new QVBoxLayout(findForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
searchButton = new QPushButton(findForm);
searchButton->setObjectName(QString::fromUtf8("searchButton"));
gridLayout->addWidget(searchButton, 1, 2, 1, 1);
findFieldCombobox = new QComboBox(findForm);
findFieldCombobox->setObjectName(QString::fromUtf8("findFieldCombobox"));
gridLayout->addWidget(findFieldCombobox, 0, 0, 1, 1);
searchLine = new QLineEdit(findForm);
searchLine->setObjectName(QString::fromUtf8("searchLine"));
gridLayout->addWidget(searchLine, 1, 0, 1, 2);
findOperatorComboBox = new QComboBox(findForm);
findOperatorComboBox->setObjectName(QString::fromUtf8("findOperatorComboBox"));
gridLayout->addWidget(findOperatorComboBox, 0, 1, 1, 2);
vboxLayout->addLayout(gridLayout);
findTableWidget = new QTableWidget(findForm);
findTableWidget->setColumnCount(2);
findTableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem( QObject::tr("Record") ));
findTableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem( QObject::tr("Data") ));
findTableWidget->setObjectName(QString::fromUtf8("findListView"));
findTableWidget->setMidLineWidth(30);
//findTableWidget->setResizePolicy(Q3ScrollView::Manual);
//findTableWidget->setResizeMode(Q3ListView::LastColumn);
vboxLayout->addWidget(findTableWidget);
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
resultsLabel = new QLabel(findForm);
resultsLabel->setObjectName(QString::fromUtf8("resultsLabel"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(5));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(resultsLabel->sizePolicy().hasHeightForWidth());
resultsLabel->setSizePolicy(sizePolicy);
resultsLabel->setWordWrap(false);
hboxLayout->addWidget(resultsLabel);
spacer10 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacer10);
vboxLayout->addLayout(hboxLayout);
retranslateUi(findForm);
QObject::connect(searchButton, SIGNAL(clicked()), findForm, SLOT(find()));
QObject::connect(findTableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), findForm, SLOT(recordSelected(QTableWidgetItem*)));
QMetaObject::connectSlotsByName(findForm);
} // setupUi
void retranslateUi(QDialog *findForm)
{
findForm->setWindowTitle(QObject::tr("Find"));
searchButton->setText(QObject::tr("Search"));
searchButton->setProperty("toolTip", QVariant(QObject::tr("Perform the search")));
searchButton->setProperty("whatsThis", QVariant(QObject::tr("This button starts the search process")));
findFieldCombobox->clear();
findFieldCombobox->insertItems(0, QStringList()
<< QObject::tr("user")
);
findFieldCombobox->setProperty("toolTip", QVariant(QObject::tr("Field to be searched")));
findFieldCombobox->setProperty("whatsThis", QVariant(QObject::tr("Use this control to select the field to be searched in the current table")));
searchLine->setProperty("toolTip", QVariant(QObject::tr("Enter values or words to search")));
searchLine->setProperty("whatsThis", QVariant(QObject::tr("This is a place to enter the word or number to be searched in the database")));
findOperatorComboBox->clear();
findOperatorComboBox->insertItems(0, QStringList()
<< QObject::tr("=")
<< QObject::tr("contains")
<< QObject::tr(">")
<< QObject::tr(">=")
<< QObject::tr("<=")
<< QObject::tr("<")
);
findOperatorComboBox->setProperty("toolTip", QVariant(QObject::tr("Search criteria: use 'contains' for partial matches")));
findOperatorComboBox->setProperty("whatsThis", QVariant(QObject::tr("This control is used to select the search criteria used to look for the search term in the database. Use '=' or 'contains' to find words, and the comparison symbols to filter numeric data.")));
findTableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem( QObject::tr("Record") ));
findTableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem( QObject::tr("Data") ));
findTableWidget->setProperty("whatsThis", QVariant(QObject::tr("Results of the search will appear in this area. Click on a result to select the corresponding record in the database")));
resultsLabel->setText(QObject::tr("Found:"));
} // retranslateUi
};
namespace Ui {
class findForm: public Ui_findForm {};
} // namespace Ui
QT_END_NAMESPACE
class findForm : public QDialog, public Ui::findForm
{
Q_OBJECT
public:
findForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~findForm();
public slots:
virtual void showResults( resultMap rmap );
virtual void find();
virtual void resetFields( QStringList fieldlist );
virtual void resetResults();
virtual void recordSelected( QTableWidgetItem * witem );
virtual void closeEvent( QCloseEvent * );
signals:
void lookfor(const QString&, const QString&, const QString&);
void showrecord(int);
void goingAway();
protected slots:
virtual void languageChange();
};
#endif // FINDFORM_H

Binary file not shown.

Before

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 733 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 587 B

BIN
src/icons/help.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

View File

@@ -12,19 +12,23 @@
<file alias="field_edit">page_edit.png</file>
<file alias="field_delete">page_delete.png</file>
<file alias="field_add">page_add.png</file>
<file alias="add">add.png</file>
<file alias="save">accept.png</file>
<file alias="cancel">bullet_black.png</file>
<file alias="field">page_green.png</file>
<file alias="table">table.png</file>
<file alias="index">tag_blue.png</file>
<file alias="refresh">view-refresh.png</file>
<file alias="view_delete">picture_delete.png</file>
<file alias="view">picture.png</file>
<file alias="view_create">picture_add.png</file>
<file alias="trigger">script.png</file>
<file alias="trigger_create">script_add.png</file>
<file alias="trigger_delete">script_delete.png</file>
<file alias="searchfind">magnifier.png</file>
<file alias="settings">wrench.png</file>
<file alias="whatis">help.png</file>
</qresource>
<qresource prefix="/oldimages">
<file alias="128">oldimages/128.png</file>
<file alias="icon16">oldimages/icone16.png</file>
<file alias="log">oldimages/log.png</file>
<file alias="searchfind">oldimages/searchfind.png</file>
<file alias="whatis">oldimages/whatis.png</file>
</qresource>
</RCC>

BIN
src/icons/magnifier.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 B

BIN
src/icons/picture.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

BIN
src/icons/picture_add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

BIN
src/icons/script.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

BIN
src/icons/script_add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

BIN
src/icons/script_delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

BIN
src/icons/wrench.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

View File

@@ -1,256 +0,0 @@
#include "importcsvform.h"
#include <qvariant.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include <qimage.h>
#include <qpixmap.h>
#include <QProgressDialog>
/*
* Constructs a importCSVForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
importCSVForm::importCSVForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
init();
}
/*
* Destroys the object and frees any allocated resources
*/
importCSVForm::~importCSVForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void importCSVForm::languageChange()
{
retranslateUi(this);
}
void importCSVForm::init()
{
pdb = 0;
sep=',';
quote='"';
}
void importCSVForm::initialize(QString & csvfile, DBBrowserDB * db)
{
pdb = db;
csvfilename = csvfile;
preview();
}
void importCSVForm::createButtonPressed()
{
QString tabname;
QStringList fieldList;
QString sql;
//minimun validation for tabname
tabname = tableNameEdit->text();
if (tabname.isEmpty()) {
QMessageBox::information( this, QApplication::applicationName(), "Please choose a name for the new table that will hold the csv data" );
return;
}
tabname.replace(" ", "");
tabname.replace('"', "");
tabname.replace("'","");
tabname.replace(",","");
tabname.replace(";","");
if (tabname.isEmpty()) {
tabname = "tempTable";
}
//parse all csv data
curList = pdb->decodeCSV(csvfilename, sep, quote, -1, &numfields);
//can not operate on an empty result
if (numfields==0) return;
if (extractFieldNamesCheckbox->isChecked())
{
int cfieldnum = 0;
for ( QStringList::Iterator ct = curList.begin(); ct != curList.end(); ++ct ) {
QString thisfield = *ct;
//basic conforming
thisfield.replace(" ", "");
thisfield.replace('"', "");
thisfield.replace("'","");
thisfield.replace(",","");
thisfield.replace(";","");
if (thisfield.isEmpty()) thisfield.append("field");
fieldList << thisfield;
cfieldnum++;
if (cfieldnum==numfields) break;
}
//pop the fieldnames
for (int e=0; e<numfields; e++)
{
curList.pop_front();
}
} else {
//generate temp fieldnames
for (int e=0; e<numfields; e++)
{
fieldList << QString("field").append(QString::number(e+1,10));
}
}
QProgressDialog progress("Inserting data...", "Cancel", 0, curList.size());
progress.setWindowModality(Qt::ApplicationModal);
sql = "CREATE TABLE ";
sql.append(tabname);
sql.append(" (");
for (int r=0; r<numfields;r++){
sql.append(fieldList[r]);
//createStatement.append(" text");
if (r<(numfields - 1))
sql.append(", ");
}
sql.append(");");
//declare local variables we will need before the rollback jump
int colNum = 0;
//begin a savepoint, so we can rollback in case of any errors during importing
//db needs to be saved or an error will occur
if (!pdb->executeSQL(QString("SAVEPOINT CSVIMPORT;"), false, false)) goto rollback;
//execute the create table statement
if (!pdb->executeSQL(sql, false, false)) goto rollback;
{//avoid error on MSVC due to rollback label
//now lets import all data, one row at a time
for ( int i=0; i < curList.size(); ++i ) {
if (colNum==0)
{
sql = "INSERT INTO ";
sql.append(tabname);
sql.append(" VALUES(");
}
//need to mprintf here
//sql.append(*ct);
char * formSQL = sqlite3_mprintf("%Q",(const char *) curList[i].toUtf8());
sql.append(formSQL);
if (formSQL) sqlite3_free(formSQL);
colNum++;
if (colNum<numfields)
{
sql.append(",");
} else {
colNum = 0;
sql.append(");");
if (!pdb->executeSQL(sql, false, false)) goto rollback;
}
progress.setValue(i);
if (progress.wasCanceled()) goto rollback;
}
}
//everything ok, just return
//Do not commit, it will be done automatically on save
if (!pdb->executeSQL(QString("RELEASE CSVIMPORT;"))) goto rollback;
pdb->setDirtyDirect(true);
QApplication::restoreOverrideCursor(); // restore original cursor
accept();
return;
rollback:
progress.cancel();
QApplication::restoreOverrideCursor(); // restore original cursor
QString error = "Error importing data. Message from database engine: ";
error.append(pdb->lastErrorMessage);
QMessageBox::warning( this, QApplication::applicationName(), error );
//we will uncomment this when SQLite support nested transactions
pdb->executeSQL(QString("ROLLBACK TO SAVEPOINT CSVIMPORT;"), false, false);
}
void importCSVForm::preview()
{
//get only 20 lines, for preview
int maxrecs = 20;
curList = pdb->decodeCSV(csvfilename, sep, quote, maxrecs, &numfields);
//qDebug("count = %d, numfields = %d", curList .count(), numfields);
previewTable->clear();
previewTable->setColumnCount(curList.size());
//can not operate on an empty result
if (numfields==0) return;
if (extractFieldNamesCheckbox->isChecked())
{
previewTable->setHorizontalHeaderLabels(curList);
//pop the fieldnames
for (int e=0; e<numfields; e++)
{
curList.pop_front();
}
}
previewTable->setRowCount(curList.count()/numfields);
int rowNum = 0;
int colNum = 0;
for ( QStringList::Iterator ct = curList .begin(); ct != curList .end(); ++ct ) {
if (colNum==0) previewTable->setVerticalHeaderItem( rowNum, new QTableWidgetItem( QString::number(rowNum) ) );
previewTable->setItem(rowNum, colNum, new QTableWidgetItem( *ct ) );
colNum++;
if (colNum==numfields)
{
colNum = 0;
rowNum ++;
}
}
}
void importCSVForm::fieldSeparatorChanged()
{
QString curText =fieldBox->currentText();
if (curText.compare(QString("TAB"))==0)
{
sep = 9;
} else {
QChar qsep = curText.at(0);
sep = (char) qsep.toAscii();
}
preview();
}
void importCSVForm::textQuoteChanged()
{
QString curText = quoteBox->currentText();
if(curText.length() > 0)
{
QChar qquote = curText.at(0);
quote = (char) qquote.toAscii();
}
preview();
}
void importCSVForm::extractFieldNamesChanged( bool enabled )
{
preview();
}

View File

@@ -1,243 +0,0 @@
#ifndef IMPORTCSVFORM_H
#define IMPORTCSVFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QTableWidget>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCheckBox>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
#include <QtCore/QStringRef>
#include <QtCore/QStringList>
#include "sqlitedb.h"
QT_BEGIN_NAMESPACE
class Ui_importCSVForm
{
public:
QVBoxLayout *vboxLayout;
QGridLayout *gridLayout;
QLabel *textLabel3;
QLineEdit *tableNameEdit;
QCheckBox *extractFieldNamesCheckbox;
QHBoxLayout *hboxLayout;
QVBoxLayout *vboxLayout1;
QLabel *textLabel1;
QLabel *textLabel2;
QSpacerItem *spacer15;
QVBoxLayout *vboxLayout2;
QComboBox *fieldBox;
QComboBox *quoteBox;
QSpacerItem *spacer14;
QTableWidget *previewTable;
QHBoxLayout *hboxLayout1;
QSpacerItem *spacer13;
QPushButton *cancelButton;
QPushButton *createButton;
void setupUi(QDialog *importCSVForm)
{
if (importCSVForm->objectName().isEmpty())
importCSVForm->setObjectName(QString::fromUtf8("importCSVForm"));
importCSVForm->resize(372, 382);
importCSVForm->setModal(true);
vboxLayout = new QVBoxLayout(importCSVForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
textLabel3 = new QLabel(importCSVForm);
textLabel3->setObjectName(QString::fromUtf8("textLabel3"));
textLabel3->setWordWrap(false);
gridLayout->addWidget(textLabel3, 0, 0, 1, 1);
tableNameEdit = new QLineEdit(importCSVForm);
tableNameEdit->setObjectName(QString::fromUtf8("tableNameEdit"));
gridLayout->addWidget(tableNameEdit, 0, 1, 1, 1);
extractFieldNamesCheckbox = new QCheckBox(importCSVForm);
extractFieldNamesCheckbox->setObjectName(QString::fromUtf8("extractFieldNamesCheckbox"));
gridLayout->addWidget(extractFieldNamesCheckbox, 2, 0, 1, 2);
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
vboxLayout1 = new QVBoxLayout();
vboxLayout1->setSpacing(6);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
textLabel1 = new QLabel(importCSVForm);
textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
textLabel1->setWordWrap(false);
vboxLayout1->addWidget(textLabel1);
textLabel2 = new QLabel(importCSVForm);
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
textLabel2->setWordWrap(false);
vboxLayout1->addWidget(textLabel2);
hboxLayout->addLayout(vboxLayout1);
spacer15 = new QSpacerItem(81, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacer15);
vboxLayout2 = new QVBoxLayout();
vboxLayout2->setSpacing(6);
vboxLayout2->setObjectName(QString::fromUtf8("vboxLayout2"));
fieldBox = new QComboBox(importCSVForm);
fieldBox->setObjectName(QString::fromUtf8("fieldBox"));
vboxLayout2->addWidget(fieldBox);
quoteBox = new QComboBox(importCSVForm);
quoteBox->setObjectName(QString::fromUtf8("quoteBox"));
vboxLayout2->addWidget(quoteBox);
hboxLayout->addLayout(vboxLayout2);
gridLayout->addLayout(hboxLayout, 1, 0, 1, 2);
vboxLayout->addLayout(gridLayout);
spacer14 = new QSpacerItem(138, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
vboxLayout->addItem(spacer14);
previewTable = new QTableWidget(importCSVForm);
previewTable->setObjectName(QString::fromUtf8("previewTable"));
previewTable->setRowCount(0);
previewTable->setColumnCount(0);
previewTable->setSelectionMode(QTableWidget::NoSelection);
vboxLayout->addWidget(previewTable);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
spacer13 = new QSpacerItem(41, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout1->addItem(spacer13);
cancelButton = new QPushButton(importCSVForm);
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
hboxLayout1->addWidget(cancelButton);
createButton = new QPushButton(importCSVForm);
createButton->setObjectName(QString::fromUtf8("createButton"));
hboxLayout1->addWidget(createButton);
vboxLayout->addLayout(hboxLayout1);
retranslateUi(importCSVForm);
QObject::connect(cancelButton, SIGNAL(clicked()), importCSVForm, SLOT(reject()));
QObject::connect(createButton, SIGNAL(clicked()), importCSVForm, SLOT(createButtonPressed()));
QObject::connect(fieldBox, SIGNAL(activated(int)), importCSVForm, SLOT(fieldSeparatorChanged()));
QObject::connect(quoteBox, SIGNAL(activated(int)), importCSVForm, SLOT(textQuoteChanged()));
QObject::connect(extractFieldNamesCheckbox, SIGNAL(toggled(bool)), importCSVForm, SLOT(extractFieldNamesChanged(bool)));
QMetaObject::connectSlotsByName(importCSVForm);
} // setupUi
void retranslateUi(QDialog *importCSVForm)
{
importCSVForm->setWindowTitle(QApplication::translate("importCSVForm", "Create table from CSV file", 0, QApplication::UnicodeUTF8));
textLabel3->setText(QApplication::translate("importCSVForm", "New table name:", 0, QApplication::UnicodeUTF8));
extractFieldNamesCheckbox->setText(QApplication::translate("importCSVForm", "Extract field names from first line", 0, QApplication::UnicodeUTF8));
textLabel1->setText(QApplication::translate("importCSVForm", "Field separator:", 0, QApplication::UnicodeUTF8));
textLabel2->setText(QApplication::translate("importCSVForm", "Text quote character:", 0, QApplication::UnicodeUTF8));
fieldBox->clear();
fieldBox->insertItems(0, QStringList()
<< QApplication::translate("importCSVForm", ",", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("importCSVForm", ";", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("importCSVForm", "TAB", 0, QApplication::UnicodeUTF8)
);
quoteBox->clear();
quoteBox->insertItems(0, QStringList()
<< QApplication::translate("importCSVForm", "\"", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("importCSVForm", "'", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("importCSVForm", "\\", 0, QApplication::UnicodeUTF8)
<< QString()
);
cancelButton->setText(QApplication::translate("importCSVForm", "Cancel", 0, QApplication::UnicodeUTF8));
createButton->setText(QApplication::translate("importCSVForm", "Create", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class importCSVForm: public Ui_importCSVForm {};
} // namespace Ui
QT_END_NAMESPACE
class importCSVForm : public QDialog, public Ui::importCSVForm
{
Q_OBJECT
public:
importCSVForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~importCSVForm();
public slots:
virtual void initialize( QString & csvfile, DBBrowserDB * db );
virtual void createButtonPressed();
virtual void preview();
virtual void fieldSeparatorChanged();
virtual void textQuoteChanged();
virtual void extractFieldNamesChanged( bool enabled );
protected:
QStringList curList;
char quote;
char sep;
int numfields;
QString csvfilename;
DBBrowserDB * pdb;
protected slots:
virtual void languageChange();
private:
void init();
};
#endif // IMPORTCSVFORM_H

View File

@@ -1,6 +1,9 @@
#include "mainwindow.h"
#include "MainWindow.h"
#include <QApplication>
#include <QTextCodec>
#include <QTranslator>
#include <QLibraryInfo>
#include <QLocale>
#if defined(Q_WS_MAC)
#include <Carbon/Carbon.h>
@@ -71,8 +74,22 @@ static pascal OSErr odocHandler(const AppleEvent* inEvent, AppleEvent*
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
a.setOrganizationName("duckmansoftware");
a.setApplicationName("SQLite Database Browser " + QString(APP_VERSION));
a.setOrganizationName("sqlitebrowser");
a.setApplicationName("SQLite Database Browser");
// Set character encoding to UTF8
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
// Enable translation
QTranslator translator;
translator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
a.installTranslator(&translator);
QTranslator apptranslator;
apptranslator.load("translations/tr_" + QLocale::system().name());
a.installTranslator(&apptranslator);
MainWindow w;
#if defined(Q_WS_MAC)
AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,

File diff suppressed because it is too large Load Diff

View File

@@ -1,238 +0,0 @@
#ifndef MAINFORM_H
#define MAINFORM_H
#include <QVariant>
#include <QTableView>
#include <QStandardItemModel>
#include <QtGui/QTreeWidget>
#include <QtGui/QMainWindow>
#include <QTableWidget>
#include <QTextEdit>
#include <QtGui/QToolBar>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QTabWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
#include <QtCore/QPoint>
#include <QDragEnterEvent>
#include "sqlitedb.h"
#define ORDERMODE_ASC 0
#define ORDERMODE_DESC 1
class SQLLogDock;
class editForm;
class findForm;
class SQLiteSyntaxHighlighter;
class MainWindow : public QMainWindow
{
Q_OBJECT
private:
SQLLogDock * logWin;
QAction *fileNewAction;
QAction *fileOpenAction;
QAction *fileExitAction;
QAction *editCopyAction;
QAction *editPasteAction;
QAction *editFindAction;
QAction *helpContentsAction;
QAction *helpIndexAction;
QAction *helpAboutAction;
QAction *fileCloseAction;
QAction *newRecordAction;
QAction *fileCompactAction;
QAction *helpWhatsThisAction;
QAction *sqlLogAction;
QAction *viewDBToolbarAction;
QAction *fileImportCSVAction;
QAction *fileExportCSVAction;
QAction *fileSaveAction;
QAction *fileRevertAction;
//QAction *fileImportAction;
//QAction *fileExportAction;
QAction *editCreateTableAction;
QAction *editDeleteTableAction;
QAction *editModifyTableAction;
QAction *editCreateIndexAction;
QAction *editDeleteIndexAction;
QAction *fileImportSQLAction;
QAction *fileExportSQLAction;
QAction *editPreferencesAction;
QWidget *widget;
QVBoxLayout *vboxLayout;
QTabWidget *mainTab;
QWidget *structure;
QVBoxLayout *vboxLayout1;
QTreeWidget *dbTreeWidget;
QMenu *popupTableMenu;
QMenu *popupFieldMenu;
QAction *editModifyTableActionPopup;
QAction *editDeleteTableActionPopup;
QAction *editAddFieldActionPopup;
QAction *editModifyFieldActionPopup;
QAction *editDeleteFieldActionPopup;
QWidget *browser;
QVBoxLayout *vboxLayout2;
QHBoxLayout *hboxLayout;
QLabel *textLabel1;
QComboBox *comboBrowseTable;
QPushButton *buttonFind;
QPushButton *buttonRefresh;
QSpacerItem *spacer1;
QPushButton *buttonNewRecord;
QPushButton *buttonDeleteRecord;
QTableWidget *dataTable;
QHBoxLayout *hboxLayout1;
QPushButton *buttonPrevious;
QLabel *labelRecordset;
QPushButton *buttonNext;
QSpacerItem *spacer4;
QPushButton *buttonGoto;
QLineEdit *editGoto;
QWidget *query;
QVBoxLayout *vboxLayout3;
QLabel *textLabel1_2;
QTextEdit *sqlTextEdit;
QHBoxLayout *hboxLayout2;
QPushButton *executeQueryButton;
QSpacerItem *spacer4_2;
QLabel *textLabel2;
QLineEdit *queryErrorLineEdit;
QLabel *textLabel3;
QTableView *queryResultTableView;
QStandardItemModel *queryResultListModel;
QToolBar *toolbarDB;
QMenuBar *menubar;
QMenu *fileMenu;
QMenu *importMenu;
QMenu *exportMenu;
QMenu *EditMenu;
QMenu *ViewMenu;
QMenu *PopupMenu;
QMenu *recentFilesMenu;
SQLiteSyntaxHighlighter* sqliteHighlighter;
enum { MaxRecentFiles = 5 };
QAction *recentFileActs[MaxRecentFiles];
QAction *recentSeparatorAct;
int curBrowseOrderByIndex;
int curBrowseOrderByMode;
public:
MainWindow(QWidget* parent = 0);
~MainWindow();
editForm * editWin;
QClipboard * clipboard;
findForm * findWin;
int recAtTop;
int recsPerView;
QIntValidator * gotoValidator;
QString defaultlocation;
private:
void init();
void destroy();
void setupUi();
void retranslateUi();
void updateRecentFileActions();
void setCurrentFile(const QString& fileName);
void activateFields(bool enable = true);
protected:
void closeEvent(QCloseEvent *);
public slots:
virtual void on_tree_context_menu(const QPoint & qPoint);
virtual void on_tree_selection_changed();
virtual void on_add_field();
virtual void on_edit_field();
virtual void fileOpen( const QString & fileName );
virtual void fileOpen();
virtual void fileNew();
virtual void populateStructure();
virtual void populateTable(const QString & tablename , bool keepColumnWidths = false);
virtual void resetBrowser();
virtual void fileClose();
virtual void fileExit();
virtual void addRecord();
virtual void deleteRecord();
virtual void updateTableView(int lineToSelect , bool keepColumnWidths = false);
virtual void selectTableLine( int lineToSelect );
virtual void navigatePrevious();
virtual void navigateNext();
virtual void navigateGoto();
virtual void setRecordsetLabel();
virtual void browseFind( bool open );
virtual void browseFindAway();
virtual void browseRefresh();
virtual void lookfor( const QString & wfield, const QString & woperator, const QString & wsearchterm );
virtual void showrecord( int dec );
virtual void createTable();
virtual void createIndex();
virtual void compact();
virtual void deleteTable();
virtual void editTable();
virtual void deleteIndex();
virtual void copy();
virtual void paste();
virtual void helpWhatsThis();
virtual void helpAbout();
virtual void updateRecordText( int row, int col, QString newtext );
virtual void logWinAway();
virtual void editWinAway();
virtual void editText( int row, int col );
virtual void doubleClickTable( int row, int col );
virtual void executeQuery();
virtual void importTableFromCSV();
virtual void exportTableToCSV();
virtual void dbState( bool dirty );
virtual void fileSave();
virtual void fileRevert();
virtual void exportDatabaseToSQL();
virtual void importDatabaseFromSQL();
virtual void openPreferences();
virtual void updatePreferences();
virtual void openRecentFile();
protected:
DBBrowserDB db;
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
protected slots:
virtual void languageChange();
virtual void deleteTablePopup();
virtual void editTablePopup();
virtual void mainTabSelected( int tabindex );
virtual void browseTableHeaderClicked(int logicalindex);
};
#endif // MAINFORM_H

View File

@@ -1,164 +0,0 @@
#include "preferencesform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
#include "qdir.h"
#include "qsettings.h"
#include <QFileDialog>
#include "sqlitedb.h"
/*
* Constructs a preferencesForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
preferencesForm::preferencesForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
init();
}
/*
* Destroys the object and frees any allocated resources
*/
preferencesForm::~preferencesForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void preferencesForm::languageChange()
{
retranslateUi(this);
}
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
void preferencesForm::init()
{
loadSettings();
}
void preferencesForm::defaultDataChanged( int which )
{
if (which==2) {
defaultnewdata = QString("\'\'");
} else if (which==1) {
defaultnewdata = QString("0");
} else {
defaultnewdata = QString("NULL");
}
}
void preferencesForm::defaultTextChanged( int which )
{
if (which==1) {
defaulttext = QString("Auto");
} else {
defaulttext = QString("Plain");
}
}
void preferencesForm::encodingChanged( int which )
{
if (which==1) {
defaultencoding = QString("Latin1");
} else {
defaultencoding = QString("UTF8");
}
}
void preferencesForm::chooseLocation()
{
QString s = QFileDialog::getExistingDirectory(
this,
tr("Choose a directory"),
defaultlocation,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if(!s.isEmpty())
{
defaultlocation = s;
locationEdit->setText(defaultlocation);
}
}
void preferencesForm::loadSettings()
{
QSettings settings(QApplication::organizationName(), g_sApplicationNameShort);
settings.sync();
defaultencoding = settings.value( "/db/defaultencoding", "UTF8" ).toString();
defaultnewdata = settings.value( "/db/defaultnewdata", "NULL" ).toString();
defaultlocation = settings.value( "/db/defaultlocation", QDir::homePath() ).toString();
defaulttext = settings.value( "/db/defaulttext", "Plain" ).toString();
if (defaultencoding=="Latin1")
{
encodingComboBox->setCurrentIndex(1);
} else {
encodingComboBox->setCurrentIndex(0) ;
defaultencoding = QString("UTF8");
}
if (defaultnewdata=="\'\'")
{
defaultdataComboBox->setCurrentIndex(2) ;
} else if (defaultnewdata=="0")
{
defaultdataComboBox->setCurrentIndex(1) ;
} else {
defaultdataComboBox->setCurrentIndex(0) ;
defaultnewdata = QString("NULL");
}
if (defaulttext=="Auto")
{
defaultTextComboBox->setCurrentIndex(1) ;
} else {
defaultTextComboBox->setCurrentIndex(0) ;
defaulttext = QString("Plain");
}
locationEdit->setText(defaultlocation);
}
void preferencesForm::saveSettings()
{
QSettings settings(QApplication::organizationName(), g_sApplicationNameShort);
settings.setValue( "/db/defaultencoding", defaultencoding );
settings.setValue( "/db/defaultnewdata", defaultnewdata );
settings.setValue( "/db/defaultlocation", defaultlocation );
settings.setValue( "/db/defaulttext", defaulttext );
settings.sync();
accept();
}

View File

@@ -1,264 +0,0 @@
#ifndef PREFERENCESFORM_H
#define PREFERENCESFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
QT_BEGIN_NAMESPACE
class Ui_preferencesForm
{
public:
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;
QLabel *textLabel1;
QSpacerItem *spacer9;
QComboBox *encodingComboBox;
QHBoxLayout *hboxLayout1;
QLabel *textLabel2;
QSpacerItem *spacer10;
QComboBox *defaultdataComboBox;
QHBoxLayout *hboxLayout2;
QLabel *textLabel1_2;
QSpacerItem *spacer9_2;
QComboBox *defaultTextComboBox;
QHBoxLayout *hboxLayout3;
QLabel *textLabel3;
QSpacerItem *spacer11;
QLineEdit *locationEdit;
QPushButton *setLocationButton;
QSpacerItem *spacer13;
QHBoxLayout *hboxLayout4;
QSpacerItem *spacer12;
QPushButton *OKButton;
QPushButton *cancelButton;
void setupUi(QDialog *preferencesForm)
{
if (preferencesForm->objectName().isEmpty())
preferencesForm->setObjectName(QString::fromUtf8("preferencesForm"));
preferencesForm->resize(470, 198);
vboxLayout = new QVBoxLayout(preferencesForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
textLabel1 = new QLabel(preferencesForm);
textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
textLabel1->setWordWrap(false);
hboxLayout->addWidget(textLabel1);
spacer9 = new QSpacerItem(31, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacer9);
encodingComboBox = new QComboBox(preferencesForm);
encodingComboBox->setObjectName(QString::fromUtf8("encodingComboBox"));
hboxLayout->addWidget(encodingComboBox);
vboxLayout->addLayout(hboxLayout);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
textLabel2 = new QLabel(preferencesForm);
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
textLabel2->setWordWrap(false);
hboxLayout1->addWidget(textLabel2);
spacer10 = new QSpacerItem(21, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout1->addItem(spacer10);
defaultdataComboBox = new QComboBox(preferencesForm);
defaultdataComboBox->setObjectName(QString::fromUtf8("defaultdataComboBox"));
hboxLayout1->addWidget(defaultdataComboBox);
vboxLayout->addLayout(hboxLayout1);
hboxLayout2 = new QHBoxLayout();
hboxLayout2->setSpacing(6);
hboxLayout2->setObjectName(QString::fromUtf8("hboxLayout2"));
textLabel1_2 = new QLabel(preferencesForm);
textLabel1_2->setObjectName(QString::fromUtf8("textLabel1_2"));
textLabel1_2->setWordWrap(false);
hboxLayout2->addWidget(textLabel1_2);
spacer9_2 = new QSpacerItem(81, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout2->addItem(spacer9_2);
defaultTextComboBox = new QComboBox(preferencesForm);
defaultTextComboBox->setObjectName(QString::fromUtf8("defaultTextComboBox"));
hboxLayout2->addWidget(defaultTextComboBox);
vboxLayout->addLayout(hboxLayout2);
hboxLayout3 = new QHBoxLayout();
hboxLayout3->setSpacing(6);
hboxLayout3->setObjectName(QString::fromUtf8("hboxLayout3"));
textLabel3 = new QLabel(preferencesForm);
textLabel3->setObjectName(QString::fromUtf8("textLabel3"));
textLabel3->setWordWrap(false);
hboxLayout3->addWidget(textLabel3);
spacer11 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout3->addItem(spacer11);
locationEdit = new QLineEdit(preferencesForm);
locationEdit->setObjectName(QString::fromUtf8("locationEdit"));
locationEdit->setEnabled(false);
hboxLayout3->addWidget(locationEdit);
setLocationButton = new QPushButton(preferencesForm);
setLocationButton->setObjectName(QString::fromUtf8("setLocationButton"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(setLocationButton->sizePolicy().hasHeightForWidth());
setLocationButton->setSizePolicy(sizePolicy);
hboxLayout3->addWidget(setLocationButton);
vboxLayout->addLayout(hboxLayout3);
spacer13 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
vboxLayout->addItem(spacer13);
hboxLayout4 = new QHBoxLayout();
hboxLayout4->setSpacing(6);
hboxLayout4->setObjectName(QString::fromUtf8("hboxLayout4"));
spacer12 = new QSpacerItem(51, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout4->addItem(spacer12);
OKButton = new QPushButton(preferencesForm);
OKButton->setObjectName(QString::fromUtf8("OKButton"));
hboxLayout4->addWidget(OKButton);
cancelButton = new QPushButton(preferencesForm);
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
cancelButton->setDefault(true);
hboxLayout4->addWidget(cancelButton);
vboxLayout->addLayout(hboxLayout4);
retranslateUi(preferencesForm);
QObject::connect(OKButton, SIGNAL(clicked()), preferencesForm, SLOT(saveSettings()));
QObject::connect(cancelButton, SIGNAL(clicked()), preferencesForm, SLOT(reject()));
QObject::connect(defaultdataComboBox, SIGNAL(activated(int)), preferencesForm, SLOT(defaultDataChanged(int)));
QObject::connect(encodingComboBox, SIGNAL(activated(int)), preferencesForm, SLOT(encodingChanged(int)));
QObject::connect(setLocationButton, SIGNAL(clicked()), preferencesForm, SLOT(chooseLocation()));
QObject::connect(defaultTextComboBox, SIGNAL(activated(int)), preferencesForm, SLOT(defaultTextChanged(int)));
QMetaObject::connectSlotsByName(preferencesForm);
} // setupUi
void retranslateUi(QDialog *preferencesForm)
{
preferencesForm->setWindowTitle(QApplication::translate("preferencesForm", "Preferences", 0, QApplication::UnicodeUTF8));
textLabel1->setText(QApplication::translate("preferencesForm", "Database encoding:", 0, QApplication::UnicodeUTF8));
encodingComboBox->clear();
encodingComboBox->insertItems(0, QStringList()
<< QApplication::translate("preferencesForm", "UTF8 (Unicode)", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("preferencesForm", "Latin1 (8bit)", 0, QApplication::UnicodeUTF8)
);
textLabel2->setText(QApplication::translate("preferencesForm", "Default data for new records:", 0, QApplication::UnicodeUTF8));
defaultdataComboBox->clear();
defaultdataComboBox->insertItems(0, QStringList()
<< QApplication::translate("preferencesForm", "NULL", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("preferencesForm", "0", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("preferencesForm", "Empty string", 0, QApplication::UnicodeUTF8)
);
textLabel1_2->setText(QApplication::translate("preferencesForm", "Default text editor format:", 0, QApplication::UnicodeUTF8));
defaultTextComboBox->clear();
defaultTextComboBox->insertItems(0, QStringList()
<< QApplication::translate("preferencesForm", "Plain", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("preferencesForm", "Auto", 0, QApplication::UnicodeUTF8)
);
textLabel3->setText(QApplication::translate("preferencesForm", "Default location:", 0, QApplication::UnicodeUTF8));
setLocationButton->setText(QApplication::translate("preferencesForm", "...", 0, QApplication::UnicodeUTF8));
OKButton->setText(QApplication::translate("preferencesForm", "O&K", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("preferencesForm", "Ca&ncel", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class preferencesForm: public Ui_preferencesForm {};
} // namespace Ui
QT_END_NAMESPACE
class preferencesForm : public QDialog, public Ui::preferencesForm
{
Q_OBJECT
public:
preferencesForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~preferencesForm();
QString defaulttext;
QString defaultlocation;
QString defaultnewdata;
QString defaultencoding;
public slots:
virtual void defaultDataChanged( int which );
virtual void defaultTextChanged( int which );
virtual void encodingChanged( int which );
virtual void chooseLocation();
virtual void loadSettings();
virtual void saveSettings();
protected slots:
virtual void languageChange();
private:
void init();
};
#endif // PREFERENCESFORM_H

View File

@@ -1,62 +0,0 @@
#include "renametableform.h"
#include <qvariant.h>
#include <qmessagebox.h>
#include <qimage.h>
#include <qpixmap.h>
#include "sqlitedb.h"
/*
* Constructs a renameTableForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
renameTableForm::renameTableForm(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
setupUi(this);
}
/*
* Destroys the object and frees any allocated resources
*/
renameTableForm::~renameTableForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void renameTableForm::languageChange()
{
retranslateUi(this);
}
void renameTableForm::renameClicked()
{
QString tabname = tablenameLineEdit->text();
if (tabname.isEmpty()) {
QMessageBox::information( this, QApplication::applicationName(), "Table name can not be empty" );
return;
}
if (tabname.contains(" ")>0) {
QMessageBox::warning( this, QApplication::applicationName(), "Spaces are not allowed in the table name" );
return;
}
accept();
}
QString renameTableForm::getTableName()
{
return tablenameLineEdit->text();
}
void renameTableForm::setTableName(QString name)
{
tablenameLineEdit->setText(name);
}

View File

@@ -1,123 +0,0 @@
#ifndef RENAMETABLEFORM_H
#define RENAMETABLEFORM_H
#include <qvariant.h>
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
#ifndef QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
#endif
#ifndef QT_END_NAMESPACE
#define QT_END_NAMESPACE
#endif
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
QT_BEGIN_NAMESPACE
class Ui_renameTableForm
{
public:
QVBoxLayout *vboxLayout;
QLineEdit *tablenameLineEdit;
QSpacerItem *spacer27;
QHBoxLayout *hboxLayout;
QSpacerItem *spacer26;
QPushButton *closeButton;
QPushButton *renameButton;
void setupUi(QDialog *renameTableForm)
{
if (renameTableForm->objectName().isEmpty()){
renameTableForm->setObjectName(QString::fromUtf8("renameTableForm"));
}
renameTableForm->setWindowIcon(QIcon(":/icons/table_modify"));
renameTableForm->resize(313, 101);
vboxLayout = new QVBoxLayout(renameTableForm);
vboxLayout->setSpacing(6);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
tablenameLineEdit = new QLineEdit(renameTableForm);
tablenameLineEdit->setObjectName(QString::fromUtf8("tablenameLineEdit"));
vboxLayout->addWidget(tablenameLineEdit);
spacer27 = new QSpacerItem(20, 21, QSizePolicy::Minimum, QSizePolicy::Expanding);
vboxLayout->addItem(spacer27);
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
spacer26 = new QSpacerItem(31, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacer26);
closeButton = new QPushButton(renameTableForm);
closeButton->setObjectName(QString::fromUtf8("closeButton"));
closeButton->setIcon(QIcon(":/icons/cancel"));
hboxLayout->addWidget(closeButton);
renameButton = new QPushButton(renameTableForm);
renameButton->setObjectName(QString::fromUtf8("renameButton"));
renameButton->setDefault(true);
renameButton->setIcon(QIcon(":/icons/save"));
hboxLayout->addWidget(renameButton);
vboxLayout->addLayout(hboxLayout);
retranslateUi(renameTableForm);
QObject::connect(closeButton, SIGNAL(clicked()), renameTableForm, SLOT(reject()));
QObject::connect(renameButton, SIGNAL(clicked()), renameTableForm, SLOT(renameClicked()));
QMetaObject::connectSlotsByName(renameTableForm);
} // setupUi
void retranslateUi(QDialog *renameTableForm)
{
renameTableForm->setWindowTitle(QApplication::translate("renameTableForm", "Rename table", 0, QApplication::UnicodeUTF8));
closeButton->setText(QApplication::translate("renameTableForm", "Cancel", 0, QApplication::UnicodeUTF8));
renameButton->setText(QApplication::translate("renameTableForm", "Rename", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class renameTableForm: public Ui_renameTableForm {};
} // namespace Ui
QT_END_NAMESPACE
class renameTableForm : public QDialog, public Ui::renameTableForm
{
Q_OBJECT
public:
renameTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
~renameTableForm();
virtual QString getTableName();
public slots:
virtual void renameClicked();
virtual void setTableName( QString name );
protected slots:
virtual void languageChange();
};
#endif // RENAMETABLEFORM_H

View File

@@ -1,342 +1,12 @@
#include "sqlbrowser_util.h"
#include "sqlite_source/sqlite3.h"
#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite_source/sqlite3.h"
#include <ctype.h>
/*following routines extracted from shell.c for dump support*/
/*
** Determines if a string is a number of not.
*/
static int isNumber(const char *z, int *realnum){
if( *z=='-' || *z=='+' ) z++;
if( !isdigit(*z) ){
return 0;
}
z++;
if( realnum ) *realnum = 0;
while( isdigit(*z) ){ z++; }
if( *z=='.' ){
z++;
if( !isdigit(*z) ) return 0;
while( isdigit(*z) ){ z++; }
if( realnum ) *realnum = 1;
}
if( *z=='e' || *z=='E' ){
z++;
if( *z=='+' || *z=='-' ) z++;
if( !isdigit(*z) ) return 0;
while( isdigit(*z) ){ z++; }
if( realnum ) *realnum = 1;
}
return *z==0;
}
char *modeDescr[MODE_NUM_OF] = {
"line",
"column",
"list",
"semi",
"html",
"insert"
};
/*
** Number of elements in an array
*/
#define ArraySize(X) (sizeof(X)/sizeof(X[0]))
/*
** Output the given string as a quoted string using SQL quoting conventions.
*/
static void output_quoted_string(FILE *out, const char *z){
int i;
int nSingle = 0;
for(i=0; z[i]; i++){
if( z[i]=='\'' ) nSingle++;
}
if( nSingle==0 ){
fprintf(out,"'%s'",z);
}else{
fprintf(out,"'");
while( *z ){
for(i=0; z[i] && z[i]!='\''; i++){}
if( i==0 ){
fprintf(out,"''");
z++;
}else if( z[i]=='\'' ){
fprintf(out,"%.*s''",i,z);
z += i+1;
}else{
fprintf(out,"%s",z);
break;
}
}
fprintf(out,"'");
}
}
/*
** Output the given string with characters that are special to
** HTML escaped.
*/
static void output_html_string(FILE *out, const char *z){
int i;
while( *z ){
for(i=0; z[i] && z[i]!='<' && z[i]!='&'; i++){}
if( i>0 ){
fprintf(out,"%.*s",i,z);
}
if( z[i]=='<' ){
fprintf(out,"&lt;");
}else if( z[i]=='&' ){
fprintf(out,"&amp;");
}else{
break;
}
z += i + 1;
}
}
/*
** This is the callback routine that the SQLite library
** invokes for each row of a query result.
*/
static int callback(void *pArg, int nArg, char **azArg, char **azCol){
int i;
struct callback_data *p = (struct callback_data*)pArg;
switch( p->mode ){
case MODE_Line: {
int w = 5;
if( azArg==0 ) break;
for(i=0; i<nArg; i++){
int len = strlen(azCol[i]);
if( len>w ) w = len;
}
if( p->cnt++>0 ) fprintf(p->out,"\n");
for(i=0; i<nArg; i++){
fprintf(p->out,"%*s = %s\n", w, azCol[i],
azArg[i] ? azArg[i] : p->nullvalue);
}
break;
}
case MODE_Column: {
if( p->cnt++==0 ){
for(i=0; i<nArg; i++){
int w, n;
if( i<ArraySize(p->colWidth) ){
w = p->colWidth[i];
}else{
w = 0;
}
if( w<=0 ){
w = strlen(azCol[i] ? azCol[i] : "");
if( w<10 ) w = 10;
n = strlen(azArg && azArg[i] ? azArg[i] : p->nullvalue);
if( w<n ) w = n;
}
if( i<ArraySize(p->actualWidth) ){
p->actualWidth[i] = w;
}
if( p->showHeader ){
fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": " ");
}
}
if( p->showHeader ){
for(i=0; i<nArg; i++){
int w;
if( i<ArraySize(p->actualWidth) ){
w = p->actualWidth[i];
}else{
w = 10;
}
fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
"----------------------------------------------------------",
i==nArg-1 ? "\n": " ");
}
}
}
if( azArg==0 ) break;
for(i=0; i<nArg; i++){
int w;
if( i<ArraySize(p->actualWidth) ){
w = p->actualWidth[i];
}else{
w = 10;
}
fprintf(p->out,"%-*.*s%s",w,w,
azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
}
break;
}
case MODE_Semi:
case MODE_List: {
if( p->cnt++==0 && p->showHeader ){
for(i=0; i<nArg; i++){
fprintf(p->out,"%s%s",azCol[i], i==nArg-1 ? "\n" : p->separator);
}
}
if( azArg==0 ) break;
for(i=0; i<nArg; i++){
char *z = azArg[i];
if( z==0 ) z = p->nullvalue;
fprintf(p->out, "%s", z);
if( i<nArg-1 ){
fprintf(p->out, "%s", p->separator);
}else if( p->mode==MODE_Semi ){
fprintf(p->out, ";\n");
}else{
fprintf(p->out, "\n");
}
}
break;
}
case MODE_Html: {
if( p->cnt++==0 && p->showHeader ){
fprintf(p->out,"<TR>");
for(i=0; i<nArg; i++){
fprintf(p->out,"<TH>%s</TH>",azCol[i]);
}
fprintf(p->out,"</TR>\n");
}
if( azArg==0 ) break;
fprintf(p->out,"<TR>");
for(i=0; i<nArg; i++){
fprintf(p->out,"<TD>");
output_html_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
fprintf(p->out,"</TD>\n");
}
fprintf(p->out,"</TR>\n");
break;
}
case MODE_Insert: {
if( azArg==0 ) break;
fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
for(i=0; i<nArg; i++){
char *zSep = i>0 ? ",": "";
if( azArg[i]==0 ){
fprintf(p->out,"%sNULL",zSep);
}else if( isNumber(azArg[i], 0) ){
fprintf(p->out,"%s%s",zSep, azArg[i]);
}else{
if( zSep[0] ) fprintf(p->out,"%s",zSep);
output_quoted_string(p->out, azArg[i]);
}
}
fprintf(p->out,");\n");
break;
}
}
return 0;
}
/*
** Set the destination table field of the callback_data structure to
** the name of the table given. Escape any quote characters in the
** table name.
*/
static void set_table_name(struct callback_data *p, const char *zName){
int i, n;
int needQuote;
char *z;
if( p->zDestTable ){
free(p->zDestTable);
p->zDestTable = 0;
}
if( zName==0 ) return;
needQuote = !isalpha(*zName) && *zName!='_';
for(i=n=0; zName[i]; i++, n++){
if( !isalnum(zName[i]) && zName[i]!='_' ){
needQuote = 1;
if( zName[i]=='\'' ) n++;
}
}
if( needQuote ) n += 2;
z = p->zDestTable = malloc( n+1 );
if( z==0 ){
fprintf(stderr,"Out of memory!\n");
exit(1);
}
n = 0;
if( needQuote ) z[n++] = '\'';
for(i=0; zName[i]; i++){
z[n++] = zName[i];
if( zName[i]=='\'' ) z[n++] = '\'';
}
if( needQuote ) z[n++] = '\'';
z[n] = 0;
}
/*
** This is a different callback routine used for dumping the database.
** Each row received by this callback consists of a table name,
** the table type ("index" or "table") and SQL to create the table.
** This routine should print text sufficient to recreate the table.
*/
static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
struct callback_data *p = (struct callback_data *)pArg;
if( nArg!=3 ) return 1;
fprintf(p->out, "%s;\n", azArg[2]);
if( strcmp(azArg[1],"table")==0 ){
struct callback_data d2;
char* stmt;
d2 = *p;
d2.mode = MODE_Insert;
d2.zDestTable = 0;
set_table_name(&d2, azArg[0]);
stmt = sqlite3_mprintf("SELECT * FROM '%q'", azArg[0]);
sqlite3_exec(p->db,stmt, callback, &d2, 0);
sqlite3_free(stmt);
set_table_name(&d2, 0);
}
return 0;
}
/*
/Dump database to a file
*/
int dump_database(sqlite3 * db, FILE * outfile){
int rc = 0;
char *zErrMsg = 0;
struct callback_data p;
memset(&p, 0, sizeof(p));
p.db = db;
p.mode = MODE_List;
strcpy(p.separator,"|");
p.showHeader = 0;
p.out = outfile;
//open_db(p);
fprintf(p.out, "BEGIN TRANSACTION;\n");
sqlite3_exec(p.db,
"SELECT name, type, sql FROM sqlite_master "
"WHERE type!='meta' AND sql NOT NULL "
"ORDER BY substr(type,2,1), name",
dump_callback, &p, &zErrMsg
);
if( zErrMsg ){
/*fprintf(stderr,"Error: %s\n", zErrMsg);*/
free(zErrMsg);
}else{
fprintf(p.out, "COMMIT;\n");
}
return rc;
}
/*
/Dump database to a file
*/
int load_database(sqlite3 * db, FILE * infile, int * lineErr){
int rc = 0;
process_input(db, infile, lineErr);
return rc;
}
/*
** Return TRUE if the last non-whitespace character in z[] is a semicolon.
** z[] is N characters long.
@@ -371,7 +41,7 @@ static int _all_whitespace(const char *z){
}
char *sqlbrowser_getline(FILE *in){
static char *sqlbrowser_getline(FILE *in){
char *zLine;
int nLine;
int n;
@@ -409,7 +79,7 @@ char *sqlbrowser_getline(FILE *in){
return zLine;
}
void process_input(sqlite3 * db, FILE *in, int * lineErr){
static void process_input(sqlite3 * db, FILE *in, int * lineErr){
char *zLine;
char *zSql = 0;
char * zErrMsg = 0;
@@ -417,7 +87,7 @@ void process_input(sqlite3 * db, FILE *in, int * lineErr){
int rc;
while((zLine = sqlbrowser_getline(in))!=0 ){
if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
(*lineErr)++;
(*lineErr)++;
if( zSql==0 ){
int i;
for(i=0; zLine[i] && isspace(zLine[i]); i++){}
@@ -446,12 +116,12 @@ void process_input(sqlite3 * db, FILE *in, int * lineErr){
/*printf("SQL error: %s\n", zErrMsg);*/
free(zErrMsg);
zErrMsg = 0;
if( zSql ){
free(zSql);
}
return;
if( zSql ){
free(zSql);
}
return;
}/*else{
printf("SQL error: %s\n", sqlite3_error_string(rc));
printf("SQL error: %s\n", sqlite3_error_string(rc));
}*/
}
free(zSql);
@@ -467,5 +137,14 @@ void process_input(sqlite3 * db, FILE *in, int * lineErr){
*lineErr = 0;
}
/* end of shell.c routines*/
/*
/Dump database to a file
*/
int load_database(sqlite3 * db, FILE * infile, int * lineErr){
int rc = 0;
process_input(db, infile, lineErr);
return rc;
}
/* end of shell.c routines*/

View File

@@ -5,57 +5,10 @@
extern "C" {
#endif
#include <ctype.h>
#include "sqlite_source/sqlite3.h"
#include <sqlite3.h>
#include <stdio.h>
struct previous_mode_data {
int valid; /* Is there legit data in here? */
int mode;
int showHeader;
int colWidth[100];
};
/*
** An pointer to an instance of this structure is passed from
** the main program to the callback. This is used to communicate
** state and mode information.
*/
struct callback_data {
sqlite3 *db; /* The database */
int echoOn; /* True to echo input commands */
int cnt; /* Number of records displayed so far */
FILE *out; /* Write results here */
int mode; /* An output mode setting */
int showHeader; /* True to show column names in List or Column mode */
char *zDestTable; /* Name of destination table when MODE_Insert */
char separator[20]; /* Separator character for MODE_List */
int colWidth[100]; /* Requested width of each column when in column mode*/
int actualWidth[100]; /* Actual width of each column */
char nullvalue[20]; /* The text to print when a NULL comes back from
** the database */
struct previous_mode_data explainPrev;
/* Holds the mode information just before
** .explain ON */
char outfile[FILENAME_MAX]; /* Filename for *out */
const char *zDbFilename; /* name of the database file */
};
/*
** These are the allowed modes.
*/
#define MODE_Line 0 /* One column per line. Blank line between records */
#define MODE_Column 1 /* One record per line in neat columns */
#define MODE_List 2 /* One record per line with a separator */
#define MODE_Semi 3 /* Same as MODE_List but append ";" to each line */
#define MODE_Html 4 /* Generate an XHTML table */
#define MODE_Insert 5 /* Generate SQL "insert" statements */
#define MODE_NUM_OF 6 /* The number of modes (not a mode itself) */
int dump_database(sqlite3 * db, FILE * outfile);
int load_database(sqlite3 * db, FILE * infile, int * lineErr);
void process_input(sqlite3 * db, FILE *in, int * lineErr);
char *sqlbrowser_getline(FILE *in);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,447 +0,0 @@
/*
** 2006 June 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the SQLite interface for use by
** shared libraries that want to be imported as extensions into
** an SQLite instance. Shared libraries that intend to be loaded
** as extensions by SQLite should #include this file instead of
** sqlite3.h.
*/
#ifndef _SQLITE3EXT_H_
#define _SQLITE3EXT_H_
#include "sqlite3.h"
typedef struct sqlite3_api_routines sqlite3_api_routines;
/*
** The following structure holds pointers to all of the SQLite API
** routines.
**
** WARNING: In order to maintain backwards compatibility, add new
** interfaces to the end of this structure only. If you insert new
** interfaces in the middle of this structure, then older different
** versions of SQLite will not be able to load each others' shared
** libraries!
*/
struct sqlite3_api_routines {
void * (*aggregate_context)(sqlite3_context*,int nBytes);
int (*aggregate_count)(sqlite3_context*);
int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*));
int (*bind_double)(sqlite3_stmt*,int,double);
int (*bind_int)(sqlite3_stmt*,int,int);
int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64);
int (*bind_null)(sqlite3_stmt*,int);
int (*bind_parameter_count)(sqlite3_stmt*);
int (*bind_parameter_index)(sqlite3_stmt*,const char*zName);
const char * (*bind_parameter_name)(sqlite3_stmt*,int);
int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*));
int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
int (*busy_handler)(sqlite3*,int(*)(void*,int),void*);
int (*busy_timeout)(sqlite3*,int ms);
int (*changes)(sqlite3*);
int (*close)(sqlite3*);
int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
int eTextRep,const char*));
int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
int eTextRep,const void*));
const void * (*column_blob)(sqlite3_stmt*,int iCol);
int (*column_bytes)(sqlite3_stmt*,int iCol);
int (*column_bytes16)(sqlite3_stmt*,int iCol);
int (*column_count)(sqlite3_stmt*pStmt);
const char * (*column_database_name)(sqlite3_stmt*,int);
const void * (*column_database_name16)(sqlite3_stmt*,int);
const char * (*column_decltype)(sqlite3_stmt*,int i);
const void * (*column_decltype16)(sqlite3_stmt*,int);
double (*column_double)(sqlite3_stmt*,int iCol);
int (*column_int)(sqlite3_stmt*,int iCol);
sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol);
const char * (*column_name)(sqlite3_stmt*,int);
const void * (*column_name16)(sqlite3_stmt*,int);
const char * (*column_origin_name)(sqlite3_stmt*,int);
const void * (*column_origin_name16)(sqlite3_stmt*,int);
const char * (*column_table_name)(sqlite3_stmt*,int);
const void * (*column_table_name16)(sqlite3_stmt*,int);
const unsigned char * (*column_text)(sqlite3_stmt*,int iCol);
const void * (*column_text16)(sqlite3_stmt*,int iCol);
int (*column_type)(sqlite3_stmt*,int iCol);
sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol);
void * (*commit_hook)(sqlite3*,int(*)(void*),void*);
int (*complete)(const char*sql);
int (*complete16)(const void*sql);
int (*create_collation)(sqlite3*,const char*,int,void*,
int(*)(void*,int,const void*,int,const void*));
int (*create_collation16)(sqlite3*,const void*,int,void*,
int(*)(void*,int,const void*,int,const void*));
int (*create_function)(sqlite3*,const char*,int,int,void*,
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
void (*xFinal)(sqlite3_context*));
int (*create_function16)(sqlite3*,const void*,int,int,void*,
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
void (*xFinal)(sqlite3_context*));
int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
int (*data_count)(sqlite3_stmt*pStmt);
sqlite3 * (*db_handle)(sqlite3_stmt*);
int (*declare_vtab)(sqlite3*,const char*);
int (*enable_shared_cache)(int);
int (*errcode)(sqlite3*db);
const char * (*errmsg)(sqlite3*);
const void * (*errmsg16)(sqlite3*);
int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
int (*expired)(sqlite3_stmt*);
int (*finalize)(sqlite3_stmt*pStmt);
void (*free)(void*);
void (*free_table)(char**result);
int (*get_autocommit)(sqlite3*);
void * (*get_auxdata)(sqlite3_context*,int);
int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
int (*global_recover)(void);
void (*interruptx)(sqlite3*);
sqlite_int64 (*last_insert_rowid)(sqlite3*);
const char * (*libversion)(void);
int (*libversion_number)(void);
void *(*malloc)(int);
char * (*mprintf)(const char*,...);
int (*open)(const char*,sqlite3**);
int (*open16)(const void*,sqlite3**);
int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
void (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
void *(*realloc)(void*,int);
int (*reset)(sqlite3_stmt*pStmt);
void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_double)(sqlite3_context*,double);
void (*result_error)(sqlite3_context*,const char*,int);
void (*result_error16)(sqlite3_context*,const void*,int);
void (*result_int)(sqlite3_context*,int);
void (*result_int64)(sqlite3_context*,sqlite_int64);
void (*result_null)(sqlite3_context*);
void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_value)(sqlite3_context*,sqlite3_value*);
void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
const char*,const char*),void*);
void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
char * (*snprintf)(int,char*,const char*,...);
int (*step)(sqlite3_stmt*);
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
char const**,char const**,int*,int*,int*);
void (*thread_cleanup)(void);
int (*total_changes)(sqlite3*);
void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*);
int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
sqlite_int64),void*);
void * (*user_data)(sqlite3_context*);
const void * (*value_blob)(sqlite3_value*);
int (*value_bytes)(sqlite3_value*);
int (*value_bytes16)(sqlite3_value*);
double (*value_double)(sqlite3_value*);
int (*value_int)(sqlite3_value*);
sqlite_int64 (*value_int64)(sqlite3_value*);
int (*value_numeric_type)(sqlite3_value*);
const unsigned char * (*value_text)(sqlite3_value*);
const void * (*value_text16)(sqlite3_value*);
const void * (*value_text16be)(sqlite3_value*);
const void * (*value_text16le)(sqlite3_value*);
int (*value_type)(sqlite3_value*);
char *(*vmprintf)(const char*,va_list);
/* Added ??? */
int (*overload_function)(sqlite3*, const char *zFuncName, int nArg);
/* Added by 3.3.13 */
int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
int (*clear_bindings)(sqlite3_stmt*);
/* Added by 3.4.1 */
int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,
void (*xDestroy)(void *));
/* Added by 3.5.0 */
int (*bind_zeroblob)(sqlite3_stmt*,int,int);
int (*blob_bytes)(sqlite3_blob*);
int (*blob_close)(sqlite3_blob*);
int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,
int,sqlite3_blob**);
int (*blob_read)(sqlite3_blob*,void*,int,int);
int (*blob_write)(sqlite3_blob*,const void*,int,int);
int (*create_collation_v2)(sqlite3*,const char*,int,void*,
int(*)(void*,int,const void*,int,const void*),
void(*)(void*));
int (*file_control)(sqlite3*,const char*,int,void*);
sqlite3_int64 (*memory_highwater)(int);
sqlite3_int64 (*memory_used)(void);
sqlite3_mutex *(*mutex_alloc)(int);
void (*mutex_enter)(sqlite3_mutex*);
void (*mutex_free)(sqlite3_mutex*);
void (*mutex_leave)(sqlite3_mutex*);
int (*mutex_try)(sqlite3_mutex*);
int (*open_v2)(const char*,sqlite3**,int,const char*);
int (*release_memory)(int);
void (*result_error_nomem)(sqlite3_context*);
void (*result_error_toobig)(sqlite3_context*);
int (*sleep)(int);
void (*soft_heap_limit)(int);
sqlite3_vfs *(*vfs_find)(const char*);
int (*vfs_register)(sqlite3_vfs*,int);
int (*vfs_unregister)(sqlite3_vfs*);
int (*xthreadsafe)(void);
void (*result_zeroblob)(sqlite3_context*,int);
void (*result_error_code)(sqlite3_context*,int);
int (*test_control)(int, ...);
void (*randomness)(int,void*);
sqlite3 *(*context_db_handle)(sqlite3_context*);
int (*extended_result_codes)(sqlite3*,int);
int (*limit)(sqlite3*,int,int);
sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
const char *(*sql)(sqlite3_stmt*);
int (*status)(int,int*,int*,int);
int (*backup_finish)(sqlite3_backup*);
sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*);
int (*backup_pagecount)(sqlite3_backup*);
int (*backup_remaining)(sqlite3_backup*);
int (*backup_step)(sqlite3_backup*,int);
const char *(*compileoption_get)(int);
int (*compileoption_used)(const char*);
int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
void (*xFinal)(sqlite3_context*),
void(*xDestroy)(void*));
int (*db_config)(sqlite3*,int,...);
sqlite3_mutex *(*db_mutex)(sqlite3*);
int (*db_status)(sqlite3*,int,int*,int*,int);
int (*extended_errcode)(sqlite3*);
void (*log)(int,const char*,...);
sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
const char *(*sourceid)(void);
int (*stmt_status)(sqlite3_stmt*,int,int);
int (*strnicmp)(const char*,const char*,int);
int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
int (*wal_autocheckpoint)(sqlite3*,int);
int (*wal_checkpoint)(sqlite3*,const char*);
void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
int (*vtab_config)(sqlite3*,int op,...);
int (*vtab_on_conflict)(sqlite3*);
};
/*
** The following macros redefine the API routines so that they are
** redirected throught the global sqlite3_api structure.
**
** This header file is also used by the loadext.c source file
** (part of the main SQLite library - not an extension) so that
** it can get access to the sqlite3_api_routines structure
** definition. But the main library does not want to redefine
** the API. So the redefinition macros are only valid if the
** SQLITE_CORE macros is undefined.
*/
#ifndef SQLITE_CORE
#define sqlite3_aggregate_context sqlite3_api->aggregate_context
#ifndef SQLITE_OMIT_DEPRECATED
#define sqlite3_aggregate_count sqlite3_api->aggregate_count
#endif
#define sqlite3_bind_blob sqlite3_api->bind_blob
#define sqlite3_bind_double sqlite3_api->bind_double
#define sqlite3_bind_int sqlite3_api->bind_int
#define sqlite3_bind_int64 sqlite3_api->bind_int64
#define sqlite3_bind_null sqlite3_api->bind_null
#define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count
#define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index
#define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name
#define sqlite3_bind_text sqlite3_api->bind_text
#define sqlite3_bind_text16 sqlite3_api->bind_text16
#define sqlite3_bind_value sqlite3_api->bind_value
#define sqlite3_busy_handler sqlite3_api->busy_handler
#define sqlite3_busy_timeout sqlite3_api->busy_timeout
#define sqlite3_changes sqlite3_api->changes
#define sqlite3_close sqlite3_api->close
#define sqlite3_collation_needed sqlite3_api->collation_needed
#define sqlite3_collation_needed16 sqlite3_api->collation_needed16
#define sqlite3_column_blob sqlite3_api->column_blob
#define sqlite3_column_bytes sqlite3_api->column_bytes
#define sqlite3_column_bytes16 sqlite3_api->column_bytes16
#define sqlite3_column_count sqlite3_api->column_count
#define sqlite3_column_database_name sqlite3_api->column_database_name
#define sqlite3_column_database_name16 sqlite3_api->column_database_name16
#define sqlite3_column_decltype sqlite3_api->column_decltype
#define sqlite3_column_decltype16 sqlite3_api->column_decltype16
#define sqlite3_column_double sqlite3_api->column_double
#define sqlite3_column_int sqlite3_api->column_int
#define sqlite3_column_int64 sqlite3_api->column_int64
#define sqlite3_column_name sqlite3_api->column_name
#define sqlite3_column_name16 sqlite3_api->column_name16
#define sqlite3_column_origin_name sqlite3_api->column_origin_name
#define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16
#define sqlite3_column_table_name sqlite3_api->column_table_name
#define sqlite3_column_table_name16 sqlite3_api->column_table_name16
#define sqlite3_column_text sqlite3_api->column_text
#define sqlite3_column_text16 sqlite3_api->column_text16
#define sqlite3_column_type sqlite3_api->column_type
#define sqlite3_column_value sqlite3_api->column_value
#define sqlite3_commit_hook sqlite3_api->commit_hook
#define sqlite3_complete sqlite3_api->complete
#define sqlite3_complete16 sqlite3_api->complete16
#define sqlite3_create_collation sqlite3_api->create_collation
#define sqlite3_create_collation16 sqlite3_api->create_collation16
#define sqlite3_create_function sqlite3_api->create_function
#define sqlite3_create_function16 sqlite3_api->create_function16
#define sqlite3_create_module sqlite3_api->create_module
#define sqlite3_create_module_v2 sqlite3_api->create_module_v2
#define sqlite3_data_count sqlite3_api->data_count
#define sqlite3_db_handle sqlite3_api->db_handle
#define sqlite3_declare_vtab sqlite3_api->declare_vtab
#define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache
#define sqlite3_errcode sqlite3_api->errcode
#define sqlite3_errmsg sqlite3_api->errmsg
#define sqlite3_errmsg16 sqlite3_api->errmsg16
#define sqlite3_exec sqlite3_api->exec
#ifndef SQLITE_OMIT_DEPRECATED
#define sqlite3_expired sqlite3_api->expired
#endif
#define sqlite3_finalize sqlite3_api->finalize
#define sqlite3_free sqlite3_api->free
#define sqlite3_free_table sqlite3_api->free_table
#define sqlite3_get_autocommit sqlite3_api->get_autocommit
#define sqlite3_get_auxdata sqlite3_api->get_auxdata
#define sqlite3_get_table sqlite3_api->get_table
#ifndef SQLITE_OMIT_DEPRECATED
#define sqlite3_global_recover sqlite3_api->global_recover
#endif
#define sqlite3_interrupt sqlite3_api->interruptx
#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid
#define sqlite3_libversion sqlite3_api->libversion
#define sqlite3_libversion_number sqlite3_api->libversion_number
#define sqlite3_malloc sqlite3_api->malloc
#define sqlite3_mprintf sqlite3_api->mprintf
#define sqlite3_open sqlite3_api->open
#define sqlite3_open16 sqlite3_api->open16
#define sqlite3_prepare sqlite3_api->prepare
#define sqlite3_prepare16 sqlite3_api->prepare16
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
#define sqlite3_profile sqlite3_api->profile
#define sqlite3_progress_handler sqlite3_api->progress_handler
#define sqlite3_realloc sqlite3_api->realloc
#define sqlite3_reset sqlite3_api->reset
#define sqlite3_result_blob sqlite3_api->result_blob
#define sqlite3_result_double sqlite3_api->result_double
#define sqlite3_result_error sqlite3_api->result_error
#define sqlite3_result_error16 sqlite3_api->result_error16
#define sqlite3_result_int sqlite3_api->result_int
#define sqlite3_result_int64 sqlite3_api->result_int64
#define sqlite3_result_null sqlite3_api->result_null
#define sqlite3_result_text sqlite3_api->result_text
#define sqlite3_result_text16 sqlite3_api->result_text16
#define sqlite3_result_text16be sqlite3_api->result_text16be
#define sqlite3_result_text16le sqlite3_api->result_text16le
#define sqlite3_result_value sqlite3_api->result_value
#define sqlite3_rollback_hook sqlite3_api->rollback_hook
#define sqlite3_set_authorizer sqlite3_api->set_authorizer
#define sqlite3_set_auxdata sqlite3_api->set_auxdata
#define sqlite3_snprintf sqlite3_api->snprintf
#define sqlite3_step sqlite3_api->step
#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
#define sqlite3_total_changes sqlite3_api->total_changes
#define sqlite3_trace sqlite3_api->trace
#ifndef SQLITE_OMIT_DEPRECATED
#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings
#endif
#define sqlite3_update_hook sqlite3_api->update_hook
#define sqlite3_user_data sqlite3_api->user_data
#define sqlite3_value_blob sqlite3_api->value_blob
#define sqlite3_value_bytes sqlite3_api->value_bytes
#define sqlite3_value_bytes16 sqlite3_api->value_bytes16
#define sqlite3_value_double sqlite3_api->value_double
#define sqlite3_value_int sqlite3_api->value_int
#define sqlite3_value_int64 sqlite3_api->value_int64
#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type
#define sqlite3_value_text sqlite3_api->value_text
#define sqlite3_value_text16 sqlite3_api->value_text16
#define sqlite3_value_text16be sqlite3_api->value_text16be
#define sqlite3_value_text16le sqlite3_api->value_text16le
#define sqlite3_value_type sqlite3_api->value_type
#define sqlite3_vmprintf sqlite3_api->vmprintf
#define sqlite3_overload_function sqlite3_api->overload_function
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
#define sqlite3_clear_bindings sqlite3_api->clear_bindings
#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
#define sqlite3_blob_bytes sqlite3_api->blob_bytes
#define sqlite3_blob_close sqlite3_api->blob_close
#define sqlite3_blob_open sqlite3_api->blob_open
#define sqlite3_blob_read sqlite3_api->blob_read
#define sqlite3_blob_write sqlite3_api->blob_write
#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2
#define sqlite3_file_control sqlite3_api->file_control
#define sqlite3_memory_highwater sqlite3_api->memory_highwater
#define sqlite3_memory_used sqlite3_api->memory_used
#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc
#define sqlite3_mutex_enter sqlite3_api->mutex_enter
#define sqlite3_mutex_free sqlite3_api->mutex_free
#define sqlite3_mutex_leave sqlite3_api->mutex_leave
#define sqlite3_mutex_try sqlite3_api->mutex_try
#define sqlite3_open_v2 sqlite3_api->open_v2
#define sqlite3_release_memory sqlite3_api->release_memory
#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem
#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig
#define sqlite3_sleep sqlite3_api->sleep
#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit
#define sqlite3_vfs_find sqlite3_api->vfs_find
#define sqlite3_vfs_register sqlite3_api->vfs_register
#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister
#define sqlite3_threadsafe sqlite3_api->xthreadsafe
#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob
#define sqlite3_result_error_code sqlite3_api->result_error_code
#define sqlite3_test_control sqlite3_api->test_control
#define sqlite3_randomness sqlite3_api->randomness
#define sqlite3_context_db_handle sqlite3_api->context_db_handle
#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes
#define sqlite3_limit sqlite3_api->limit
#define sqlite3_next_stmt sqlite3_api->next_stmt
#define sqlite3_sql sqlite3_api->sql
#define sqlite3_status sqlite3_api->status
#define sqlite3_backup_finish sqlite3_api->backup_finish
#define sqlite3_backup_init sqlite3_api->backup_init
#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount
#define sqlite3_backup_remaining sqlite3_api->backup_remaining
#define sqlite3_backup_step sqlite3_api->backup_step
#define sqlite3_compileoption_get sqlite3_api->compileoption_get
#define sqlite3_compileoption_used sqlite3_api->compileoption_used
#define sqlite3_create_function_v2 sqlite3_api->create_function_v2
#define sqlite3_db_config sqlite3_api->db_config
#define sqlite3_db_mutex sqlite3_api->db_mutex
#define sqlite3_db_status sqlite3_api->db_status
#define sqlite3_extended_errcode sqlite3_api->extended_errcode
#define sqlite3_log sqlite3_api->log
#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64
#define sqlite3_sourceid sqlite3_api->sourceid
#define sqlite3_stmt_status sqlite3_api->stmt_status
#define sqlite3_strnicmp sqlite3_api->strnicmp
#define sqlite3_unlock_notify sqlite3_api->unlock_notify
#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint
#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint
#define sqlite3_wal_hook sqlite3_api->wal_hook
#define sqlite3_blob_reopen sqlite3_api->blob_reopen
#define sqlite3_vtab_config sqlite3_api->vtab_config
#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict
#endif /* SQLITE_CORE */
#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0;
#define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v;
#endif /* _SQLITE3EXT_H_ */

View File

@@ -1,11 +0,0 @@
/*types for encoded media data*/
enum
{
kSQLiteMediaType_Void,
kSQLiteMediaType_Integer,
kSQLiteMediaType_String,
kSQLiteMediaType_Binary
};

View File

@@ -1,15 +1,13 @@
#include "sqlitedb.h"
#include "sqlbrowser_util.h"
#include <stdlib.h>
#include <qregexp.h>
#include <qimage.h>
#include <qfile.h>
#include <qmessagebox.h>
#include <QFile>
#include <QMessageBox>
#include <QProgressDialog>
#include "SQLLogDock.h"
#include <QApplication>
#include <QTextStream>
void DBBrowserTable::addField(int order, const QString& wfield,const QString& wtype)
void DBBrowserObject::addField(int order, const QString& wfield,const QString& wtype)
{
fldmap[order] = DBBrowserField(wfield,wtype);
}
@@ -21,10 +19,6 @@ bool DBBrowserDB::isOpen ( )
void DBBrowserDB::setDirty(bool dirtyval)
{
if ((dirty==false)&&(dirtyval==true))
{
setRestorePoint();
}
dirty = dirtyval;
if (logWin)
{
@@ -95,15 +89,15 @@ bool DBBrowserDB::open ( const QString & db)
QString contents = QString(buffer);
dbfile.close();
if (!contents.startsWith("SQLite format 3")) {
lastErrorMessage = QString("File is not a SQLite 3 database");
lastErrorMessage = QObject::tr("File is not a SQLite 3 database");
return false;
}
} else {
lastErrorMessage = QString("File could not be read");
lastErrorMessage = QObject::tr("File could not be read");
return false;
}
lastErrorMessage = QString("no error");
lastErrorMessage = QObject::tr("no error");
err = sqlite3_open_v2(db.toUtf8(), &_db, SQLITE_OPEN_READWRITE, NULL);
if ( err ) {
@@ -122,8 +116,10 @@ bool DBBrowserDB::open ( const QString & db)
setDirty(false);
}
curDBFilename = db;
setRestorePoint();
}
}
return ok;
}
@@ -158,10 +154,8 @@ bool DBBrowserDB::revert()
if (_db){
sqlite3_exec(_db,"ROLLBACK TO SAVEPOINT RESTOREPOINT;",
NULL,NULL,NULL);
qDebug(sqlite3_errmsg(_db));
sqlite3_exec(_db,"RELEASE RESTOREPOINT;",
NULL,NULL,NULL);
qDebug(sqlite3_errmsg(_db));
setDirty(false);
}
return true;
@@ -173,7 +167,7 @@ bool DBBrowserDB::create ( const QString & db)
if (isOpen()) close();
lastErrorMessage = QString("no error");
lastErrorMessage = QObject::tr("no error");
if( sqlite3_open(db.toUtf8(), &_db) != SQLITE_OK ){
lastErrorMessage = sqlite3_errmsg(_db);
@@ -204,22 +198,16 @@ void DBBrowserDB::close (){
{
if (getDirty())
{
QString msg = "Do you want to save the changes made to the database file ";
msg.append(curDBFilename);
msg.append(" ?");
QString msg = QObject::tr("Do you want to save the changes made to the database file %1?").arg(curDBFilename);
if (QMessageBox::question( 0, QApplication::applicationName() ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
save();
} else {
//not really necessary, I think... but will not hurt.
revert();
}
else
revert(); //not really necessary, I think... but will not hurt.
}
sqlite3_close(_db);
}
_db = 0;
idxmap.clear();
tbmap.clear();
objMap.clear();
idmap.clear();
browseRecs.clear();
browseFields.clear();
@@ -266,16 +254,92 @@ bool DBBrowserDB::reload( const QString & filename, int * lineErr)
return true;
}
bool DBBrowserDB::dump( const QString & filename)
bool DBBrowserDB::dump(const QString& filename)
{
FILE * cfile = fopen(filename.toUtf8(), (const char *) "w");
if (!cfile)
// Open file
QFile file(filename);
if(file.open(QIODevice::WriteOnly))
{
// Create progress dialog. For this count the number of all table rows to be exported first; this does neither take the table creation itself nor
// indices, views or triggers into account but compared to the number of rows those should be neglectable
unsigned int numRecordsTotal = 0, numRecordsCurrent = 0;
QList<DBBrowserObject> tables = objMap.values("table");
for(QList<DBBrowserObject>::ConstIterator it=tables.begin();it!=tables.end();++it)
numRecordsTotal += getFindResults(QString("SELECT COUNT(*) FROM `%1`;").arg((*it).getname())).value(0).toInt();
QProgressDialog progress(QObject::tr("Exporting database to SQL file..."), QObject::tr("Cancel"), 0, numRecordsTotal);
progress.setWindowModality(Qt::ApplicationModal);
// Regular expression to check for numeric strings
QRegExp regexpIsNumeric("\\d*");
// Open text stream to the file
QTextStream stream(&file);
// Put the SQL commands in a transaction block
stream << "BEGIN TRANSACTION;\n";
// Loop through all tables first as they are required to generate views, indices etc. later
for(QList<DBBrowserObject>::ConstIterator it=tables.begin();it!=tables.end();++it)
{
// Write the SQL string used to create this table to the output file
stream << (*it).getsql() << ";\n";
// Get data of this table
browseTable((*it).getname());
// Dump all the content of the table
rowList data = browseRecs;
for(int row=0;row<data.size();row++)
{
stream << "INSERT INTO `" << (*it).getname() << "` VALUES(";
for(int col=1;col<data[row].size();col++)
{
QString content = data[row][col];
content.replace("'", "''");
if(content.isNull())
content = "NULL";
else if(content.length() && !regexpIsNumeric.exactMatch(content))
content = "'" + content + "'";
else if(content.length() == 0)
content = "''";
stream << content;
if(col < data[row].count() - 1)
stream << ",";
else
stream << ");\n";
}
// Update progress dialog
progress.setValue(++numRecordsCurrent);
qApp->processEvents();
if(progress.wasCanceled())
{
file.close();
file.remove();
return false;
}
}
}
// Now dump all the other objects
for(objectMap::ConstIterator it=objMap.begin();it!=objMap.end();++it)
{
// Make sure it's not a table again
if(it.value().gettype() == "table")
continue;
// Write the SQL string used to create this object to the output file
stream << (*it).getsql() << ";\n";
}
// Done
stream << "COMMIT;\n";
file.close();
return true;
} else {
return false;
}
dump_database(_db, cfile);
fclose(cfile);
return true;
}
bool DBBrowserDB::executeSQL ( const QString & statement, bool dirtyDB, bool logsql)
@@ -311,15 +375,13 @@ bool DBBrowserDB::addRecord ( )
int fields = browseFields.count();
QString emptyvalue = curNewData;
QString statement = "INSERT INTO ";
statement.append(GetEncodedQString(curBrowseTableName));
statement.append(" VALUES(");
QString statement = QString("INSERT INTO `%1` VALUES(").arg(GetEncodedQString(curBrowseTableName));
for ( int i=1; i<=fields; i++ ) {
statement.append(emptyvalue);
if (i<fields) statement.append(", ");
}
statement.append(");");
lastErrorMessage = QString("no error");
lastErrorMessage = QObject::tr("no error");
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
@@ -345,11 +407,7 @@ bool DBBrowserDB::deleteRecord( int wrow)
QString& rowid = rt[0];
lastErrorMessage = QString("no error");
QString statement = "DELETE FROM ";
statement.append(GetEncodedQString(curBrowseTableName));
statement.append(" WHERE rowid=");
statement.append(rowid);
statement.append(";");
QString statement = QString("DELETE FROM `%1` WHERE rowid=%2;").arg(GetEncodedQString(curBrowseTableName)).arg(rowid);
if (_db){
logSQL(statement, kLogMsg_App);
@@ -378,11 +436,7 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext)
QString& cv = rt[wcol+1];//must account for rowid
QString ct = browseFields.at(wcol);
QString statement = "UPDATE ";
statement.append(GetEncodedQString(curBrowseTableName));
statement.append(" SET ");
statement.append(GetEncodedQString(ct));
statement.append("=");
QString statement = QString("UPDATE `%1` SET `%2`=").arg(GetEncodedQString(curBrowseTableName)).arg(ct);
QString wenc = GetEncodedQString(wtext);
char * formSQL = sqlite3_mprintf("%Q", wenc.toUtf8().constData());
@@ -407,10 +461,8 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext)
}
return ok;
}
bool DBBrowserDB::browseTable( const QString & tablename, const QString& orderby )
{
QStringList testFields = getTableFields( tablename );
@@ -430,18 +482,202 @@ bool DBBrowserDB::browseTable( const QString & tablename, const QString& orderby
return hasValidBrowseSet;
}
bool DBBrowserDB::createColumn( QString tablename, QString fieldname, QString fieldtype ){
qDebug("create column");
QString sql = QString("ALTER TABLE `%1` ADD COLUMN `%2` %3").arg(tablename).arg(fieldname).arg(fieldtype);
qDebug(sql.toUtf8());
bool DBBrowserDB::createTable(QString name, const QList<DBBrowserField>& structure)
{
// Build SQL statement
QString sql = QString("CREATE TABLE `%1` (").arg(name);
for(int i=0;i<structure.count();i++)
sql.append(QString("`%1` %2,").arg(structure.at(i).getname()).arg(structure.at(i).gettype()));
sql.remove(sql.count() - 1, 1); // Remove last comma
sql.append(");");
// Execute it
return executeSQL(sql);
}
bool DBBrowserDB::renameTable(QString from_table, QString to_table){
qDebug("renameTable column");
bool DBBrowserDB::createColumn(QString tablename, QString fieldname, QString fieldtype)
{
QString sql = QString("ALTER TABLE `%1` ADD COLUMN `%2` %3").arg(tablename).arg(fieldname).arg(fieldtype);
return executeSQL(sql);
}
bool DBBrowserDB::renameColumn(QString tablename, QString from, QString to, QString type)
{
// NOTE: This function is working around the incomplete ALTER TABLE command in SQLite. If SQLite should fully support this command one day, this entire
// function can be changed to executing something like this:
//QString sql = QString("ALTER TABLE `%1` MODIFY `%2` %3").arg(tablename).arg(to).arg(type);
//return executeSQL(sql);
// Collect information on the current DB layout
DBBrowserObject table = getObjectByName(tablename);
if(table.getname() == "" || table.getField(from).getname() == "")
{
lastErrorMessage = QObject::tr("renameColumn: cannot find table %1 with column %2").arg(tablename).arg(from);
qDebug(lastErrorMessage.toStdString().c_str());
return false;
}
// Create savepoint to be able to go back to it in case of any error
if(!executeSQL("SAVEPOINT sqlitebrowser_rename_column"))
{
lastErrorMessage = QObject::tr("renameColumn: creating savepoint failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
return false;
}
// Create a new table with a name that hopefully doesn't exist yet. Its layout is exactly the same as the one of the table to change - except for the column to change
// of course
QList<DBBrowserField> new_table_structure;
for(int i=0;i<table.fldmap.count();i++)
{
// Is this the column to rename?
if(table.fldmap.value(i).getname() == from)
new_table_structure.push_back(DBBrowserField(to, type));
else
new_table_structure.push_back(DBBrowserField(table.fldmap.value(i).getname(), table.fldmap.value(i).gettype()));
}
if(!createTable("sqlitebrowser_rename_column_new_table", new_table_structure))
{
lastErrorMessage = QObject::tr("renameColumn: creating new table failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
return false;
}
// Copy the data from the old table to the new one
if(!executeSQL(QString("INSERT INTO sqlitebrowser_rename_column_new_table SELECT * FROM `%1`;").arg(tablename)))
{
lastErrorMessage = QObject::tr("renameColumn: copying data to new table failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
return false;
}
// Delete the old table
if(!executeSQL(QString("DROP TABLE `%1`;").arg(tablename)))
{
lastErrorMessage = QObject::tr("renameColumn: deleting old table failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
return false;
}
// Rename the temporary table
if(!renameTable("sqlitebrowser_rename_column_new_table", tablename))
{
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
return false;
}
// Release the savepoint - everything went fine
if(!executeSQL("RELEASE SAVEPOINT sqlitebrowser_rename_column;"))
{
lastErrorMessage = QObject::tr("renameColumn: releasing savepoint failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
return false;
}
// Success
return true;
}
bool DBBrowserDB::dropColumn(QString tablename, QString column)
{
// NOTE: This function is working around the incomplete ALTER TABLE command in SQLite. If SQLite should fully support this command one day, this entire
// function can be changed to executing something like this:
//QString sql = QString("ALTER TABLE `%1` DROP COLUMN `%2`;").arg(table).arg(column);
//return executeSQL(sql);
// Collect information on the current DB layout
DBBrowserObject table = getObjectByName(tablename);
if(table.getname() == "" || table.getField(column).getname() == "" || table.fldmap.count() == 1)
{
lastErrorMessage = QObject::tr("dropColumn: cannot find table %1 or column %2. Also you can not delete the last column").arg(tablename).arg(column);
qDebug(lastErrorMessage.toStdString().c_str());
return false;
}
// Create savepoint to be able to go back to it in case of any error
if(!executeSQL("SAVEPOINT sqlitebrowser_drop_column"))
{
lastErrorMessage = QObject::tr("dropColumn: creating savepoint failed");
qDebug(lastErrorMessage.toStdString().c_str());
return false;
}
// Create a new table with a name that hopefully doesn't exist yet. Its layout is exactly the same as the one of the table to change - except for the column to drop
// of course. Also prepare the columns to be copied in a later step now.
QList<DBBrowserField> new_table_structure;
QString select_cols;
for(int i=0;i<table.fldmap.count();i++)
{
// Only add this if it is not the column to drop?
if(table.fldmap.value(i).getname() != column)
{
new_table_structure.push_back(DBBrowserField(table.fldmap.value(i).getname(), table.fldmap.value(i).gettype()));
select_cols.append(QString("`%1`,").arg(table.fldmap.value(i).getname()));
}
}
if(!createTable("sqlitebrowser_drop_column_new_table", new_table_structure))
{
lastErrorMessage = QObject::tr("dropColumn: creating new table failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_drop_column;");
return false;
}
select_cols.remove(select_cols.count() - 1, 1);
// Copy the data from the old table to the new one
if(!executeSQL(QString("INSERT INTO sqlitebrowser_drop_column_new_table SELECT %1 FROM `%2`;").arg(select_cols).arg(tablename)))
{
lastErrorMessage = QObject::tr("dropColumn: copying data to new table failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_drop_column;");
return false;
}
// Delete the old table
if(!executeSQL(QString("DROP TABLE `%1`;").arg(tablename)))
{
lastErrorMessage = QObject::tr("dropColumn: deleting old table failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_drop_column;");
return false;
}
// Rename the temporary table
if(!renameTable("sqlitebrowser_drop_column_new_table", tablename))
{
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_drop_column;");
return false;
}
// Release the savepoint - everything went fine
if(!executeSQL("RELEASE SAVEPOINT sqlitebrowser_drop_column;"))
{
lastErrorMessage = QObject::tr("dropColumn: releasing savepoint failed. DB says: %1").arg(lastErrorMessage);
qDebug(lastErrorMessage.toStdString().c_str());
return false;
}
// Success
return true;
}
bool DBBrowserDB::renameTable(QString from_table, QString to_table)
{
QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(from_table, to_table);
if(!executeSQL(sql))
{
QString error = QObject::tr("Error renaming table '%1' to '%2'. Message from database engine:\n%3").arg(from_table).arg(to_table).arg(lastErrorMessage);
lastErrorMessage = error;
qDebug(error.toStdString().c_str());
return false;
} else {
return true;
}
}
void DBBrowserDB::getTableRecords( const QString & tablename, const QString& orderby )
{
sqlite3_stmt *vm;
@@ -454,14 +690,9 @@ void DBBrowserDB::getTableRecords( const QString & tablename, const QString& ord
// int tabnum = 0;
browseRecs.clear();
idmap.clear();
lastErrorMessage = QString("no error");
lastErrorMessage = QObject::tr("no error");
QString statement = "SELECT rowid, * FROM ";
statement.append( GetEncodedQString(tablename) );
statement.append(" ORDER BY ");
statement.append(orderby);
statement.append(";");
//qDebug(statement);
QString statement = QString("SELECT rowid, * FROM `%1` ORDER BY %2;").arg(GetEncodedQString(tablename)).arg(orderby);
logSQL(statement, kLogMsg_App);
err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(),
&vm, &tail);
@@ -487,7 +718,7 @@ void DBBrowserDB::getTableRecords( const QString & tablename, const QString& ord
sqlite3_finalize(vm);
}else{
lastErrorMessage = QString ("could not get fields");
lastErrorMessage = QObject::tr("could not get fields");
}
}
@@ -501,7 +732,7 @@ resultMap DBBrowserDB::getFindResults( const QString & wstatement)
// char *errmsg;
int err=0;
resultMap res;
lastErrorMessage = QString("no error");
lastErrorMessage = QObject::tr("no error");
QString encstatement = GetEncodedQString(wstatement);
logSQL(encstatement, kLogMsg_App);
err=sqlite3_prepare(_db,encstatement.toUtf8(),encstatement.length(),
@@ -533,26 +764,42 @@ resultMap DBBrowserDB::getFindResults( const QString & wstatement)
}
QStringList DBBrowserDB::getTableNames()
QStringList DBBrowserDB::getBrowsableObjectNames()
{
tableMap::ConstIterator it;
objectMap::ConstIterator it;
QStringList res;
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
res.append( it.value().getname() );
for(it=objMap.begin();it!=objMap.end();++it)
{
if(it.key() == "table" || it.key() == "view")
res.append(it.value().getname());
}
return res;
}
objectMap DBBrowserDB::getBrowsableObjects()
{
objectMap::ConstIterator it;
objectMap res;
for(it=objMap.begin();it!=objMap.end();++it)
{
if(it.key() == "table" || it.key() == "view")
res.insert(it.key(), it.value());
}
return res;
}
QStringList DBBrowserDB::getIndexNames()
{
indexMap::Iterator it;
indexMap tmap = idxmap;
QList<DBBrowserObject> tmap = objMap.values("index");
QList<DBBrowserObject>::ConstIterator it;
QStringList res;
for ( it = tmap.begin(); it != tmap.end(); ++it ) {
res.append( it.value().getname() );
res.append( (*it).getname() );
}
return res;
@@ -560,14 +807,16 @@ QStringList DBBrowserDB::getIndexNames()
QStringList DBBrowserDB::getTableFields(const QString & tablename)
{
tableMap::ConstIterator it;
objectMap::ConstIterator it;
QStringList res;
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
if (tablename.compare(it.value().getname())==0 ){
for ( it = objMap.begin(); it != objMap.end(); ++it )
{
if((*it).getname() == tablename)
{
fieldMap::ConstIterator fit;
for ( fit = it.value().fldmap.begin(); fit != it.value().fldmap.end(); ++fit ) {
for ( fit = (*it).fldmap.begin(); fit != (*it).fldmap.end(); ++fit ) {
res.append( fit.value().getname() );
}
}
@@ -577,14 +826,16 @@ QStringList DBBrowserDB::getTableFields(const QString & tablename)
QStringList DBBrowserDB::getTableTypes(const QString & tablename)
{
tableMap::ConstIterator it;
objectMap::ConstIterator it;
QStringList res;
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
if (tablename.compare(it.value().getname())==0 ){
for ( it = objMap.begin(); it != objMap.end(); ++it )
{
if((*it).getname() == tablename)
{
fieldMap::ConstIterator fit;
for ( fit = it.value().fldmap.begin(); fit != it.value().fldmap.end(); ++fit ) {
for ( fit = (*it).fldmap.begin(); fit != (*it).fldmap.end(); ++fit ) {
res.append( fit.value().gettype() );
}
}
@@ -592,6 +843,19 @@ QStringList DBBrowserDB::getTableTypes(const QString & tablename)
return res;
}
DBBrowserObject DBBrowserDB::getObjectByName(const QString& name)
{
objectMap::ConstIterator it;
QStringList res;
for ( it = objMap.begin(); it != objMap.end(); ++it )
{
if((*it).getname() == name)
return *it;
}
return DBBrowserObject();
}
int DBBrowserDB::getRecordCount()
{
return browseRecs.count();
@@ -606,7 +870,7 @@ void DBBrowserDB::logSQL(QString statement, int msgtype)
if ((statement.length() > loglimit)&&(msgtype==kLogMsg_App))
{
statement.truncate(32);
statement.append("... <string too wide to log, probably contains binary data> ...");
statement.append(QObject::tr("... <string too wide to log, probably contains binary data> ..."));
}
logWin->log(statement, msgtype);
}
@@ -615,84 +879,67 @@ void DBBrowserDB::logSQL(QString statement, int msgtype)
void DBBrowserDB::updateSchema( )
{
// qDebug ("Getting list of tables");
sqlite3_stmt *vm;
const char *tail;
int err=0;
idxmap.clear();
tbmap.clear();
objMap.clear();
lastErrorMessage = QString("no error");
QString statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='table' ;";
lastErrorMessage = QObject::tr("no error");
QString statement = "SELECT type, name, sql FROM sqlite_master;";
err=sqlite3_prepare(_db, (const char *) statement.toUtf8(),statement.length(),
&vm, &tail);
if (err == SQLITE_OK){
logSQL(statement, kLogMsg_App);
while ( sqlite3_step(vm) == SQLITE_ROW ){
QString val1, val2;
QString val1, val2, val3;
val1 = QString((const char *) sqlite3_column_text(vm, 0));
val2 = QString((const char *) sqlite3_column_text(vm, 1));
tbmap[val1] = DBBrowserTable(GetDecodedQString(val1), GetDecodedQString(val2));
}
sqlite3_finalize(vm);
}else{
qDebug ("could not get list of tables: %d, %s",err,sqlite3_errmsg(_db));
}
qDebug(sqlite3_errmsg(_db));
val3 = QString((const char *) sqlite3_column_text(vm, 2));
//now get the field list for each table in tbmap
tableMap::Iterator it;
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
statement = "PRAGMA TABLE_INFO(";
statement.append( it.value().getname());
statement.append(");");
logSQL(statement, kLogMsg_App);
err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(),
&vm, &tail);
if (err == SQLITE_OK){
it.value(). fldmap.clear();
int e = 0;
while ( sqlite3_step(vm) == SQLITE_ROW ){
if (sqlite3_column_count(vm)==6) {
QString val1, val2;
int ispk= 0;
val1 = QString((const char *) sqlite3_column_text(vm, 1));
val2 = QString((const char *) sqlite3_column_text(vm, 2));
ispk = sqlite3_column_int(vm, 5);
if (ispk==1){
val2.append(QString(" PRIMARY KEY"));
}
it.value().addField(e,GetDecodedQString(val1),GetDecodedQString(val2));
e++;
}
}
sqlite3_finalize(vm);
} else{
lastErrorMessage = QString ("could not get types");
}
}
statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='index' ";
/*"ORDER BY name;"*/
//finally get indices
err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(),
&vm, &tail);
logSQL(statement, kLogMsg_App);
if (err == SQLITE_OK){
while ( sqlite3_step(vm) == SQLITE_ROW ){
QString val1, val2;
val1 = QString((const char *) sqlite3_column_text(vm, 0));
val2 = QString((const char *) sqlite3_column_text(vm, 1));
idxmap[val1] = DBBrowserIndex(GetDecodedQString(val1),GetDecodedQString(val2));
if(val1 == "table" || val1 == "index" || val1 == "view" || val1 == "trigger")
objMap.insert(val1, DBBrowserObject(GetDecodedQString(val2), GetDecodedQString(val3), GetDecodedQString(val1)));
else
qDebug(QObject::tr("unknown object type %1").arg(val1).toStdString().c_str());
}
sqlite3_finalize(vm);
}else{
lastErrorMessage = QString ("could not get list of indices");
qDebug(QObject::tr("could not get list of db objects: %1, %2").arg(err).arg(sqlite3_errmsg(_db)).toStdString().c_str());
}
//now get the field list for each table
objectMap::Iterator it;
for ( it = objMap.begin(); it != objMap.end(); ++it )
{
if((*it).gettype() == "table" || (*it).gettype() == "view")
{
statement = QString("PRAGMA TABLE_INFO(`%1`);").arg((*it).getname());
logSQL(statement, kLogMsg_App);
err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(),
&vm, &tail);
if (err == SQLITE_OK){
(*it).fldmap.clear();
int e = 0;
while ( sqlite3_step(vm) == SQLITE_ROW ){
if (sqlite3_column_count(vm)==6) {
QString val1, val2;
int ispk= 0;
val1 = QString((const char *) sqlite3_column_text(vm, 1));
val2 = QString((const char *) sqlite3_column_text(vm, 2));
ispk = sqlite3_column_int(vm, 5);
if(ispk==1)
val2.append(QString(" PRIMARY KEY"));
(*it).addField(e,GetDecodedQString(val1),GetDecodedQString(val2));
e++;
}
}
sqlite3_finalize(vm);
} else{
lastErrorMessage = QObject::tr("could not get types");
}
}
}
}
@@ -707,11 +954,11 @@ QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char q
*numfields = 0;
if ( file.open( QIODevice::ReadWrite ) ) {
QProgressDialog progress("Decoding CSV file...", "Cancel", 0, file.size());
QProgressDialog progress(QObject::tr("Decoding CSV file..."), QObject::tr("Cancel"), 0, file.size());
progress.setWindowModality(Qt::ApplicationModal);
char c=0;
while ( c!=-1) {
file.getChar(&c);
while(file.getChar(&c))
{
if (c==quote){
if (inquotemode){
if (inescapemode){
@@ -755,6 +1002,7 @@ QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char q
}
recs++;
progress.setValue(file.pos());
qApp->processEvents();
if (progress.wasCanceled()) break;
if ((recs>maxrecords)&&(maxrecords!=-1)) {
break;
@@ -777,7 +1025,122 @@ QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char q
return result;
}
QString DBBrowserDB::getPragma(QString pragma)
{
if(!isOpen())
return "";
QString sql = QString("PRAGMA %1").arg(pragma);
sqlite3_stmt* vm;
const char* tail;
QString retval = "";
// Get value from DB
int err = sqlite3_prepare(_db, sql.toStdString().c_str(), sql.length(), &vm, &tail);
if(err == SQLITE_OK){
logSQL(sql, kLogMsg_App);
if(sqlite3_step(vm) == SQLITE_ROW)
{
retval = QString((const char *) sqlite3_column_text(vm, 0));
sqlite3_finalize(vm);
} else {
sqlite3_finalize(vm);
qDebug(QObject::tr("didn't receive any output from pragma %1").arg(pragma).toStdString().c_str());
}
} else {
qDebug(QObject::tr("could not execute pragma command: %1, %2").arg(err).arg(sqlite3_errmsg(_db)).toStdString().c_str());
}
// Make changes to the value when needed
if(pragma == "journal_mode")
{
retval = retval.toLower();
if(retval == "delete")
retval = "0";
else if(retval == "truncate")
retval = "1";
else if(retval == "persist")
retval = "2";
else if(retval == "memory")
retval = "3";
else if(retval == "wal")
retval = "4";
else if(retval == "off")
retval = "5";
else
retval = "0";
} else if(pragma == "locking_mode") {
retval = retval.toLower();
if(retval == "normal")
retval = "0";
else if(retval == "exclusive")
retval = "1";
else
retval = "0";
} else if(pragma == "encoding") {
retval = retval.toLower();
if(retval == "utf-8")
retval = "0";
else if(retval == "utf-16")
retval = "1";
else if(retval == "utf-16le")
retval = "2";
else if(retval == "utf-16be")
retval = "3";
else
retval = "0";
}
// Return it
return retval;
}
bool DBBrowserDB::setPragma(QString pragma, QString value)
{
// Make changes to the value when needed
if(pragma == "journal_mode")
{
if(value == "0")
value = "delete";
else if(value == "1")
value = "truncate";
else if(value == "2")
value = "persist";
else if(value == "3")
value = "memory";
else if(value == "4")
value = "wal";
else if(value == "5")
value = "off";
else
value = "delete";
} else if(value == "locking_mode") {
if(value == "0")
value = "normal";
else if(value == "1")
value = "exclusive";
else
value = "normal";
} else if(pragma == "encoding") {
if(value == "0")
value = "\"utf-8\"";
else if(value == "1")
value = "\"utf-16\"";
else if(value == "2")
value = "\"utf-16le\"";
else if(value == "3")
value = "\"utf-16be\"";
else
value = "\"utf-8\"";
}
// Set the pragma value
QString sql = QString("PRAGMA %1 = %2;").arg(pragma).arg(value);
if(!executeSQL(sql))
{
qDebug(QObject::tr("Error setting pragma %1 to %2: %3").arg(pragma).arg(value).arg(lastErrorMessage).toStdString().c_str());
return false;
} else {
return true;
}
}

View File

@@ -1,11 +1,10 @@
#ifndef SQLITEDB_H
#define SQLITEDB_H
#include <qstringlist.h>
#include <qmap.h>
#include <qobject.h>
#include "sqlite3.h"
#include "sqlitebrowsertypes.h"
#include <QStringList>
#include <QMap>
#include <QMultiMap>
#include <sqlite3.h>
class SQLLogDock;
@@ -22,13 +21,17 @@ enum
kEncodingNONE
};
static QString g_sApplicationNameShort = QString("sqlitebrowser");
static QString g_applicationIconName = QString(":/oldimages/icon16");
/*types for encoded media data*/
enum
{
kSQLiteMediaType_Void,
kSQLiteMediaType_Integer,
kSQLiteMediaType_String,
kSQLiteMediaType_Binary
};
typedef QMap<int, class DBBrowserField> fieldMap;
typedef QMap<QString, class DBBrowserTable> tableMap;
typedef QMap<QString, class DBBrowserIndex> indexMap;
typedef QMultiMap<QString, class DBBrowserObject> objectMap;
typedef QMap<int, int> rowIdMap;
typedef QList<QStringList> rowList;
@@ -48,37 +51,31 @@ private:
QString type;
};
class DBBrowserIndex
class DBBrowserObject
{
public:
DBBrowserIndex() : name( "" ) { }
DBBrowserIndex( const QString& wname,const QString& wsql )
: name( wname), sql( wsql )
{ }
QString getname() const { return name; }
QString getsql() const { return sql; }
private:
QString name;
QString sql;
};
class DBBrowserTable
{
public:
DBBrowserTable() : name( "" ) { }
DBBrowserTable( const QString& wname,const QString& wsql )
: name( wname), sql( wsql )
DBBrowserObject() : name( "" ) { }
DBBrowserObject( const QString& wname,const QString& wsql, const QString& wtype )
: name( wname), sql( wsql ), type(wtype)
{ }
void addField(int order, const QString& wfield,const QString& wtype);
QString getname() const { return name; }
QString getsql() const { return sql; }
QString gettype() const { return type; }
DBBrowserField getField(const QString& name) const
{
for(fieldMap::ConstIterator i=fldmap.begin();i!=fldmap.end();++i)
if(i.value().getname() == name)
return *i;
return DBBrowserField();
}
fieldMap fldmap;
private:
QString name;
QString sql;
QString type;
};
@@ -103,12 +100,17 @@ public:
bool updateRecord(int wrow, int wcol, const QString & wtext);
bool browseTable( const QString & tablename, const QString& orderby = "rowid" );
bool createTable(QString name, const QList<DBBrowserField>& structure);
bool renameTable(QString from_table, QString to_table);
bool createColumn(QString table, QString field, QString type);
bool renameColumn(QString tablename, QString from, QString to, QString type);
bool dropColumn(QString tablename, QString column);
QStringList getTableFields(const QString & tablename);
QStringList getTableTypes(const QString & tablename);
QStringList getTableNames();
QStringList getBrowsableObjectNames();
objectMap getBrowsableObjects();
DBBrowserObject getObjectByName(const QString& name);
QStringList getIndexNames();
resultMap getFindResults( const QString & wstatement);
int getRecordCount();
@@ -122,13 +124,14 @@ public:
char * GetEncodedQStringAsPointer( const QString & input);
QString GetEncodedQString( const QString & input);
QString GetDecodedQString( const QString & input);
QString getPragma(QString pragma);
bool setPragma(QString pragma, QString value);
sqlite3 * _db;
QStringList decodeCSV(const QString & csvfilename, char sep, char quote, int maxrecords, int * numfields);
tableMap tbmap;
indexMap idxmap;
objectMap objMap;
rowIdMap idmap;
rowList browseRecs;

View File

@@ -1,5 +1,8 @@
TEMPLATE = app
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sqlitebrowser
INCLUDEPATH += sqlite_source/
@@ -8,56 +11,37 @@ CONFIG += qt \
debug
HEADERS += \
sqlitebrowsertypes.h \
sqlitedb.h \
sqlbrowser_util.h \
sqlite_source/sqlite3.h \
addfieldform.h \
addfieldtypeform.h \
choosetableform.h \
createindexform.h \
createtableform.h \
deleteindexform.h \
deletetableform.h \
editfieldform.h \
editform.h \
edittableform.h \
exporttablecsvform.h \
findform.h \
importcsvform.h \
renametableform.h \
preferencesform.h \
mainwindow.h \
createtabledialog.h \
SQLLogDock.h \
sqlitesyntaxhighlighter.h \
dialogabout.h
MainWindow.h \
SQLiteSyntaxHighlighter.h \
CreateIndexDialog.h \
EditFieldDialog.h \
AboutDialog.h \
EditTableDialog.h \
PreferencesDialog.h \
FindDialog.h \
EditDialog.h \
ExportCsvDialog.h \
ImportCsvDialog.h
SOURCES += \
browsermain.cpp \
sqlitedb.cpp \
sqlbrowser_util.c \
sqlite_source/sqlite3.c \
addfieldform.cpp \
addfieldtypeform.cpp \
choosetableform.cpp \
createindexform.cpp \
createtableform.cpp \
deleteindexform.cpp \
deletetableform.cpp \
editfieldform.cpp \
editform.cpp \
edittableform.cpp \
exporttablecsvform.cpp \
findform.cpp \
importcsvform.cpp \
renametableform.cpp \
preferencesform.cpp \
mainwindow.cpp \
createtabledialog.cpp \
SQLLogDock.cpp \
sqlitesyntaxhighlighter.cpp \
dialogabout.cpp
main.cpp \
MainWindow.cpp \
SQLiteSyntaxHighlighter.cpp \
CreateIndexDialog.cpp \
EditFieldDialog.cpp \
EditTableDialog.cpp \
PreferencesDialog.cpp \
AboutDialog.cpp \
FindDialog.cpp \
EditDialog.cpp \
ExportCsvDialog.cpp \
ImportCsvDialog.cpp
QMAKE_CXXFLAGS += -DAPP_VERSION=\\\"`cd $$PWD;git log -n1 --format=%h_git`\\\"
@@ -65,7 +49,7 @@ unix {
UI_DIR = .ui
MOC_DIR = .moc
OBJECTS_DIR = .obj
LIBS += -ldl
LIBS += -ldl -lsqlite3
}
win32:RC_FILE = winapp.rc
mac {
@@ -79,5 +63,13 @@ mac {
RESOURCES += icons/icons.qrc
FORMS += \
createtabledialog.ui \
dialogabout.ui
MainWindow.ui \
CreateIndexDialog.ui \
AboutDialog.ui \
EditFieldDialog.ui \
EditTableDialog.ui \
PreferencesDialog.ui \
FindDialog.ui \
EditDialog.ui \
ExportCsvDialog.ui \
ImportCsvDialog.ui

View File