示例#1
0
        private void InitializeMembers()
        {
            this.columnExpression = null;
            this.columnIdentifier = null;
            this.tableReference   = null;

            this.columnName  = null;
            this.dataType    = DataType.Unknown;
            this.columnAlias = null;

            this.isStar = false;
            this.isComplexExpression = false;
            this.selectListIndex     = -1;
            this.columnContext       = Graywulf.SqlParser.ColumnContext.None;
        }
示例#2
0
        private void CopyMembers(ColumnReference old)
        {
            this.columnExpression = old.columnExpression;
            this.columnIdentifier = old.columnIdentifier;
            this.tableReference   = old.tableReference;

            this.columnName  = old.columnName;
            this.dataType    = old.dataType;
            this.columnAlias = old.columnAlias;

            this.isStar = old.isStar;
            this.isComplexExpression = old.isComplexExpression;
            this.selectListIndex     = old.selectListIndex;
            this.columnContext       = old.columnContext;
        }
示例#3
0
        private void InterpretColumnIdentifier(ColumnIdentifier ci)
        {
            var ds = ci.FindDescendant <DatasetName>();

            DatasetName = (ds != null) ? Util.RemoveIdentifierQuotes(ds.Value) : null;

            var dbn = ci.FindDescendant <DatabaseName>();

            DatabaseName = (dbn != null) ? Util.RemoveIdentifierQuotes(dbn.Value) : null;

            var sn = ci.FindDescendant <SchemaName>();

            SchemaName = (sn != null) ? Util.RemoveIdentifierQuotes(sn.Value) : null;

            var tn = ci.FindDescendant <TableName>();

            DatabaseObjectName = (tn != null) ? Util.RemoveIdentifierQuotes(tn.Value) : null;
        }
示例#4
0
        public static ColumnIdentifier Create(ColumnReference cr)
        {
            var nci = new ColumnIdentifier();
            nci.ColumnReference = cr;

            if (String.IsNullOrEmpty(cr.TableReference.Alias))
            {
                nci.Stack.AddLast(TableName.Create(cr.TableReference.DatabaseObjectName));
            }
            else
            {
                nci.Stack.AddLast(TableName.Create(cr.TableReference.Alias));
            }
            nci.Stack.AddLast(Dot.Create());
            nci.Stack.AddLast(ColumnName.Create(cr.ColumnName));

            return nci;
        }
示例#5
0
        public static ColumnIdentifier Create(ColumnReference cr)
        {
            var nci = new ColumnIdentifier();

            nci.ColumnReference = cr;

            if (String.IsNullOrEmpty(cr.TableReference.Alias))
            {
                nci.Stack.AddLast(TableName.Create(cr.TableReference.DatabaseObjectName));
            }
            else
            {
                nci.Stack.AddLast(TableName.Create(cr.TableReference.Alias));
            }
            nci.Stack.AddLast(Dot.Create());
            nci.Stack.AddLast(ColumnName.Create(cr.ColumnName));

            return(nci);
        }
示例#6
0
        public static SelectList Create(ColumnReference cr)
        {
            // Create new expression
            var nsl = new SelectList();

            var nce = new ColumnExpression();

            nce.ColumnReference = new ColumnReference(cr);
            nsl.Stack.AddLast(nce);

            var nex = new Expression();

            nce.Stack.AddLast(nex);

            var nav = new AnyVariable();

            nex.Stack.AddLast(nav);

            nav.Stack.AddLast(ColumnIdentifier.Create(new ColumnReference(cr)));

            return(nsl);
        }
示例#7
0
        protected void ValidateColumnIdentifier(QuerySpecification qs, ColumnIdentifier ci)
        {
            // TODO: modify to look for stars inside expressions

            /*
             * if (ci.ColumnReference.IsStar)
             * {
             *  // Check if it's a count(*), that's the only expression allowed to
             *  // contain a *
             *  var fc = ci.FindAscendant<FunctionCall>();
             *  if (fc != null)
             *  {
             *      var fn = fc.FindDescendantRecursive<FunctionName>();
             *      if (fn != null && SqlParser.ComparerInstance.Compare(fn.Value, "COUNT") == 0)
             *      {
             *          return;
             *      }
             *  }
             *
             *  throw CreateException(ExceptionMessages.StarColumnNotAllowed, null, null, ci);
             * }*/
        }
