Show triggers and views

Also show the triggers and views in the DB structure tab.
This commit is contained in:
Martin Kleusberg
2013-01-02 18:50:27 +01:00
parent c0b2c073a6
commit 0edfb7e9d3
10 changed files with 58 additions and 45 deletions

View File

@@ -19,6 +19,12 @@
<file alias="table">table.png</file>
<file alias="index">tag_blue.png</file>
<file alias="refresh">view-refresh.png</file>
<file alias="view_delete">picture_delete.png</file>
<file alias="view">picture.png</file>
<file alias="view_create">picture_add.png</file>
<file alias="trigger">script.png</file>
<file alias="trigger_create">script_add.png</file>
<file alias="trigger_delete">script_delete.png</file>
</qresource>
<qresource prefix="/oldimages">
<file alias="128">oldimages/128.png</file>

BIN
src/icons/picture.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

BIN
src/icons/picture_add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

BIN
src/icons/script.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

BIN
src/icons/script_add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

BIN
src/icons/script_delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

View File

@@ -214,8 +214,6 @@ void MainWindow::populateStructure()
db.updateSchema();
QStringList tblnames = db.getTableNames();
sqliteHighlighter->setTableNames(tblnames);
// logWin->userSqliteHighlighter()->setTableNames(tblnames);
// logWin->appSqliteHighlighter()->setTableNames(tblnames);
tableMap::ConstIterator it;
for ( it = db.tbmap.begin(); it != db.tbmap.end(); ++it ) {
@@ -240,14 +238,30 @@ void MainWindow::populateStructure()
// TODO make an options/setting autoexpand
ui->dbTreeWidget->setItemExpanded(tableItem, true);
}
indexMap::ConstIterator it2;
objectMap::ConstIterator it2;
for ( it2 = db.idxmap.begin(); it2 != db.idxmap.end(); ++it2 ) {
QTreeWidgetItem *idxItem = new QTreeWidgetItem();
idxItem->setText( 0, it2.value().getname() );
idxItem->setText( 1, "index" );
idxItem->setText( 3, it2.value().getsql() );
idxItem->setIcon(0, QIcon(":/icons/index"));
ui->dbTreeWidget->addTopLevelItem(idxItem);
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText( 0, it2.value().getname() );
item->setText( 1, "index" );
item->setText( 3, it2.value().getsql() );
item->setIcon(0, QIcon(":/icons/index"));
ui->dbTreeWidget->addTopLevelItem(item);
}
for ( it2 = db.viewmap.begin(); it2 != db.viewmap.end(); ++it2 ) {
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText( 0, it2.value().getname() );
item->setText( 1, "view" );
item->setText( 3, it2.value().getsql() );
item->setIcon(0, QIcon(":/icons/view"));
ui->dbTreeWidget->addTopLevelItem(item);
}
for ( it2 = db.trgmap.begin(); it2 != db.trgmap.end(); ++it2 ) {
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText( 0, it2.value().getname() );
item->setText( 1, "trigger" );
item->setText( 3, it2.value().getsql() );
item->setIcon(0, QIcon(":/icons/trigger"));
ui->dbTreeWidget->addTopLevelItem(item);
}
}

View File

