grammar: Add support for CHECK table constraints

This adds support for CHECK table constraints. We already had support
for CHECK column constraints and still mostly use that but with this
commit there are no more hickups when encountering such a table. It also
adds basic support for editing those tables: the CHECK constraint isn't
removed anymore when editing a different part of the table.

Example:
CREATE TABLE test(
	a int CHECK a IN(1,2,3),	-- This was supported before
	b int,
	CHECK b IN (1,2,3)		-- This is added by this commit
);
This commit is contained in:
Martin Kleusberg
2017-04-30 23:35:48 +02:00
parent 1eece9ef06
commit 3596bf6c8d
2 changed files with 84 additions and 10 deletions
+20
View File
@@ -108,6 +108,7 @@ public:
PrimaryKeyConstraintType,
UniqueConstraintType,
ForeignKeyConstraintType,
CheckConstraintType,
};
Constraint(const QString& name = QString())
@@ -183,6 +184,25 @@ public:
virtual ConstraintTypes type() const { return PrimaryKeyConstraintType; }
};
class CheckConstraint : public Constraint
{
public:
CheckConstraint(const QString& expr = QString())
: m_expression(expr)
{
}
void setExpression(const QString& expr) { m_expression = expr; }
QString expression() const { return m_expression; }
virtual QString toSql(const FieldVector& applyOn) const;
virtual ConstraintTypes type() const { return CheckConstraintType; }
private:
QString m_expression;
};
class Field
{
public: