public override DeclareStatement Execute() { if (Tokenizer.HasMoreTokens) { do { string name = Tokenizer.Current.Value; Tokenizer.ReadNextToken(); if (!Tokenizer.HasMoreTokens) { throw new SyntaxException(String.Format("type missing for declaration of variable '{0}'", name)); } string type = GetSqlType(); var definition = new VariableDefinition(name, type); if (Tokenizer.TokenEquals(Constants.Assignment)) { var parser = new ExpressionParser(Tokenizer); definition.DefaultValue = parser.Execute(); } _statement.Definitions.Add(definition); } while (Tokenizer.TokenEquals(Constants.Comma)); } if (_statement.Definitions.Count == 0) { throw new SyntaxException("DECLARE requires at least one variable declaration"); } return(_statement); }
private void ReadAssignment(SetStatement statement) { var parser = new ExpressionParser(Tokenizer); statement.Assignment = parser.Execute(); }
private void ProcessFieldDefinition() { Nullability nullability = Nullability.Nullable; bool isPrimaryKey = false; Identity identity = null; string fieldName = GetIdentifier(); SqlType type = ProcessType(); if (type == null) { FieldDefinition calcExpression = new FieldDefinition { Name = fieldName, Nullability = Nullability.Nullable, Type = null }; ExpressionParser parser = new ExpressionParser(Tokenizer); calcExpression.CalculatedValue = parser.Execute(); _statement.Fields.Add(calcExpression); return; } if (Tokenizer.TokenEquals(Constants.Identity)) { identity = ProcessIdentity(); } if (Tokenizer.TokenEquals(Constants.Collate)) { type.Collation = CurrentToken; ReadNextToken(); } if (Tokenizer.TokenEquals(Constants.Null)) { nullability = Nullability.Nullable; } if (Tokenizer.TokenEquals(Constants.Not)) { Tokenizer.ExpectToken(Constants.Null); nullability = Nullability.NotNullable; } if (Tokenizer.TokenEquals(Constants.Identity)) { identity = ProcessIdentity(); } if (Tokenizer.TokenEquals(Constants.Primary)) { Tokenizer.ExpectToken(Constants.Key); nullability = Nullability.NotNullable; isPrimaryKey = true; } if (Tokenizer.TokenEquals(Constants.Constraint)) { // TODO: process column constraint string name = GetIdentifier(); Tokenizer.ExpectToken(Constants.Default); using (Tokenizer.ExpectBrackets()) { Expression expression = ProcessExpression(); string defaultValue = expression.Value; } } if (Tokenizer.TokenEquals(Constants.Default)) { // TODO: process column constraint Expression expression = ProcessExpression(); string defaultValue = expression.Value; } _statement.Fields.Add( new FieldDefinition { Name = fieldName, Type = type, Nullability = nullability, IsPrimaryKey = isPrimaryKey, Identity = identity } ); }