*** empty log message ***

This commit is contained in:
tabuleiro
2004-07-20 20:29:51 +00:00
parent a083e69cb4
commit 68d60c1e5b
46 changed files with 5892 additions and 719 deletions

View File

@@ -1,4 +1,4 @@
<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>aboutForm</class>
<widget class="QDialog">
<property name="name">
@@ -8,60 +8,79 @@
<rect>
<x>0</x>
<y>0</y>
<width>396</width>
<height>218</height>
<width>510</width>
<height>177</height>
</rect>
</property>
<property name="caption">
<string>About</string>
</property>
<grid>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QTextBrowser" row="0" column="0" rowspan="1" colspan="2">
<widget class="QLabel">
<property name="name">
<cstring>aboutBrowser</cstring>
<cstring>textLabel1</cstring>
</property>
<property name="frameShape">
<enum>NoFrame</enum>
</property>
<property name="frameShadow">
<enum>Plain</enum>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Text</string>
<string>Version 1.1
SQLite Database Browser is an open source, public domain, freeware visual tool used to create, design and edit SQLite 2.x database files.
More information at http://sqlitebrowser.sourceforge.net.</string>
</property>
<property name="alignment">
<set>WordBreak|AlignVCenter</set>
</property>
</widget>
<widget class="QPushButton" row="1" column="1">
<widget class="QLayoutWidget">
<property name="name">
<cstring>okButton</cstring>
</property>
<property name="text">
<string>Close</string>
</property>
<property name="default">
<bool>true</bool>
<cstring>layout55</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer5</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>141</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>okButton</cstring>
</property>
<property name="text">
<string>Close</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</hbox>
</widget>
<spacer row="1" column="0">
<property name="name">
<cstring>spacer5</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>141</width>
<height>20</height>
</size>
</property>
</spacer>
</grid>
</vbox>
</widget>
<connections>
<connection>

View File

@@ -10,5 +10,5 @@
void aboutForm::init()
{
this->setCaption(applicationName);
aboutBrowser->setText(aboutText);
//aboutBrowser->setText(aboutText);
}

View File

@@ -0,0 +1,222 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>addFieldForm</class>
<widget class="QDialog">
<property name="name">
<cstring>addFieldForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>338</width>
<height>136</height>
</rect>
</property>
<property name="caption">
<string>Add database field</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer row="1" column="1">
<property name="name">
<cstring>spacer17</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
<widget class="QLayoutWidget" row="2" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>layout21</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer15</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>41</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>cancelButton</cstring>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>createButton</cstring>
</property>
<property name="text">
<string>Create</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget" row="0" column="0">
<property name="name">
<cstring>layout23</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1</cstring>
</property>
<property name="text">
<string>Field name:</string>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>textLabel2</cstring>
</property>
<property name="text">
<string>Field type:</string>
</property>
</widget>
</vbox>
</widget>
<widget class="QLayoutWidget" row="0" column="1">
<property name="name">
<cstring>layout7</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLineEdit">
<property name="name">
<cstring>nameLineEdit</cstring>
</property>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout6</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<item>
<property name="text">
<string></string>
</property>
</item>
<item>
<property name="text">
<string>text</string>
</property>
</item>
<item>
<property name="text">
<string>integer</string>
</property>
</item>
<item>
<property name="text">
<string>blob</string>
</property>
</item>
<property name="name">
<cstring>typeBox</cstring>
</property>
</widget>
<widget class="QToolButton">
<property name="name">
<cstring>typeButton</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>...</string>
</property>
<property name="toolTip" stdset="0">
<string>Custom type</string>
</property>
<property name="whatsThis" stdset="0">
<string>Click this button to enter a new type for the field</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
</grid>
</widget>
<connections>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>addFieldForm</receiver>
<slot>reject()</slot>
</connection>
<connection>
<sender>createButton</sender>
<signal>clicked()</signal>
<receiver>addFieldForm</receiver>
<slot>confirmAddField()</slot>
</connection>
<connection>
<sender>typeButton</sender>
<signal>clicked()</signal>
<receiver>addFieldForm</receiver>
<slot>getCustomType()</slot>
</connection>
</connections>
<includes>
<include location="global" impldecl="in implementation">qmessagebox.h</include>
<include location="local" impldecl="in implementation">sqlitedb.h</include>
<include location="local" impldecl="in implementation">addfieldtypeform.h</include>
<include location="local" impldecl="in implementation">addfieldform.ui.h</include>
</includes>
<variables>
<variable access="public">QString fname;</variable>
<variable access="public">QString ftype;</variable>
</variables>
<slots>
<slot>setInitialValues( QString name, QString type )</slot>
<slot>confirmAddField()</slot>
<slot>getCustomType()</slot>
</slots>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,48 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void addFieldForm::setInitialValues(QString name, QString type)
{
nameLineEdit->setText(name);
typeBox->clear();
typeBox->insertItem(type);
QString tString = "";
if (type.compare(tString)!=0) typeBox->insertItem(tString);
tString = "text";
if (type.compare(tString)!=0) typeBox->insertItem(tString);
tString = "numeric";
if (type.compare(tString)!=0) typeBox->insertItem(tString);
tString = "blob";
if (type.compare(tString)!=0) typeBox->insertItem(tString);
}
void addFieldForm::confirmAddField()
{
QString fieldname = nameLineEdit->text();
if (fieldname.isEmpty()) {
QMessageBox::information( this, applicationName, "Field name can not be empty" );
return;
}
if (fieldname.contains(" ")>0) {
QMessageBox::warning( this, applicationName, "Spaces are not allowed in the field name" );
return;
}
fname = fieldname;
ftype = typeBox->currentText();
accept();
}
void addFieldForm::getCustomType()
{
addFieldTypeForm * addForm = new addFieldTypeForm( this, "addfieldtype", TRUE );
if (addForm->exec())
{
QString nospaces = addForm->typeNameEdit->text().remove(" ");
setInitialValues(nameLineEdit->text(),nospaces );
}
}

View File

@@ -0,0 +1,95 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>addFieldTypeForm</class>
<widget class="QDialog">
<property name="name">
<cstring>addFieldTypeForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>294</width>
<height>98</height>
</rect>
</property>
<property name="caption">
<string>Enter field type</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLineEdit" row="0" column="0">
<property name="name">
<cstring>typeNameEdit</cstring>
</property>
</widget>
<widget class="QLayoutWidget" row="1" column="0">
<property name="name">
<cstring>layout11</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer5</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>31</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>cancelButton</cstring>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>okButton</cstring>
</property>
<property name="text">
<string>OK</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</hbox>
</widget>
</grid>
</widget>
<connections>
<connection>
<sender>okButton</sender>
<signal>clicked()</signal>
<receiver>addFieldTypeForm</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>addFieldTypeForm</receiver>
<slot>reject()</slot>
</connection>
</connections>
<includes>
<include location="global" impldecl="in implementation">qmessagebox.h</include>
<include location="local" impldecl="in implementation">sqlitedb.h</include>
</includes>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -1,14 +1,3 @@
/*
** This file is part of SQLite Database Browser
** http://sqlitebrowser.sourceforge.net
**
** Originally developed by Mauricio Piacentini, Tabuleiro
**
** The author disclaims copyright to this source code.
** Consult the LICENSING file for known restrictions
**
*/
#include <qapplication.h>
#include "form1.h"
@@ -17,6 +6,10 @@ int main( int argc, char ** argv )
QApplication a( argc, argv );
mainForm w;
w.show();
if (argc>1) {
//first and only argument we accept is the name of the database to open
w.fileOpen(QString(argv[1]));
}
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}

View File

@@ -0,0 +1,148 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>chooseTableForm</class>
<widget class="QDialog">
<property name="name">
<cstring>chooseTableForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>256</width>
<height>163</height>
</rect>
</property>
<property name="caption">
<string>Select table to edit</string>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout21</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel2</cstring>
</property>
<property name="text">
<string>Table name:</string>
</property>
</widget>
<widget class="QComboBox">
<property name="name">
<cstring>comboOptions</cstring>
</property>
<property name="toolTip" stdset="0">
<string>Choose the table to delete</string>
</property>
<property name="whatsThis" stdset="0">
<string>Use this control to select the name of the table to be edited</string>
</property>
</widget>
</hbox>
</widget>
<spacer>
<property name="name">
<cstring>spacer13</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>41</height>
</size>
</property>
</spacer>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout19</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer11</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>31</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>buttonEdit</cstring>
</property>
<property name="text">
<string>Edit</string>
</property>
<property name="toolTip" stdset="0">
<string>Edit table</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>buttonCancel</cstring>
</property>
<property name="text">
<string>Cancel</string>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="toolTip" stdset="0">
<string>Cancel and close dialog box</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
<connections>
<connection>
<sender>buttonCancel</sender>
<signal>clicked()</signal>
<receiver>chooseTableForm</receiver>
<slot>reject()</slot>
</connection>
<connection>
<sender>buttonEdit</sender>
<signal>clicked()</signal>
<receiver>chooseTableForm</receiver>
<slot>editPressed()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">choosetableform.ui.h</include>
</includes>
<variables>
<variable access="public">QString option;</variable>
</variables>
<slots>
<slot>editPressed()</slot>
<slot>populateOptions( QStringList entries )</slot>
</slots>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,21 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void chooseTableForm::editPressed()
{
option = comboOptions->currentText();
accept();
}
void chooseTableForm::populateOptions(QStringList entries)
{
comboOptions->clear();
for ( QStringList::Iterator ct = entries.begin(); ct != entries.end(); ++ct ) {
comboOptions->insertItem(*ct,-1);
}
}

View File

@@ -1,4 +1,4 @@
<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>createTableForm</class>
<widget class="QDialog">
<property name="name">
@@ -9,7 +9,7 @@
<x>0</x>
<y>0</y>
<width>309</width>
<height>312</height>
<height>320</height>
</rect>
</property>
<property name="caption">
@@ -68,43 +68,51 @@
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QTable">
<widget class="QListView">
<column>
<property name="text">
<string>Field Name</string>
<string>Field name</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<column>
<property name="text">
<string>Field Type</string>
<string>Field type</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<property name="name">
<cstring>fieldsTable</cstring>
<item>
<property name="text">
<string>New Item</string>
</property>
<property name="acceptDrops">
<bool>true</bool>
<property name="text">
<string></string>
</property>
<property name="pixmap">
<pixmap></pixmap>
</property>
<property name="pixmap">
<pixmap></pixmap>
</property>
</item>
<property name="name">
<cstring>fieldListView</cstring>
</property>
<property name="resizePolicy">
<enum>Default</enum>
<enum>Manual</enum>
</property>
<property name="numRows">
<number>0</number>
</property>
<property name="numCols">
<number>2</number>
</property>
<property name="rowMovingEnabled">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>SingleRow</enum>
</property>
<property name="focusStyle">
<enum>FollowStyle</enum>
</property>
<property name="whatsThis" stdset="0">
<string>This area contains the definitions for the fields in your new table. Add a new field using the ADD button. You can type the name of the field and the field type directly. Suggested field types are text, numeric or blob (for images and binary data)</string>
<property name="resizeMode">
<enum>AllColumns</enum>
</property>
</widget>
<widget class="QLayoutWidget">
@@ -150,6 +158,9 @@
<property name="name">
<cstring>buttonDeleteField</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Delete</string>
</property>
@@ -243,10 +254,17 @@
<receiver>createTableForm</receiver>
<slot>deleteField()</slot>
</connection>
<connection>
<sender>fieldListView</sender>
<signal>selectionChanged()</signal>
<receiver>createTableForm</receiver>
<slot>fieldSelectionChanged()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">qmessagebox.h</include>
<include location="local" impldecl="in declaration">sqlitedb.h</include>
<include location="local" impldecl="in implementation">qmessagebox.h</include>
<include location="local" impldecl="in implementation">addfieldform.h</include>
<include location="local" impldecl="in implementation">createtableform.ui.h</include>
</includes>
<variables>
@@ -256,6 +274,7 @@
<slot>confirmCreate()</slot>
<slot>addField()</slot>
<slot>deleteField()</slot>
<slot>fieldSelectionChanged()</slot>
</slots>
<functions>
<function access="private" specifier="non virtual">init()</function>

View File

