コード例 #1
0
        public SystemTable CreateTable(TableName tableName)
        {
            CheckNotDisposed();
            // Check the table name given is qualified
            CheckTableNameQualified(tableName);

            // Does an object with this name already exist in the directory?
            ITable tables = GetTable(SystemTableNames.Tables);
            IRowCursor ind = GetNames(tables, tableName);
            if (ind.Count > 0)
                throw new ApplicationException("Table '" + tableName + "' already exists.");

            ITable table = state.CreateTable(tableName);
            if (table == null)
                throw new ApplicationException("The table '" + tableName + "' was not created.");

            long tableId = state.CreateUniqueId(SystemTableNames.Tables);

            // Construct and create the table
            SystemTable sysTable = new SystemTable(this, table, tableId);

            // Add this table to the tables.
            AddObject(tableId, tableName, "TABLE");

            // Log the change in the journal
            journal.AddEntry(JournalCommandCode.TableCreate, tableId);
            OnChanged();

            // Put it in the cache
            tableNameMap[tableName] = sysTable;

            // And return it
            return sysTable;
        }
コード例 #2
0
ファイル: InputToml.cs プロジェクト: yutakasi634/Coral-iMD-VR
        // This method generate BoundaryManager for local of SceneBuilder by side effect.
        internal void GenerateBoundaryManager(GameObject scene_builder, List <GameObject> base_particles)
        {
            if (!SimulatorTable.ContainsKey("boundary_type"))
            {
                return;
            }

            string boundary_type = SimulatorTable.Get <string>("boundary_type");

            if (boundary_type == "Unlimited")
            {
                return;
            }

            Vector3 upper_boundary = new Vector3();
            Vector3 lower_boundary = new Vector3();

            if ((boundary_type == "Periodic" || boundary_type == "PeriodicCuboid") && SystemTable.ContainsKey("boundary_shape"))
            {
                TomlTable    boundary_shape  = SystemTable.Get <TomlTable>("boundary_shape");
                List <float> upper_bound_arr = boundary_shape.Get <List <float> >("upper");
                List <float> lower_bound_arr = boundary_shape.Get <List <float> >("lower");
                upper_boundary = new Vector3(upper_bound_arr[0], upper_bound_arr[1], upper_bound_arr[2]);
                lower_boundary = new Vector3(lower_bound_arr[0], lower_bound_arr[1], lower_bound_arr[2]);
                ReflectingBoundaryManager rb_manager
                    = scene_builder.AddComponent <ReflectingBoundaryManager>() as ReflectingBoundaryManager;
                rb_manager.Init(base_particles, upper_boundary, lower_boundary);
            }
            Debug.Log("BoundaryManager initialization finished.");
        }
コード例 #3
0
ファイル: SpatialDbBuilder.cs プロジェクト: configare/hispeed
        protected virtual void CreateTables(IDbConnection connection, SystemTable table, IDbCommand cmd)
        {
            if (table.Name == null)
            {
                throw new ArgumentNullException("元数据表名称为空。");
            }
            if (table.Fields == null)
            {
                throw new ArgumentNullException("元数据表\"" + table.Name + "\"没有定义字段。");
            }
            List <string> fieldTypes = new List <string>();

            foreach (SystemField fld in table.Fields)
            {
                fieldTypes.Add(fld.Name + " " + _adapter.GetFieldTypeString(fld.FieldType));
            }
            _adapter.CreateTable(connection, false, "ID", null, table.Name, fieldTypes.ToArray(), cmd);
        }
コード例 #4
0
        private static int GetOrAddSystem(string name, LookupTables lookupTables, AdoDataConnection connection)
        {
            SystemTable system = new SystemTable
            {
                Name = name,
            };

            if (lookupTables.SystemsLookup.ContainsKey(name))
            {
                system.ID = lookupTables.SystemsLookup[name].ID;
                (new TableOperations <SystemTable>(connection)).UpdateRecord(system);
            }
            else
            {
                (new TableOperations <SystemTable>(connection)).AddNewRecord(system);
                system.ID = connection.ExecuteScalar <int>("SELECT @@IDENTITY");
                lookupTables.SystemsLookup.Add(name, system);
            }

            return(system.ID);
        }
