Exemplo n.º 1
0
        /// <summary>
        /// Adds a column map into this table.
        /// </summary>
        /// <param name="mapping">The array containing a map to the column in
        /// the parent table that we want the column number to reference.</param>
        /// <param name="aliases"></param>
        public void SetColumnMap(int[] mapping, ObjectName[] aliases)
        {
            reverse_column_map = new int[Parent.ColumnCount];
            for (int i = 0; i < reverse_column_map.Length; ++i)
            {
                reverse_column_map[i] = -1;
            }
            column_map = mapping;

            this.aliases = aliases;

            DataTableInfo parentInfo = Parent.TableInfo;

            subsetTableInfo = new DataTableInfo(parentInfo.TableName);

            for (int i = 0; i < mapping.Length; ++i)
            {
                int            map_to  = mapping[i];
                DataColumnInfo colInfo = Parent.GetColumnInfo(map_to).Clone();
                colInfo.Name = aliases[i].Name;
                subsetTableInfo.AddColumn(colInfo);
                reverse_column_map[map_to] = i;
            }

            subsetTableInfo.IsReadOnly = true;
        }
Exemplo n.º 2
0
        ///<summary>
        ///</summary>
        ///<param name="crossRefTable"></param>
        ///<param name="inExpList"></param>
        ///<param name="columnNames"></param>
        ///<param name="context"></param>
        public FunctionTable(Table crossRefTable, Expression[] inExpList, string[] columnNames, IQueryContext context)
            : base(context.Connection.Database)
        {
            // Make sure we are synchronized over the class.
            lock (typeof(FunctionTable)) {
                uniqueId = UniqueKeySeq;
                ++UniqueKeySeq;
            }
            uniqueId = (uniqueId & 0x0FFFFFFF) | 0x010000000;

            this.context = context;

            this.crossRefTable = crossRefTable;
            crResolver         = crossRefTable.GetVariableResolver();
            crResolver.SetId   = 0;

            // Create a DataTableInfo object for this function table.
            funTableInfo = new DataTableInfo(FunctionTableName);

            expList = new Expression[inExpList.Length];
            expInfo = new byte[inExpList.Length];

            // Create a new DataColumnInfo for each expression, and work out if the
            // expression is simple or not.
            for (int i = 0; i < inExpList.Length; ++i)
            {
                Expression expr = inExpList[i];
                // Examine the expression and determine if it is simple or not
                if (expr.IsConstant() && !expr.HasAggregateFunction(context))
                {
                    // If expression is a constant, solve it
                    DataObject result = expr.Evaluate(null, null, context);
                    expr       = Expression.Constant(result);
                    expList[i] = expr;
                    expInfo[i] = 1;
                }
                else
                {
                    // Otherwise must be dynamic
                    expList[i] = expr;
                    expInfo[i] = 0;
                }
                // Make the column info
                funTableInfo.AddColumn(columnNames[i], expr.ReturnType(crResolver, context));
            }

            // Make sure the table info isn't changed from this point on.
            funTableInfo.IsReadOnly = true;

            // Function tables are the size of the referring table.
            row_count = crossRefTable.RowCount;

            // Set schemes to 'blind search'.
            BlankSelectableSchemes(1);
        }
Exemplo n.º 3
0
        ///<summary>
        ///</summary>
        ///<param name="database"></param>
        ///<param name="name"></param>
        ///<param name="fields"></param>
        public TemporaryTable(IDatabase database, String name, DataColumnInfo[] fields)
            : base(database)
        {
            tableStorage = new List<DataObject[]>();

            tableInfo = new DataTableInfo(new ObjectName(null, name));
            foreach (DataColumnInfo field in fields) {
                tableInfo.AddColumn(field.Clone());
            }
            tableInfo.IsReadOnly = true;
        }
Exemplo n.º 4
0
        ///<summary>
        ///</summary>
        ///<param name="database"></param>
        ///<param name="name"></param>
        ///<param name="fields"></param>
        public TemporaryTable(IDatabase database, String name, DataColumnInfo[] fields)
            : base(database)
        {
            tableStorage = new List <DataObject[]>();

            tableInfo = new DataTableInfo(new ObjectName(null, name));
            foreach (DataColumnInfo field in fields)
            {
                tableInfo.AddColumn(field.Clone());
            }
            tableInfo.IsReadOnly = true;
        }