@@ -218,6 +218,8 @@ void DBBrowserDB::close (){
}
_db = 0;
idxmap.clear();
trgmap.clear();
viewmap.clear();
tbmap.clear();
idmap.clear();
browseRecs.clear();
@@ -446,7 +448,7 @@ bool DBBrowserDB::renameColumn(QString tablename, QString from, QString to, QStr
}
bool DBBrowserDB::renameTable(QString from_table, QString to_table){
qDebug("renameTable column");
qDebug("renameTable");
return true;
}
@@ -555,8 +557,8 @@ QStringList DBBrowserDB::getTableNames()
QStringList DBBrowserDB::getIndexNames()
{
indexMap::Iterator it;
indexMap tmap = idxmap;
objectMap::Iterator it;
objectMap tmap = idxmap;
QStringList res;
for ( it = tmap.begin(); it != tmap.end(); ++it ) {
@@ -623,32 +625,42 @@ void DBBrowserDB::logSQL(QString statement, int msgtype)
void DBBrowserDB::updateSchema( )
{
// qDebug ("Getting list of tables");
sqlite3_stmt *vm;
const char *tail;
int err=0;
idxmap.clear();
tbmap.clear();
viewmap.clear();
trgmap.clear();
lastErrorMessage = QString("no error");
QString statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='table' ;";
QString statement = "SELECT type, name, sql FROM sqlite_master;";
err=sqlite3_prepare(_db, (const char *) statement.toUtf8(),statement.length(),
&vm, &tail);
if (err == SQLITE_OK){
logSQL(statement, kLogMsg_App);
while ( sqlite3_step(vm) == SQLITE_ROW ){
QString val1, val2;
QString val1, val2, val3;
val1 = QString((const char *) sqlite3_column_text(vm, 0));
val2 = QString((const char *) sqlite3_column_text(vm, 1));
tbmap[val1] = DBBrowserTable(GetDecodedQString(val1), GetDecodedQString(val2));
val3 = QString((const char *) sqlite3_column_text(vm, 2));
if(val1 == "table")
tbmap[val2] = DBBrowserTable(GetDecodedQString(val2), GetDecodedQString(val3));
else if(val1 == "index")
idxmap[val2] = DBBrowserObject(GetDecodedQString(val2), GetDecodedQString(val3));
else if(val1 == "view")
viewmap[val2] = DBBrowserObject(GetDecodedQString(val2), GetDecodedQString(val3));
else if(val1 == "trigger")
trgmap[val2] = DBBrowserObject(GetDecodedQString(val2), GetDecodedQString(val3));
else
qDebug("unknown object type %s", val1.toStdString().c_str());
}
sqlite3_finalize(vm);
}else{
qDebug ("could not get list of tables: %d, %s",err,sqlite3_errmsg(_db));
qDebug ("could not get list of db objects: %d, %s",err,sqlite3_errmsg(_db));
}
qDebug(sqlite3_errmsg(_db));
@@ -683,25 +695,6 @@ void DBBrowserDB::updateSchema( )
lastErrorMessage = QString ("could not get types");
}
}
statement = "SELECT name, sql "
"FROM sqlite_master "
"WHERE type='index' ";
/*"ORDER BY name;"*/
//finally get indices
err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(),
&vm, &tail);
logSQL(statement, kLogMsg_App);
if (err == SQLITE_OK){
while ( sqlite3_step(vm) == SQLITE_ROW ){
QString val1, val2;
val1 = QString((const char *) sqlite3_column_text(vm, 0));
val2 = QString((const char *) sqlite3_column_text(vm, 1));
idxmap[val1] = DBBrowserIndex(GetDecodedQString(val1),GetDecodedQString(val2));
}
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

@@ -24,10 +24,9 @@ enum
static QString g_sApplicationNameShort = QString("sqlitebrowser");
static QString g_applicationIconName = QString(":/oldimages/icon16");
typedef QMap<int, class DBBrowserField> fieldMap;
typedef QMap<QString, class DBBrowserTable> tableMap;
typedef QMap<QString, class DBBrowserIndex> indexMap;
typedef QMap<QString, class DBBrowserObject> objectMap;
typedef QMap<int, int> rowIdMap;
typedef QList<QStringList> rowList;
@@ -47,11 +46,11 @@ private:
QString type;
};
class DBBrowserIndex
class DBBrowserObject
{
public:
DBBrowserIndex() : name( "" ) { }
DBBrowserIndex( const QString& wname,const QString& wsql )
DBBrowserObject() : name( "" ) { }
DBBrowserObject( const QString& wname,const QString& wsql )
: name( wname), sql( wsql )
{ }
QString getname() const { return name; }
@@ -61,7 +60,6 @@ private:
QString sql;
};
class DBBrowserTable
{
public:
@@ -128,7 +126,9 @@ public:
QStringList decodeCSV(const QString & csvfilename, char sep, char quote, int maxrecords, int * numfields);
tableMap tbmap;
indexMap idxmap;
objectMap idxmap;
objectMap viewmap;
objectMap trgmap;
rowIdMap idmap;
rowList browseRecs;