@@ -8,8 +8,7 @@
*****************************************************************************/
void createTableForm::init()
{
fieldsTable->setNumRows(0);
// fieldsTable->setNumCols(0);
fieldListView->clear();
}
void createTableForm::confirmCreate()
@@ -27,14 +26,15 @@ void createTableForm::confirmCreate()
return;
}
if (fieldsTable->numRows()==0) {
if (fieldListView->firstChild()==0) {
ok = false;
QMessageBox::information( this, applicationName, "No fields defined" );
return;
}
/*check field names for empty or illegal names*/
/*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()) {
@@ -47,7 +47,7 @@ void createTableForm::confirmCreate()
QMessageBox::warning( this, applicationName, "Spaces are not allowed in the field names" );
break;
}
}
}*/
if (!ok){
return;
@@ -57,13 +57,26 @@ void createTableForm::confirmCreate()
createStatement = "CREATE TABLE ";
createStatement.append(tabname);
createStatement.append(" (");
for (int r=0; r<fieldsTable->numRows();r++){
QListViewItemIterator it( fieldListView );
QListViewItem * item;
while ( it.current() ) {
item = it.current();
createStatement.append(item->text(0));
createStatement.append(" ");
createStatement.append(item->text(1));
if (item->nextSibling() != 0)
{
createStatement.append(", ");
}
++it;
}
/*for (int r=0; r<fieldsTable->numRows();r++){
createStatement.append(fieldsTable->text(r, 0));
createStatement.append(" ");
createStatement.append(fieldsTable->text(r, 1));
if (r<(fieldsTable->numRows() - 1))
createStatement.append(", ");
}
}*/
createStatement.append(");");
accept();
}
@@ -72,13 +85,38 @@ void createTableForm::confirmCreate()
void createTableForm::addField()
{
fieldsTable->insertRows(fieldsTable->numRows());
addFieldForm * addForm = new addFieldForm( this, "addfield", TRUE );
addForm->setInitialValues(QString(""),QString(""));
if (addForm->exec())
{
//qDebug(addForm->fname + addForm->ftype);
QListViewItem * tbitem = new QListViewItem( fieldListView);
tbitem->setText( 0, addForm->fname );
tbitem->setText( 1, addForm->ftype );
}
}
void createTableForm::deleteField()
{
if (fieldsTable->currentRow()!=-1){
fieldsTable->removeRow(fieldsTable->currentRow());
}
QListViewItem * item = fieldListView->selectedItem();
if (item==0) {
//should never happen, the button would not be active, but...
return;
} else {
delete item;
}
}
void createTableForm::fieldSelectionChanged()
{
QListViewItem * item = fieldListView->selectedItem();
if (item==0) {
buttonDeleteField->setEnabled(false);
} else {
buttonDeleteField->setEnabled(true);
}
}

View File

@@ -0,0 +1,232 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>editFieldForm</class>
<widget class="QDialog">
<property name="name">
<cstring>editFieldForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>352</width>
<height>140</height>
</rect>
</property>
<property name="caption">
<string>Edit field name and type</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget" row="0" column="0">
<property name="name">
<cstring>layout23</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1</cstring>
</property>
<property name="text">
<string>Field name:</string>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>textLabel2</cstring>
</property>
<property name="text">
<string>Field type:</string>
</property>
</widget>
</vbox>
</widget>
<spacer row="1" column="1">
<property name="name">
<cstring>spacer17</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>14</height>
</size>
</property>
</spacer>
<widget class="QLayoutWidget" row="2" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>layout21</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer15</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>41</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>cancelButton</cstring>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>saveButton</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Apply Changes</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget" row="0" column="1">
<property name="name">
<cstring>layout26</cstring>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget" row="1" column="0">
<property name="name">
<cstring>layout25</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<item>
<property name="text">
<string></string>
</property>
</item>
<item>
<property name="text">
<string>text</string>
</property>
</item>
<item>
<property name="text">
<string>integer</string>
</property>
</item>
<item>
<property name="text">
<string>blob</string>
</property>
</item>
<property name="name">
<cstring>typeBox</cstring>
</property>
</widget>
<widget class="QToolButton">
<property name="name">
<cstring>typeButton</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>...</string>
</property>
<property name="toolTip" stdset="0">
<string>Custom type</string>
</property>
<property name="whatsThis" stdset="0">
<string>Click this button to enter a new type for the field</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLineEdit" row="0" column="0">
<property name="name">
<cstring>nameLineEdit</cstring>
</property>
</widget>
</grid>
</widget>
</grid>
</widget>
<connections>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>editFieldForm</receiver>
<slot>reject()</slot>
</connection>
<connection>
<sender>saveButton</sender>
<signal>clicked()</signal>
<receiver>editFieldForm</receiver>
<slot>confirmEdit()</slot>
</connection>
<connection>
<sender>nameLineEdit</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>editFieldForm</receiver>
<slot>enableSave()</slot>
</connection>
<connection>
<sender>typeButton</sender>
<signal>clicked()</signal>
<receiver>editFieldForm</receiver>
<slot>getCustomType()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">sqlitedb.h</include>
<include location="global" impldecl="in implementation">qmessagebox.h</include>
<include location="local" impldecl="in implementation">addfieldtypeform.h</include>
<include location="local" impldecl="in implementation">editfieldform.ui.h</include>
</includes>
<variables>
<variable access="public">QString name;</variable>
<variable access="public">QString type;</variable>
</variables>
<slots>
<slot>setInitialValues( QString name, QString type )</slot>
<slot>confirmEdit()</slot>
<slot>enableSave()</slot>
<slot>getCustomType()</slot>
</slots>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,54 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void editFieldForm::setInitialValues(QString name, QString type)
{
nameLineEdit->setText(name);
typeBox->clear();
typeBox->insertItem(type);
QString tString = "";
if (type.compare(tString)!=0) typeBox->insertItem(tString);
tString = "text";
if (type.compare(tString)!=0) typeBox->insertItem(tString);
tString = "numeric";
if (type.compare(tString)!=0) typeBox->insertItem(tString);
tString = "blob";
if (type.compare(tString)!=0) typeBox->insertItem(tString);
}
void editFieldForm::confirmEdit()
{
QString fieldname = nameLineEdit->text();
if (fieldname.isEmpty()) {
QMessageBox::information( this, applicationName, "Field name can not be empty" );
return;
}
if (fieldname.contains(" ")>0) {
QMessageBox::warning( this, applicationName, "Spaces are not allowed in the field name" );
return;
}
name = fieldname;
type = typeBox->currentText();
accept();
}
void editFieldForm::enableSave()
{
saveButton->setEnabled(true);
}
void editFieldForm::getCustomType()
{
addFieldTypeForm * addForm = new addFieldTypeForm( this, "addfieldtype", TRUE );
if (addForm->exec())
{
QString nospaces = addForm->typeNameEdit->text().remove(" ");
setInitialValues(nameLineEdit->text(),nospaces );
enableSave();
}
}

View File

@@ -0,0 +1,369 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>editForm</class>
<widget class="QDialog">
<property name="name">
<cstring>editForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>366</width>
<height>431</height>
</rect>
</property>
<property name="caption">
<string>Edit database cell</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout11</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QToolButton">
<property name="name">
<cstring>importButton</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Import</string>
</property>
<property name="toolTip" stdset="0">
<string>Import text</string>
</property>
<property name="whatsThis" stdset="0">
<string>Opens a file dialog used to import text to this database cell.</string>
</property>
</widget>
<widget class="QToolButton">
<property name="name">
<cstring>exportButton</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Export</string>
</property>
<property name="toolTip" stdset="0">
<string>Export text</string>
</property>
<property name="whatsThis" stdset="0">
<string>Opens a file dialog used to export the contents of this database cell to a text file.</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer11_2</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>81</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QToolButton">
<property name="name">
<cstring>clearButton</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Clear</string>
</property>
<property name="toolTip" stdset="0">
<string>Clear cell data</string>
</property>
<property name="whatsThis" stdset="0">
<string>Erases the contents of the cell</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QWidgetStack">
<property name="name">
<cstring>editWidgetStack</cstring>
</property>
<widget class="QWidget">
<property name="name">
<cstring>WStackPage</cstring>
</property>
<attribute name="id">
<number>0</number>
</attribute>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QTextEdit" row="0" column="0">
<property name="name">
<cstring>textEditor</cstring>
</property>
</widget>
</grid>
</widget>
<widget class="QWidget">
<property name="name">
<cstring>WStackPage</cstring>
</property>
<attribute name="id">
<number>1</number>
</attribute>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel" row="0" column="0">
<property name="name">
<cstring>editPixmap</cstring>
</property>
<property name="maximumSize">
<size>
<width>320</width>
<height>240</height>
</size>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>AlignCenter</set>
</property>
</widget>
</grid>
</widget>
</widget>
<widget class="QFrame">
<property name="name">
<cstring>frame9</cstring>
</property>
<property name="frameShape">
<enum>Box</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="toolTip" stdset="0">
<string></string>
</property>
<property name="whatsThis" stdset="0">
<string>This area displays information about the data present in this database cell</string>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>currentTypeLabel</cstring>
</property>
<property name="text">
<string>Type of data currently in cell: Empty</string>
</property>
<property name="alignment">
<set>AlignVCenter|AlignLeft</set>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>currentDataInfo</cstring>
</property>
<property name="text">
<string>Data information</string>
</property>
<property name="alignment">
<set>WordBreak|AlignVCenter|AlignLeft</set>
</property>
</widget>
</vbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout3</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer11</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>90</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>closeButton</cstring>
</property>
<property name="text">
<string>Close</string>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="toolTip" stdset="0">
<string>Close</string>
</property>
<property name="whatsThis" stdset="0">
<string>Close the window without saving changes</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>saveChangesButton</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Apply Changes</string>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="toolTip" stdset="0">
<string>Save changes to database</string>
</property>
<property name="whatsThis" stdset="0">
<string>Close this window saving changes to the database</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
<connections>
<connection>
<sender>importButton</sender>
<signal>clicked()</signal>
<receiver>editForm</receiver>
<slot>importData()</slot>
</connection>
<connection>
<sender>exportButton</sender>
<signal>clicked()</signal>
<receiver>editForm</receiver>
<slot>exportData()</slot>
</connection>
<connection>
<sender>saveChangesButton</sender>
<signal>clicked()</signal>
<receiver>editForm</receiver>
<slot>saveChanges()</slot>
</connection>
<connection>
<sender>clearButton</sender>
<signal>clicked()</signal>
<receiver>editForm</receiver>
<slot>clearData()</slot>
</connection>
<connection>
<sender>textEditor</sender>
<signal>textChanged()</signal>
<receiver>editForm</receiver>
<slot>editTextChanged()</slot>
</connection>
<connection>
<sender>closeButton</sender>
<signal>clicked()</signal>
<receiver>editForm</receiver>
<slot>close()</slot>
</connection>
<connection>
<sender>textEditor</sender>
<signal>clicked(int,int)</signal>
<receiver>editForm</receiver>
<slot>editorClicked()</slot>
</connection>
</connections>
<includes>
<include location="global" impldecl="in declaration">qimage.h</include>
<include location="global" impldecl="in declaration">qapplication.h</include>
<include location="global" impldecl="in declaration">qfile.h</include>
<include location="global" impldecl="in declaration">stdlib.h</include>
<include location="local" impldecl="in implementation">sqlitedb.h</include>
<include location="global" impldecl="in implementation">qfiledialog.h</include>
<include location="global" impldecl="in implementation">qmessagebox.h</include>
<include location="local" impldecl="in implementation">editform.ui.h</include>
</includes>
<variables>
<variable>bool modified;</variable>
<variable>int dataType;</variable>
<variable>int dataSize;</variable>
<variable>int dataDepth;</variable>
<variable access="public">int curCol;</variable>
<variable access="public">int curRow;</variable>
</variables>
<signals>
<signal>goingAway();</signal>
<signal>updateRecordText(int, int, QString);</signal>
<signal>updateRecordBinary(int, int, unsigned char *);</signal>
</signals>
<slots>
<slot>reset()</slot>
<slot>setModified( bool modifiedstate )</slot>
<slot>enableExport( bool enabled )</slot>
<slot>enableTextEditor( bool enabled )</slot>
<slot>setDataType( int type, int size )</slot>
<slot>closeEvent( QCloseEvent * )</slot>
<slot>loadText( QString text, int row, int col )</slot>
<slot>importData()</slot>
<slot>exportData()</slot>
<slot>clearData()</slot>
<slot>saveChanges()</slot>
<slot>editTextChanged()</slot>
<slot>editorClicked()</slot>
</slots>
<functions>
<function access="private" specifier="non virtual">init()</function>
<function access="private" specifier="non virtual">destroy()</function>
</functions>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,200 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void editForm::init()
{
setModified(false);
dataType = kSQLiteMediaType_Void;
dataSize = 0;
dataDepth = 0;
curRow = -1;
curCol = -1;
textEditor->setText("");
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::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->length()>1) charstr = QString("chars"); else charstr = QString("char");
currentDataInfo->setText(QString("%1 %2").arg(textEditor->length()).arg(charstr));
editWidgetStack->raiseWidget(0);
enableExport(true);
enableTextEditor(true);
break;
case kSQLiteMediaType_Void:
currentTypeLabel->setText("Type of data currently in cell: Empty");
currentDataInfo->setText("");
editWidgetStack->raiseWidget(0);
enableExport(false);
enableTextEditor(true);
break;
}
}
void editForm::closeEvent( QCloseEvent * )
{
emit goingAway();
}
void editForm::loadText(QString text, int row, int col)
{
textEditor->setText(text);
curRow = row;
curCol = col;
if (textEditor->length() > 0)
{
setDataType(kSQLiteMediaType_String, 0);
} else {
setDataType(kSQLiteMediaType_Void, 0);
}
setModified(false);
}
void editForm::importData()
{
int type = kSQLiteMediaType_Void;
QString fileName = QFileDialog::getOpenFileName(
"",
QString( "Text files (*.txt);;"
"All files (*.*);;"),
this,
"open file dialog"
"Choose an image file" );
if (QFile::exists(fileName) )
{
type = kSQLiteMediaType_String;
QFile file( fileName );
if ( file.open( IO_ReadOnly ) ) {
QTextStream stream( &file );
textEditor->setText(stream.read());
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(
"",
filter,
this,
"save file dialog"
"Choose a filename to export data" );
if (fileName)
{
switch (dataType)
{
case kSQLiteMediaType_String:
{
QFile file(fileName);
if ( file.open( IO_WriteOnly ) ) {
QTextStream stream( &file );
stream << textEditor->text();
file.close();
}
}
break;
default:
return;
}
}
}
void editForm::clearData()
{
textEditor->setText("");
setDataType(kSQLiteMediaType_Void, 0);
setModified(true);
}
void editForm::saveChanges()
{
if (dataType==kSQLiteMediaType_String)
emit updateRecordText(curRow, curCol, textEditor->text());
if (dataType==kSQLiteMediaType_Void)
emit updateRecordText(curRow, curCol, QString(""));
setModified(false);
emit goingAway();
}
void editForm::editTextChanged()
{
int newtype = kSQLiteMediaType_String;
if (textEditor->length() == 0)
{
newtype = kSQLiteMediaType_Void;
}
if (newtype!=dataType)
{
setDataType(newtype, 0);
}
setModified(true);
}
void editForm::editorClicked()
{
enableTextEditor(true);
}

View File

@@ -0,0 +1,329 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>editFormWindow</class>
<widget class="QMainWindow">
<property name="name">
<cstring>editFormWindow</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>435</height>
</rect>
</property>
<property name="caption">
<string>Edit database cell</string>
</property>
<property name="dockWindowsMovable">
<bool>true</bool>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
</vbox>
</widget>
<menubar>
<property name="name">
<cstring>MenuBar</cstring>
</property>
<item text="&amp;File" name="fileMenu">
<action name="fileOpenAction"/>
<action name="fileSaveAction"/>
<separator/>
<action name="filePrintAction"/>
<separator/>
</item>
<item text="&amp;Edit" name="editMenu">
<action name="editUndoAction"/>
<action name="editRedoAction"/>
<separator/>
<action name="editCutAction"/>
<action name="editCopyAction"/>
<action name="editPasteAction"/>
</item>
<item text="&amp;Help" name="helpMenu">
<action name="helpAboutAction"/>
</item>
</menubar>
<toolbars>
<toolbar dock="2">
<property name="name">
<cstring>toolBar</cstring>
</property>
<property name="label">
<string>Tools</string>
</property>
<action name="fileOpenAction"/>
<action name="fileSaveAction"/>
<action name="filePrintAction"/>
<separator/>
<action name="editCutAction"/>
<action name="editCopyAction"/>
<action name="editPasteAction"/>
<action name="helpContentsAction"/>
</toolbar>
</toolbars>
<actions>
<action>
<property name="name">
<cstring>fileNewAction</cstring>
</property>
<property name="iconSet">
<iconset>filenew</iconset>
</property>
<property name="text">
<string>New</string>
</property>
<property name="menuText">
<string>&amp;New</string>
</property>
<property name="accel">
<string>Ctrl+N</string>
</property>
</action>
<action>
<property name="name">
<cstring>fileOpenAction</cstring>
</property>
<property name="iconSet">
<iconset>fileopen</iconset>
</property>
<property name="text">
<string>&amp;Import</string>
</property>
<property name="menuText">
<string>&amp;Import</string>
</property>
<property name="accel">
<string>Ctrl+I</string>
</property>
</action>
<action>
<property name="name">
<cstring>fileSaveAction</cstring>
</property>
<property name="iconSet">
<iconset>filesave</iconset>
</property>
<property name="text">
<string>&amp;Export</string>
</property>
<property name="menuText">
<string>&amp;Export</string>
</property>
<property name="accel">
<string>Ctrl+E</string>
</property>
</action>
<action>
<property name="name">
<cstring>fileSaveAsAction</cstring>
</property>
<property name="text">
<string>Save As</string>
</property>
<property name="menuText">
<string>Save &amp;As...</string>
</property>
<property name="accel">
<string></string>
</property>
</action>
<action>
<property name="name">
<cstring>filePrintAction</cstring>
</property>
<property name="iconSet">
<iconset>print</iconset>
</property>
<property name="text">
<string>Print</string>
</property>
<property name="menuText">
<string>&amp;Print...</string>
</property>
<property name="accel">
<string>Ctrl+P</string>
</property>
</action>
<action>
<property name="name">
<cstring>fileExitAction</cstring>
</property>
<property name="text">
<string>Exit</string>
</property>
<property name="menuText">
<string>E&amp;xit</string>
</property>
<property name="accel">
<string></string>
</property>
</action>
<action>
<property name="name">
<cstring>editUndoAction</cstring>
</property>
<property name="iconSet">
<iconset>undo</iconset>
</property>
<property name="text">
<string>Undo</string>
</property>
<property name="menuText">
<string>&amp;Undo</string>
</property>
<property name="accel">
<string>Ctrl+Z</string>
</property>
</action>
<action>
<property name="name">
<cstring>editRedoAction</cstring>
</property>
<property name="iconSet">
<iconset>redo</iconset>
</property>
<property name="text">
<string>Redo</string>
</property>
<property name="menuText">
<string>&amp;Redo</string>
</property>
<property name="accel">
<string>Ctrl+Y</string>
</property>
</action>
<action>
<property name="name">
<cstring>editCutAction</cstring>
</property>
<property name="iconSet">
<iconset>editcut</iconset>
</property>
<property name="text">
<string>Cut</string>
</property>
<property name="menuText">
<string>&amp;Cut</string>
</property>
<property name="accel">
<string>Ctrl+X</string>
</property>
</action>
<action>
<property name="name">
<cstring>editCopyAction</cstring>
</property>
<property name="iconSet">
<iconset>editcopy</iconset>
</property>
<property name="text">
<string>Copy</string>
</property>
<property name="menuText">
<string>C&amp;opy</string>
</property>
<property name="accel">
<string>Ctrl+C</string>
</property>
</action>
<action>
<property name="name">
<cstring>editPasteAction</cstring>
</property>
<property name="iconSet">
<iconset>editpaste</iconset>
</property>
<property name="text">
<string>Paste</string>
</property>
<property name="menuText">
<string>&amp;Paste</string>
</property>
<property name="accel">
<string>Ctrl+V</string>
</property>
</action>
<action>
<property name="name">
<cstring>editFindAction</cstring>
</property>
<property name="iconSet">
<iconset>searchfind</iconset>
</property>
<property name="text">
<string>Find</string>
</property>
<property name="menuText">
<string>&amp;Find...</string>
</property>
<property name="accel">
<string>Ctrl+F</string>
</property>
</action>
<action>
<property name="name">
<cstring>helpContentsAction</cstring>
</property>
<property name="text">
<string>Contents</string>
</property>
<property name="menuText">
<string>&amp;Contents...</string>
</property>
<property name="accel">
<string></string>
</property>
</action>
<action>
<property name="name">
<cstring>helpIndexAction</cstring>
</property>
<property name="text">
<string>Index</string>
</property>
<property name="menuText">
<string>&amp;Index...</string>
</property>
<property name="accel">
<string></string>
</property>
</action>
<action>
<property name="name">
<cstring>helpAboutAction</cstring>
</property>
<property name="text">
<string>&amp;What is</string>
</property>
<property name="menuText">
<string>&amp;What is</string>
</property>
<property name="accel">
<string></string>
</property>
</action>
</actions>
<slots>
<slot>fileNew()</slot>
<slot>fileOpen()</slot>
<slot>fileSave()</slot>
<slot>fileSaveAs()</slot>
<slot>filePrint()</slot>
<slot>fileExit()</slot>
<slot>editUndo()</slot>
<slot>editRedo()</slot>
<slot>editCut()</slot>
<slot>editCopy()</slot>
<slot>editPaste()</slot>
<slot>editFind()</slot>
<slot>helpIndex()</slot>
<slot>helpContents()</slot>
<slot>helpAbout()</slot>
</slots>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,260 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>editTableForm</class>
<widget class="QDialog">
<property name="name">
<cstring>editTableForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>428</width>
<height>266</height>
</rect>
</property>
<property name="caption">
<string>Edit table definition</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget" row="0" column="0">
<property name="name">
<cstring>layout50</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLineEdit">
<property name="name">
<cstring>tableLine</cstring>
</property>
<property name="focusPolicy">
<enum>NoFocus</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QListView">
<column>
<property name="text">
<string>Field name</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<column>
<property name="text">
<string>Field type</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<item>
<property name="text">
<string>New Item</string>
</property>
<property name="text">
<string></string>
</property>
<property name="pixmap">
<pixmap></pixmap>
</property>
<property name="pixmap">
<pixmap></pixmap>
</property>
</item>
<property name="name">
<cstring>fieldListView</cstring>
</property>
<property name="resizePolicy">
<enum>Manual</enum>
</property>
<property name="resizeMode">
<enum>AllColumns</enum>
</property>
</widget>
</vbox>
</widget>
<widget class="QLayoutWidget" row="0" column="1">
<property name="name">
<cstring>layout42</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QPushButton">
<property name="name">
<cstring>renameTableButton</cstring>
</property>
<property name="text">
<string>Rename table</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer31</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>23</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>renameFieldButton</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit field</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>removeFieldButton</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Remove field</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>addFieldButton</cstring>
</property>
<property name="text">
<string>Add field</string>
</property>
</widget>
</vbox>
</widget>
<widget class="QLayoutWidget" row="1" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>layout41</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer34</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>161</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>closeButton</cstring>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
</hbox>
</widget>
</grid>
</widget>
<connections>
<connection>
<sender>closeButton</sender>
<signal>clicked()</signal>
<receiver>editTableForm</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>renameTableButton</sender>
<signal>clicked()</signal>
<receiver>editTableForm</receiver>
<slot>renameTable()</slot>
</connection>
<connection>
<sender>removeFieldButton</sender>
<signal>clicked()</signal>
<receiver>editTableForm</receiver>
<slot>removeField()</slot>
</connection>
<connection>
<sender>addFieldButton</sender>
<signal>clicked()</signal>
<receiver>editTableForm</receiver>
<slot>addField()</slot>
</connection>
<connection>
<sender>renameFieldButton</sender>
<signal>clicked()</signal>
<receiver>editTableForm</receiver>
<slot>editField()</slot>
</connection>
<connection>
<sender>fieldListView</sender>
<signal>selectionChanged()</signal>
<receiver>editTableForm</receiver>
<slot>fieldSelectionChanged()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in declaration">sqlitedb.h</include>
<include location="local" impldecl="in implementation">renametableform.h</include>
<include location="global" impldecl="in implementation">qmessagebox.h</include>
<include location="local" impldecl="in implementation">addfieldform.h</include>
<include location="local" impldecl="in implementation">editfieldform.h</include>
<include location="global" impldecl="in implementation">qapplication.h</include>
<include location="local" impldecl="in implementation">edittableform.ui.h</include>
</includes>
<variables>
<variable access="public">bool modified;</variable>
<variable>QStringList types;</variable>
<variable>QStringList fields;</variable>
<variable>DBBrowserDB * pdb;</variable>
<variable access="public">QString curTable;</variable>
</variables>
<slots>
<slot>setActiveTable( DBBrowserDB * thedb, QString tableName )</slot>
<slot>populateFields()</slot>
<slot>renameTable()</slot>
<slot>editField()</slot>
<slot>addField()</slot>
<slot>removeField()</slot>
<slot>fieldSelectionChanged()</slot>
</slots>
<functions>
<function access="private" specifier="non virtual">init()</function>
</functions>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,530 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
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);
fieldListView->clear();
fieldListView->setSorting (-1, FALSE);
QListViewItem * lasttbitem = 0;
QStringList::Iterator tt = types.begin();
for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) {
QListViewItem * tbitem = new QListViewItem( fieldListView, lasttbitem);
tbitem->setText( 0, *ct );
tbitem->setText( 1, *tt );
lasttbitem = tbitem;
++tt;
}
}
void editTableForm::renameTable()
{
renameTableForm * renTableForm = new renameTableForm( this, "renametable", TRUE );
renTableForm->setTableName(curTable);
if (renTableForm->exec())
{
QApplication::setOverrideCursor( 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;
sql = "CREATE TEMPORARY TABLE TEMP_TABLE(";
QListViewItemIterator it( fieldListView );
QListViewItem * 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 = QListViewItemIterator( 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 = QListViewItemIterator( 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 = QListViewItemIterator( 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()
{
QListViewItem * item = fieldListView->selectedItem();
if (item==0) {
//should never happen, the button would not be active, but...
return;
} else {
editFieldForm * fieldForm = new editFieldForm( this, "editfield", TRUE );
fieldForm->setInitialValues(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->name);
item->setText(1,fieldForm->type);
//not until nested transaction are supported
//if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback;
QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE(";
QListViewItemIterator it( fieldListView );
QListViewItem * 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 = QListViewItemIterator( 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 = QListViewItemIterator( 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, "addfield", TRUE );
addForm->setInitialValues(QString(""),QString(""));
if (addForm->exec())
{
modified = true;
QListViewItem * tbitem = new QListViewItem( fieldListView);
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(";
QListViewItemIterator it( fieldListView );
QListViewItem * 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 = QListViewItemIterator( 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);
}
}
void editTableForm::removeField()
{
QListViewItem * 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(remitem->text(0));
msg.append("? \n All data currently stored in this field will be lost");
if (QMessageBox::warning( this, 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(";
QListViewItemIterator it( fieldListView );
QListViewItem * item;
//not until nested transaction are supported
// if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback;
it = QListViewItemIterator( 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 = QListViewItemIterator( 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 = QListViewItemIterator( 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 = QListViewItemIterator( fieldListView );
while ( it.current() ) {
item = it.current();
sql.append(item->text(0));
if (item->nextSibling() != 0)
{
sql.append(", ");
}
++it;
}
sql.append(") SELECT ");
it = QListViewItemIterator( 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()
{
QListViewItem * item = fieldListView->selectedItem();
if (item==0) {
renameFieldButton->setEnabled(false);
removeFieldButton->setEnabled(false);
} else {
renameFieldButton->setEnabled(true);
removeFieldButton->setEnabled(true);
}
}

View File

@@ -0,0 +1,148 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>exportTableCSVForm</class>
<widget class="QDialog">
<property name="name">
<cstring>exportTableCSVForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>365</width>
<height>150</height>
</rect>
</property>
<property name="caption">
<string>Choose table to export as CSV text</string>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout21</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel2</cstring>
</property>
<property name="text">
<string>Table name:</string>
</property>
</widget>
<widget class="QComboBox">
<property name="name">
<cstring>comboOptions</cstring>
</property>
<property name="toolTip" stdset="0">
<string>Choose the table to delete</string>
</property>
<property name="whatsThis" stdset="0">
<string>Use this control to select the name of the table to be deleted</string>
</property>
</widget>
</hbox>
</widget>
<spacer>
<property name="name">
<cstring>spacer13</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>41</height>
</size>
</property>
</spacer>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout69</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer11</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>29</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>buttonCancel</cstring>
</property>
<property name="text">
<string>Cancel</string>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="toolTip" stdset="0">
<string>Cancel and close dialog box</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>buttonExport</cstring>
</property>
<property name="text">
<string>Export</string>
</property>
<property name="toolTip" stdset="0">
<string>Delete the selected table</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
<connections>
<connection>
<sender>buttonExport</sender>
<signal>clicked()</signal>
<receiver>exportTableCSVForm</receiver>
<slot>exportPressed()</slot>
</connection>
<connection>
<sender>buttonCancel</sender>
<signal>clicked()</signal>
<receiver>exportTableCSVForm</receiver>
<slot>reject()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">exporttablecsvform.ui.h</include>
</includes>
<variables>
<variable access="public">QString option;</variable>
</variables>
<slots>
<slot>exportPressed()</slot>
<slot>populateOptions( QStringList entries )</slot>
</slots>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,21 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void exportTableCSVForm::exportPressed()
{
option = comboOptions->currentText();
accept();
}
void exportTableCSVForm::populateOptions(QStringList entries)
{
comboOptions->clear();
for ( QStringList::Iterator ct = entries.begin(); ct != entries.end(); ++ct ) {
comboOptions->insertItem(*ct,-1);
}
}

View File

@@ -17,7 +17,13 @@ void findForm::showResults(resultMap rmap)
QListViewItem * tbitem = new QListViewItem( findListView, lasttbitem );
//tbitem->setOpen( TRUE );
tbitem->setText( 0, QString::number(it.key() + 1,10) ); //increase from index 0
tbitem->setText( 1, it.data() );
QString firstline = it.data().section( '\n', 0,0 );
if (firstline.length()>MAX_DISPLAY_LENGTH)
{
firstline.truncate(MAX_DISPLAY_LENGTH);
firstline.append("...");
}
tbitem->setText( 1, firstline );
lasttbitem = tbitem;
}
QString results = "Found: ";

File diff suppressed because it is too large Load Diff

View File

@@ -14,47 +14,85 @@ void mainForm::init()
clipboard->setSelectionMode( TRUE );
findWin = 0;
editWin = 0;
logWin = 0;
recsPerView = 1000;
recAtTop = 0;
gotoValidator = new QIntValidator(0,0,this);
editGoto->setValidator(gotoValidator);
gotoValidator->setRange ( 0, 0);
resetBrowser();
this->setCaption(applicationName);
this->setCaption(applicationName);
this->setIcon( QPixmap::fromMimeSource( applicationIconName ) );
buttonNext->setEnabled(FALSE);
buttonPrevious->setEnabled(FALSE);
if (!editWin)
{
editWin = new editForm(this);
connect( editWin, SIGNAL( goingAway() ),this, SLOT( editWinAway() ) );
connect( editWin, SIGNAL( updateRecordText(int, int , QString) ),
this, SLOT( updateRecordText(int, int , QString) ) );
}
if (!logWin)
{
logWin = new sqlLogForm(this);
connect( logWin, SIGNAL( goingAway() ),this, SLOT( logWinAway() ) );
connect( logWin, SIGNAL( dbState(bool) ),this, SLOT( dbState(bool) ) );
}
//connect db and log
db.logWin = logWin;
}
void mainForm::destroy()
{
if (gotoValidator)
delete gotoValidator;
}
void mainForm::fileOpen()
void mainForm::fileOpen(const QString & fileName)
{
QString fileName = QFileDialog::getOpenFileName(
QString wFile = fileName;
if (!QFile::exists(wFile))
{
wFile = QFileDialog::getOpenFileName(
"",
"",
this,
"open file dialog"
"Choose a database file" );
if (QFile::exists(fileName) )
}
if (QFile::exists(wFile) )
{
db.open(fileName);
db.buildParameterMap();
populateStructure();
populateParameter();
resetParamBrowser();
resetBrowser();
if (db.open(wFile))
{
this->setCaption(applicationName+" - "+wFile);
fileCloseAction->setEnabled(true);
compactAction->setEnabled(true);
fileCompactAction->setEnabled(true);
editCreateTableAction->setEnabled(true);
editDeleteTableAction->setEnabled(true);
editModifyTableAction->setEnabled(true);
editCreateIndexAction->setEnabled(true);
editDeleteIndexAction->setEnabled(true);
}
populateStructure();
resetBrowser();
}
}
void mainForm::fileOpen()
{
fileOpen(QString());
}
void mainForm::fileNew()
{
QString fileName = QFileDialog::getSaveFileName(
@@ -74,14 +112,17 @@ void mainForm::fileNew()
if (!fileName.isNull())
{
db.create(fileName);
db.buildParameterMap();
this->setCaption(applicationName+" - "+fileName);
populateStructure();
populateParameter();
resetParamBrowser();
resetBrowser();
resetBrowser();
createTable();
fileCloseAction->setEnabled(true);
compactAction->setEnabled(true);
fileCompactAction->setEnabled(true);
editCreateTableAction->setEnabled(true);
editDeleteTableAction->setEnabled(true);
editModifyTableAction->setEnabled(true);
editCreateIndexAction->setEnabled(true);
editDeleteIndexAction->setEnabled(true);
}
}
@@ -125,31 +166,6 @@ void mainForm::populateStructure()
}
}
void mainForm::populateParameter()
{
if (!db.isOpen()){
paramTable->setNumRows( 0 );
return;
}
db.buildParameterMap();
db.updateParameter();
paramMap::Iterator it;
paramMap tmap = db.parammap;
paramTable->setNumRows( tmap.count() );
paramTable->setNumCols( 2 );
//QListViewItem * lasttbitem = 0;
int rowNum = 0;
for ( it = tmap.begin(); it != tmap.end(); ++it ) {
paramTable->setText( rowNum, 0, it.data().getname() );
paramTable->setText( rowNum, 1, it.data().getvalue() );
++rowNum;
}
}
void mainForm::populateTable( const QString & tablename)
{
bool mustreset = false;
@@ -179,15 +195,12 @@ void mainForm::populateTable( const QString & tablename)
if (findWin){
findWin->resetResults();
}
if (editWin)
{
editWin->reset();
}
}
void mainForm::getActualParamValue( const QString & paramName)
{
paramMap pmap = db.parammap;
paramValueEdit->setText(pmap[paramName].getvalue());
}
void mainForm::resetBrowser()
{
recAtTop = 0;
@@ -205,39 +218,41 @@ void mainForm::resetBrowser()
populateTable(comboBrowseTable->currentText());
}
void mainForm::resetParamBrowser()
{
comboParamTable->clear();
paramValueEdit->clear();
if (!db.isOpen()) {
comboParamTable->insertItem("",-1);
return;
}
paramMap::Iterator it;
paramMap pmap = db.parammap;
for ( it = pmap.begin(); it != pmap.end(); ++it ) {
comboParamTable->insertItem(it.key(),-1);
}
comboParamTable->setCurrentItem(0);
getActualParamValue(comboParamTable->currentText());
}
void mainForm::fileClose()
{
db.close();
this->setCaption(applicationName);
resetBrowser();
resetParamBrowser();
populateStructure();
populateParameter();
fileCloseAction->setEnabled(false);
compactAction->setEnabled(false);
fileCompactAction->setEnabled(false);
editCreateTableAction->setEnabled(false);
editDeleteTableAction->setEnabled(false);
editModifyTableAction->setEnabled(false);
editCreateIndexAction->setEnabled(false);
editDeleteIndexAction->setEnabled(false);
}
void mainForm::fileExit()
{
db.close();
if (db.isOpen())
{
if (db.getDirty())
{
QString msg = "Do you want to save the changes made to the database file ";
msg.append(db.curDBFilename);
msg.append("?");
if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
db.save();
} else {
//not really necessary, I think... but will not hurt.
db.revert();
}
}
db.close();
}
QApplication::exit( 0 );
}
@@ -259,26 +274,10 @@ void mainForm::addRecord()
}
void mainForm::recordEdited( int wrow, int wcol )
{
if (!db.updateRecord(wrow+recAtTop, wcol, dataTable->text(wrow, wcol))){
//could not update
rowList tab = db.browseRecs;
rowList::iterator rt = tab.at(wrow+recAtTop);
QString rowid = (*rt).first();
QStringList::Iterator cv = (*rt).at(wcol+1);//must account for rowid
dataTable->setText( wrow, wcol, *cv );
QMessageBox::information( this, applicationName, "Data can not be edited" );
}
dataTable->setVScrollBarMode(QScrollView::AlwaysOff);
dataTable->setVScrollBarMode(QScrollView::Auto);
}
void mainForm::deleteRecord()
{
if (dataTable->currentRow()!=-1){
int lastselected = dataTable->currentRow();
int lastselected = dataTable->currentRow();
db.deleteRecord(dataTable->currentRow()+recAtTop);
populateTable(db.curBrowseTableName);
int nextselected = lastselected ;
@@ -287,7 +286,7 @@ void mainForm::deleteRecord()
}
if (nextselected>0){
selectTableLine(nextselected);
}
}
} else {
QMessageBox::information( this, applicationName, "Please select a record first" ); }
}
@@ -298,7 +297,7 @@ void mainForm::updateTableView(int lineToSelect)
QApplication::setOverrideCursor( waitCursor, TRUE );
QStringList fields = db.browseFields;
dataTable->setNumRows(0);
dataTable->setNumRows(0);
dataTable->setNumCols( fields.count() );
int cheadnum = 0;
for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) {
@@ -329,7 +328,14 @@ void mainForm::updateTableView(int lineToSelect)
for ( QStringList::Iterator it = (*rt).begin(); it != (*rt).end(); ++it ) {
//skip first one (the rowid)
if (it!=(*rt).begin()){
dataTable->setText( rowNum, colNum, *it );
QString content = *it;
QString firstline = content.section( '\n', 0,0 );
if (content.length()>MAX_DISPLAY_LENGTH)
{
firstline.truncate(MAX_DISPLAY_LENGTH);
firstline.append("...");
}
dataTable->setText( rowNum, colNum, firstline);
colNum++;
}
}
@@ -339,14 +345,9 @@ void mainForm::updateTableView(int lineToSelect)
//dataTable->clearSelection(true);
if (lineToSelect!=-1){
//qDebug("inside selection");
selectTableLine(lineToSelect);
//qDebug("inside selection");
selectTableLine(lineToSelect);
}
// dataTable->clearSelection(true);
// dataTable->selectRow(lineToSelect);
// dataTable->setCurrentCell(lineToSelect, 0);
// dataTable->ensureCellVisible (lineToSelect, 0 ) ;
// }
setRecordsetLabel();
QApplication::restoreOverrideCursor();
}
@@ -407,7 +408,7 @@ void mainForm::setRecordsetLabel()
label.append(" of ");
label.append(QString::number(db.getRecordCount(),10));
labelRecordset->setText(label);
}
}
gotoValidator->setRange ( 0, db.getRecordCount());
if (db.getRecordCount()>1000){
@@ -562,7 +563,7 @@ void mainForm::compact()
populateStructure();
resetBrowser();
fileCloseAction->setEnabled(true);
compactAction->setEnabled(true);
fileCompactAction->setEnabled(true);
QApplication::restoreOverrideCursor( );
}
@@ -590,6 +591,34 @@ void mainForm::deleteTable()
}
}
void mainForm::editTable()
{
if (!db.isOpen()){
QMessageBox::information( this, applicationName, "There is no database opened." );
return;
}
chooseTableForm * tableForm = new chooseTableForm( this, "choosetable", TRUE );
QStringList tablelist = db.getTableNames();
if (tablelist.empty()){
QMessageBox::information( this, applicationName, "There are no tables to edit in this database." );
return;
}
tableForm->populateOptions( tablelist );
if ( tableForm->exec() ) {
//statement.append(tableForm->option);
editTableForm * edTableForm = new editTableForm( this, "edittable", TRUE );
//send table name ? or handle it all from here?
edTableForm->setActiveTable(&db, tableForm->option);
edTableForm->exec();
//check modified status
if (edTableForm->modified)
{
populateStructure();
resetBrowser();
}
}
}
void mainForm::deleteIndex()
{
@@ -666,19 +695,381 @@ void mainForm::helpAbout()
}
void mainForm::setParamValue()
void mainForm::updateRecordText(int row, int col, QString newtext)
{
if(!db.isOpen()) {
QMessageBox::information( this, applicationName,
"Please open a database first" );
if (!db.updateRecord(row, col, newtext)){
QMessageBox::information( this, applicationName, "Data could not be updated" );
}
/*dataTable->setVScrollBarMode(QScrollView::AlwaysOff);
dataTable->setVScrollBarMode(QScrollView::Auto);
dataTable->setReadOnly(true);*/
rowList tab = db.browseRecs;
rowList::iterator rt = tab.at(row);
QString rowid = (*rt).first();
QStringList::Iterator cv = (*rt).at(col+1);//must account for rowid
QString content = *cv ;
QString firstline = content.section( '\n', 0,0 );
if (content.length()>14)
{
firstline.truncate(14);
firstline.append("...");
}
dataTable->setText( row - recAtTop, col, firstline);
}
void mainForm::logWinAway()
{
sqlLogAction->toggle();
}
void mainForm::editWinAway()
{
editWin->hide();
setActiveWindow();
dataTable->selectCells ( editWin->curRow - recAtTop, editWin->curCol, editWin->curRow- recAtTop, editWin->curCol);
}
void mainForm::editText(int row, int col)
{
rowList tab = db.browseRecs;
rowList::iterator rt = tab.at(row);
QString rowid = (*rt).first();
QStringList::Iterator cv = (*rt).at(col+1);//must account for rowid
//dataTable->setText( row - recAtTop, col, *cv );
editWin->loadText(*cv , row, col);
editWin ->show();
}
void mainForm::doubleClickTable( int row, int col, int button, const QPoint & mousepoint )
{
if ((row==-1) || (col==-1)){
qDebug("no cell selected");
return;
}
const QString newValue = paramValueEdit->text();
const QString paramName = comboParamTable->currentText();
paramMap pmap = db.parammap;
db.setParameter(pmap[paramName].getname(), newValue);
populateParameter( );
int realRow = row + recAtTop;
editText(realRow , col);
}
void mainForm::executeQuery()
{
QString query = sqlTextEdit->text();
if (query.isEmpty())
{
QMessageBox::information( this, applicationName, "Query string is empty" );
return;
}
//log the query
db.logSQL(query, kLogMsg_User);
sqlite_vm *vm;
const char *tail;
const char **vals;
const char **names;
int ncol;
char *errmsg;
int err=0;
QString lastErrorMessage = QString("No error");
queryResultListView->clear();
queryResultListView->setSorting (-1, FALSE);
while (queryResultListView->columns()>0)
{
queryResultListView->removeColumn(0);
}
err=sqlite_compile(db._db,query,
&tail, &vm, &errmsg);
if (err == SQLITE_OK){
db.setDirty(true);
int rownum = 0;
QListViewItem * lasttbitem = 0;
bool mustCreateColumns = true;
while ( sqlite_step(vm,&ncol,&vals, &names) == SQLITE_ROW ){
//r.clear()
QListViewItem * tbitem = new QListViewItem( queryResultListView, lasttbitem);
//setup num of cols here for display grid
if (mustCreateColumns)
{
for (int e=0; e<ncol; e++)
queryResultListView->addColumn("");
mustCreateColumns = false;
}
for (int e=0; e<ncol; e++){
QString rv = vals[e];
//show it here
QString firstline = rv.section( '\n', 0,0 );
if (firstline.length()>MAX_DISPLAY_LENGTH)
{
firstline.truncate(MAX_DISPLAY_LENGTH);
firstline.append("...");
}
tbitem->setText( e, firstline);
lasttbitem = tbitem;
rownum++;
}
}
sqlite_finalize(vm, NULL);
}else{
lastErrorMessage = QString (errmsg);
}
queryErrorLineEdit->setText(lastErrorMessage);
}
void mainForm::mainTabSelected(const QString & tabname)
{
if ((mainTab->currentPageIndex ()==0)||(mainTab->currentPageIndex ()==1))
{
populateStructure();
resetBrowser();
}
}
void mainForm::toggleLogWindow( bool enable )
{
if (enable){
logWin->show();
} else {
logWin->hide();
}
}
void mainForm::importTableFromCSV()
{
if (!db.isOpen()){
QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file first." );
return;
}
if (db.getDirty())
{
QString msg = "Database needs to be saved before the import operation.\nSave current changes and continue?";
if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
db.save();
} else {
return;
}
}
QString wFile = QFileDialog::getOpenFileName(
"",
"Text files (*.csv *.txt)",
this,
"import csv data"
"Choose a text file" );
if (QFile::exists(wFile) )
{
importCSVForm * csvForm = new importCSVForm( this, "importcsv", TRUE );
csvForm->initialize(wFile, &db);
if ( csvForm->exec() ) {
populateStructure();
resetBrowser();
QMessageBox::information( this, applicationName, "Import completed" );
}
}
}
void mainForm::exportTableToCSV()
{
if (!db.isOpen()){
QMessageBox::information( this, applicationName, "There is no database opened to export" );
return;
}
exportTableCSVForm * exportForm = new exportTableCSVForm( this, "export table", TRUE );
exportForm->populateOptions( db.getTableNames());
if ( exportForm->exec() ) {
//qDebug(exportForm->option);
//load our table
db.browseTable(exportForm->option);
QString fileName = QFileDialog::getSaveFileName(
"",
"Text files (*.csv *txt)",
this,
"save file dialog"
"Choose a filename to export data" );
if (fileName)
{
QFile file(fileName);
if ( file.open( IO_WriteOnly ) )
{
char quote = '"';
char sep = ',';
char feed = 10;
int colNum = 0;
int colCount = 0;
QTextStream stream( &file );
//fieldnames on first row
QStringList fields = db.browseFields;
colCount = fields.count();
for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) {
stream << quote;
stream << *ct;
stream << quote;
colNum++;
if (colNum<colCount)
{
stream << sep;
} else {
stream << feed;
colNum = 0;
}
}
//now export data
rowList tab = db.browseRecs;
rowList::iterator rt;
//int dcols =0;
QString rowLabel;
for ( rt = tab.at(0); rt !=tab.end(); ++rt )
{
for ( QStringList::Iterator it = (*rt).begin(); it != (*rt).end(); ++it ) {
//skip first one (the rowid)
if (it!=(*rt).begin()){
QString content = *it;
stream<< quote;
QChar qquote = quote;
content.replace(quote, QString(qquote).append(qquote));
stream<< content;
stream<< quote;
colNum++;
if (colNum<colCount)
{
stream << sep;
} else {
stream << feed;
colNum = 0;
}
}
}
}
file.close();
QMessageBox::information( this, applicationName, "Export completed" );
}
}
populateStructure();
resetBrowser();
}
}
void mainForm::dbState( bool dirty )
{
fileSaveAction->setEnabled(dirty);
fileRevertAction->setEnabled(dirty);
}
void mainForm::fileSave()
{
if (db.isOpen()){
db.save();
}
}
void mainForm::fileRevert()
{
if (db.isOpen()){
QString msg = "Are you sure you want to undo all changes made to the database file \n ";
msg.append(db.curDBFilename);
msg.append(" since the last save?");
if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
db.revert();
populateStructure();
resetBrowser();
}
}
}
void mainForm::exportDatabaseToSQL()
{
if (!db.isOpen()){
QMessageBox::information( this, applicationName, "There is no database opened to export" );
return;
}
QString fileName = QFileDialog::getSaveFileName(
"",
"Text files (*.sql *txt)",
0,
"save file dialog"
"Choose a filename to export" );
if (fileName)
{
if (!db.dump(fileName))
{
QMessageBox::information( this, applicationName, "Could not create export file" );
} else {
QMessageBox::information( this, applicationName, "Export completed" );
}
}
}
void mainForm::importDatabaseFromSQL()
{
QString fileName = QFileDialog::getOpenFileName(
"",
"Text files (*.sql *txt)",
0,
"import file dialog"
"Choose a file to import" );
if (fileName)
{
QString msg = "Do you want to create a new database file to hold the imported data?\nIf you answer NO we will attempt to import data in the .sql file to the current database.";
if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
QString newDBfile = QFileDialog::getSaveFileName(
"",
"",
this,
"create file dialog"
"Choose a filename to save under" );
if (QFile::exists(newDBfile) )
{
QString err = "File ";
err.append(newDBfile);
err.append(" already exists. Please choose a different name");
QMessageBox::information( this, applicationName ,err);
return;
}
if (!fileName.isNull())
{
db.create(newDBfile);
}
}
int lineErr;
if (!db.reload(fileName, &lineErr))
{
QMessageBox::information( this, applicationName, QString("Error importing data at line %1").arg(lineErr) );
}
else
{
QMessageBox::information( this, applicationName, "Import completed" );
}
populateStructure();
resetBrowser();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

View File

@@ -0,0 +1,304 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>importCSVForm</class>
<widget class="QDialog">
<property name="name">
<cstring>importCSVForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>372</width>
<height>382</height>
</rect>
</property>
<property name="caption">
<string>Create table from CSV file</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout27</cstring>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel" row="0" column="0">
<property name="name">
<cstring>textLabel3</cstring>
</property>
<property name="text">
<string>New table name:</string>
</property>
</widget>
<widget class="QLineEdit" row="0" column="1">
<property name="name">
<cstring>tableNameEdit</cstring>
</property>
</widget>
<widget class="QCheckBox" row="2" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>extractFieldNamesCheckbox</cstring>
</property>
<property name="text">
<string>Extract field names from first line</string>
</property>
</widget>
<widget class="QLayoutWidget" row="1" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>layout25</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout23</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1</cstring>
</property>
<property name="text">
<string>Field separator:</string>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>textLabel2</cstring>
</property>
<property name="text">
<string>Text quote character:</string>
</property>
</widget>
</vbox>
</widget>
<spacer>
<property name="name">
<cstring>spacer15</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>81</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout22</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<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>
<property name="name">
<cstring>fieldBox</cstring>
</property>
</widget>
<widget class="QComboBox">
<item>
<property name="text">
<string>"</string>
</property>
</item>
<item>
<property name="text">
<string>'</string>
</property>
</item>
<item>
<property name="text">
<string>\</string>
</property>
</item>
<item>
<property name="text">
<string></string>
</property>
</item>
<property name="name">
<cstring>quoteBox</cstring>
</property>
</widget>
</vbox>
</widget>
</hbox>
</widget>
</grid>
</widget>
<spacer>
<property name="name">
<cstring>spacer14</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>138</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QTable">
<property name="name">
<cstring>previewTable</cstring>
</property>
<property name="numRows">
<number>0</number>
</property>
<property name="numCols">
<number>0</number>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>NoSelection</enum>
</property>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout20</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer13</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>41</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>cancelButton</cstring>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>createButton</cstring>
</property>
<property name="text">
<string>Create</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
<connections>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>importCSVForm</receiver>
<slot>reject()</slot>
</connection>
<connection>
<sender>createButton</sender>
<signal>clicked()</signal>
<receiver>importCSVForm</receiver>
<slot>createButtonPressed()</slot>
</connection>
<connection>
<sender>fieldBox</sender>
<signal>activated(int)</signal>
<receiver>importCSVForm</receiver>
<slot>fieldSeparatorChanged()</slot>
</connection>
<connection>
<sender>quoteBox</sender>
<signal>activated(int)</signal>
<receiver>importCSVForm</receiver>
<slot>textQuoteChanged()</slot>
</connection>
<connection>
<sender>extractFieldNamesCheckbox</sender>
<signal>toggled(bool)</signal>
<receiver>importCSVForm</receiver>
<slot>extractFieldNamesChanged(bool)</slot>
</connection>
</connections>
<includes>
<include location="global" impldecl="in declaration">qstringlist.h</include>
<include location="global" impldecl="in declaration">qstring.h</include>
<include location="local" impldecl="in declaration">sqlitedb.h</include>
<include location="global" impldecl="in implementation">qmessagebox.h</include>
<include location="global" impldecl="in implementation">qapplication.h</include>
<include location="local" impldecl="in implementation">importcsvform.ui.h</include>
</includes>
<variables>
<variable>QStringList curList;</variable>
<variable>char quote;</variable>
<variable>char sep;</variable>
<variable>int numfields;</variable>
<variable>QString csvfilename;</variable>
<variable>DBBrowserDB * pdb;</variable>
</variables>
<slots>
<slot>initialize( QString &amp; csvfile, DBBrowserDB * db )</slot>
<slot>createButtonPressed()</slot>
<slot>preview()</slot>
<slot>fieldSeparatorChanged()</slot>
<slot>textQuoteChanged()</slot>
<slot>extractFieldNamesChanged( bool enabled )</slot>
</slots>
<functions>
<function access="private" specifier="non virtual">init()</function>
</functions>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,217 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
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, 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));
}
}
sql = "CREATE TABLE ";
sql.append(tabname);
sql.append(" (");
for (int r=0; r<numfields;r++){
sql.append(*fieldList.at(r));
//createStatement.append(" text");
if (r<(numfields - 1))
sql.append(", ");
}
sql.append(");");
//declare local variables we will need before the rollback jump
int rowNum = 0;
int colNum = 0;
//begin a transaction, so we can rollback in case of any errors during importing
//db needs to be saved or an error will occur
if (!pdb->executeSQLDirect(QString("BEGIN TRANSACTION RESTOREPOINT;"))) goto rollback;
//execute the create table statement
if (!pdb->executeSQLDirect(sql)) goto rollback;
{//avoid error on MSVC due to rollback label
//now lets import all data, one row at a time
for ( QStringList::Iterator ct = curList .begin(); ct != curList .end(); ++ct ) {
if (colNum==0)
{
sql = "INSERT INTO ";
sql.append(tabname);
sql.append(" VALUES(");
}
//need to mprintf here
//sql.append(*ct);
char * formSQL = sqlite_mprintf("%Q",(*ct).latin1());
sql.append(formSQL);
if (formSQL) sqlite_freemem(formSQL);
colNum++;
if (colNum<numfields)
{
sql.append(",");
} else {
colNum = 0;
sql.append(");");
if (!pdb->executeSQLDirect(sql)) goto rollback;
}
}
}
//everything ok, just return
//if (!pdb->executeSQL(QString("COMMIT TRANSACTION RESTOREPOINT;"))) goto rollback;
pdb->setDirtyDirect(true);
QApplication::restoreOverrideCursor(); // restore original cursor
accept();
return;
rollback:
QApplication::restoreOverrideCursor(); // restore original cursor
QString error = "Error importing data. Message from database engine: ";
error.append(pdb->lastErrorMessage);
QMessageBox::warning( this, applicationName, error );
//we will uncomment this when SQLite support nested transactions
pdb->executeSQLDirect(QString("ROLLBACK TRANSACTION RESTOREPOINT;"));
}
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->setNumRows(0);
previewTable->setNumCols(0);
previewTable->setNumCols(numfields);
int cheadnum = 0;
//can not operate on an empty result
if (numfields==0) return;
if (extractFieldNamesCheckbox->isChecked())
{
for ( QStringList::Iterator ct = curList.begin(); ct != curList.end(); ++ct ) {
previewTable->horizontalHeader()->setLabel( cheadnum, *ct );
cheadnum++;
if (cheadnum==numfields) break;
}
//pop the fieldnames
for (int e=0; e<numfields; e++)
{
curList.pop_front();
}
}
previewTable->setNumRows(curList.count()/numfields);
int rowNum = 0;
int colNum = 0;
for ( QStringList::Iterator ct = curList .begin(); ct != curList .end(); ++ct ) {
if (colNum==0) previewTable->verticalHeader()->setLabel( rowNum, QString::number(rowNum,10) );
previewTable->setText( rowNum, colNum,*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;
}
preview();
}
void importCSVForm::textQuoteChanged()
{
QString curText = quoteBox->currentText();
QChar qquote = curText.at(0);
quote = (char) qquote;
preview();
}
void importCSVForm::extractFieldNamesChanged( bool enabled )
{
preview();
}

View File

@@ -0,0 +1,120 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>renameTableForm</class>
<widget class="QDialog">
<property name="name">
<cstring>renameTableForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>313</width>
<height>101</height>
</rect>
</property>
<property name="caption">
<string>Rename table</string>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLineEdit">
<property name="name">
<cstring>tablenameLineEdit</cstring>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer27</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>21</height>
</size>
</property>
</spacer>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout34</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<spacer>
<property name="name">
<cstring>spacer26</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>31</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>closeButton</cstring>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>renameButton</cstring>
</property>
<property name="text">
<string>Rename</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
<connections>
<connection>
<sender>closeButton</sender>
<signal>clicked()</signal>
<receiver>renameTableForm</receiver>
<slot>reject()</slot>
</connection>
<connection>
<sender>renameButton</sender>
<signal>clicked()</signal>
<receiver>renameTableForm</receiver>
<slot>renameClicked()</slot>
</connection>
</connections>
<includes>
<include location="global" impldecl="in implementation">qmessagebox.h</include>
<include location="local" impldecl="in implementation">sqlitedb.h</include>
<include location="local" impldecl="in implementation">renametableform.ui.h</include>
</includes>
<slots>
<slot>renameClicked()</slot>
<slot>setTableName( QString name )</slot>
</slots>
<functions>
<function returnType="QString">getTableName()</function>
</functions>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,33 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void renameTableForm::renameClicked()
{
QString tabname = tablenameLineEdit->text();
if (tabname.isEmpty()) {
QMessageBox::information( this, applicationName, "Table name can not be empty" );
return;
}
if (tabname.contains(" ")>0) {
QMessageBox::warning( this, 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

@@ -0,0 +1,459 @@
#include "sqlbrowser_util.h"
#include "sqlite_source/sqlite.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite_source/sqliteInt.h"
/*following routines extracted from shell.c for dump support*/
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( sqliteIsNumber(azArg[i]) ){
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;
d2 = *p;
d2.mode = MODE_Insert;
d2.zDestTable = 0;
set_table_name(&d2, azArg[0]);
sqlite_exec_printf(p->db,
"SELECT * FROM '%q'",
callback, &d2, 0, azArg[0]
);
set_table_name(&d2, 0);
}
return 0;
}
/*
/Dump database to a file
*/
int dump_database(sqlite * 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");
sqlite_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(sqlite * 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.
*/
static int _ends_with_semicolon(const char *z, int N){
while( N>0 && isspace(z[N-1]) ){ N--; }
return N>0 && z[N-1]==';';
}
/*
** Test to see if a line consists entirely of whitespace.
*/
static int _all_whitespace(const char *z){
for(; *z; z++){
if( isspace(*z) ) continue;
if( *z=='/' && z[1]=='*' ){
z += 2;
while( *z && (*z!='*' || z[1]!='/') ){ z++; }
if( *z==0 ) return 0;
z++;
continue;
}
if( *z=='-' && z[1]=='-' ){
z += 2;
while( *z && *z!='\n' ){ z++; }
if( *z==0 ) return 1;
continue;
}
return 0;
}
return 1;
}
/*
** Return TRUE if the line typed in is an SQL command terminator other
** than a semi-colon. The SQL Server style "go" command is understood
** as is the Oracle "/".
*/
static int _is_command_terminator(const char *zLine){
extern int sqliteStrNICmp(const char*,const char*,int);
while( isspace(*zLine) ){ zLine++; };
if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ) return 1; /* Oracle */
if( sqliteStrNICmp(zLine,"go",2)==0 && _all_whitespace(&zLine[2]) ){
return 1; /* SQL Server */
}
return 0;
}
char *getline(FILE *in){
char *zLine;
int nLine;
int n;
int eol;
nLine = 100;
zLine = malloc( nLine );
if( zLine==0 ) return 0;
n = 0;
eol = 0;
while( !eol ){
if( n+100>nLine ){
nLine = nLine*2 + 100;
zLine = realloc(zLine, nLine);
if( zLine==0 )
return 0;
}
if( fgets(&zLine[n], nLine - n, in)==0 ){
if( n==0 ){
free(zLine);
return 0;
}
zLine[n] = 0;
eol = 1;
break;
}
while( zLine[n] ){ n++; }
if( n>0 && zLine[n-1]=='\n' ){
n--;
zLine[n] = 0;
eol = 1;
}
}
zLine = realloc( zLine, n+1 );
return zLine;
}
void process_input(sqlite * db, FILE *in, int * lineErr){
char *zLine;
char *zSql = 0;
char * zErrMsg = 0;
int nSql = 0;
int rc;
while((zLine = getline(in))!=0 ){
if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
(*lineErr)++;
if( zSql==0 ){
int i;
for(i=0; zLine[i] && isspace(zLine[i]); i++){}
if( zLine[i]!=0 ){
nSql = strlen(zLine);
zSql = malloc( nSql+1 );
strcpy(zSql, zLine);
}
}else{
int len = strlen(zLine);
zSql = realloc( zSql, nSql + len + 2 );
/*if( zSql==0 ){
fprintf(stderr,"%s: out of memory!\n", Argv0);
exit(1);
}*/
strcpy(&zSql[nSql++], "\n");
strcpy(&zSql[nSql], zLine);
nSql += len;
}
free(zLine);
if( zSql && _ends_with_semicolon(zSql, nSql) && sqlite_complete(zSql) ){
rc = sqlite_exec(db, zSql, NULL, NULL, &zErrMsg);//&zErrMsg
if( rc || zErrMsg ){
//if( in!=0 && !p->echoOn ) printf("%s\n",zSql);
if( zErrMsg!=0 ){
/*printf("SQL error: %s\n", zErrMsg);*/
free(zErrMsg);
zErrMsg = 0;
if( zSql ){
free(zSql);
}
return;
}/*else{
printf("SQL error: %s\n", sqlite_error_string(rc));
}*/
}
free(zSql);
zSql = 0;
nSql = 0;
}
}
if( zSql ){
/*if( !_all_whitespace(zSql) ) printf("Incomplete SQL: %s\n", zSql);*/
free(zSql);
}
/*normal exit, clear err*/
*lineErr = 0;
}
/* end of shell.c routines*/

View File

@@ -0,0 +1,64 @@
#ifndef _H_SQLBROWSERUTIL
#define _H_SQLBROWSERUTIL
#ifdef __cplusplus
extern "C" {
#endif
#include <ctype.h>
#include "sqlite_source/sqlite.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 {
sqlite *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(sqlite * db, FILE * outfile);
int load_database(sqlite * db, FILE * infile, int * lineErr);
void process_input(sqlite * db, FILE *in, int * lineErr);
char *sqlbrowser_getline(FILE *in);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
#endif
#endif

View File

@@ -1,6 +1,70 @@
TEMPLATE = app
LANGUAGE = C++
CONFIG += qt warn_on release
HEADERS += sqlitebrowsertypes.h \
sqlitedb.h \
sqlbrowser_util.h
SOURCES += browsermain.cpp \
sqlitedb.cpp
HEADERS += sqlitedb.h
sqlitedb.cpp \
sqlbrowser_util.c
FORMS = aboutform.ui \
addfieldform.ui \
addfieldtypeform.ui \
choosetableform.ui \
createindexform.ui \
createtableform.ui \
deleteindexform.ui \
deletetableform.ui \
editfieldform.ui \
editform.ui \
edittableform.ui \
exporttablecsvform.ui \
findform.ui \
form1.ui \
importcsvform.ui \
renametableform.ui \
sqllogform.ui
IMAGES = images/create_index.png \
images/create_table.png \
images/delete_index.png \
images/delete_table.png \
images/icone16.png \
images/log.png \
images/modify_table.png \
images/new.png \
images/open.png \
images/revert.png \
images/save.png \
images/searchfind.png \
images/whatis.png
unix {
UI_DIR = .ui
MOC_DIR = .moc
@@ -13,25 +77,117 @@ win32 {
}
mac {
RC_FILE = macapp.icns
LIBS += -framework Carbon -framework Quicktime -lz ./sqlite_source/libsqlite_source.a
LIBS += -framework Carbon ./sqlite_source/libsqlite_source.a
}
FORMS = form1.ui \
findform.ui \
createtableform.ui \
createindexform.ui \
deletetableform.ui \
deleteindexform.ui \
aboutform.ui
IMAGES = images/whatsthis.png \
images/filenew.png \
images/editpaste.png \
images/fileopen.png \
images/icone16.png \
images/searchfind.png \
images/editcopy.png
TEMPLATE =app
CONFIG += qt warn_on release
LANGUAGE = C++
unix {
UI_DIR = .ui
MOC_DIR = .moc
OBJECTS_DIR = .obj
}

View File

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

View File

@@ -1,29 +1,54 @@
/*
** This file is part of SQLite Database Browser
** http://sqlitebrowser.sourceforge.net
**
** Originally developed by Mauricio Piacentini, Tabuleiro
**
** The author disclaims copyright to this source code.
** Consult the LICENSING file for known restrictions
**
*/
#include "sqlitedb.h"
#include "sqlbrowser_util.h"
#include <stdlib.h>
#include <qregexp.h>
#include <qimage.h>
#include <qfile.h>
#include <qfiledialog.h>
#include <qmessagebox.h>
void DBBrowserTable::addField(int order, const QString& wfield,const QString& wtype)
{
fldmap[order] = DBBrowserField(wfield,wtype);
}
bool DBBrowserDB::isOpen ( )
{
return _db!=0;
}
void DBBrowserDB::setDirty(bool dirtyval)
{
if ((dirty==false)&&(dirtyval==true))
{
setRestorePoint();
}
dirty = dirtyval;
if (logWin)
{
logWin->msgDBDirtyState(dirty);
}
}
void DBBrowserDB::setDirtyDirect(bool dirtyval)
{
dirty = dirtyval;
if (logWin)
{
logWin->msgDBDirtyState(dirty);
}
}
bool DBBrowserDB::getDirty()
{
return dirty;
}
bool DBBrowserDB::open ( const QString & db)
{
char *errmsg;
bool ok=false;
if (isOpen()) close();
lastErrorMessage = QString("no error");
@@ -45,6 +70,7 @@ bool DBBrowserDB::open ( const QString & db)
if (SQLITE_OK==sqlite_exec(_db,"PRAGMA show_datatypes = ON;",
NULL,NULL,NULL)){
ok=true;
setDirty(false);
}
curDBFilename = db;
}
@@ -52,6 +78,42 @@ bool DBBrowserDB::open ( const QString & db)
return ok;
}
bool DBBrowserDB::setRestorePoint()
{
if (!isOpen()) return false;
if (_db){
sqlite_exec(_db,"BEGIN TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
return true;
}
bool DBBrowserDB::save()
{
if (!isOpen()) return false;
if (_db){
sqlite_exec(_db,"COMMIT TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
return true;
}
bool DBBrowserDB::revert()
{
if (!isOpen()) return false;
if (_db){
sqlite_exec(_db,"ROLLBACK TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
return true;
}
bool DBBrowserDB::create ( const QString & db)
{
char *errmsg;
@@ -75,9 +137,11 @@ bool DBBrowserDB::create ( const QString & db)
if (SQLITE_OK==sqlite_exec(_db,"PRAGMA show_datatypes = ON;",
NULL,NULL,NULL)){
ok=true;
setDirty(false);
}
curDBFilename = db;
}
}
return ok;
@@ -85,7 +149,22 @@ bool DBBrowserDB::create ( const QString & db)
void DBBrowserDB::close (){
if (_db)
{
if (getDirty())
{
QString msg = "Do you want to save the changes made to the database file ";
msg.append(curDBFilename);
msg.append(" ?");
if (QMessageBox::question( 0, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
save();
} else {
//not really necessary, I think... but will not hurt.
revert();
}
}
sqlite_close(_db);
}
_db = 0;
idxmap.clear();
tbmap.clear();
@@ -103,9 +182,63 @@ bool DBBrowserDB::compact ( )
if (!isOpen()) return false;
if (_db){
save();
logSQL(QString("VACUUM;"), kLogMsg_App);
if (SQLITE_OK==sqlite_exec(_db,"VACUUM;",
NULL,NULL,&errmsg)){
ok=true;
setDirty(false);
}
}
if (!ok){
lastErrorMessage = QString(errmsg);
return false;
}else{
return true;
}
}
bool DBBrowserDB::reload( const QString & filename, int * lineErr)
{
/*to avoid a nested transaction error*/
sqlite_exec(_db,"COMMIT;", NULL,NULL,NULL);
FILE * cfile = fopen((const char *) filename, (const char *) "r");
load_database(_db, cfile, lineErr);
fclose(cfile);
setDirty(false);
if ((*lineErr)!=0)
{
return false;
}
return true;
}
bool DBBrowserDB::dump( const QString & filename)
{
FILE * cfile = fopen((const char *) filename, (const char *) "w");
if (!cfile)
{
return false;
}
dump_database(_db, cfile);
fclose(cfile);
return true;
}
bool DBBrowserDB::executeSQL ( const QString & statement)
{
char *errmsg;
bool ok=false;
if (!isOpen()) return false;
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite_exec(_db,statement.latin1(),
NULL,NULL,&errmsg)){
ok=true;
}
}
@@ -117,15 +250,16 @@ bool DBBrowserDB::compact ( )
}
}
bool DBBrowserDB::executeSQL ( const QString & statement)
bool DBBrowserDB::executeSQLDirect ( const QString & statement)
{
//no transaction support
char *errmsg;
bool ok=false;
if (!isOpen()) return false;
if (_db){
logSQL(statement, kLogMsg_App);
if (SQLITE_OK==sqlite_exec(_db,statement.latin1(),
NULL,NULL,&errmsg)){
ok=true;
@@ -154,6 +288,8 @@ bool DBBrowserDB::addRecord ( )
statement.append(") VALUES(NULL);");
lastErrorMessage = QString("no error");
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite_exec(_db,statement.latin1(),NULL,NULL, &errmsg)){
ok=true;
int newrowid = sqlite_last_insert_rowid(_db);
@@ -194,6 +330,8 @@ bool DBBrowserDB::deleteRecord( int wrow)
statement.append(";");
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite_exec(_db,statement.latin1(),
NULL,NULL,&errmsg)){
ok=true;
@@ -216,11 +354,6 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext)
rowList::iterator rt = browseRecs.at(wrow);
QString rowid = (*rt).first();
QStringList::Iterator cv = (*rt).at(wcol+1);//must account for rowid
//qDebug(*cv);
#ifdef ARCABUILD
if((*cv).compare(binarySignature)==0)
return false;
#endif
QStringList::Iterator ct = browseFields.at(wcol);
@@ -239,6 +372,8 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext)
statement.append(";");
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite_exec(_db,statement.latin1(),
NULL,NULL,&errmsg)){
ok=true;
@@ -255,6 +390,7 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext)
}
bool DBBrowserDB::browseTable( const QString & tablename )
{
QStringList testFields = getTableFields( tablename );
@@ -294,6 +430,7 @@ void DBBrowserDB::getTableRecords( const QString & tablename )
statement.append( tablename.latin1());
statement.append(" ORDER BY rowid; ");
//qDebug(statement);
logSQL(statement, kLogMsg_App);
err=sqlite_compile(_db,statement.latin1(),
&tail, &vm, NULL);
if (err == SQLITE_OK){
@@ -301,15 +438,8 @@ void DBBrowserDB::getTableRecords( const QString & tablename )
while ( sqlite_step(vm,&ncol,&vals, &names) == SQLITE_ROW ){
r.clear();
for (int e=0; e<ncol; e++){
#ifdef ARCABUILD
if (QString(vals[e]).startsWith(binaryPattern)){
r<< binarySignature;
} else {
r << vals[e];
}
#else
r << vals[e];
#endif
QString rv = vals[e];
r << rv;
if (e==0){
idmap.insert(QString(vals[e]).toInt(),rownum);
rownum++;
@@ -338,6 +468,7 @@ resultMap DBBrowserDB::getFindResults( const QString & wstatement)
resultMap res;
lastErrorMessage = QString("no error");
logSQL(wstatement, kLogMsg_App);
err=sqlite_compile(_db,wstatement.latin1(),
&tail, &vm, &errmsg);
if (err == SQLITE_OK){
@@ -346,15 +477,7 @@ resultMap DBBrowserDB::getFindResults( const QString & wstatement)
QString r;
while ( sqlite_step(vm,&ncol,&vals, &names) == SQLITE_ROW ){
for (int e=0; e<ncol; e++){
#ifdef ARCABUILD
if (QString(vals[e]).startsWith(binaryPattern)){
r = binarySignature;
} else {
r = vals[e];
}
#else
r = vals[e];
#endif
r = vals[e];
if (e==0){
rownum = QString(vals[e]).toInt();
rowIdMap::iterator mit = idmap.find(rownum);
@@ -417,10 +540,46 @@ QStringList DBBrowserDB::getTableFields(const QString & tablename)
return res;
}
QStringList DBBrowserDB::getTableTypes(const QString & tablename)
{
tableMap::Iterator it;
tableMap tmap = tbmap;
QStringList res;
for ( it = tmap.begin(); it != tmap.end(); ++it ) {
if (tablename.compare(it.data().getname())==0 ){
fieldMap::Iterator fit;
fieldMap fmap = it.data().fldmap;
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
res.append( fit.data().gettype() );
}
}
}
return res;
}
int DBBrowserDB::getRecordCount()
{
return browseRecs.count();
}
void DBBrowserDB::logSQL(QString statement, int msgtype)
{
if (logWin)
{
/*limit log message to a sensible size, this will truncate some binary messages*/
uint loglimit = 300;
if ((statement.length() > loglimit)&&(msgtype==kLogMsg_App))
{
statement.truncate(32);
statement.append("... <string too wide to log, probably contains binary data> ...");
}
logWin->log(statement, msgtype);
}
}
void DBBrowserDB::updateSchema( )
{
// qDebug ("Getting list of tables");
@@ -441,14 +600,15 @@ void DBBrowserDB::updateSchema( )
tbmap.clear();
lastErrorMessage = QString("no error");
err=sqlite_compile(_db,"SELECT name, sql "
QString statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='table' ;"
"WHERE type='table' ;";
err=sqlite_compile(_db,statement.latin1()
/*"ORDER BY name;"*/ ,
&tail, &vm, &errmsg);
if (err == SQLITE_OK){
logSQL(statement, kLogMsg_App);
while ( sqlite_step(vm,&ncol,&vals, &names) == SQLITE_ROW ){
num.setNum(tabnum);
tbmap[num] = DBBrowserTable(vals[0],vals[1]);
@@ -462,9 +622,10 @@ void DBBrowserDB::updateSchema( )
//now get the field list for each table in tbmap
tableMap::Iterator it;
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
QString statement = "SELECT * FROM ";
statement = "SELECT * FROM ";
statement.append( (const char *) it.data().getname().latin1());
statement.append(" LIMIT 1;");
logSQL(statement, kLogMsg_App);
err=sqlite_compile(_db,statement.latin1(),
&tail, &vm, NULL);
if (err == SQLITE_OK){
@@ -480,13 +641,14 @@ void DBBrowserDB::updateSchema( )
lastErrorMessage = QString ("could not get types");
}
}
//finally get indices
err=sqlite_compile(_db,"SELECT name, sql "
statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='index' "
/*"ORDER BY name;"*/,
"WHERE type='index' ";
/*"ORDER BY name;"*/
//finally get indices
err=sqlite_compile(_db,statement.latin1(),
&tail, &vm, &errmsg);
logSQL(statement, kLogMsg_App);
if (err == SQLITE_OK){
while ( sqlite_step(vm,&ncol,&vals, &names) == SQLITE_ROW ){
num.setNum(idxnum);
@@ -499,77 +661,82 @@ void DBBrowserDB::updateSchema( )
}
}
void DBBrowserDB::updateParameter( )
QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char quote, int maxrecords, int * numfields)
{
// qDebug ("Getting list of parameters");
sqlite_vm *vm;
const char *tail;
const char **vals;
const char **names;
int ncol;
QStringList r;
char *errmsg;
int err=0;
QString num;
paramMap::Iterator it;
for ( it = parammap.begin(); it != parammap.end(); ++it ) {
lastErrorMessage = QString("no error");
err=sqlite_compile(_db,"PRAGMA " + it.data().getname() + ';',
&tail, &vm, &errmsg);
if (err == SQLITE_OK) {
if (sqlite_step(vm,&ncol,&vals, &names) == SQLITE_ROW )
//parammap.remove(it);
parammap[it.key()] = DBBrowserParam(it.data().getname(),vals[0]);
sqlite_finalize(vm, NULL);
}else{
qDebug ("could not get list of parameters: %d, %s",err,errmsg);
}
}
QFile file(csvfilename);
QStringList result;
QString current = "";
bool inquotemode = false;
bool inescapemode = false;
int recs = 0;
*numfields = 0;
if ( file.open( IO_ReadWrite ) ) {
char c=0;
while ( c!=-1) {
c = file.getch();
if (c==quote){
if (inquotemode){
if (inescapemode){
inescapemode = false;
//add the escaped char here
current.append(c);
} else {
//are we escaping, or just finishing the quote?
char d = file.getch();
if (d==quote) {
inescapemode = true;
} else {
inquotemode = false;
}
file.ungetch(d);
}
} else {
inquotemode = true;
}
} else if (c==sep) {
if (inquotemode){
//add the sep here
current.append(c);
} else {
//not quoting, start new record
result << current;
current = "";
}
} else if (c==10) {
if (inquotemode){
//add the newline
current.append(c);
} else {
//not quoting, start new record
result << current;
current = "";
//for the first line, store the field count
if (*numfields == 0){
*numfields = result.count();
}
recs++;
if ((recs>maxrecords)&&(maxrecords!=-1)) {
break;
}
}
} else if (c==13) {
if (inquotemode){
//add the carrier return if in quote mode only
current.append(c);
}
} else {//another character type
current.append(c);
}
}
file.close();
//do we still have a last result, not appended?
//proper csv files should end with a linefeed , so this is not necessary
//if (current.length()>0) result << current;
}
return result;
}
void DBBrowserDB::buildParameterMap( )
{
parammap.clear();
parammap["cache size"] = DBBrowserParam("CACHE_SIZE", "2000");
parammap["default cache size"] = DBBrowserParam("DEFAULT_CACHE_SIZE", "2000");
parammap["temp store"] = DBBrowserParam("TEMP_STORE", "OFF");
parammap["default temp store"] = DBBrowserParam("DEFAULT_TEMP_STORE", "DEFAULT");
parammap["count changes"] = DBBrowserParam("COUNT_CHANGES", "");
parammap["synchronous"] = DBBrowserParam("SYNCHRONOUS", "DEFAULT");
parammap["default synchronous"] = DBBrowserParam("DEFAULT_SYNCHRONOUS", "DEFAULT");
parammap["empty result callbacks"] = DBBrowserParam("EMPTY_RESULT_CALLBACKS", "OFF");
parammap["full column names"] = DBBrowserParam("FULL_COLUMN_NAMES", "OFF");
parammap["parser trace"] = DBBrowserParam("PARSER_TRACE", "OFF");
parammap["show datatype"] = DBBrowserParam("SHOW_DATATYPES", "OFF");
parammap["vdbe trace"] = DBBrowserParam("VDBE_TRACE", "OFF");
}
void DBBrowserDB::setParameter(const QString & paramName, const QString & paramValue )
{
// qDebug ("Getting list of parameters");
sqlite_vm *vm;
const char *tail;
const char **vals;
const char **names;
int ncol;
char *errmsg;
int err=0;
lastErrorMessage = QString("no error");
err=sqlite_compile(_db,"PRAGMA " + paramName + "=" + paramValue + ';',
&tail, &vm, &errmsg);
if (err == SQLITE_OK) {
if (sqlite_step(vm,&ncol,&vals, &names) == SQLITE_ROW )
sqlite_finalize(vm, NULL);
}else{
qDebug ("could not get list of parameters: %d, %s",err,errmsg);
}
}

View File

@@ -1,15 +1,3 @@
/*
** This file is part of SQLite Database Browser
** http://sqlitebrowser.sourceforge.net
**
** Originally developed by Mauricio Piacentini, Tabuleiro
**
** The author disclaims copyright to this source code.
** Consult the LICENSING file for known restrictions
**
*/
#ifndef SQLITEDB_H
#define SQLITEDB_H
@@ -17,25 +5,37 @@
#include <qstringlist.h>
#include <qmap.h>
#include <qvaluelist.h>
#include <qobject.h>
#include "sqllogform.h"
#include "sqlite_source/sqlite.h"
#include "sqlitebrowsertypes.h"
/*#include "sqlite_source/sqlxtra_util.h"
#include "sqlite_source/encode.h"
#include "sqlite_source/swap.h"*/
#define MAX_DISPLAY_LENGTH 14
enum
{
kLogMsg_User,
kLogMsg_App
};
static QString applicationName = QString("SQLite Database Browser");
static QString applicationIconName = QString("icone16.png");
static QString aboutText = QString("Version 1.01\n\nSQLite Database Browser is a freeware, public domain, open source visual tool used to create, design and edit database files compatible with SQLite 2.x.\n\n You can find the latest versions of the source code of SQLite Database browser at http://sqlitebrowser.sourceforge.net. \n\nIn the spirit of the original SQLite source code, the authors disclaims copyright to this source code.");
static QString aboutText = QString("Version 1.1\n\nSQLite Database Browser is a freeware, public domain, open source visual tool used to create, design and edit database files compatible with SQLite 2.x.\n\nIt has been developed originally by Mauricio Piacentini from Tabuleiro Producoes. \n\nIn the spirit of the original SQLite source code, the author disclaims copyright to this source code.");
typedef QMap<int, class DBBrowserField> fieldMap;
typedef QMap<QString, class DBBrowserTable> tableMap;
typedef QMap<QString, class DBBrowserIndex> indexMap;
typedef QMap<QString, class DBBrowserParam> paramMap;
typedef QMap<int, int> rowIdMap;
typedef QValueList<QStringList> rowList;
typedef QMap<int, QString> resultMap;
class DBBrowserField
{
{
public:
DBBrowserField() : name( 0 ) { }
DBBrowserField( const QString& wname,const QString& wtype )
@@ -49,7 +49,7 @@ class DBBrowserField
};
class DBBrowserIndex
{
{
public:
DBBrowserIndex() : name( 0 ) { }
DBBrowserIndex( const QString& wname,const QString& wsql )
@@ -64,7 +64,7 @@ private:
class DBBrowserTable
{
{
public:
DBBrowserTable() : name( 0 ) { }
DBBrowserTable( const QString& wname,const QString& wsql )
@@ -81,19 +81,6 @@ private:
QString sql;
};
class DBBrowserParam
{
public:
DBBrowserParam() : name( 0 ) { }
DBBrowserParam( const QString& wname,const QString& wvalue )
: name( wname), value( wvalue )
{ }
QString getname() const { return name; }
QString getvalue() const { return value; }
private:
QString name;
QString value;
};
class DBBrowserDB
{
@@ -104,27 +91,37 @@ public:
bool create ( const QString & db);
void close ();
bool compact ();
bool setRestorePoint();
bool save ();
bool revert ();
bool dump( const QString & filename);
bool reload( const QString & filename, int * lineErr);
bool executeSQL ( const QString & statement);
bool executeSQLDirect ( const QString & statement);
void updateSchema() ;
void updateParameter();
void buildParameterMap();
void setParameter(const QString & paramname, const QString & paramvalue);
bool addRecord();
bool deleteRecord(int wrow);
bool updateRecord(int wrow, int wcol, const QString & wtext);
bool browseTable( const QString & tablename );
QStringList getTableFields(const QString & tablename);
QStringList getTableTypes(const QString & tablename);
QStringList getTableNames();
QStringList getIndexNames();
resultMap getFindResults( const QString & wstatement);
int getRecordCount();
bool isOpen() const { return _db!=0; }
bool isOpen();
void setDirty(bool dirtyval);
void setDirtyDirect(bool dirtyval);
bool getDirty();
void logSQL(QString statement, int msgtype);
sqlite * _db;
QStringList decodeCSV(const QString & csvfilename, char sep, char quote, int maxrecords, int * numfields);
tableMap tbmap;
indexMap idxmap;
rowIdMap idmap;
paramMap parammap;
rowList browseRecs;
QStringList browseFields;
@@ -132,8 +129,15 @@ public:
QString curBrowseTableName;
QString lastErrorMessage;
QString curDBFilename;
sqlLogForm * logWin;
private:
bool dirty;
void getTableRecords( const QString & tablename );
};
#endif

View File

@@ -0,0 +1,165 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>sqlLogForm</class>
<widget class="QDialog">
<property name="name">
<cstring>sqlLogForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>547</width>
<height>203</height>
</rect>
</property>
<property name="caption">
<string>SQL Log</string>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout6</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1</cstring>
</property>
<property name="text">
<string>Show SQL submitted by:</string>
</property>
</widget>
<widget class="QComboBox">
<item>
<property name="text">
<string>User</string>
</property>
</item>
<item>
<property name="text">
<string>Application</string>
</property>
</item>
<property name="name">
<cstring>comboBox3</cstring>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer10</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>150</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>clearButton</cstring>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QWidgetStack">
<property name="name">
<cstring>logStack</cstring>
</property>
<widget class="QWidget">
<property name="name">
<cstring>WStackPage</cstring>
</property>
<attribute name="id">
<number>0</number>
</attribute>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QTextEdit" row="0" column="0">
<property name="name">
<cstring>userLogText</cstring>
</property>
<property name="textFormat">
<enum>PlainText</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</grid>
</widget>
<widget class="QWidget">
<property name="name">
<cstring>WStackPage</cstring>
</property>
<attribute name="id">
<number>1</number>
</attribute>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QTextEdit">
<property name="name">
<cstring>appLogText</cstring>
</property>
<property name="textFormat">
<enum>PlainText</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</vbox>
</widget>
</widget>
</vbox>
</widget>
<connections>
<connection>
<sender>clearButton</sender>
<signal>clicked()</signal>
<receiver>sqlLogForm</receiver>
<slot>clearLog()</slot>
</connection>
<connection>
<sender>comboBox3</sender>
<signal>activated(int)</signal>
<receiver>logStack</receiver>
<slot>raiseWidget(int)</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">sqlitedb.h</include>
<include location="local" impldecl="in implementation">sqllogform.ui.h</include>
</includes>
<signals>
<signal>goingAway();</signal>
<signal>dbState(bool dirty);</signal>
</signals>
<slots>
<slot>closeEvent( QCloseEvent * )</slot>
<slot>log( QString &amp; statement, int msgtype )</slot>
<slot>msgDBDirtyState( bool dirty )</slot>
<slot>clearLog()</slot>
</slots>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@@ -0,0 +1,38 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void sqlLogForm::closeEvent( QCloseEvent * )
{
emit goingAway();
}
void sqlLogForm::log( QString & statement, int msgtype)
{
if (msgtype==kLogMsg_User)
{
userLogText->setText(userLogText->text()+statement+"\n");
} else {
appLogText->setText(appLogText->text()+statement+"\n");
}
}
void sqlLogForm::msgDBDirtyState( bool dirty)
{
emit dbState(dirty);
}
void sqlLogForm::clearLog()
{
if (logStack->id(logStack->visibleWidget())==kLogMsg_User)
{
userLogText->clear();
} else {
appLogText->clear();
}
}