Skip to content

Commit

Permalink
grammar: Add stub for the trigger class
Browse files Browse the repository at this point in the history
  • Loading branch information
MKleusberg committed Jan 23, 2017
1 parent f8165d4 commit 9266d20
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ void DBBrowserDB::updateSchema( )
continue;

DBBrowserObject obj(val_name, val_sql, type, val_tblname);
if((type == sqlb::Object::Types::Table || type == sqlb::Object::Types::Index || type == sqlb::Object::Types::View) && !val_sql.isEmpty())
if(!val_sql.isEmpty())
{
obj.object = sqlb::Object::parseSQL(type, val_sql);
if(val_temp == "1")
Expand All @@ -1274,6 +1274,10 @@ void DBBrowserDB::updateSchema( )
foreach(const auto& column, columns)
view->addField(sqlb::FieldPtr(new sqlb::Field(column.first, column.second)));
}
} else if(type == sqlb::Object::Types::Trigger) {
// For triggers set the name of the table the trigger operates on here because we don't have a parser for trigger statements yet.
sqlb::TriggerPtr trg = obj.object.dynamicCast<sqlb::Trigger>();
trg->setTable(val_tblname);
}
}
objMap.insert(val_type, obj);
Expand Down
12 changes: 12 additions & 0 deletions src/sqlitetypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ ObjectPtr Object::parseSQL(Object::Types type, const QString& sSQL)
case Object::Types::View:
result = View::parseSQL(sSQL);
break;
case Object::Types::Trigger:
result = Trigger::parseSQL(sSQL);
break;
default:
return ObjectPtr(nullptr);
}
Expand Down Expand Up @@ -1191,4 +1194,13 @@ FieldInfoList View::fieldInformation() const
return result;
}



ObjectPtr Trigger::parseSQL(const QString& /*sSQL*/)
{
// TODO

return TriggerPtr(new Trigger(""));
}

} //namespace sqlb
23 changes: 23 additions & 0 deletions src/sqlitetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Object;
class Table;
class Index;
class View;
class Trigger;
class Field;
class Constraint;
class IndexedColumn;
Expand All @@ -24,6 +25,7 @@ typedef QSharedPointer<Object> ObjectPtr;
typedef QSharedPointer<Table> TablePtr;
typedef QSharedPointer<Index> IndexPtr;
typedef QSharedPointer<View> ViewPtr;
typedef QSharedPointer<Trigger> TriggerPtr;
typedef QSharedPointer<Field> FieldPtr;
typedef QSharedPointer<Constraint> ConstraintPtr;
typedef QVector<FieldPtr> FieldVector;
Expand Down Expand Up @@ -406,6 +408,27 @@ class View : public Object
FieldVector m_fields;
};

class Trigger : public Object
{
public:
explicit Trigger(const QString& name): Object(name) {}
virtual ~Trigger() {}

virtual Types type() const { return Object::Trigger; }

QString sql() const { /* TODO */ return m_originalSql; }

static ObjectPtr parseSQL(const QString& sSQL);

virtual QString baseTable() const { return m_table; }

void setTable(const QString& table) { m_table = table; }
QString table() const { return m_table; }

private:
QString m_table;
};

} //namespace sqlb

#endif // SQLITETYPES_H

0 comments on commit 9266d20

Please sign in to comment.