Exemplo n.º 5
0
        internal void CopyColumnsTo(DataTableInfo tableInfo)
        {
            foreach (var column in columns)
            {
                var newColumn = new DataColumnInfo(tableInfo, column.Name, column.DataType)
                {
                    DefaultExpression = column.DefaultExpression,
                    IsNullable        = column.IsNullable
                };

                tableInfo.AddColumn(newColumn);
            }
        }
Exemplo n.º 6
0
        ///<summary>
        ///</summary>
        ///<param name="database"></param>
        ///<param name="name"></param>
        ///<param name="fields"></param>
        public TemporaryTable(IDatabase database, String name, DataColumnInfo[] fields)
            : base(database)
        {
            tableStorage = new List<DataObject[]>();

            tableInfo = new DataTableInfo(new ObjectName(name));

            foreach (DataColumnInfo field in fields) {
                var newColumn = tableInfo.NewColumn(field.Name, field.DataType);
                newColumn.DefaultExpression = field.DefaultExpression;
                newColumn.IsNullable = field.IsNullable;
                tableInfo.AddColumn(newColumn);
            }
            tableInfo.IsReadOnly = true;
        }
Exemplo n.º 7
0
        ///<summary>
        ///</summary>
        ///<param name="database"></param>
        ///<param name="name"></param>
        ///<param name="fields"></param>
        public TemporaryTable(IDatabase database, String name, DataColumnInfo[] fields)
            : base(database)
        {
            tableStorage = new List <DataObject[]>();

            tableInfo = new DataTableInfo(new ObjectName(name));

            foreach (DataColumnInfo field in fields)
            {
                var newColumn = tableInfo.NewColumn(field.Name, field.DataType);
                newColumn.DefaultExpression = field.DefaultExpression;
                newColumn.IsNullable        = field.IsNullable;
                tableInfo.AddColumn(newColumn);
            }
            tableInfo.IsReadOnly = true;
        }
Exemplo n.º 8
0
            public ITableQueryInfo GetTableQueryInfo(ObjectName tableName, ObjectName givenName)
            {
                DataTableInfo tableInfo = GetTableInfo(tableName);

                // If the table is aliased, set a new DataTableInfo with the given name
                if (givenName != null)
                {
                    var newTableInfo = new DataTableInfo(givenName.Clone());
                    for (int i = 0; i < tableInfo.ColumnCount; i++)
                    {
                        var columnInfo = tableInfo[i];
                        newTableInfo.AddColumn(columnInfo.Name, columnInfo.DataType, !columnInfo.IsNotNull);
                    }

                    newTableInfo.IsReadOnly = true;
                    tableInfo = newTableInfo;
                }

                return(new TableQueryInfo(this, tableInfo, tableName, givenName));
            }
Exemplo n.º 9
0
        /// <summary>
        /// Helper function for initializing the variables in the joined table.
        /// </summary>
        /// <param name="tables"></param>
        protected virtual void Init(Table[] tables)
        {
            int tableCount = tables.Length;

            referenceList = tables;

            int colCount = ColumnCount;

            columnScheme = new SelectableScheme[colCount];

            vtTableInfo = new DataTableInfo(new ObjectName(null, "#VIRTUAL TABLE#"));

            // Generate look up tables for column_table and column_filter information

            columnTable  = new int[colCount];
            columnFilter = new int[colCount];
            int index = 0;

            for (int i = 0; i < referenceList.Length; ++i)
            {
                Table         curTable     = referenceList[i];
                DataTableInfo curTableInfo = curTable.TableInfo;
                int           refColCount  = curTable.ColumnCount;

                // For each column
                for (int n = 0; n < refColCount; ++n)
                {
                    columnFilter[index] = n;
                    columnTable[index]  = i;
                    ++index;

                    // Add this column to the data table info of this table.
                    vtTableInfo.AddColumn(curTableInfo[n].Clone());
                }
            }

            vtTableInfo.IsReadOnly = true;
        }
