Backport of all fixes from ArcaBrowser to the open source version, including a better port to Qt4. Previous implementation using Q3Value compiled but was not working for updates

This commit is contained in:
tabuleiro
2009-11-28 19:11:31 +00:00
parent 8901339bf2
commit a1486769f3
30 changed files with 836 additions and 388 deletions

View File

@@ -10,6 +10,7 @@
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
@@ -23,36 +24,32 @@ class Ui_aboutForm
{
public:
QVBoxLayout *vboxLayout;
QLabel *textLabel1;
QGridLayout *gridLayout;
QHBoxLayout *hboxLayout;
QSpacerItem *spacer5;
QPushButton *okButton;
QSpacerItem *spacer13;
QVBoxLayout *vboxLayout1;
QLabel *pixmapLabel1;
QSpacerItem *spacer12;
QLabel *textLabel1;
void setupUi(QDialog *aboutForm)
{
if (aboutForm->objectName().isEmpty())
aboutForm->setObjectName(QString::fromUtf8("aboutForm"));
aboutForm->resize(514, 191);
aboutForm->resize(542, 257);
vboxLayout = new QVBoxLayout(aboutForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
textLabel1 = new QLabel(aboutForm);
textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(7));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(textLabel1->sizePolicy().hasHeightForWidth());
textLabel1->setSizePolicy(sizePolicy);
textLabel1->setAlignment(Qt::AlignVCenter);
textLabel1->setWordWrap(true);
vboxLayout->addWidget(textLabel1);
gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
spacer5 = new QSpacerItem(141, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
spacer5 = new QSpacerItem(424, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacer5);
@@ -63,7 +60,38 @@ public:
hboxLayout->addWidget(okButton);
vboxLayout->addLayout(hboxLayout);
gridLayout->addLayout(hboxLayout, 1, 0, 1, 3);
spacer13 = new QSpacerItem(16, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(spacer13, 0, 1, 1, 1);
vboxLayout1 = new QVBoxLayout();
vboxLayout1->setSpacing(6);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
pixmapLabel1 = new QLabel(aboutForm);
pixmapLabel1->setObjectName(QString::fromUtf8("pixmapLabel1"));
pixmapLabel1->setPixmap(QPixmap(qPixmapFromMimeSource("128.png")));
pixmapLabel1->setScaledContents(false);
pixmapLabel1->setWordWrap(false);
vboxLayout1->addWidget(pixmapLabel1);
spacer12 = new QSpacerItem(20, 31, QSizePolicy::Minimum, QSizePolicy::Expanding);
vboxLayout1->addItem(spacer12);
gridLayout->addLayout(vboxLayout1, 0, 0, 1, 1);
textLabel1 = new QLabel(aboutForm);
textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
textLabel1->setWordWrap(false);
gridLayout->addWidget(textLabel1, 0, 2, 1, 1);
vboxLayout->addLayout(gridLayout);
retranslateUi(aboutForm);
@@ -82,7 +110,6 @@ public:
"\n"
"More information at http://sqlitebrowser.sourceforge.net.", 0, QApplication::UnicodeUTF8));
okButton->setText(QApplication::translate("aboutForm", "Close", 0, QApplication::UnicodeUTF8));
Q_UNUSED(aboutForm);
} // retranslateUi
};

View File

@@ -76,7 +76,8 @@ void addFieldForm::getCustomType()
addFieldTypeForm * addForm = new addFieldTypeForm( this, "addfieldtype", TRUE );
if (addForm->exec())
{
QString nospaces = addForm->typeNameEdit->text().remove(" ");
//QString nospaces = addForm->typeNameEdit->text().remove(" ");
QString nospaces = addForm->typeNameEdit->text();
setInitialValues(nameLineEdit->text(),nospaces );
}
}

View File

@@ -48,7 +48,7 @@ public:
addFieldForm->resize(338, 136);
gridLayout = new QGridLayout(addFieldForm);
gridLayout->setSpacing(6);
gridLayout->setMargin(11);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
spacer17 = new QSpacerItem(20, 16, QSizePolicy::Minimum, QSizePolicy::Expanding);
@@ -144,9 +144,10 @@ public:
typeBox->clear();
typeBox->insertItems(0, QStringList()
<< QString()
<< QApplication::translate("addFieldForm", "text", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "integer", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "blob", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "TEXT", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "NUMERIC", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "BLOB", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("addFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8)
);
typeButton->setText(QApplication::translate("addFieldForm", "...", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
@@ -155,7 +156,6 @@ public:
#ifndef QT_NO_WHATSTHIS
typeButton->setProperty("whatsThis", QVariant(QApplication::translate("addFieldForm", "Click this button to enter a new type for the field", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
Q_UNUSED(addFieldForm);
} // retranslateUi
};

View File

@@ -36,7 +36,7 @@ public:
addFieldTypeForm->resize(294, 98);
gridLayout = new QGridLayout(addFieldTypeForm);
gridLayout->setSpacing(6);
gridLayout->setMargin(11);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
typeNameEdit = new QLineEdit(addFieldTypeForm);
typeNameEdit->setObjectName(QString::fromUtf8("typeNameEdit"));
@@ -77,7 +77,6 @@ public:
addFieldTypeForm->setWindowTitle(QApplication::translate("addFieldTypeForm", "Enter field type", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("addFieldTypeForm", "Cancel", 0, QApplication::UnicodeUTF8));
okButton->setText(QApplication::translate("addFieldTypeForm", "OK", 0, QApplication::UnicodeUTF8));
Q_UNUSED(addFieldTypeForm);
} // retranslateUi
};

View File

@@ -40,7 +40,7 @@ public:
chooseTableForm->resize(256, 163);
vboxLayout = new QVBoxLayout(chooseTableForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -110,7 +110,6 @@ public:
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("chooseTableForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
Q_UNUSED(chooseTableForm);
} // retranslateUi
};

View File

@@ -55,7 +55,7 @@ public:
createIndexForm->resize(300, 258);
vboxLayout = new QVBoxLayout(createIndexForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -78,7 +78,7 @@ public:
groupBox2->setObjectName(QString::fromUtf8("groupBox2"));
groupBox2->setColumnLayout(0, Qt::Vertical);
groupBox2->layout()->setSpacing(6);
groupBox2->layout()->setMargin(11);
groupBox2->layout()->setContentsMargins(11, 11, 11, 11);
gridLayout = new QGridLayout();
QBoxLayout *boxlayout = qobject_cast<QBoxLayout *>(groupBox2->layout());
if (boxlayout)
@@ -236,7 +236,6 @@ public:
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
Q_UNUSED(createIndexForm);
} // retranslateUi
};

View File

@@ -41,6 +41,7 @@ void createTableForm::languageChange()
void createTableForm::init()
{
fieldListView->clear();
fieldListView->setSorting (-1, FALSE);
}
void createTableForm::confirmCreate()
@@ -122,7 +123,7 @@ void createTableForm::addField()
if (addForm->exec())
{
//qDebug(addForm->fname + addForm->ftype);
Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView);
Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView, fieldListView->lastItem() );
tbitem->setText( 0, addForm->fname );
tbitem->setText( 1, addForm->ftype );
}
@@ -152,4 +153,3 @@ void createTableForm::fieldSelectionChanged()
}
}

View File

