grammar: Introduce basic View class stub

Parsing views or generating a CREATE VIEW statement isn't implemented
yet.

Also unify the process by which it's possible to retrieve information on
the fields of a database object.
This commit is contained in:
Martin Kleusberg
2017-01-23 17:06:41 +01:00
parent ebc3869627
commit d236f6df9f
5 changed files with 130 additions and 24 deletions

View File

@@ -76,6 +76,9 @@ ObjectPtr Object::parseSQL(Object::Types type, const QString& sSQL)
case Object::Types::Index:
result = Index::parseSQL(sSQL);
break;
case Object::Types::View:
result = View::parseSQL(sSQL);
break;
default:
return ObjectPtr(nullptr);
}
@@ -310,6 +313,14 @@ QStringList Table::fieldNames() const
return sl;
}
FieldInfoList Table::fieldInformation() const
{
FieldInfoList result;
foreach(FieldPtr f, m_fields)
result.append({f->name(), f->type(), f->toString(" ", " ")});
return result;
}
bool Table::hasAutoIncrement() const
{
foreach(FieldPtr f, m_fields) {
@@ -1132,4 +1143,52 @@ void CreateIndexWalker::parsecolumn(Index* index, antlr::RefAST c)
index->addColumn(IndexedColumnPtr(new IndexedColumn(name, isExpression, order)));
}
View::~View()
{
clear();
}
ObjectPtr View::parseSQL(const QString& /*sSQL*/)
{
// TODO
return ViewPtr(new View(""));
}
void View::clear()
{
m_fields.clear();
}
void View::addField(const FieldPtr& f)
{
m_fields.append(FieldPtr(f));
}
void View::setFields(const FieldVector& fields)
{
clear();
m_fields = fields;
}
QStringList View::fieldNames() const
{
QStringList sl;
foreach(FieldPtr f, m_fields)
sl << f->name();
return sl;
}
FieldInfoList View::fieldInformation() const
{
FieldInfoList result;
foreach(FieldPtr f, m_fields)
result.append({f->name(), f->type(), f->toString(" ", " ")});
return result;
}
} //namespace sqlb