Skip to content

Commit

Permalink
Merge branch 'alpha'
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-jang committed Jul 21, 2021
2 parents 89c591d + 26e4896 commit 2e51a85
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 74 deletions.
4 changes: 2 additions & 2 deletions Qsi.PrimarSql/Analyzers/PrimarSqlTableAnalyzer.cs
Expand Up @@ -88,8 +88,8 @@ protected override QsiTableColumn ResolveColumnReference(TableCompileContext con
var columnName = columnReferenceNode.Name[^1];
object[] path = columnReferenceNode.Accessors.Select(AccessorToValue).ToArray();

if (source.Type != QsiTableType.Table)
throw new QsiException(QsiError.Internal);
if (source?.Type != QsiTableType.Table)
throw new QsiException(QsiError.UnknownColumn, columnName);

PrimarSqlTableColumn[] columns = source
.Columns
Expand Down
26 changes: 17 additions & 9 deletions Qsi.PrimarSql/PrimarSqlParser.cs
Expand Up @@ -6,6 +6,7 @@
using Qsi.Parsing.Antlr;
using Qsi.PrimarSql.Tree;
using Qsi.Tree;
using static PrimarSql.Internal.PrimarSqlParser;

namespace Qsi.PrimarSql
{
Expand Down Expand Up @@ -40,20 +41,27 @@ protected override IQsiTreeNode Parse(QsiScript script, Parser parser)
private IQsiTreeNode ParseInternal(QsiScript script, Parser parser)
{
var primarSqlParser = (global::PrimarSql.Internal.PrimarSqlParser)parser;
var rootContext = primarSqlParser.root();

switch (script.ScriptType)
if (rootContext.children[0] is not SqlStatementContext sqlStatement)
return null;

if (sqlStatement.children[0] is not DmlStatementContext dmlStatement)
return null;

switch (dmlStatement.children[0])
{
case QsiScriptType.Select:
return TableVisitor.VisitSelectStatement(primarSqlParser.selectStatement());
case SelectStatementContext selectStatement:
return TableVisitor.VisitSelectStatement(selectStatement);

case QsiScriptType.Insert:
return ActionVisitor.VisitInsertStatement(primarSqlParser.insertStatement());
case InsertStatementContext insertStatement:
return ActionVisitor.VisitInsertStatement(insertStatement);

case QsiScriptType.Delete:
return ActionVisitor.VisitDeleteStatement(primarSqlParser.deleteStatement());
case DeleteStatementContext deleteStatement:
return ActionVisitor.VisitDeleteStatement(deleteStatement);

case QsiScriptType.Update:
return ActionVisitor.VisitUpdateStatement(primarSqlParser.updateStatement());
case UpdateStatementContext updateStatement:
return ActionVisitor.VisitUpdateStatement(updateStatement);

default:
return null;
Expand Down
2 changes: 1 addition & 1 deletion Qsi.PrimarSql/Qsi.PrimarSql.csproj
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="PrimarSql" Version="1.2.2" />
<PackageReference Include="PrimarSql" Version="1.2.4" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 0 additions & 5 deletions Qsi.PrimarSql/Tree/Visitors/ActionVisitor.cs
Expand Up @@ -25,11 +25,6 @@ public static QsiActionNode VisitInsertStatement(InsertStatementContext context)

switch (context.insertStatementValue())
{
case SubqueryInsertStatementContext _:
{
throw TreeHelper.NotSupportedFeature("subquery insert");
}

case ExpressionInsertStatementContext expressionContext:
{
if (context.columns != null)
Expand Down
17 changes: 2 additions & 15 deletions Qsi.PrimarSql/Tree/Visitors/ExpressionVisitor.cs
Expand Up @@ -91,16 +91,9 @@ public static QsiBinaryExpressionNode VisitInPredicate(InPredicateContext contex
return TreeHelper.Create<QsiBinaryExpressionNode>(n =>
{
n.Operator = JoinTokens(context.NOT(), context.IN());
n.Left.SetValue(VisitPredicate(context.predicate()));
if (context.selectStatement() != null)
{
n.Right.SetValue(VisitSelectStatement(context.selectStatement()));
}
else
{
n.Right.SetValue(VisitExpressions(context.expressions()));
}
n.Left.SetValue(VisitPredicate(context.predicate()));
n.Right.SetValue(VisitExpressions(context.expressions()));
PrimarSqlTree.PutContextSpan(n, context);
});
Expand Down Expand Up @@ -182,12 +175,6 @@ public static QsiExpressionNode VisitExpressionAtom(ExpressionAtomContext contex
return node;
}

case ExistsExpressionAtomContext _:
throw TreeHelper.NotSupportedFeature("Exists expression");

case SubqueryExpressionAtomContext subqueryExpressionAtomContext:
return VisitSelectStatement(subqueryExpressionAtomContext.selectStatement());

case BitExpressionAtomContext bitExpressionAtomContext:
{
return TreeHelper.Create<QsiBinaryExpressionNode>(n =>
Expand Down
43 changes: 1 addition & 42 deletions Qsi.PrimarSql/Tree/Visitors/TableVisitor.cs
Expand Up @@ -207,48 +207,7 @@ public static QsiTableNode VisitTableSource(TableSourceContext context)

public static QsiTableNode VisitTableSourceItem(TableSourceItemContext context)
{
switch (context)
{
case AtomTableItemContext atomTableItemContext:
return VisitAtomTableItem(atomTableItemContext);

case SubqueryTableItemContext subqueryTableItemContext:
return VisitSubqueryTableItem(subqueryTableItemContext);
}

throw TreeHelper.NotSupportedTree(context);
}

public static QsiTableNode VisitAtomTableItem(AtomTableItemContext context)
{
QsiTableNode node = VisitTableName(context.tableName());

if (context.alias == null)
return node;

return TreeHelper.Create<QsiDerivedTableNode>(n =>
{
n.Columns.SetValue(TreeHelper.CreateAllColumnsDeclaration());
n.Source.SetValue(node);
n.Alias.SetValue(CreateAliasNode(context.alias));
PrimarSqlTree.PutContextSpan(n, context);
});
}

public static QsiTableNode VisitSubqueryTableItem(SubqueryTableItemContext context)
{
if (context.alias == null)
throw new QsiException(QsiError.NoAlias);

return TreeHelper.Create<QsiDerivedTableNode>(n =>
{
n.Columns.SetValue(TreeHelper.CreateAllColumnsDeclaration());
n.Source.SetValue(VisitSelectStatement(context.selectStatement()));
n.Alias.SetValue(CreateAliasNode(context.alias));
PrimarSqlTree.PutContextSpan(n, context);
});
return VisitTableName(context.tableName());
}

public static QsiWhereExpressionNode VisitWhereExpression(FromClauseContext context)
Expand Down

0 comments on commit 2e51a85

Please sign in to comment.