Exemplo n.º 10
0
            public ITableQueryInfo GetTableQueryInfo(ObjectName tableName, ObjectName givenName)
            {
                DataTableInfo tableInfo = GetTableInfo(tableName);
                // If the table is aliased, set a new DataTableInfo with the given name
                if (givenName != null) {
                    var newTableInfo = new DataTableInfo(givenName.Clone());
                    for (int i = 0; i < tableInfo.ColumnCount; i++) {
                        var columnInfo = tableInfo[i];
                        newTableInfo.AddColumn(columnInfo.Name, columnInfo.DataType, !columnInfo.IsNotNull);
                    }

                    newTableInfo.IsReadOnly = true;
                    tableInfo = newTableInfo;
                }

                return new TableQueryInfo(this, tableInfo, tableName, givenName);
            }
Exemplo n.º 11
0
        /// <summary>
        /// Helper function for initializing the variables in the joined table.
        /// </summary>
        /// <param name="tables"></param>
        protected virtual void Init(Table[] tables)
        {
            int tableCount = tables.Length;
            referenceList = tables;

            int colCount = ColumnCount;
            columnScheme = new SelectableScheme[colCount];

            vtTableInfo = new DataTableInfo(new ObjectName(null, "#VIRTUAL TABLE#"));

            // Generate look up tables for column_table and column_filter information

            columnTable = new int[colCount];
            columnFilter = new int[colCount];
            int index = 0;
            for (int i = 0; i < referenceList.Length; ++i) {
                Table curTable = referenceList[i];
                DataTableInfo curTableInfo = curTable.TableInfo;
                int refColCount = curTable.ColumnCount;

                // For each column
                for (int n = 0; n < refColCount; ++n) {
                    columnFilter[index] = n;
                    columnTable[index] = i;
                    ++index;

                    // Add this column to the data table info of this table.
                    vtTableInfo.AddColumn(curTableInfo[n].Clone());
                }

            }

            vtTableInfo.IsReadOnly = true;
        }
Exemplo n.º 12
0
        public void SetUp()
        {
            database = new TestDatabase();

            var tableInfo = new DataTableInfo("APP", "person");

            tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("first_name", PrimitiveTypes.String());
            tableInfo.AddColumn("last_name", PrimitiveTypes.String());
            tableInfo.AddColumn("age", PrimitiveTypes.Numeric());

            var table = database.CreateTable(tableInfo);

            long rowIndex = table.NewRow();

            table.SetValue(0, rowIndex, DataObject.Number(0));
            table.SetValue(1, rowIndex, new DataObject(PrimitiveTypes.String(), new StringObject("Antonello")));
            table.SetValue(2, rowIndex, new DataObject(PrimitiveTypes.String(), new StringObject("Provenzano")));
            table.SetValue(3, rowIndex, new DataObject(PrimitiveTypes.Numeric(), Number.FromInt32(32)));

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(1));
            table.SetValue(1, rowIndex, DataObject.String("Mart"));
            table.SetValue(2, rowIndex, DataObject.String("Roosmaa"));
            table.SetValue(3, rowIndex, DataObject.Number(28));

            tableInfo = new DataTableInfo("APP", "lives");
            tableInfo.AddColumn("person_id", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("city", PrimitiveTypes.String());
            tableInfo.AddColumn("country", PrimitiveTypes.String());
            table = database.CreateTable(tableInfo);

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(0));
            table.SetValue(1, rowIndex, DataObject.String("Oslo"));
            table.SetValue(2, rowIndex, DataObject.String("Norway"));

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(1));
            table.SetValue(1, rowIndex, DataObject.String("Tallinn"));
            table.SetValue(2, rowIndex, DataObject.String("Estonia"));

            tableInfo = new DataTableInfo("APP", "devices");
            tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("person_id", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("device_name", PrimitiveTypes.String());
            tableInfo.AddColumn("os", PrimitiveTypes.String());
            tableInfo.AddColumn("date", PrimitiveTypes.Date());
            table = database.CreateTable(tableInfo);

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(0));
            table.SetValue(1, rowIndex, DataObject.Number(0));
            table.SetValue(2, rowIndex, DataObject.String("Work Notebook"));
            table.SetValue(3, rowIndex, DataObject.String("Windows 8.1"));
            table.SetValue(4, rowIndex, DataObject.Now());

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(1));
            table.SetValue(1, rowIndex, DataObject.Number(0));
            table.SetValue(2, rowIndex, DataObject.String("Tablet"));
            table.SetValue(3, rowIndex, DataObject.String("Android 4.4"));
            table.SetValue(4, rowIndex, DataObject.Now());

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(2));
            table.SetValue(1, rowIndex, DataObject.Number(0));
            table.SetValue(2, rowIndex, DataObject.String("Other Notebook"));
            table.SetValue(3, rowIndex, DataObject.String("Ubuntu Linux"));
            table.SetValue(4, rowIndex, DataObject.Now());

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(3));
            table.SetValue(1, rowIndex, DataObject.Number(1));
            table.SetValue(2, rowIndex, DataObject.String("Mac Work Notebook"));
            table.SetValue(3, rowIndex, DataObject.String("Mac OS X"));
            table.SetValue(4, rowIndex, DataObject.Now());

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(4));
            table.SetValue(1, rowIndex, DataObject.Number(1));
            table.SetValue(2, rowIndex, DataObject.String("Tablet"));
            table.SetValue(3, rowIndex, DataObject.String("Android 4.2"));
            table.SetValue(4, rowIndex, DataObject.Now());
        }