示例#8
0
        public static ColumnReference Interpret(ColumnIdentifier ci)
        {
            var cr = new ColumnReference();

            cr.columnIdentifier = ci;
            cr.tableReference   = new TableReference(ci);

            var star = ci.FindDescendant <Mul>();

            if (star != null)
            {
                cr.isStar     = true;
                cr.columnName = star.Value;
            }
            else
            {
                cr.isStar     = false;
                cr.columnName = Util.RemoveIdentifierQuotes(ci.FindDescendant <ColumnName>().Value);
            }

            cr.isComplexExpression = false;

            return(cr);
        }
示例#9
0
        protected void ValidateColumnIdentifier(QuerySpecification qs, ColumnIdentifier ci)
        {
            // TODO: modify to look for stars inside expressions
            /*
            if (ci.ColumnReference.IsStar)
            {
                // Check if it's a count(*), that's the only expression allowed to
                // contain a *
                var fc = ci.FindAscendant<FunctionCall>();
                if (fc != null)
                {
                    var fn = fc.FindDescendantRecursive<FunctionName>();
                    if (fn != null && SqlParser.ComparerInstance.Compare(fn.Value, "COUNT") == 0)
                    {
                        return;
                    }
                }

                throw CreateException(ExceptionMessages.StarColumnNotAllowed, null, null, ci);
            }*/
        }
示例#10
0
 public TableReference(ColumnIdentifier ci)
     : this()
 {
     InitializeMembers();
     InterpretColumnIdentifier(ci);
 }
示例#11
0
        private void InterpretColumnIdentifier(ColumnIdentifier ci)
        {
            var ds = ci.FindDescendant<DatasetName>();
            datasetName = (ds != null) ? Util.RemoveIdentifierQuotes(ds.Value) : null;

            var dbn = ci.FindDescendant<DatabaseName>();
            databaseName = (dbn != null) ? Util.RemoveIdentifierQuotes(dbn.Value) : null;

            var sn = ci.FindDescendant<SchemaName>();
            schemaName = (sn != null) ? Util.RemoveIdentifierQuotes(sn.Value) : null;

            var tn = ci.FindDescendant<TableName>();
            databaseObjectName = (tn != null) ? Util.RemoveIdentifierQuotes(tn.Value) : null;
        }
示例#12
0
        private void InitializeMembers()
        {
            this.columnExpression = null;
            this.columnIdentifier = null;
            this.tableReference = null;

            this.columnName = null;
            this.dataType = DataType.Unknown;
            this.columnAlias = null;

            this.isStar = false;
            this.isComplexExpression = false;
            this.selectListIndex = -1;
            this.columnContext = Graywulf.SqlParser.ColumnContext.None;
        }
示例#13
0
        private void CopyMembers(ColumnReference old)
        {
            this.columnExpression = old.columnExpression;
            this.columnIdentifier = old.columnIdentifier;
            this.tableReference = old.tableReference;

            this.columnName = old.columnName;
            this.dataType = old.dataType;
            this.columnAlias = old.columnAlias;

            this.isStar = old.isStar;
            this.isComplexExpression = old.isComplexExpression;
            this.selectListIndex = old.selectListIndex;
            this.columnContext = old.columnContext;
        }
示例#14
0
        public static ColumnReference Interpret(ColumnIdentifier ci)
        {
            var cr = new ColumnReference();

            cr.columnIdentifier = ci;
            cr.tableReference = new TableReference(ci);

            var star = ci.FindDescendant<Mul>();

            if (star != null)
            {
                cr.isStar = true;
                cr.columnName = star.Value;
            }
            else
            {
                cr.isStar = false;
                cr.columnName = Util.RemoveIdentifierQuotes(ci.FindDescendant<ColumnName>().Value);
            }

            cr.isComplexExpression = false;

            return cr;
        }
示例#15
0
 /// <summary>
 /// Writes a column identifier, optionally with resolved
 /// names and quoted
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public void WriteColumnIdentifier(ColumnIdentifier node)
 {
     if (ResolveNames)
     {
         Writer.Write(GetResolvedColumnName(node.ColumnReference));
     }
     else
     {
         // Fall back to original behavior
         base.WriteNode(node);
     }
 }
示例#16
0
 public TableReference(ColumnIdentifier ci)
     : this()
 {
     InitializeMembers();
     InterpretColumnIdentifier(ci);
 }
示例#17
0
 public abstract bool WriteColumnIdentifier(ColumnIdentifier node);