コード例 #5
0
ファイル: InputToml.cs プロジェクト: yutakasi634/Coral-iMD-VR
        // This method generate BaseParticle in system by side effect.
        internal void GenerateIntegratorManagers(
            GameObject scene_builder, List <GameObject> base_particles, float kb_scaled, float timescale)
        {
            if (SimulatorTable.ContainsKey("integrator"))
            {
                TomlTable integrator = SimulatorTable.Get <TomlTable>("integrator");
                if (integrator.ContainsKey("type"))
                {
                    string integrator_type = integrator.Get <string>("type");
                    if (integrator_type == "UnderdampedLangevin")
                    {
                        if (integrator.ContainsKey("gammas"))
                        {
                            int base_particles_num         = base_particles.Count;
                            List <TomlTable> gammas_tables = integrator.Get <List <TomlTable> >("gammas");
                            float[]          gammas        = new float[base_particles.Count];
                            foreach (TomlTable gamma_table in gammas_tables)
                            {
                                // TODO: check dupulicate and lacking of declaration.
                                gammas[gamma_table.Get <int>("index")] = gamma_table.Get <float>("gamma");
                            }
                            var temperature = SystemTable.Get <TomlTable>("attributes").Get <float>("temperature");

                            UnderdampedLangevinManager ul_manager
                                = scene_builder.AddComponent <UnderdampedLangevinManager>() as UnderdampedLangevinManager;
                            ul_manager.Init(kb_scaled, temperature, base_particles, gammas, timescale);
                            Debug.Log("UnderdampedLangevinManager initialization finished.");
                        }
                        else
                        {
                            throw new System.Exception(
                                      "When you use UnderdampedLangevin integrator, you must specify gammas for integrator.");
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: InputToml.cs プロジェクト: yutakasi634/Coral-iMD-VR
        // This method generate BaseParticle in system by side effect.
        internal List <GameObject> GenerateBaseParticles(GameObject original_base_particle, float kb_scaled)
        {
            var return_list = new List <GameObject>();

            var temperature = SystemTable.Get <TomlTable>("attributes").Get <float>("temperature");

            List <TomlTable> particles = SystemTable.Get <List <TomlTable> >("particles");

            foreach (TomlTable particle_info in particles)
            {
                var        position     = particle_info.Get <List <float> >("pos");
                GameObject new_particle =
                    GameObject.Instantiate(original_base_particle,
                                           new Vector3(position[0], position[1], position[2]),
                                           original_base_particle.transform.rotation);

                // initialize particle velocity
                Rigidbody new_rigid = new_particle.GetComponent <Rigidbody>();
                new_rigid.mass = particle_info.Get <float>("m");
                if (particle_info.ContainsKey("vel"))
                {
                    var velocity = particle_info.Get <List <float> >("vel");
                    new_rigid.velocity = new Vector3(velocity[0], velocity[1], velocity[2]);
                }
                else
                {
                    float sigma = Mathf.Sqrt(kb_scaled * temperature / new_rigid.mass);
                    new_rigid.velocity = new Vector3(Rng.Generate() * sigma,
                                                     Rng.Generate() * sigma,
                                                     Rng.Generate() * sigma);
                }
                return_list.Add(new_particle);
            }

            return(return_list);
        }
コード例 #7
0
        private static DbDataReader GetDbDataReaderFromSimpleStatement(DbConnection connection, string commandText)
        {
            // Command text format is
            // show <what> [where <condition>] [order by <order>]
            //    <what> can be
            //          tables
            //          tablecolumns
            //
            //          indexes | ix
            //          indexcolumns | ixc
            //
            //          views
            //          viewscolumns
            //          viewconstraints
            //          viewconstraintcolumns
            //          viewforeignkeys
            //
            //          checkconstraints
            //          foreignkeys
            //          foreingkeyconstraints
            //          constraintcolumns
            //
            //          functions
            //          functionparameters
            //          functionreturntablecolumns
            //
            //          procedures
            //          procedureparameters
            //
            //
            //          constraints
            //          constraintcolumns
            //          checkconstraints | cc
            //          foreignkeyconstraints | fkc
            //          foreignkeys | fk
            //          viewconstraints | vc
            //          viewconstraintcolumns | vcc
            //          viewforeignkeys | vfk


            Match match = _regExParseShowCommand.Match(commandText);

            if (!match.Success)
            {
                throw new Exception(string.Format("Unrecognized show statement '{0}'. show syntax is show <object> [where <condition>]", commandText));
            }

            string dbObject  = match.Groups["object"].Value;
            string condition = match.Groups["condition"].Value;
            string order     = match.Groups["order"].Value;

            DataTable dataTable;

            OleDbConnection oleDbConnection = (OleDbConnection)connection;

            ConnectionState oldConnectionState = connection.State;

            SystemTable systemTable = null;

            try
            {
                systemTable = _systemTables[dbObject];
            }
            catch
            {
                // ignored
            }

            if (systemTable == null)
            {
                try
                {
                    if (oldConnectionState != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    // Check if is a table not handled by SchemaDefinition
                    switch (dbObject.ToLower())
                    {
                    case "ix":
                    case "indexes":
                        dataTable = GetIndexes(oleDbConnection);
                        break;

                    case "ixc":
                    case "indexcolumns":
                        dataTable = GetIndexColumns(oleDbConnection);
                        break;

                    default:
                        throw new Exception(string.Format("Unknown system table {0}", dbObject));
                    }
                    return(dataTable.CreateDataReader());
                }
                finally
                {
                    if (oldConnectionState != ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }

            if (systemTable == null)
            {
                throw new Exception(string.Format("Unknown system table {0}", dbObject));
            }

            if (oldConnectionState != ConnectionState.Open)
            {
                connection.Open();
            }

            try
            {
                dataTable = systemTable.GetDataTable(oleDbConnection);
            }
            finally
            {
                if (oldConnectionState != ConnectionState.Open)
                {
                    connection.Close();
                }
            }


            DataRow[] selectedRows;
            DataTable selectedDataTable = dataTable.Clone();

            if (!string.IsNullOrWhiteSpace(condition) && !string.IsNullOrWhiteSpace(order))
            {
                selectedRows = dataTable.Select(condition, order);
            }
            else if (!string.IsNullOrWhiteSpace(condition))
            {
                selectedRows = dataTable.Select(condition);
            }
            else if (!string.IsNullOrWhiteSpace(order))
            {
                selectedRows = dataTable.Select("1=1", order);
            }
            else
            {
                return(dataTable.CreateDataReader());
            }

            foreach (DataRow row in selectedRows)
            {
                selectedDataTable.ImportRow(row);
            }

            return(selectedDataTable.CreateDataReader());
        }
コード例 #8
0
ファイル: SqlInterpreter.cs プロジェクト: ikvm/deveelsql
        private static IRowCursor QueryAllMatches(SystemTransaction transaction, TableName tableName, SystemTable table,
            IList<string> columns, SqlObject val)
        {
            // Try and find an index on these columns
            SystemIndexSetDataSource indexSet = transaction.FindIndexOn(tableName, columns);

            // If index found
            if (indexSet != null)
                // Query the index and find all matches
                return indexSet.Select(SelectableRange.Is(val));

            // Otherwise no index, so scan the table for matches

            // Make an Expression for the operation;
            //  (column1, column2, ...columnn) = val
            Expression compExp;
            int sz = columns.Count;
            if (sz > 1) {
                FunctionExpression cfunExp = new FunctionExpression("composite_fetch");
                for (int i = 0; i < sz; ++i) {
                    Expression varRef = new FetchVariableExpression(new Variable(tableName, columns[i]));
                    cfunExp.Parameters.Add(varRef);
                }
                compExp = cfunExp;
            } else if (sz == 1) {
                compExp = new FetchVariableExpression(new Variable(tableName, columns[0]));
            } else {
                throw new ApplicationException("Invalid columns list size");
            }

            // Equality test
            FunctionExpression funExp = new FunctionExpression("@is_sql");
            funExp.Parameters.Add(compExp);
            funExp.Parameters.Add(new FetchStaticExpression(val));

            // Create a query processor and perform the scan operation
            QueryProcessor processor = new QueryProcessor(transaction);
            ITable result = processor.FilterByScan(table, funExp);
            // Return the row cursor
            return result.GetRowCursor();
        }
コード例 #9
0
ファイル: DatabaseSession.cs プロジェクト: ikvm/deveelsql
 private void AddColumnIndex(SystemTransaction transaction, SystemTable schemaTable, string indexName, string column)
 {
     throw new NotImplementedException();
 }
コード例 #10
0
ファイル: DatabaseSession.cs プロジェクト: ikvm/deveelsql
 private void Add3ColumnIndex(SystemTransaction transaction, SystemTable table, string indexName, string column1, string column2, string column3)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
ファイル: DatabaseSession.cs プロジェクト: ikvm/deveelsql
        public IDatabase CreateDatabase(string name, string adminUser, string adminPass, bool changeInSession)
        {
            if (sysState == null)
                throw new InvalidOperationException("Cannot create databases in this context.");

            if (sysState.GetDatabase(name) != null)
                throw new InvalidOperationException("Database '" + name + "' already exists.");

            IDatabase state = sysState.CreateDatabase(name);

            SystemTransaction transaction = CreateTransaction(User.System.Name);

            try {
                // First of all, the INFORMATION_SCHEMA ....
                transaction.State.CreateSchema(SystemTableNames.SystemSchema);

                // Create the system directory table (table id 1),
                SystemTable tables = new SystemTable(transaction, transaction.State.CreateTable(SystemTableNames.Tables), 1);
                tables.Columns.Add("id", SqlType.Numeric, true);
                tables.Columns.Add("schema", SqlType.String, true);
                tables.Columns.Add("name", SqlType.String, true);
                tables.Columns.Add("type", SqlType.String, true);

                // Create the system index tables (table id 2),
                SystemTable indext = new SystemTable(transaction, transaction.State.CreateTable(SystemTableNames.Index), 2);
                indext.Columns.Add("id", SqlType.Numeric, true);
                indext.Columns.Add("schema", SqlType.String, true);
                indext.Columns.Add("name", SqlType.String, true);
                indext.Columns.Add("index_name", SqlType.String, true);
                indext.Columns.Add("type", SqlType.String, true);

                // Create an index over the system tables
                Add2ColumnIndex(transaction, indext, "composite_name_idx", "schema", "name");
                Add3ColumnIndex(transaction, indext, "index_composite_idx",
                                                      "schema", "name", "index_name");
                AddColumnIndex(transaction, indext, "id_idx", "id");
                AddColumnIndex(transaction, tables, "id_idx", "id");
                AddColumnIndex(transaction, tables, "schema_idx", "schema");
                AddColumnIndex(transaction, tables, "name_idx", "name");
                Add2ColumnIndex(transaction, tables, "composite_name_idx", "schema", "name");
                AddColumnIndex(transaction, tables, "source_idx", "source");

                // Dispose the table objects
                tables.Dispose();
                indext.Dispose();

                // Add the directory item for this table itself
                transaction.AddObject(1, SystemTableNames.Tables, "TABLE");
                transaction.AddObject(2, SystemTableNames.Index, "TABLE");
                transaction.RebuildSystemIndexes();

                // We have now configured enough for all directory operations.

                // ----- The schema table -----

                // All valid schema defined by the database,
                SystemTable schemaTable = transaction.CreateTable(SystemTableNames.Schema);
                schemaTable.Columns.Add("name", SqlType.String, true);
                AddColumnIndex(transaction, schemaTable, "name_idx", "name");

                // Add an entry for the system SYS_INFO schema.
                TableRow nrow = schemaTable.NewRow();
                nrow.SetValue(0, SystemTableNames.SystemSchema);
                nrow.Insert();

                // ----- Table constraints -----

                // A set of columns tied with a unique id used by the referential
                // integrity tables.
                SystemTable columnSetTable = transaction.CreateTable(SystemTableNames.ColumnSet);
                columnSetTable.Columns.Add("id", SqlType.Numeric, true);
                columnSetTable.Columns.Add("seq_no", SqlType.Numeric, true);
                columnSetTable.Columns.Add("column_name", SqlType.String, true);
                AddColumnIndex(transaction, columnSetTable, "id_idx", "id");

                // Unique/Primary key constraints
                SystemTable constraintsUnique = transaction.CreateTable(SystemTableNames.ConstraintsUnique);
                constraintsUnique.Columns.Add("object_id", SqlType.Numeric, true);
                constraintsUnique.Columns.Add("name", SqlType.String, false);
                constraintsUnique.Columns.Add("column_set_id", SqlType.Numeric, true);
                constraintsUnique.Columns.Add("deferred", SqlType.Boolean, false);
                constraintsUnique.Columns.Add("deferrable", SqlType.Boolean, false);
                constraintsUnique.Columns.Add("primary_key", SqlType.Boolean, false);
                AddColumnIndex(transaction, constraintsUnique, "object_id_idx", "object_id");
                AddColumnIndex(transaction, constraintsUnique, "name_idx", "name");

                // Foreign key reference constraints
                SystemTable constraintsForeign = transaction.CreateTable(SystemTableNames.ConstraintsForeign);
                constraintsForeign.Columns.Add("object_id", SqlType.Numeric, true);
                constraintsForeign.Columns.Add("name", SqlType.String, false);
                constraintsForeign.Columns.Add("column_set_id", SqlType.Numeric, true);
                constraintsForeign.Columns.Add("ref_schema", SqlType.String, true);
                constraintsForeign.Columns.Add("ref_object", SqlType.Numeric, true);
                constraintsForeign.Columns.Add("ref_column_set_id", SqlType.Numeric, true);
                constraintsForeign.Columns.Add("update_action", SqlType.String, false);
                constraintsForeign.Columns.Add("delete_action", SqlType.String, false);
                constraintsForeign.Columns.Add("deferred", SqlType.Boolean, true);
                constraintsForeign.Columns.Add("deferrable", SqlType.Boolean, false);
                AddColumnIndex(transaction, constraintsForeign, "object_id_idx", "object_id");
                AddColumnIndex(transaction, constraintsForeign, "name_idx", "name");
                Add2ColumnIndex(transaction, constraintsForeign, "composite_name_idx", "ref_schema", "ref_object");

                // Expression check constraints
                SystemTable constraintsCheck = transaction.CreateTable(SystemTableNames.ConstraintsCheck);
                constraintsCheck.Columns.Add("object_id", SqlType.Numeric, true);
                constraintsCheck.Columns.Add("name", SqlType.String, false);
                constraintsCheck.Columns.Add("check_source", SqlType.String, true);
                constraintsCheck.Columns.Add("check_bin", SqlType.Binary, true);
                constraintsCheck.Columns.Add("deferred", SqlType.Boolean, false);
                constraintsCheck.Columns.Add("deferrable", SqlType.Boolean, false);
                AddColumnIndex(transaction, constraintsCheck, "object_id_idx", "object_id");
                AddColumnIndex(transaction, constraintsCheck, "name_idx", "name");

                // Default column expressions
                SystemTable default_column_expr_ts = transaction.CreateTable(SystemTableNames.DefaultColumnExpression);
                default_column_expr_ts.Columns.Add("object_id", SqlType.Numeric, true);
                default_column_expr_ts.Columns.Add("column", SqlType.String, true);
                default_column_expr_ts.Columns.Add("default_source", SqlType.String, true);
                default_column_expr_ts.Columns.Add("default_bin", SqlType.Binary, true);
                AddColumnIndex(transaction, default_column_expr_ts, "object_id_idx", "object_id");

                // Insert referential constraints on the system tables so they cascade
                // delete.
                long src_col_set, dst_col_set;

                src_col_set = AddColumnSet(transaction, new String[] { "object_id" });
                dst_col_set = AddColumnSet(transaction, new String[] { "id" });
                AddForeignConstraint(transaction, SystemTableNames.ConstraintsUnique, src_col_set,
                                     SystemTableNames.Tables, dst_col_set);
                src_col_set = AddColumnSet(transaction, new String[] { "object_id" });
                dst_col_set = AddColumnSet(transaction, new String[] { "id" });
                AddForeignConstraint(transaction, SystemTableNames.ConstraintsForeign, src_col_set,
                                     SystemTableNames.Tables, dst_col_set);
                src_col_set = AddColumnSet(transaction, new String[] { "object_id" });
                dst_col_set = AddColumnSet(transaction, new String[] { "id" });
                AddForeignConstraint(transaction, SystemTableNames.ConstraintsCheck, src_col_set,
                                     SystemTableNames.Tables, dst_col_set);
                src_col_set = AddColumnSet(transaction, new String[] { "object_id" });
                dst_col_set = AddColumnSet(transaction, new String[] { "id" });
                AddForeignConstraint(transaction, SystemTableNames.DefaultColumnExpression, src_col_set,
                                     SystemTableNames.Tables, dst_col_set);
                src_col_set = AddColumnSet(transaction, new String[] { "id" });
                dst_col_set = AddColumnSet(transaction, new String[] { "column_set_id" });
                AddForeignConstraint(transaction, SystemTableNames.ColumnSet, src_col_set,
                                     SystemTableNames.ConstraintsForeign, dst_col_set);
                src_col_set = AddColumnSet(transaction, new String[] { "id" });
                dst_col_set = AddColumnSet(transaction, new String[] { "ref_column_set_id" });
                AddForeignConstraint(transaction, SystemTableNames.ColumnSet, src_col_set,
                                     SystemTableNames.ConstraintsForeign, dst_col_set);
                src_col_set = AddColumnSet(transaction, new String[] { "id" });
                dst_col_set = AddColumnSet(transaction, new String[] { "column_set_id" });
                AddForeignConstraint(transaction, SystemTableNames.ColumnSet, src_col_set,
                                     SystemTableNames.ConstraintsUnique, dst_col_set);

                // Rebuild the indexes on the tables we added information to.
                transaction.RebuildIndexes(SystemTableNames.ColumnSet);
                transaction.RebuildIndexes(SystemTableNames.ConstraintsForeign);

                // Add a directory item for the system columns table
                transaction.AddObject(4, SystemTableNames.TableColumns, "DYN:Deveel.Data.Sql.SystemColumnsTable");

                // The empty and single row zero column item (should this be in
                // TSTransaction?)
                transaction.AddObject(5, SystemTableNames.EmptyTable, "PRIMITIVE:EmptyTable");
                transaction.AddObject(6, SystemTableNames.OneRowTable, "PRIMITIVE:OneRowTable");

                // Commit the transaction and finish
                CommitTransaction(transaction);
            } catch (Exception e) {
                throw new Exception("Unable to create the database '" + name + "': " + e.Message, e);
            } finally {
                DisposeTransaction(transaction);
            }

            if (changeInSession)
                db = state;

            return state;
        }
コード例 #12
0
        private SystemTable InternalGetTable(TableName tableName)
        {
            // Is it in the cache?
            SystemTable table;
            if (!tableNameMap.TryGetValue(tableName, out table)) {
                // Directory table is special case,
                if (tableName.Equals(SystemTableNames.Tables)) {
                    ITable t = state.GetTable(tableName);
                    if (t == null)
                        return null;

                    table = new SystemTable(this, t, -1);
                }
                    // Index tables are special cases
                else if (tableName.Equals(SystemTableNames.Index)) {
                    ITable t = state.GetTable(tableName);
                    if (t == null)
                        return null;

                    table = new SystemTable(this, t, -1);
                }
                    // Not a special case table,
                else {
                    // If the table is in the table id map
                    long tableId;
                    if (tableIdMap.TryGetValue(tableName, out tableId)) {
                        // Simply fetch if it is,
                        table = GetTable(tableId);
                    } else {
                        // Otherwise we need to resolve the table name to an id
                        // Discover the id for this table name from a query on the directory
                        // table.
                        // This is probably going to be a very heavy operation for what is a
                        // simple TableName to id lookup, and I think ultimately this
                        // operation will be backed by a cache.

                        // first check if we have the system TABLES table, that means
                        // we have a full setup
                        if (!TableExists(SystemTableNames.Tables)) {
                            // we have not a full setup: try to get the table
                            // directly from the state
                            ITable t = state.GetTable(tableName);
                            if (t == null)
                                return null;

                            tableId = state.CreateUniqueId(SystemTableNames.Tables);
                            table = new SystemTable(this, t, tableId);
                            tableIdMap[tableName] = tableId;
                        } else {
                            // Query the composite index
                            SystemTable tables = GetTable(SystemTableNames.Tables);
                            // Find the RowIndex that represents the set of all schema/name
                            // items in the table
                            IRowCursor i = GetNames(tables, tableName);
                            // Fail conditions
                            if (i.Count == 0)
                                return null;

                            if (i.Count > 1)
                                throw new ApplicationException("Multiple '" + tableName + "' tables.");

                            if (!i.MoveNext())
                                throw new ArgumentException();

                            // Read the result
                            RowId rowid = i.Current;
                            tableId = tables.GetValue(0, rowid);
                            string tableType = tables.GetValue(3, rowid);

                            // Fetch the table info
                            if (tableType.Equals("TABLE")) {
                                // Handle table_id overflow gracefully
                                if (tableId > Int32.MaxValue)
                                    throw new ApplicationException("table_id overflow (" + tableId + ")");

                                // Put the table id in the map
                                tableIdMap[tableName] = tableId;
                                // Fetch the table,
                                table = GetTable(tableId);
                            }

                                // Sequences
                            else if (tableType.Equals("SEQUENCE")) {
                                // NOTE, this doesn't get put on the table cache!
                                //TODO:
                            }

                                // Table primitives
                            else if (tableType.StartsWith("PRIMITIVE:")) {
                                // The name of the primitive
                                string tableOb = tableType.Substring(10);
                                if (tableOb.Equals("EmptyTable"))
                                    return SystemTable.Empty;
                                if (tableOb.Equals("OneRowTable"))
                                    return SystemTable.OneRow;
                            }

                                // Dynamically created tables created via reflection
                            else if (tableType.StartsWith("DYN:")) {
                                // A dynamic table type
                                //TODO:
                            } else {
                                throw new ApplicationException("Unknown table type: " + tableType);
                            }
                        }
                    }
                }

                tableNameMap[tableName] = table;
            }
            return table;
        }
コード例 #13
0
        private IndexCollation DecodeCollation(SystemTable table)
        {
            string[] columnNames = index.ColumnNames;

            // Each column is encoded as '(+|-)[column name]' representing ascending
            // or descending order of the column.
            int sz = columnNames.Length;
            CollationColumn[] sortColumns = new CollationColumn[sz];
            SqlType[] columnTypes = new SqlType[sz];

            // For each column in the index,
            for (int i = 0; i < sz; ++i) {
                string columnName = columnNames[i];
                bool ascending = index.ColumnOrder[i];

                columnTypes[i] = table.Columns[columnName].Type;

                // Fail if the column is a type we can't index
                if (columnTypes[i].IsBinary)
                    //TODO: check better...
                    return null;

                sortColumns[i] = new CollationColumn(columnName, ascending);
            }

            // No columns, so return null
            if (sz == 0)
                return null;

            if (sz == 1)
                // Create the collation
                return new IndexCollation(columnTypes[0], sortColumns[0]);

            SqlCompositeType compositeType = new SqlCompositeType(columnTypes);
            return new IndexCollation(compositeType, sortColumns);
        }