Exemplo n.º 13
0
        ///<summary>
        ///</summary>
        ///<param name="crossRefTable"></param>
        ///<param name="inExpList"></param>
        ///<param name="columnNames"></param>
        ///<param name="context"></param>
        public FunctionTable(Table crossRefTable, Expression[] inExpList, string[] columnNames, IQueryContext context)
            : base(context.Connection.Database)
        {
            // Make sure we are synchronized over the class.
            lock (typeof (FunctionTable)) {
                uniqueId = UniqueKeySeq;
                ++UniqueKeySeq;
            }
            uniqueId = (uniqueId & 0x0FFFFFFF) | 0x010000000;

            this.context = context;

            this.crossRefTable = crossRefTable;
            crResolver = crossRefTable.GetVariableResolver();
            crResolver.SetId = 0;

            // Create a DataTableInfo object for this function table.
            funTableInfo = new DataTableInfo(FunctionTableName);

            expList = new Expression[inExpList.Length];
            expInfo = new byte[inExpList.Length];

            // Create a new DataColumnInfo for each expression, and work out if the
            // expression is simple or not.
            for (int i = 0; i < inExpList.Length; ++i) {
                Expression expr = inExpList[i];
                // Examine the expression and determine if it is simple or not
                if (expr.IsConstant() && !expr.HasAggregateFunction(context)) {
                    // If expression is a constant, solve it
                    DataObject result = expr.Evaluate(null, null, context);
                    expr = Expression.Constant(result);
                    expList[i] = expr;
                    expInfo[i] = 1;
                } else {
                    // Otherwise must be dynamic
                    expList[i] = expr;
                    expInfo[i] = 0;
                }
                // Make the column info
                funTableInfo.AddColumn(columnNames[i], expr.ReturnType(crResolver, context));
            }

            // Make sure the table info isn't changed from this point on.
            funTableInfo.IsReadOnly = true;

            // Function tables are the size of the referring table.
            row_count = crossRefTable.RowCount;

            // Set schemes to 'blind search'.
            BlankSelectableSchemes(1);
        }