@@ -50,7 +50,7 @@ public:
createTableForm->resize(309, 320);
vboxLayout = new QVBoxLayout(createTableForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -73,7 +73,7 @@ public:
groupBox1->setObjectName(QString::fromUtf8("groupBox1"));
groupBox1->setColumnLayout(0, Qt::Vertical);
groupBox1->layout()->setSpacing(6);
groupBox1->layout()->setMargin(11);
groupBox1->layout()->setContentsMargins(11, 11, 11, 11);
vboxLayout1 = new QVBoxLayout();
QBoxLayout *boxlayout = qobject_cast<QBoxLayout *>(groupBox1->layout());
if (boxlayout)
@@ -192,7 +192,6 @@ public:
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
Q_UNUSED(createTableForm);
} // retranslateUi
};

View File

@@ -43,7 +43,7 @@ public:
deleteIndexForm->resize(236, 137);
vboxLayout = new QVBoxLayout(deleteIndexForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -113,7 +113,6 @@ public:
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("deleteIndexForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
Q_UNUSED(deleteIndexForm);
} // retranslateUi
};

View File

@@ -43,7 +43,7 @@ public:
deleteTableForm->resize(236, 137);
vboxLayout = new QVBoxLayout(deleteTableForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -113,7 +113,6 @@ public:
#ifndef QT_NO_TOOLTIP
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("deleteTableForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
Q_UNUSED(deleteTableForm);
} // retranslateUi
};

View File

@@ -45,7 +45,6 @@ void editFieldForm::setInitialValues(QString name, QString type)
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";
@@ -82,7 +81,8 @@ void editFieldForm::getCustomType()
addFieldTypeForm * addForm = new addFieldTypeForm( this, "addfieldtype", TRUE );
if (addForm->exec())
{
QString nospaces = addForm->typeNameEdit->text().remove(" ");
//QString nospaces = addForm->typeNameEdit->text().remove(" ");
QString nospaces = addForm->typeNameEdit->text();
setInitialValues(nameLineEdit->text(),nospaces );
enableSave();
}

View File