Exemplo n.º 14
0
        public void SetUp()
        {
            database = new TestDatabase();

            var tableInfo = new DataTableInfo("APP", "person");
            tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("first_name", PrimitiveTypes.String());
            tableInfo.AddColumn("last_name", PrimitiveTypes.String());
            tableInfo.AddColumn("age", PrimitiveTypes.Numeric());

            var table = database.CreateTable(tableInfo);

            long rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(0));
            table.SetValue(1, rowIndex, new DataObject(PrimitiveTypes.String(), new StringObject("Antonello")));
            table.SetValue(2, rowIndex, new DataObject(PrimitiveTypes.String(), new StringObject("Provenzano")));
            table.SetValue(3, rowIndex, new DataObject(PrimitiveTypes.Numeric(), Number.FromInt32(32)));

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(1));
            table.SetValue(1, rowIndex, DataObject.String("Mart"));
            table.SetValue(2, rowIndex, DataObject.String("Roosmaa"));
            table.SetValue(3, rowIndex, DataObject.Number(28));

            tableInfo = new DataTableInfo("APP", "lives");
            tableInfo.AddColumn("person_id", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("city", PrimitiveTypes.String());
            tableInfo.AddColumn("country", PrimitiveTypes.String());
            table = database.CreateTable(tableInfo);

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(0));
            table.SetValue(1, rowIndex, DataObject.String("Oslo"));
            table.SetValue(2, rowIndex, DataObject.String("Norway"));

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(1));
            table.SetValue(1, rowIndex, DataObject.String("Tallinn"));
            table.SetValue(2, rowIndex, DataObject.String("Estonia"));

            tableInfo = new DataTableInfo("APP", "devices");
            tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("person_id", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("device_name", PrimitiveTypes.String());
            tableInfo.AddColumn("os", PrimitiveTypes.String());
            tableInfo.AddColumn("date", PrimitiveTypes.Date());
            table = database.CreateTable(tableInfo);

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(0));
            table.SetValue(1, rowIndex, DataObject.Number(0));
            table.SetValue(2, rowIndex, DataObject.String("Work Notebook"));
            table.SetValue(3, rowIndex, DataObject.String("Windows 8.1"));
            table.SetValue(4, rowIndex, DataObject.Now());

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(1));
            table.SetValue(1, rowIndex, DataObject.Number(0));
            table.SetValue(2, rowIndex, DataObject.String("Tablet"));
            table.SetValue(3, rowIndex, DataObject.String("Android 4.4"));
            table.SetValue(4, rowIndex, DataObject.Now());

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(2));
            table.SetValue(1, rowIndex, DataObject.Number(0));
            table.SetValue(2, rowIndex, DataObject.String("Other Notebook"));
            table.SetValue(3, rowIndex, DataObject.String("Ubuntu Linux"));
            table.SetValue(4, rowIndex, DataObject.Now());

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(3));
            table.SetValue(1, rowIndex, DataObject.Number(1));
            table.SetValue(2, rowIndex, DataObject.String("Mac Work Notebook"));
            table.SetValue(3, rowIndex, DataObject.String("Mac OS X"));
            table.SetValue(4, rowIndex, DataObject.Now());

            rowIndex = table.NewRow();
            table.SetValue(0, rowIndex, DataObject.Number(4));
            table.SetValue(1, rowIndex, DataObject.Number(1));
            table.SetValue(2, rowIndex, DataObject.String("Tablet"));
            table.SetValue(3, rowIndex, DataObject.String("Android 4.2"));
            table.SetValue(4, rowIndex, DataObject.Now());
        }
Exemplo n.º 15
0
        /// <summary>
        /// Adds a column map into this table.
        /// </summary>
        /// <param name="mapping">The array containing a map to the column in 
        /// the parent table that we want the column number to reference.</param>
        /// <param name="aliases"></param>
        public void SetColumnMap(int[] mapping, ObjectName[] aliases)
        {
            reverse_column_map = new int[Parent.ColumnCount];
            for (int i = 0; i < reverse_column_map.Length; ++i) {
                reverse_column_map[i] = -1;
            }
            column_map = mapping;

            this.aliases = aliases;

            DataTableInfo parentInfo = Parent.TableInfo;
            subsetTableInfo = new DataTableInfo(parentInfo.TableName);

            for (int i = 0; i < mapping.Length; ++i) {
                int map_to = mapping[i];
                DataColumnInfo colInfo = Parent.GetColumnInfo(map_to).Clone();
                colInfo.Name = aliases[i].Name;
                subsetTableInfo.AddColumn(colInfo);
                reverse_column_map[map_to] = i;
            }

            subsetTableInfo.IsReadOnly = true;
        }