@@ -48,7 +48,7 @@ public:
editFieldForm->resize(352, 140);
gridLayout = new QGridLayout(editFieldForm);
gridLayout->setSpacing(6);
gridLayout->setMargin(11);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
vboxLayout = new QVBoxLayout();
vboxLayout->setSpacing(6);
@@ -146,9 +146,10 @@ public:
typeBox->clear();
typeBox->insertItems(0, QStringList()
<< QString()
<< QApplication::translate("editFieldForm", "text", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("editFieldForm", "integer", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("editFieldForm", "blob", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("editFieldForm", "TEXT", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("editFieldForm", "NUMERIC", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("editFieldForm", "BLOB", 0, QApplication::UnicodeUTF8)
<< QApplication::translate("editFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8)
);
typeButton->setText(QApplication::translate("editFieldForm", "...", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
@@ -157,7 +158,6 @@ public:
#ifndef QT_NO_WHATSTHIS
typeButton->setProperty("whatsThis", QVariant(QApplication::translate("editFieldForm", "Click this button to enter a new type for the field", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
Q_UNUSED(editFieldForm);
} // retranslateUi
};

View File

@@ -79,6 +79,16 @@ void editForm::enableTextEditor(bool enabled)
textEditor->setReadOnly(!enabled);
}
void editForm::setTextFormat(QString format)
{
if (format=="Auto")
{
textEditor->setTextFormat(Qt::AutoText);
} else {
textEditor->setTextFormat(Qt::PlainText);
}
}
void editForm::setDataType(int type, int size)
{
dataType = type;
@@ -164,7 +174,7 @@ void editForm::exportData()
QString fileName = Q3FileDialog::getSaveFileName(
"",
defaultlocation,
filter,
this,
"save file dialog"

View File

@@ -62,7 +62,7 @@ public:
editForm->setModal(true);
vboxLayout = new QVBoxLayout(editForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -104,11 +104,12 @@ public:
WStackPage->setObjectName(QString::fromUtf8("WStackPage"));
gridLayout = new QGridLayout(WStackPage);
gridLayout->setSpacing(6);
gridLayout->setMargin(11);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setContentsMargins(0, 0, 0, 0);
textEditor = new Q3TextEdit(WStackPage);
textEditor->setObjectName(QString::fromUtf8("textEditor"));
textEditor->setTextFormat(Qt::PlainText);
gridLayout->addWidget(textEditor, 0, 0, 1, 1);
@@ -117,7 +118,7 @@ public:
WStackPage1->setObjectName(QString::fromUtf8("WStackPage1"));
gridLayout1 = new QGridLayout(WStackPage1);
gridLayout1->setSpacing(6);
gridLayout1->setMargin(11);
gridLayout1->setContentsMargins(11, 11, 11, 11);
gridLayout1->setObjectName(QString::fromUtf8("gridLayout1"));
gridLayout1->setContentsMargins(0, 0, 0, 0);
editPixmap = new QLabel(WStackPage1);
@@ -240,7 +241,6 @@ public:
#ifndef QT_NO_WHATSTHIS
saveChangesButton->setProperty("whatsThis", QVariant(QApplication::translate("editForm", "Close this window saving changes to the database", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
Q_UNUSED(editForm);
} // retranslateUi
};
@@ -261,12 +261,14 @@ public:
int curCol;
int curRow;
QString defaultlocation;
public slots:
virtual void reset();
virtual void setModified( bool modifiedstate );
virtual void enableExport( bool enabled );
virtual void enableTextEditor( bool enabled );
virtual void setTextFormat( QString format );
virtual void setDataType( int type, int size );
virtual void closeEvent( QCloseEvent * );
virtual void loadText( QString text, int row, int col );

View File

@@ -62,8 +62,6 @@ void editTableForm::populateFields()
//make sure we are not using cached information
pdb->updateSchema();
fields= pdb->getTableFields(curTable);
types= pdb->getTableTypes(curTable);
fieldListView->clear();

View File

@@ -47,7 +47,7 @@ public:
editTableForm->resize(428, 266);
gridLayout = new QGridLayout(editTableForm);
gridLayout->setSpacing(6);
gridLayout->setMargin(11);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
vboxLayout = new QVBoxLayout();
vboxLayout->setSpacing(6);
@@ -151,7 +151,6 @@ public:
removeFieldButton->setText(QApplication::translate("editTableForm", "Remove field", 0, QApplication::UnicodeUTF8));
addFieldButton->setText(QApplication::translate("editTableForm", "Add field", 0, QApplication::UnicodeUTF8));
closeButton->setText(QApplication::translate("editTableForm", "Close", 0, QApplication::UnicodeUTF8));
Q_UNUSED(editTableForm);
} // retranslateUi
};

View File

@@ -40,7 +40,7 @@ public:
exportTableCSVForm->resize(365, 150);
vboxLayout = new QVBoxLayout(exportTableCSVForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -110,7 +110,6 @@ public:
#ifndef QT_NO_TOOLTIP
buttonExport->setProperty("toolTip", QVariant(QApplication::translate("exportTableCSVForm", "Delete the selected table", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_TOOLTIP
Q_UNUSED(exportTableCSVForm);
} // retranslateUi
};

View File

@@ -46,7 +46,7 @@ public:
findForm->resize(239, 319);
vboxLayout = new QVBoxLayout(findForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
@@ -164,7 +164,6 @@ public:
findListView->setProperty("whatsThis", QVariant(QApplication::translate("findForm", "Results of the search will appear in this area. Click on a result to select the corresponding record in the database", 0, QApplication::UnicodeUTF8)));
#endif // QT_NO_WHATSTHIS
resultsLabel->setText(QApplication::translate("findForm", "Found:", 0, QApplication::UnicodeUTF8));
Q_UNUSED(findForm);
} // retranslateUi
};

View File

@@ -20,6 +20,7 @@
#include "edittableform.h"
#include "importcsvform.h"
#include "exporttablecsvform.h"
#include "preferencesform.h"
/*
* Constructs a mainForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
@@ -54,12 +55,13 @@ void mainForm::languageChange()
void mainForm::init()
{
clipboard = QApplication::clipboard();
findWin = 0;
editWin = 0;
logWin = 0;
clipboard = QApplication::clipboard();
if ( clipboard->supportsSelection() )
recsPerView = 1000;
recAtTop = 0;
@@ -88,6 +90,8 @@ void mainForm::init()
connect( logWin, SIGNAL( dbState(bool) ),this, SLOT( dbState(bool) ) );
}
updatePreferences();
//connect db and log
db.logWin = logWin;
@@ -106,7 +110,7 @@ void mainForm::fileOpen(const QString & fileName)
if (!QFile::exists(wFile))
{
wFile = Q3FileDialog::getOpenFileName(
"",
defaultlocation,
"",
this,
"open file dialog"
@@ -145,7 +149,7 @@ void mainForm::fileOpen()
void mainForm::fileNew()
{
QString fileName = Q3FileDialog::getSaveFileName(
"",
defaultlocation,
"",
this,
"create file dialog"
@@ -294,25 +298,7 @@ void mainForm::fileExit()
msg.append("?");
if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
bool done(false);
do {
if ( db.save() )
done = true;
else {
QString error = "Error: could not save the database.\nMessage from database engine: ";
error.append(db.lastErrorMessage);
switch ( QMessageBox::warning( this, applicationName, error, QMessageBox::Retry|QMessageBox::Default, QMessageBox::Cancel|QMessageBox::Escape, QMessageBox::Ignore) ) {
case QMessageBox::Retry:
break;
case QMessageBox::Ignore:
db.revert();
done = true;
break;
case QMessageBox::Cancel:
return;
}
}
} while ( !done );
db.save();
} else {
//not really necessary, I think... but will not hurt.
db.revert();
@@ -337,7 +323,10 @@ void mainForm::addRecord()
updateTableView(db.getRecordCount()-recAtTop-1);
}else{
QMessageBox::information( this, applicationName,
"Error adding record, make sure a table is selected" );
"Error adding record, make sure a table is selected.\n\n"
"If the table contain fields declared as NOT NULL\n"
"please select EDIT->PREFERENCES and adjust the\n"
"default value for new records to insert an empty string." );
}
}
@@ -530,8 +519,42 @@ void mainForm::lookfor( const QString & wfield, const QString & woperator, const
QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file." );
return;
}
//we may need to modify woperator and wsearchterm, so use copies
QString finaloperator = QString(woperator);
QString finalsearchterm = QString(wsearchterm);
//special case for CONTAINS operator: use LIKE and surround the search word with % characters
if (woperator.compare("contains")==0){
finaloperator = QString("LIKE");
QString newsearchterm = "%";
newsearchterm.append(wsearchterm);
newsearchterm.append("%");
finalsearchterm = QString(newsearchterm);
}
QApplication::setOverrideCursor( Qt::waitCursor, TRUE );
resultMap res = db.getFindResults(wfield, woperator, wsearchterm);
QString statement = "SELECT rowid, ";
statement.append(wfield);
statement.append(" FROM ");
statement.append(db.curBrowseTableName);
statement.append(" WHERE ");
statement.append(wfield);
statement.append(" ");
statement.append(finaloperator);
statement.append(" ");
//searchterm needs to be quoted if it is not a number
bool ok = false;
wsearchterm.toDouble(&ok);
if (!ok) wsearchterm.toInt(&ok, 10);
if (!ok) {//not a number, quote it
char * formSQL = sqlite3_mprintf("%Q",(const char *) finalsearchterm);
statement.append(formSQL);
if (formSQL) sqlite3_free(formSQL);
} else {//append the number, unquoted
statement.append(*finalsearchterm);
}
statement.append(" ORDER BY rowid; ");
resultMap res = db.getFindResults(statement);
findWin->showResults(res);
QApplication::restoreOverrideCursor();
}
@@ -724,10 +747,6 @@ void mainForm::helpWhatsThis()
void mainForm::helpAbout()
{
/*QString wcaption = "About ";
wcaption.append(applicationName);
QString wtext = "This text, etc...";
QMessageBox::about ( this, wcaption, wtext);*/
aboutForm * aForm = new aboutForm( this, "about", TRUE );
aForm ->exec() ;
}
@@ -738,18 +757,17 @@ void mainForm::updateRecordText(int row, int col, QString newtext)
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();
QString content = (*rt).at(col+1);//must account for rowid
content = newtext; //AKG
QString cv = (*rt).at(col+1);//must account for rowid
QString content = cv ;
QString firstline = content.section( '\n', 0,0 );
if (content.length()>MAX_DISPLAY_LENGTH )
if (content.length()>14)
{
firstline.truncate(MAX_DISPLAY_LENGTH );
firstline.truncate(14);
firstline.append("...");
}
dataTable->setText( row - recAtTop, col, firstline);
@@ -798,11 +816,7 @@ void mainForm::doubleClickTable( int row, int col, int button, const QPoint & mo
void mainForm::executeQuery()
{
if (!db.isOpen()){
QMessageBox::information( this, applicationName, "There is no database opened." );
return;
}
QString query = sqlTextEdit->text();
QString query = db.GetEncodedQString(sqlTextEdit->text());
if (query.isEmpty())
{
QMessageBox::information( this, applicationName, "Query string is empty" );
@@ -823,28 +837,31 @@ void mainForm::executeQuery()
queryResultListView->removeColumn(0);
}
err=sqlite3_prepare(db._db,query.utf8(),-1,&vm,&tail);
err=sqlite3_prepare(db._db,query,query.length(),
&vm, &tail);
if (err == SQLITE_OK){
db.setDirty(true);
int rownum = 0;
Q3ListViewItem * lasttbitem = 0;
bool mustCreateColumns = true;
while ( sqlite3_step(vm) == SQLITE_ROW ){
//r.clear()
ncol = sqlite3_data_count(vm);
Q3ListViewItem * tbitem = new Q3ListViewItem( queryResultListView, lasttbitem);
//setup num of cols here for display grid
if (mustCreateColumns)
{
ncol = sqlite3_data_count(vm);
for (int e=0; e<ncol; e++)
queryResultListView->addColumn("");
queryResultListView->addColumn(sqlite3_column_name(vm, e));
mustCreateColumns = false;
}
for (int e=0; e<ncol; e++){
QString rv(QString::fromUtf8((const char *) sqlite3_column_text(vm, e)));
char * strresult = 0;
QString rv;
strresult = (char *) sqlite3_column_text(vm, e);
rv = QString(strresult);
//show it here
QString firstline = rv.section( '\n', 0,0 );
QString decoded = db.GetDecodedQString(rv);
QString firstline = decoded.section( '\n', 0,0 );
if (firstline.length()>MAX_DISPLAY_LENGTH)
{
firstline.truncate(MAX_DISPLAY_LENGTH);
@@ -897,32 +914,14 @@ void mainForm::importTableFromCSV()
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)
{
bool done(false);
do {
if ( db.save() )
done = true;
else {
QString error = "Error: could not save the database.\nMessage from database engine: ";
error.append(db.lastErrorMessage);
switch ( QMessageBox::warning( this, applicationName, error, QMessageBox::Retry|QMessageBox::Default, QMessageBox::Cancel|QMessageBox::Escape, QMessageBox::Ignore) ) {
case QMessageBox::Retry:
break;
case QMessageBox::Ignore:
db.revert();
done = true;
break;
case QMessageBox::Cancel:
return;
}
}
} while ( !done );
db.save();
} else {
return;
}
}
QString wFile = Q3FileDialog::getOpenFileName(
"",
defaultlocation,
"Text files (*.csv *.txt)",
this,
"import csv data"
@@ -954,7 +953,7 @@ void mainForm::exportTableToCSV()
db.browseTable(exportForm->option);
QString fileName = Q3FileDialog::getSaveFileName(
"",
defaultlocation,
"Text files (*.csv *txt)",
this,
"save file dialog"
@@ -1037,14 +1036,7 @@ void mainForm::dbState( bool dirty )
void mainForm::fileSave()
{
if (db.isOpen()){
do {
if ( !db.save() ) {
QString error = "Error: could not save the database.\nMessage from database engine: ";
error.append(db.lastErrorMessage);
if ( QMessageBox::warning( this, applicationName, error, QMessageBox::Ok, QMessageBox::Retry|QMessageBox::Default) != QMessageBox::Retry )
break;
}
} while ( db.getDirty() );
db.save();
}
}
@@ -1073,7 +1065,7 @@ void mainForm::exportDatabaseToSQL()
}
QString fileName = Q3FileDialog::getSaveFileName(
"",
defaultlocation,
"Text files (*.sql *txt)",
0,
"save file dialog"
@@ -1094,7 +1086,7 @@ void mainForm::exportDatabaseToSQL()
void mainForm::importDatabaseFromSQL()
{
QString fileName = Q3FileDialog::getOpenFileName(
"",
defaultlocation,
"Text files (*.sql *txt)",
0,
"import file dialog"
@@ -1106,7 +1098,7 @@ void mainForm::importDatabaseFromSQL()
if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
QString newDBfile = Q3FileDialog::getSaveFileName(
"",
defaultlocation,
"",
this,
"create file dialog"
@@ -1139,3 +1131,28 @@ void mainForm::importDatabaseFromSQL()
}
void mainForm::openPreferences()
{
preferencesForm * prefForm = new preferencesForm( this, "preferences", TRUE );
if ( prefForm->exec() ) {
updatePreferences();
resetBrowser();
}
}
void mainForm::updatePreferences()
{
preferencesForm * prefForm = new preferencesForm( this, "preferences", TRUE );
prefForm->loadSettings();
if (prefForm->defaultencoding=="Latin1")
{
db.setEncoding(kEncodingLatin1);
} else {
db.setEncoding(kEncodingUTF8);
}
db.setDefaultNewData(prefForm->defaultnewdata);
defaultlocation= prefForm->defaultlocation;
editWin->defaultlocation = defaultlocation;
editWin->setTextFormat(prefForm->defaulttext);
}

View File

@@ -66,6 +66,7 @@ public:
QAction *editDeleteIndexAction;
QAction *fileImportSQLAction;
QAction *fileExportSQLAction;
QAction *editPreferencesAction;
QWidget *widget;
QVBoxLayout *vboxLayout;
QTabWidget *mainTab;
@@ -229,11 +230,14 @@ public:
fileExportSQLAction = new QAction(mainForm);
fileExportSQLAction->setObjectName(QString::fromUtf8("fileExportSQLAction"));
fileExportSQLAction->setName("fileExportSQLAction");
editPreferencesAction = new QAction(mainForm);
editPreferencesAction->setObjectName(QString::fromUtf8("editPreferencesAction"));
editPreferencesAction->setName("editPreferencesAction");
widget = new QWidget(mainForm);
widget->setObjectName(QString::fromUtf8("widget"));
vboxLayout = new QVBoxLayout(widget);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
vboxLayout->setContentsMargins(0, 0, 0, 0);
mainTab = new QTabWidget(widget);
@@ -242,7 +246,7 @@ public:
structure->setObjectName(QString::fromUtf8("structure"));
vboxLayout1 = new QVBoxLayout(structure);
vboxLayout1->setSpacing(6);
vboxLayout1->setMargin(11);
vboxLayout1->setContentsMargins(11, 11, 11, 11);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
dblistView = new Q3ListView(structure);
dblistView->addColumn(QApplication::translate("mainForm", "Name", 0, QApplication::UnicodeUTF8));
@@ -270,7 +274,7 @@ public:
browser->setObjectName(QString::fromUtf8("browser"));
vboxLayout2 = new QVBoxLayout(browser);
vboxLayout2->setSpacing(6);
vboxLayout2->setMargin(11);
vboxLayout2->setContentsMargins(11, 11, 11, 11);
vboxLayout2->setObjectName(QString::fromUtf8("vboxLayout2"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -374,7 +378,7 @@ public:
query->setObjectName(QString::fromUtf8("query"));
vboxLayout3 = new QVBoxLayout(query);
vboxLayout3->setSpacing(6);
vboxLayout3->setMargin(11);
vboxLayout3->setContentsMargins(11, 11, 11, 11);
vboxLayout3->setObjectName(QString::fromUtf8("vboxLayout3"));
textLabel1_2 = new QLabel(query);
textLabel1_2->setObjectName(QString::fromUtf8("textLabel1_2"));
@@ -427,7 +431,7 @@ public:
queryResultListView = new Q3ListView(query);
queryResultListView->setObjectName(QString::fromUtf8("queryResultListView"));
queryResultListView->setResizePolicy(Q3ScrollView::Default);
queryResultListView->setResizePolicy(Q3ScrollView::Manual);
queryResultListView->setSelectionMode(Q3ListView::NoSelection);
queryResultListView->setResizeMode(Q3ListView::AllColumns);
@@ -497,6 +501,8 @@ public:
EditMenu->addSeparator();
EditMenu->addAction(editCreateIndexAction);
EditMenu->addAction(editDeleteIndexAction);
EditMenu->addSeparator();
EditMenu->addAction(editPreferencesAction);
ViewMenu->addAction(sqlLogAction);
PopupMenu->addAction(helpWhatsThisAction);
PopupMenu->addAction(helpAboutAction);
@@ -534,6 +540,7 @@ public:
QObject::connect(editModifyTableAction, SIGNAL(activated()), mainForm, SLOT(editTable()));
QObject::connect(fileExportSQLAction, SIGNAL(activated()), mainForm, SLOT(exportDatabaseToSQL()));
QObject::connect(fileImportSQLAction, SIGNAL(activated()), mainForm, SLOT(importDatabaseFromSQL()));
QObject::connect(editPreferencesAction, SIGNAL(activated()), mainForm, SLOT(openPreferences()));
QMetaObject::connectSlotsByName(mainForm);
} // setupUi
@@ -682,6 +689,13 @@ public:
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
fileExportSQLAction->setWhatsThis(QApplication::translate("mainForm", "This option lets you export a database to a .sql dump text file. SQL dump files contain all data necessary to recreate the database on most database engines, including MySQL and PostgreSQL.", 0, QApplication::UnicodeUTF8));
#endif // QT_NO_WHATSTHIS
editPreferencesAction->setIconText(QApplication::translate("mainForm", "Preferences", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
editPreferencesAction->setToolTip(QApplication::translate("mainForm", "Open the preferences window..", 0, QApplication::UnicodeUTF8));
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_WHATSTHIS
editPreferencesAction->setWhatsThis(QApplication::translate("mainForm", "Open the preferences window.", 0, QApplication::UnicodeUTF8));
#endif // QT_NO_WHATSTHIS
#ifndef QT_NO_TOOLTIP
mainTab->setProperty("toolTip", QVariant(QString()));
@@ -824,6 +838,7 @@ public:
int recAtTop;
int recsPerView;
QIntValidator * gotoValidator;
QString defaultlocation;
public slots:
virtual void fileOpen( const QString & fileName );
@@ -872,6 +887,8 @@ public slots:
virtual void fileRevert();
virtual void exportDatabaseToSQL();
virtual void importDatabaseFromSQL();
virtual void openPreferences();
virtual void updatePreferences();
protected:
DBBrowserDB db;

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -122,7 +122,6 @@ void importCSVForm::createButtonPressed()
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
@@ -143,7 +142,7 @@ void importCSVForm::createButtonPressed()
}
//need to mprintf here
//sql.append(*ct);
char * formSQL = sqlite3_mprintf("%Q",(*ct).latin1());
char * formSQL = sqlite3_mprintf("%Q",(const char *) (*ct));
sql.append(formSQL);
if (formSQL) sqlite3_free(formSQL);

View File

@@ -59,7 +59,7 @@ public:
importCSVForm->setModal(true);
vboxLayout = new QVBoxLayout(importCSVForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
@@ -193,7 +193,6 @@ public:
);
cancelButton->setText(QApplication::translate("importCSVForm", "Cancel", 0, QApplication::UnicodeUTF8));
createButton->setText(QApplication::translate("importCSVForm", "Create", 0, QApplication::UnicodeUTF8));
Q_UNUSED(importCSVForm);
} // retranslateUi
};

View File

@@ -0,0 +1,160 @@
#include "preferencesform.h"
#include <qvariant.h>
#include <qimage.h>
#include <qpixmap.h>
#include "qdir.h"
#include "qsettings.h"
#include "q3filedialog.h"
/*
* Constructs a preferencesForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
preferencesForm::preferencesForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
: QDialog(parent, name, modal, fl)
{
setupUi(this);
init();
}
/*
* Destroys the object and frees any allocated resources
*/
preferencesForm::~preferencesForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void preferencesForm::languageChange()
{
retranslateUi(this);
}
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
void preferencesForm::init()
{
loadSettings();
}
void preferencesForm::defaultDataChanged( int which )
{
if (which==2) {
defaultnewdata = QString("\'\'");
} else if (which==1) {
defaultnewdata = QString("0");
} else {
defaultnewdata = QString("NULL");
}
}
void preferencesForm::defaultTextChanged( int which )
{
if (which==1) {
defaulttext = QString("Auto");
} else {
defaulttext = QString("Plain");
}
}
void preferencesForm::encodingChanged( int which )
{
if (which==1) {
defaultencoding = QString("Latin1");
} else {
defaultencoding = QString("UTF8");
}
}
void preferencesForm::chooseLocation()
{
QString s = Q3FileDialog::getExistingDirectory(
defaultlocation,
this,
"get existing directory",
"Choose a directory",
TRUE );
defaultlocation = s;
locationEdit->setText(defaultlocation);
}
void preferencesForm::loadSettings()
{
QSettings settings;
settings.setPath( "Tabuleiro.com", "Arca Database Browser 2", QSettings::UserScope );
defaultencoding = settings.readEntry( "/db/defaultencoding", "UTF8" );
defaultnewdata = settings.readEntry( "/db/defaultnewdata", "NULL" );
defaultlocation = settings.readEntry( "/db/defaultlocation", QDir::homeDirPath () );
defaulttext = settings.readEntry( "/db/defaulttext", "Plain" );
if (defaultencoding=="Latin1")
{
encodingComboBox->setCurrentItem(1) ;
} else {
encodingComboBox->setCurrentItem(0) ;
defaultencoding = QString("UTF8");
}
if (defaultnewdata=="\'\'")
{
defaultdataComboBox->setCurrentItem(2) ;
} else if (defaultnewdata=="0")
{
defaultdataComboBox->setCurrentItem(1) ;
} else {
defaultdataComboBox->setCurrentItem(0) ;
defaultnewdata = QString("NULL");
}
if (defaulttext=="Auto")
{
defaultTextComboBox->setCurrentItem(1) ;
} else {
defaultTextComboBox->setCurrentItem(0) ;
defaulttext = QString("Plain");
}
locationEdit->setText(defaultlocation);
}
void preferencesForm::saveSettings()
{
QSettings settings;
settings.setPath( "sqlitebrowser.sf.net", "SQLite Database Browser 2", QSettings::UserScope );
settings.writeEntry( "/db/defaultencoding", defaultencoding );
settings.writeEntry( "/db/defaultnewdata", defaultnewdata );
settings.writeEntry( "/db/defaultlocation", defaultlocation );
settings.writeEntry( "/db/defaulttext", defaulttext );
accept();
}

View File

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

View File

@@ -37,7 +37,7 @@ public:
renameTableForm->resize(313, 101);
vboxLayout = new QVBoxLayout(renameTableForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
tablenameLineEdit = new QLineEdit(renameTableForm);
tablenameLineEdit->setObjectName(QString::fromUtf8("tablenameLineEdit"));
@@ -82,7 +82,6 @@ public:
renameTableForm->setWindowTitle(QApplication::translate("renameTableForm", "Rename table", 0, QApplication::UnicodeUTF8));
closeButton->setText(QApplication::translate("renameTableForm", "Cancel", 0, QApplication::UnicodeUTF8));
renameButton->setText(QApplication::translate("renameTableForm", "Rename", 0, QApplication::UnicodeUTF8));
Q_UNUSED(renameTableForm);
} // retranslateUi
};

View File

@@ -26,7 +26,8 @@ HEADERS += extendedmainform.h \
form1.h \
importcsvform.h \
renametableform.h \
sqllogform.h
sqllogform.h \
preferencesform.h
SOURCES += extendedmainform.cpp \
browsermain.cpp \
sqlitedb.cpp \
@@ -49,8 +50,8 @@ SOURCES += extendedmainform.cpp \
form1.cpp \
importcsvform.cpp \
renametableform.cpp \
sqllogform.cpp
sqllogform.cpp \
preferencesform.cpp
IMAGES = images/create_index.png \
images/create_table.png \
images/delete_index.png \
@@ -63,7 +64,8 @@ IMAGES = images/create_index.png \
images/revert.png \
images/save.png \
images/searchfind.png \
images/whatis.png
images/whatis.png \
images/128.png
unix {
UI_DIR = .ui
MOC_DIR = .moc
@@ -76,4 +78,3 @@ mac {
Carbon
QMAKE_INFO_PLIST = app.plist
}

View File

@@ -7,24 +7,6 @@
#include <q3filedialog.h>
#include <qmessagebox.h>
//utility functions
/*
uint utf16len(const ushort* utf16)
{
uint len=0;
if ( utf16 )
while ( *utf16++ ) ++len;
return len;
}
QString StringFromUTF16(const void* utf16)
{
QString result;
result.setUnicodeCodes(static_cast<const ushort*>(utf16), utf16len(static_cast<const ushort*>(utf16)));
return result;
}*/
void DBBrowserTable::addField(int order, const QString& wfield,const QString& wtype)
{
fldmap[order] = DBBrowserField(wfield,wtype);
@@ -62,6 +44,32 @@ bool DBBrowserDB::getDirty()
return dirty;
}
void DBBrowserDB::setEncoding( int encoding )
{
curEncoding = encoding;
}
void DBBrowserDB::setDefaultNewData( const QString & data )
{
curNewData = data;
}
QString DBBrowserDB::GetEncodedQString( const QString & input)
{
if (curEncoding==kEncodingUTF8) return input.utf8();
if (curEncoding==kEncodingLatin1) return input.latin1();
return input;
}
QString DBBrowserDB::GetDecodedQString( const QString & input)
{
if (curEncoding==kEncodingUTF8) return QString::fromUtf8(input);
if (curEncoding==kEncodingLatin1) return QString::fromLatin1(input);
return input;
}
bool DBBrowserDB::open ( const QString & db)
{
bool ok=false;
@@ -87,9 +95,9 @@ bool DBBrowserDB::open ( const QString & db)
lastErrorMessage = QString("no error");
err = sqlite3_open(db.utf8(), &_db);
err = sqlite3_open(GetEncodedQString(db), &_db);
if ( err ) {
lastErrorMessage = QString::fromUtf8(sqlite3_errmsg(_db));
lastErrorMessage = sqlite3_errmsg(_db);
sqlite3_close(_db);
_db = 0;
return false;
@@ -114,11 +122,8 @@ bool DBBrowserDB::setRestorePoint()
if (!isOpen()) return false;
if (_db){
if ( SQLITE_OK != sqlite3_exec(_db,"BEGIN TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL) ) {
lastErrorMessage = QString::fromUtf8(sqlite3_errmsg(_db));
return false;
}
sqlite3_exec(_db,"BEGIN TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
return true;
@@ -129,11 +134,8 @@ bool DBBrowserDB::save()
if (!isOpen()) return false;
if (_db){
if ( SQLITE_OK != sqlite3_exec(_db,"COMMIT TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL) ) {
lastErrorMessage = QString::fromUtf8(sqlite3_errmsg(_db));
return false;
}
sqlite3_exec(_db,"COMMIT TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
return true;
@@ -144,11 +146,8 @@ bool DBBrowserDB::revert()
if (!isOpen()) return false;
if (_db){
if ( SQLITE_OK != sqlite3_exec(_db,"ROLLBACK TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL) ) {
lastErrorMessage = QString::fromUtf8(sqlite3_errmsg(_db));
return false;
}
sqlite3_exec(_db,"ROLLBACK TRANSACTION RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
return true;
@@ -162,8 +161,8 @@ bool DBBrowserDB::create ( const QString & db)
lastErrorMessage = QString("no error");
if( sqlite3_open(db.utf8(), &_db) != SQLITE_OK ){
lastErrorMessage = QString::fromUtf8(sqlite3_errmsg(_db));
if( sqlite3_open(GetEncodedQString(db), &_db) != SQLITE_OK ){
lastErrorMessage = sqlite3_errmsg(_db);
sqlite3_close(_db);
_db = 0;
return false;
@@ -185,6 +184,7 @@ bool DBBrowserDB::create ( const QString & db)
return ok;
}
void DBBrowserDB::close (){
if (_db)
{
@@ -274,7 +274,7 @@ bool DBBrowserDB::executeSQL ( const QString & statement)
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite3_exec(_db,statement.utf8(),
if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement),
NULL,NULL,&errmsg)){
ok=true;
}
@@ -298,7 +298,7 @@ bool DBBrowserDB::executeSQLDirect ( const QString & statement)
if (_db){
logSQL(statement, kLogMsg_App);
if (SQLITE_OK==sqlite3_exec(_db,statement.utf8(),
if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement),
NULL,NULL,&errmsg)){
ok=true;
}
@@ -319,18 +319,24 @@ bool DBBrowserDB::addRecord ( )
if (!hasValidBrowseSet) return false;
if (!isOpen()) return false;
bool ok = false;
int fields = browseFields.count();
QString emptyvalue = curNewData;
QString statement = "INSERT INTO ";
statement.append(curBrowseTableName);
statement.append("(");
statement.append(browseFields.first());
statement.append(") VALUES(NULL);");
statement.append(GetEncodedQString(curBrowseTableName));
statement.append(" VALUES(");
for ( int i=1; i<=fields; i++ ) {
statement.append(emptyvalue);
if (i<fields) statement.append(", ");
}
statement.append(");");
lastErrorMessage = QString("no error");
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite3_exec(_db,statement.utf8(),NULL,NULL, &errmsg)){
if (SQLITE_OK==sqlite3_exec(_db,statement,NULL,NULL, &errmsg)){
ok=true;
int newrowid = sqlite3_last_insert_rowid(_db);
//int newrowid = sqlite3_last_insert_rowid(_db);
} else {
lastErrorMessage = QString(errmsg);
}
@@ -351,15 +357,15 @@ bool DBBrowserDB::deleteRecord( int wrow)
lastErrorMessage = QString("no error");
QString statement = "DELETE FROM ";
statement.append(curBrowseTableName.latin1());
statement.append(GetEncodedQString(curBrowseTableName));
statement.append(" WHERE rowid=");
statement.append(rowid.latin1());
statement.append(rowid);
statement.append(";");
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite3_exec(_db,statement.utf8(),
if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement),
NULL,NULL,&errmsg)){
ok=true;
} else {
@@ -374,7 +380,8 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext)
char * errmsg;
if (!hasValidBrowseSet) return false;
if (!isOpen()) return false;
bool ok = true;
bool ok = false;
lastErrorMessage = QString("no error");
rowList::iterator rt = browseRecs.at(wrow);
@@ -382,44 +389,36 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext)
QString cv = (*rt).at(wcol+1);//must account for rowid
QString ct = browseFields.at(wcol);
sqlite3_stmt *vm;
const char *tail;
int ncol;
int err;
QString statement = "UPDATE ";
statement.append(curBrowseTableName.latin1());
statement.append(GetEncodedQString(curBrowseTableName));
statement.append(" SET ");
statement.append(ct);
statement.append("=?");
statement.append(GetEncodedQString(ct));
statement.append("=");
QString wenc = GetEncodedQString(wtext);
char * formSQL = sqlite3_mprintf("%Q",(const char *) wenc);
statement.append(formSQL);
if (formSQL) sqlite3_free(formSQL);
statement.append(" WHERE rowid=");
statement.append(rowid.latin1());
statement.append(rowid);
statement.append(";");
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite3_exec(_db,statement,
NULL,NULL,&errmsg)){
ok=true;
/*update local copy*/
(cv) = wtext;
} else {
lastErrorMessage = QString(errmsg);
}
}
setDirty(true);
err=sqlite3_prepare(_db,statement.utf8(),-1,
&vm, &tail);
if (err == SQLITE_OK){
err = sqlite3_bind_text(vm, 1, wtext.utf8(), -1, SQLITE_TRANSIENT);
if (err == SQLITE_OK){
while ( sqlite3_step(vm) == SQLITE_ROW ){
ncol = sqlite3_data_count(vm);
}
sqlite3_finalize(vm);
} else{
ok = false;
lastErrorMessage = QString::fromUtf8(sqlite3_errmsg(_db));
}
}else{
ok = false;
lastErrorMessage = QString::fromUtf8(sqlite3_errmsg(_db));
}
cv = wtext;
return ok;
}
@@ -457,20 +456,24 @@ void DBBrowserDB::getTableRecords( const QString & tablename )
lastErrorMessage = QString("no error");
QString statement = "SELECT rowid, * FROM ";
statement.append( tablename.latin1());
statement.append( GetEncodedQString(tablename) );
statement.append(" ORDER BY rowid; ");
//qDebug(statement);
logSQL(statement, kLogMsg_App);
err=sqlite3_prepare(_db,statement.utf8(),-1,
err=sqlite3_prepare(_db,statement,statement.length(),
&vm, &tail);
if (err == SQLITE_OK){
int rownum = 0;
while ( sqlite3_step(vm) == SQLITE_ROW ){
r.clear();
ncol = sqlite3_data_count(vm);
for (int e=0; e<ncol; e++){
QString rv(QString::fromUtf8((const char *) sqlite3_column_text(vm, e)));
r << rv;
char * strresult = 0;
QString rv;
strresult = (char *) sqlite3_column_text(vm, e);
rv = QString(strresult);
r << GetDecodedQString(rv);
if (e==0){
idmap.insert(rv.toInt(),rownum);
rownum++;
@@ -485,83 +488,43 @@ void DBBrowserDB::getTableRecords( const QString & tablename )
}
}
resultMap DBBrowserDB::getFindResults( const QString & wfield, const QString & woperator, const QString & wsearchterm)
resultMap DBBrowserDB::getFindResults( const QString & wstatement)
{
//we may need to modify woperator and wsearchterm, so use copies
QString * finaloperator = new QString(woperator);
QString * finalsearchterm = new QString(wsearchterm);
//special case for CONTAINS operator: use LIKE and surround the search word with % characters
if (woperator.compare("contains")==0){
finaloperator = new QString("LIKE");
QString newsearchterm = "%";
newsearchterm.append(wsearchterm);
newsearchterm.append("%");
finalsearchterm = new QString( newsearchterm);
}
QString statement = "SELECT rowid, ";
statement.append(wfield);
statement.append(" FROM ");
statement.append( curBrowseTableName);
statement.append(" WHERE ");
statement.append(wfield);
statement.append(" ");
statement.append(*finaloperator);
statement.append(" ");
statement.append(" ? ORDER BY rowid; ");
//searchterm needs to be quoted if it is not a number
bool isnumber = false;
wsearchterm.toDouble(&isnumber );
if (!isnumber ) wsearchterm.toInt(&isnumber , 10);
sqlite3_stmt *vm;
const char *tail;
int ncol;
int rownum = 0;
int recnum = 0;
QString r;
// char *errmsg;
int err=0;
resultMap res;
lastErrorMessage = QString("no error");
logSQL(statement, kLogMsg_App);
err=sqlite3_prepare(_db,statement.utf8(),-1,
QString encstatement = GetEncodedQString(wstatement);
logSQL(encstatement, kLogMsg_App);
err=sqlite3_prepare(_db,encstatement,encstatement.length(),
&vm, &tail);
if (err == SQLITE_OK){
if (!isnumber ) {//not a number, quote it
sqlite3_bind_text(vm, 1, (*finalsearchterm).utf8(), -1, SQLITE_TRANSIENT);
} else {//append the number, unquoted
double db = wsearchterm.toDouble(&isnumber );
if (isnumber)
{
sqlite3_bind_double(vm, 1, db);
}else {
int inte = wsearchterm.toInt(&isnumber, 10);
if (isnumber)
{
sqlite3_bind_int(vm, 1, inte);
}
}
}
int rownum = 0;
int recnum = 0;
QString r;
while ( sqlite3_step(vm) == SQLITE_ROW ){
ncol = sqlite3_data_count(vm);
for (int e=0; e<ncol; e++){
r = QString::fromUtf8((const char *) sqlite3_column_text(vm, e));
for (int e=0; e<ncol; e++){
char * strresult = 0;
strresult = (char *) sqlite3_column_text(vm, e);
r = QString(strresult);
if (e==0){
rownum = r.toInt();
rowIdMap::iterator mit = idmap.find(rownum);
recnum = *mit;
}
}
res.insert(recnum, r);
res.insert(recnum, GetDecodedQString(r));
}
sqlite3_finalize(vm);
}else{
lastErrorMessage = QString::fromUtf8(sqlite3_errmsg(_db));
lastErrorMessage = QString(sqlite3_errmsg(_db));
}
return res;
}
@@ -655,91 +618,91 @@ void DBBrowserDB::logSQL(QString statement, int msgtype)
void DBBrowserDB::updateSchema( )
{
// qDebug ("Getting list of tables");
sqlite3_stmt *vm;
const char *tail;
int ncol;
QStringList r;
int err=0;
int idxnum =0;
int tabnum = 0;
idxmap.clear();
tbmap.clear();
lastErrorMessage = QString("no error");
QString statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='table' "
"ORDER BY name;";
err=sqlite3_prepare(_db, (const char *) statement.latin1(),-1,
&vm, &tail);
if (err == SQLITE_OK){
logSQL(statement, kLogMsg_App);
while ( sqlite3_step(vm) == SQLITE_ROW ){
QString val1, val2;
val1 = QString((const char *) sqlite3_column_text(vm, 0));
val2 = QString((const char *) sqlite3_column_text(vm, 1));
tbmap[tabnum] = DBBrowserTable(val1, val2);
tabnum++;
}
sqlite3_finalize(vm);
}else{
qDebug ("could not get list of tables: %d, %s",err,sqlite3_errmsg(_db));
}
//now get the field list for each table in tbmap
tableMap::Iterator it;
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
statement = "PRAGMA TABLE_INFO(";
statement.append( (const char *) it.data().getname().latin1());
statement.append(");");
logSQL(statement, kLogMsg_App);
err=sqlite3_prepare(_db,statement.utf8(),-1,
&vm, &tail);
if (err == SQLITE_OK){
it.data(). fldmap.clear();
int e = 0;
while ( sqlite3_step(vm) == SQLITE_ROW ){
if (sqlite3_column_count(vm)==6) {
QString val1, val2;
int ispk= 0;
val1 = QString((const char *) sqlite3_column_text(vm, 1));
val2 = QString((const char *) sqlite3_column_text(vm, 2));
ispk = sqlite3_column_int(vm, 5);
if (ispk==1){
val2.append(QString(" PRIMARY KEY"));
}
it.data().addField(e,val1,val2);
e++;
}
sqlite3_stmt *vm;
const char *tail;
QStringList r;
int err=0;
QString num;
int idxnum =0;
int tabnum = 0;
idxmap.clear();
tbmap.clear();
lastErrorMessage = QString("no error");
QString statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='table' ;";
err=sqlite3_prepare(_db, (const char *) statement,statement.length(),
&vm, &tail);
if (err == SQLITE_OK){
logSQL(statement, kLogMsg_App);
while ( sqlite3_step(vm) == SQLITE_ROW ){
num.setNum(tabnum);
QString val1, val2;
val1 = QString((const char *) sqlite3_column_text(vm, 0));
val2 = QString((const char *) sqlite3_column_text(vm, 1));
tbmap[num] = DBBrowserTable(GetDecodedQString(val1), GetDecodedQString(val2));
tabnum++;
}
sqlite3_finalize(vm);
}else{
qDebug ("could not get list of tables: %d, %s",err,sqlite3_errmsg(_db));
}
//now get the field list for each table in tbmap
tableMap::Iterator it;
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
statement = "PRAGMA TABLE_INFO(";
statement.append( (const char *) GetEncodedQString(it.data().getname()));
statement.append(");");
logSQL(statement, kLogMsg_App);
err=sqlite3_prepare(_db,statement,statement.length(),
&vm, &tail);
if (err == SQLITE_OK){
it.data(). fldmap.clear();
int e = 0;
while ( sqlite3_step(vm) == SQLITE_ROW ){
if (sqlite3_column_count(vm)==6) {
QString val1, val2;
int ispk= 0;
val1 = QString((const char *) sqlite3_column_text(vm, 1));
val2 = QString((const char *) sqlite3_column_text(vm, 2));
ispk = sqlite3_column_int(vm, 5);
if (ispk==1){
val2.append(QString(" PRIMARY KEY"));
}
it.data().addField(e,GetDecodedQString(val1),GetDecodedQString(val2));
e++;
}
}
sqlite3_finalize(vm);
} else{
lastErrorMessage = QString ("could not get types");
}
}
statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='index' "
"ORDER BY name;";
} else{
lastErrorMessage = QString ("could not get types");
}
}
statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='index' ";
/*"ORDER BY name;"*/
//finally get indices
err=sqlite3_prepare(_db,statement.utf8(),-1,
&vm, &tail);
logSQL(statement, kLogMsg_App);
if (err == SQLITE_OK){
while ( sqlite3_step(vm) == SQLITE_ROW ){
QString val1, val2;
val1 = QString((const char *) sqlite3_column_text(vm, 0));
val2 = QString((const char *) sqlite3_column_text(vm, 1));
idxmap[idxnum] = DBBrowserIndex(val1,val2);
//finally get indices
err=sqlite3_prepare(_db,statement,statement.length(),
&vm, &tail);
logSQL(statement, kLogMsg_App);
if (err == SQLITE_OK){
while ( sqlite3_step(vm) == SQLITE_ROW ){
QString val1, val2;
val1 = QString((const char *) sqlite3_column_text(vm, 0));
val2 = QString((const char *) sqlite3_column_text(vm, 1));
num.setNum(idxnum);
idxmap[num] = DBBrowserIndex(GetDecodedQString(val1),GetDecodedQString(val2));
idxnum ++;
}
sqlite3_finalize(vm);
}else{
lastErrorMessage = QString ("could not get list of indices");
}
}
sqlite3_finalize(vm);
}else{
lastErrorMessage = QString ("could not get list of indices");
}
}
QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char quote, int maxrecords, int * numfields)

View File

@@ -21,24 +21,26 @@ enum
kLogMsg_App
};
enum
{
kEncodingUTF8,
kEncodingLatin1,
kEncodingNONE
};
static QString applicationName = QString("SQLite Database Browser");
static QString applicationIconName = QString("icone16.png");
static QString aboutText = QString("Version 1.3\n\nSQLite Database Browser is a freeware, public domain, open source visual tool used to create, design and edit database files compatible with SQLite 3.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<int, class DBBrowserTable> tableMap;
typedef QMap<int, class DBBrowserIndex> indexMap;
typedef QMap<QString, class DBBrowserTable> tableMap;
typedef QMap<QString, class DBBrowserIndex> indexMap;
typedef QMap<int, int> rowIdMap;
typedef Q3ValueList<QStringList> rowList;
typedef QMap<int, QString> resultMap;
//utility functions
/*
uint utf16len(const ushort* utf16);
QString StringFromUTF16(const void* utf16);*/
class DBBrowserField
{
public:
@@ -90,7 +92,7 @@ private:
class DBBrowserDB
{
public:
DBBrowserDB (): _db( 0 ) , hasValidBrowseSet(false) {}
DBBrowserDB (): _db( 0 ) , hasValidBrowseSet(false), curEncoding(kEncodingUTF8) {}
~DBBrowserDB (){}
bool open ( const QString & db);
bool create ( const QString & db);
@@ -112,13 +114,17 @@ public:
QStringList getTableTypes(const QString & tablename);
QStringList getTableNames();
QStringList getIndexNames();
resultMap getFindResults( const QString & wfield, const QString & woperator, const QString & wsearchterm);
resultMap getFindResults( const QString & wstatement);
int getRecordCount();
bool isOpen();
void setDirty(bool dirtyval);
void setDirtyDirect(bool dirtyval);
bool getDirty();
void logSQL(QString statement, int msgtype);
void setEncoding( int encoding );
void setDefaultNewData( const QString & data );
QString GetEncodedQString( const QString & input);
QString GetDecodedQString( const QString & input);
sqlite3 * _db;
@@ -134,6 +140,8 @@ public:
QString curBrowseTableName;
QString lastErrorMessage;
QString curDBFilename;
int curEncoding;
QString curNewData;
sqlLogForm * logWin;

View File

@@ -48,7 +48,7 @@ public:
sqlLogForm->resize(547, 203);
vboxLayout = new QVBoxLayout(sqlLogForm);
vboxLayout->setSpacing(6);
vboxLayout->setMargin(11);
vboxLayout->setContentsMargins(11, 11, 11, 11);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
@@ -82,7 +82,7 @@ public:
WStackPage->setObjectName(QString::fromUtf8("WStackPage"));
gridLayout = new QGridLayout(WStackPage);
gridLayout->setSpacing(6);
gridLayout->setMargin(11);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setContentsMargins(0, 0, 0, 0);
userLogText = new Q3TextEdit(WStackPage);
@@ -97,7 +97,7 @@ public:
WStackPage1->setObjectName(QString::fromUtf8("WStackPage1"));
vboxLayout1 = new QVBoxLayout(WStackPage1);
vboxLayout1->setSpacing(6);
vboxLayout1->setMargin(11);
vboxLayout1->setContentsMargins(11, 11, 11, 11);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
vboxLayout1->setContentsMargins(0, 0, 0, 0);
appLogText = new Q3TextEdit(WStackPage1);
@@ -129,7 +129,6 @@ public:
<< QApplication::translate("sqlLogForm", "Application", 0, QApplication::UnicodeUTF8)
);
clearButton->setText(QApplication::translate("sqlLogForm", "Clear", 0, QApplication::UnicodeUTF8));
Q_UNUSED(sqlLogForm);
} // retranslateUi
};