Exemplo n.º 1
0
		protected internal override void Execute(bool undoEnabled)
		{
			resultStr = new TableStructure();
			table.saveStructure(resultStr);
			foreach (Command cmd in subCommands)
				if (!(cmd is RemoveItemCmd))
					cmd.Execute(undoEnabled);
		}
Exemplo n.º 2
0
        public InMemoryTable GetTable(bool wantdata)
        {
            List <DataRecord> records = new List <DataRecord>();

            foreach (string row in EnumRows())
            {
                records.Add(FieldAnalyser.AnalyseRecord(row));
            }
            var ts = new TableStructure();
            Dictionary <string, int> colindexes = new Dictionary <string, int>();

            // get column collection
            foreach (var rec in records)
            {
                foreach (var fld in rec.Fields)
                {
                    if (colindexes.ContainsKey(fld.Name))
                    {
                        continue;
                    }
                    var col = new ColumnStructure();
                    col.ColumnName       = fld.Name;
                    col.DataType         = new DbTypeString();
                    colindexes[fld.Name] = ts._Columns.Count;
                    ts._Columns.Add(col);
                }
            }
            if (!wantdata)
            {
                return(new InMemoryTable(ts));
            }
            var recs = new List <ArrayDataRecord>();

            foreach (var rec in records)
            {
                var row = new ArrayDataRecord(ts);
                foreach (var fld in rec.Fields)
                {
                    row.SeekValue(colindexes[fld.Name]);
                    row.SetString(fld.Value);
                }
                recs.Add(row);
            }
            return(InMemoryTable.FromEnumerable(ts, recs));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the type of the maml from variable.
        /// </summary>
        /// <param name="wrappedTreeNode">The wrapped tree node.</param>
        /// <returns>Term with definition structure</returns>
        private static TermWithDefinitionStructure CreateTermWithDefinitionFromVariableType(IModelNode iModelNode)
        {
            List <TableStructure> listOfAllTables       = new List <TableStructure>();
            List <string>         variableTypeHeaderRow = new List <string>
            {
                referenceString,
                minCardString,
                maxCardString,
                nodeClassString,
                symbolicNameString,
                dataTypeString,
                typeDefinitionString,
                modellingRuleString
            };
            TableStructure variableTypeChildrenTable = new TableStructure(childrenString, variableTypeHeaderRow);

            GetInformationAboutChildren((IModelNodeAdvance)iModelNode, variableTypeChildrenTable);
            if (variableTypeChildrenTable.TableRows.Count > 0)
            {
                listOfAllTables.Add(variableTypeChildrenTable);
            }
            List <string> variableTypeReferencesHeaderRow = new List <string>
            {
                referenceTypeString,
                targetIdString,
                isInverseString
            };
            TableStructure variableTypeReferencesTable = new TableStructure(referenceString, variableTypeReferencesHeaderRow);

            GetInformationAboutReferences((IModelNodeAdvance)iModelNode, variableTypeReferencesTable);
            if (variableTypeReferencesTable.TableRows.Count > 0)
            {
                listOfAllTables.Add(variableTypeReferencesTable);
            }
            string tableName = iModelNode.Name + " (" + variableTypeString + ")";

            if (listOfAllTables.Count > 0)
            {
                return(new TermWithDefinitionStructure(listOfAllTables, tableName, CheckIfTheNodeIsAbstract(iModelNode)));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        protected override void LoadIndexes(TableStructure table)
        {
            try
            {
                string tblname = table.FullName.Name;
                string schema  = table.FullName.Schema;

                DataTable                 indexlist = GetCachedTableColumnsTable("indexes", LoadIndexesTable, table.FullName);
                DataTable                 indexcols = GetCachedTableColumnsTable("indexcols", LoadIndexColsTable, table.FullName);
                TableAnalyser             tadidx    = new TableAnalyser();
                Dictionary <string, bool> dct       = new Dictionary <string, bool>();
                foreach (DataRow row in indexlist.Rows)
                {
                    TableAnalyser.Key key = new TableAnalyser.Key();
                    key.keytype      = "INDEX";
                    key.keyisunique  = Int32.Parse(row["IsUnique"].ToString()) == 1;
                    key.keyname      = row["Name"].ToString();
                    key.tblname      = tblname;
                    key.tblschema    = schema;
                    dct[key.keyname] = true;
                    tadidx.keys.Add(key);
                }
                foreach (DataRow row in indexcols.Rows)
                {
                    TableAnalyser.Col col = new TableAnalyser.Col();
                    col.keytype   = "INDEX";
                    col.keyname   = row["IndexName"].ToString();
                    col.tblname   = tblname;
                    col.tblschema = schema;
                    col.ordinal   = row["KeyOrder"].ToString();
                    col.colname   = row["ColumnName"].ToString();
                    if (!dct.ContainsKey(col.keyname))
                    {
                        continue;
                    }
                    tadidx.cols.Add(col);
                }
                tadidx.SaveConstraints(table, this);
            }
            catch (Exception err)
            {
                Logging.Warning("Error loading MSSQL indexes:" + err.ToString());
            }
            //table.FilledMembers |= TableStructureMembers.Indexes;
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            try
            {
                DBTest.RemoveDBFiles();
                DBStructure    database  = new DBStructure("", "MyPal", DatabaseMode.Create);
                TableStructure tblPeople = database.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                ColumnStructure colName =
                    tblPeople.CreateColumn("Name", ColumnType.String, false);
                colName = colName;
                tblPeople.CreateColumn("Age", ColumnType.Integer, false);
                tblPeople.CreateColumn("Type", ColumnType.Integer, true);
                tblPeople.CreateColumn("DateTime", ColumnType.DateTime, true);
                tblPeople.SetCompoundIndex("Id", "Name");
                tblPeople.SetCompoundIndex("Name", "Type");

                TableStructure tblTest = database.CreateTable("Test");
                tblTest.CreateColumn("Id", ColumnType.Integer, false);
                tblTest.CreateColumn("Date", ColumnType.DateTime, false);
                tblTest.SetCompoundIndex("Id", "Date");

                database.SaveStructure();
                database.Shutdown();
                database = new DBStructure("", "MyPal", DatabaseMode.Create);
                database.LoadStructure( );
                _database = database.Database;

                _peopleTable = _database.GetTable("People");
                _testTable   = _database.GetTable("Test");
                //m_testTable.InputMode = InputMode.Batch;
                for (int i = 0; i < 10; i++)
                {
                    IRecord record = _peopleTable.NewRecord();
                    Assert.AreEqual(i, record.GetID(), "Id is wrong");
                    record.SetValue(1, (500 - i).ToString());
                    record.Commit();
                    Assert.AreEqual((i + 1), _peopleTable.Count, "Count is wrong");
                }
            }
            catch (Exception exc)
            {
                Assert.Fail(exc.Message);
            }
        }
Exemplo n.º 6
0
        public void CheckUnlockDatabaseWhenSaveStructureTest( )
        {
            DBStructure dbStruct = new DBStructure("", "Test");

            TableStructure tableStruct = dbStruct.CreateTable("SomeTable");

            tableStruct.CreateColumn("SomeString", ColumnType.String, false);
            tableStruct.CreateColumn("SomeInt", ColumnType.Integer, false);
            tableStruct.CreateColumn("SomeDate", ColumnType.DateTime, false);
            dbStruct.SaveStructure();

            dbStruct = new DBStructure("", "Test");
            dbStruct.LoadStructure();

            IDatabase database = dbStruct.OpenDatabase( );

            database.Shutdown();
        }
Exemplo n.º 7
0
        public ITableStructure GetTableStructure(SynQueryType qtype)
        {
            var res = new TableStructure();

            FillKey(res);
            switch (qtype)
            {
            case SynQueryType.SelectAll:
                FillDataColumns(res);
                break;

            case SynQueryType.SelectKeyNull:
            case SynQueryType.SelectKeyMd5:
                res.AddColumn(new ColumnStructure {
                    DataType = new DbTypeString(), ColumnName = "HashColumn"
                }, true);
                break;
            }
            return(res);
        }
Exemplo n.º 8
0
        public override void FillTable(ITableStructure table, IDataQueue queue, TableCopyOptions opts)
        {
            TableStructure dst = null;

            try
            {
                dst = (TableStructure)m_db.Tables[table.FullName];
            }
            catch
            {
                throw new InternalError("DAE-00064 Table not found in target structure:" + table.FullName.ToString());
            }
            InMemoryTable tbl = InMemoryTable.FromEnumerable(queue.GetRowFormat, queue.EnumRows());

            if (tbl.Rows.Count == 0)
            {
                tbl = null;
            }
            dst.FixedData = tbl;
        }
Exemplo n.º 9
0
        protected override void LoadConstraints(TableStructure table)
        {
            if (m_members.TableMembers.ContainsAny(TableStructureMembers.ConstraintsNoIndexesNoRefs))
            {
                TableAnalyser ta = new TableAnalyser();

                foreach (DataRow row in GetCachedTableColumnsTable("oracle.constraints", LoadConstraintsTable, table.FullName).Rows)
                {
                    TableAnalyser.Key key = new TableAnalyser.Key();
                    key.keytype   = OracleConstraintToDatAdmin(row["CONSTRAINT_TYPE"].ToString());
                    key.keyname   = row["CONSTRAINT_NAME"].ToString();
                    key.tblname   = row["TABLE_NAME"].ToString();
                    key.tblschema = row["OWNER"].ToString();
                    key.checkexpr = row["SEARCH_CONDITION"].SafeToString();
                    ta.keys.Add(key);
                }

                foreach (DataRow row in GetCachedTableColumnsTable("oracle.constraintcols", LoadConstraintsColsTable, table.FullName).Rows)
                {
                    TableAnalyser.Col col = new TableAnalyser.Col();
                    col.keyname   = row["CONSTRAINT_NAME"].ToString();
                    col.tblname   = row["TABLE_NAME"].ToString();
                    col.tblschema = row["OWNER"].ToString();
                    col.ordinal   = row["POSITION"].ToString();
                    col.colname   = row["COLUMN_NAME"].ToString();
                    ta.cols.Add(col);
                }

                ta.SaveConstraints(table, this);
            }

            if (m_members.TableMembers.ContainsAny(TableStructureMembers.ForeignKeys | TableStructureMembers.ReferencedFrom))
            {
                GetRefsTA().SaveConstraints(table, this);
            }

            if (m_members.TableMembers.ContainsAny(TableStructureMembers.Indexes))
            {
                GetIndexesTA().SaveConstraints(table, this);
            }
        }
Exemplo n.º 10
0
 private void LoadDefaultConstraintNames(TableStructure tbl)
 {
     try
     {
         var cols = GetCachedTableColumnsTable("mssql.default_constraints", LoadDefaultConstraintNamesTable, tbl.FullName);
         if (cols == null)
         {
             return;
         }
         foreach (DataRow row in cols.Rows)
         {
             var    col     = (ColumnStructure)tbl.Columns[row.SafeString("colname").ToString()];
             string cntname = row.SafeString("cntname").ToString();
             col.SetSpecificAttribute("mssql", "defname", cntname);
         }
     }
     catch (Exception err)
     {
         Logging.Warning("Error loading default values names:" + err.Message);
     }
 }
Exemplo n.º 11
0
        protected override void LoadTableColumns(TableStructure table)
        {
            OleDbConnection c = (OleDbConnection)GetDbConn();

            Dictionary <int, string> typenames = GetTypeNames(m_conn);
            DataTable cols = c.GetSchema("Columns", new string[] { null, null, table.FullName.Name }).SelectNewTable("1=1", "ORDINAL_POSITION ASC");

            foreach (DataRow row in cols.Rows)
            {
                ColumnStructure col = new ColumnStructure();
                col.ColumnName   = row["COLUMN_NAME"].ToString();
                col.IsNullable   = (bool)row["IS_NULLABLE"];
                col.DefaultValue = SqlExpression.ParseDefaultValue((row.ColumnDefault() ?? "").ToString(), m_dialect);
                col.DataType     = MakeSpecificAccessType(new DataRowAdapter(row), typenames).ToGenericType();
                int colflags = Int32.Parse(row["COLUMN_FLAGS"].ToString());
                //if ((colflags & 0x20) == 0) col.DataType.SetAutoincrement(true);
                table._Columns.Add(col);
            }

            //table.FilledMembers |= TableStructureMembers.ColumnNames | TableStructureMembers.ColumnTypes;
        }
Exemplo n.º 12
0
        //----------------------------------------------------------------------------------------------------
        public static TableStructure Views__Get(int viewId)
        {
            AjaxService.ASPdatabaseService.GetSetVal();
            var aspdb_View = DataAccess.SQLObjectsCRUD.ASPdb_View__Get(viewId);

            if (aspdb_View == null)
            {
                return(null);
            }
            var rtn = new TableStructure()
            {
                ConnectionId     = aspdb_View.ConnectionId,
                TableId          = aspdb_View.ViewId,
                Schema           = aspdb_View.Schema,
                TableName        = aspdb_View.ViewName,
                StructureIsAView = true
            };

            rtn.Columns = Tables__Get__GetColumns(rtn);
            return(rtn);
        }
Exemplo n.º 13
0
        private static void WriteClassEncodeAndDecode(TableStructure tableStructure, string targetNamespace)
        {
            //encode
            formatWriter.NewLine();
            formatWriter.WriteLine("public void Encode(FlatBufferBuilder fbb)");
            formatWriter.BeginBlock();
            formatWriter.WriteLine(
                $"Offset<{tableStructure.tableNameWithNamespace}> offset = {targetNamespace}ConvertMethods.Encode(this, fbb);");
            formatWriter.WriteLine("fbb.Finish(offset.Value);");
            formatWriter.EndBlock();

            //decode
            formatWriter.NewLine();
            formatWriter.WriteLine("public void Decode(ByteBuffer bb)");
            formatWriter.BeginBlock();
            formatWriter.WriteLine(
                $"{tableStructure.tableNameWithNamespace} source = {tableStructure.tableNameWithNamespace}.GetRootAs{tableStructure.tableName}(bb);");
            formatWriter.WriteLine($"{targetNamespace}ConvertMethods.Decode(this, source);");

            formatWriter.EndBlock();
        }
        private static TableStructure CreateTableStructure(int records, CompressionInformation ci)
        {
            var structure = new TableStructure(ci.Page.Header.AllocationUnitId, ci.Page.Database);

            var fields = new List <RecordField>();

            for (short i = 0; i < records; i++)
            {
                var column = new Column();

                column.ColumnName = $"Column {i}";
                column.ColumnId   = i;
                column.LeafOffset = i;
                column.DataType   = SqlDbType.VarBinary;
                column.DataLength = 8000;

                structure.Columns.Add(column);
            }

            return(structure);
        }
Exemplo n.º 15
0
        public void SetUp()
        {
            try
            {
                DBTest.RemoveDBFiles();
                DBStructure    database  = new DBStructure("", "MyPal");
                TableStructure tblPeople = database.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                tblPeople.CreateColumn("Name", ColumnType.String, true);
                tblPeople.CreateColumn("Cash", ColumnType.Double, true);

                database.SaveStructure();
                m_database = database.OpenDatabase( );

                m_testTable = m_database.GetTable("People");
            }
            catch (Exception exc)
            {
                Assert.Fail(exc.Message);
            }
        }
Exemplo n.º 16
0
        public override void MigrateTable(TableStructure table, IMigrationProfile profile, IProgressInfo progress)
        {
            base.MigrateTable(table, profile, progress);

            MigrateTool.RemoveNonPk1AutoIncrements(table, progress);

            foreach (ColumnStructure col in table.Columns)
            {
                var    spec    = col.DefaultValue as SpecialConstantSqlExpression;
                string subtype = col.DataType.GetSpecificAttribute("mysql", "subtype");
                if (spec != null)
                {
                    if (subtype != "timestamp")
                    {
                        col.DefaultValue = null;
                        col.IsNullable   = true;
                        progress.Warning(String.Format("Default value for column {0}.{1} was removed, it is not valid on MySQL", table.FullName, col.ColumnName));
                    }
                }
            }
        }
Exemplo n.º 17
0
        protected override void LoadConstraints(TableStructure table)
        {
            OleDbConnection c = (OleDbConnection)GetDbConn();

            TableAnalyser tad = new TableAnalyser();
            DataTable     pks = c.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, null);

            foreach (DataRow row in pks.Rows)
            {
                if (row["TABLE_NAME"].ToString() != table.FullName.Name)
                {
                    continue;
                }
                TableAnalyser.Col col = new TableAnalyser.Col();
                col.keytype = "PRIMARY KEY";
                col.ordinal = row["ORDINAL"].ToString();
                col.keyname = row["PK_NAME"].ToString();
                col.colname = row["COLUMN_NAME"].ToString();
                col.tblname = row["TABLE_NAME"].ToString();
                tad.cols.Add(col);
            }

            DataTable fks = c.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, null);

            foreach (DataRow row in fks.Rows)
            {
                TableAnalyser.Col col = new TableAnalyser.Col();
                col.keytype    = "FOREIGN KEY";
                col.keyname    = row["FK_NAME"].ToString();
                col.ordinal    = row["ORDINAL"].ToString();
                col.colname    = row["FK_COLUMN_NAME"].ToString();
                col.tblname    = row["FK_TABLE_NAME"].ToString();
                col.dstcolname = row["PK_COLUMN_NAME"].ToString();
                col.dsttblname = row["PK_TABLE_NAME"].ToString();
                tad.cols.Add(col);
            }

            tad.SaveConstraints(table, this);
            //table.FilledMembers |= m_members.TableMembers.FilterConstraints(false);
        }
Exemplo n.º 18
0
        private static void WriteTableEncodeCode(TableStructure tableStructure)
        {
            formatWriter.WriteLine(
                $"public static Offset<{tableStructure.tableNameWithNamespace}> Encode({tableStructure.tableNameWithCSharpNamespace} source, FlatBufferBuilder fbb)");

            formatWriter.BeginBlock();

            //non scalar encode methods
            for (int i = 0; i < tableStructure.fieldInfos.Length; i++)
            {
                TableFieldInfo fieldInfo = tableStructure.fieldInfos[i];
                if (fieldInfo.isScalarType)
                {
                    continue;
                }

                GenerateNonScalarEncodeCode(tableStructure, fieldInfo);
            }

            formatWriter.WriteLine($"{tableStructure.tableNameWithNamespace}.Start{tableStructure.tableName}(fbb);");
            for (int i = 0; i < tableStructure.fieldInfos.Length; i++)
            {
                TableFieldInfo fieldInfo = tableStructure.fieldInfos[i];

                if (fieldInfo.isScalarType)
                {
                    formatWriter.WriteLine(
                        $"{tableStructure.tableNameWithNamespace}.Add{fieldInfo.upperCamelCaseFieldName}(fbb,source.{fieldInfo.fieldName});");
                }
                else
                {
                    formatWriter.WriteLine(
                        $"{tableStructure.tableNameWithNamespace}.Add{fieldInfo.upperCamelCaseFieldName}(fbb,{fieldInfo.fieldName}Offset);");
                }
            }

            formatWriter.WriteLine($"return {tableStructure.tableNameWithNamespace}.End{tableStructure.tableName}(fbb);");

            formatWriter.EndBlock();
        }
Exemplo n.º 19
0
        //----------------------------------------------------------------------------------------------------
        public static string BuildSql__Column_SelectAll(TableStructure tableStructure)
        {
            AjaxService.ASPdatabaseService.GetSetVal();

            tableStructure.Validate(Enums.ValidationTypes.Select);

            string sql = String.Format(@"
                SELECT 
	                col.TABLE_SCHEMA as [Schema],
	                col.TABLE_NAME as [TableName],
	                col.ORDINAL_POSITION as [OrdinalPosition],
	                col.COLUMN_NAME as [ColumnName],
	                col.DATA_TYPE as [DataType],
	                col.CHARACTER_MAXIMUM_LENGTH as [MaxLength],
	                col.NUMERIC_PRECISION as [Precision],
	                col.NUMERIC_SCALE as [Scale],
	                col.IS_NULLABLE as [AllowNulls],
	                col.COLUMN_DEFAULT as [DefaultValue],
                    CASE WHEN CCU.COLUMN_NAME IS NULL THEN 0 ELSE 1 END AS [IsPrimaryKey],
	                COLUMNPROPERTY(object_id('[' + col.Table_Schema + '].[' + col.Table_Name + ']'), COL.COLUMN_NAME, 'IsIdentity') AS [IsIdentity],
	                IDENT_SEED('[' + col.Table_Schema + '].[' + col.Table_Name + ']') AS Identity_Seed,
	                IDENT_INCR('[' + col.Table_Schema + '].[' + col.Table_Name + ']') AS Identity_Increment,
	                IDENT_CURRENT('[' + col.Table_Schema + '].[' + col.Table_Name + ']') AS Identity_CurrentIdentity
                FROM 
                    INFORMATION_SCHEMA.COLUMNS as col
                left JOIN
                    INFORMATION_SCHEMA.TABLE_CONSTRAINTS as tc
                    ON col.TABLE_SCHEMA = tc.TABLE_SCHEMA AND col.TABLE_NAME = tc.TABLE_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY'
                left JOIN
                    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE as ccu 
                    ON col.TABLE_SCHEMA = tc.TABLE_SCHEMA AND col.COLUMN_NAME = ccu.COLUMN_NAME AND tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME 
                where col.[TABLE_SCHEMA] = '{0}' and col.[TABLE_NAME] = '{1}'
                order by
                    col.TABLE_SCHEMA, col.TABLE_NAME, col.ORDINAL_POSITION
                ",
                                       tableStructure.Schema,
                                       tableStructure.TableName);

            return(sql);
        }
Exemplo n.º 20
0
        public void CheckSaveLoadIndex( )
        {
            DBStructure    database  = new DBStructure("", "MyPal");
            TableStructure tblPeople = database.CreateTable("People");

            tblPeople.CreateColumn("Id", ColumnType.Integer, true);
            tblPeople.CreateColumn("Name", ColumnType.String, true);

            database.SaveStructure();
            IDatabase m_database = database.OpenDatabase( );

            ITable testTable = m_database.GetTable("People");

            for (int i = 0; i < 1000; i++)
            {
                IRecord record = testTable.NewRecord();
                record.SetValue(Name, (500 - i).ToString());
                record.Commit();
                Assert.IsTrue(testTable.Count == (i + 1));
            }
            m_database.Shutdown();
        }
Exemplo n.º 21
0
        protected override void LoadTableColumns(TableStructure table)
        {
            base.LoadTableColumns(table);
            PrimaryKey pk = new PrimaryKey();

            //pk.Table = table.FullName;
            foreach (var col in table.Columns)
            {
                if (m_pkcols.ContainsKey(new Tuple <string, string>(table.FullName.Name, col.ColumnName)))
                {
                    pk.Columns.Add(new ColumnReference(col.ColumnName));
                }
            }
            if (pk.Columns.Count > 0)
            {
                table._Constraints.Add(pk);
                if (pk.Columns.Count == 1)
                {
                    table.Columns[pk.Columns[0].ColumnName].DataType.SetAutoincrement(true);
                }
            }
        }
Exemplo n.º 22
0
        public override void SetUp()
        {
            IBTree._bUseOldKeys = true;

            DBStructure dbStructure =
                new DBStructure("", "OmniaMeaPerformanceTest", DatabaseMode.Create);

            TableStructure table = dbStructure.CreateTable("IntProps");

            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.Integer, false);
            table.CreateIndex("Id");

            table = dbStructure.CreateTable("StringProps");
            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.String, false);
            table.SetCompoundIndex("PropValue", "PropType");

            table = dbStructure.CreateTable("DateProps");
            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.DateTime, false);
            table.SetCompoundIndex("Id", "PropType");
            table.CreateIndex("PropValue");

            dbStructure.SaveStructure();
            dbStructure.Shutdown();

            _dbStructure = new DBStructure("", "OmniaMeaPerformanceTest");
            _dbStructure.LoadStructure();

            IDatabase db = _dbStructure.OpenDatabase();

            _intPropsTable    = db.GetTable("IntProps");
            _stringPropsTable = db.GetTable("StringProps");
            _datePropsTable   = db.GetTable("DateProps");
        }
Exemplo n.º 23
0
        //----------------------------------------------------------------------------------------------------
        public static string BuildSql__Index_Select(TableStructure tableStructure)
        {
            AjaxService.ASPdatabaseService.GetSetVal();
            tableStructure.Validate(Enums.ValidationTypes.Select);

            string sql = String.Format(@"
                SELECT
                    [Schema] = SC.name,
                    [TableName] = T.name,
                    [IndexName] = IND.name,
                    [IsUnique] = IND.is_unique,
                    [ColumnId] = IC.index_column_id,
                    [ColumnName] = COL.name,
                    [IsDescending] = IC.is_descending_key
                FROM 
                     sys.indexes IND 
                INNER JOIN 
                     sys.index_columns IC 
	                 on IND.object_id = IC.object_id and IND.index_id = IC.index_id 
                INNER JOIN 
                     sys.columns COL 
	                 on IC.object_id = COL.object_id and IC.column_id = COL.column_id 
                INNER JOIN 
                     sys.tables T 
	                 on IND.object_id = T.object_id 
                INNER JOIN
	                 sys.schemas  SC 
	                 on T.schema_id = SC.schema_id
                WHERE
	                IND.is_primary_key = 0 
                    and SC.name = '{0}' 
	                and T.name = '{1}'
                ORDER BY 
                     SC.name, T.name, IND.name, IC.index_column_id;
                ",
                                       tableStructure.Schema, tableStructure.TableName);

            return(sql);
        }
Exemplo n.º 24
0
        public void CheckTryCreateSameCompoundIndex( )
        {
            DBStructure dbStructure = null;

            try
            {
                dbStructure = new DBStructure("", "AnotherDB");
                TableStructure tblPeople = dbStructure.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                tblPeople.CreateColumn("Name", ColumnType.String, true);
                tblPeople.CreateColumn("Age", ColumnType.Integer, true);
                tblPeople.SetCompoundIndex("Name", "Age");
                tblPeople.SetCompoundIndex("Name", "Age");
            }
            finally
            {
                if (dbStructure != null)
                {
                    dbStructure.Shutdown();
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Creates the table.
        /// </summary>
        /// <param name="tableStructure">The table structure.</param>
        /// <returns>Whole table</returns>
        private static definitionTable CreateTable(TableStructure tableStructure)
        {
            definitionTable       mamlTable  = new definitionTable();
            List <string>         headerRow  = tableStructure.HeaderRow;
            List <List <string> > listOfRows = tableStructure.TableRows;

            //Add header
            TableRowOrTableHeader[] tableWithHeader = new TableRowOrTableHeader[1];
            TableHeader             header          = new TableHeader();

            tableWithHeader[0]       = header;
            header.row               = new TableRow();
            header.row.RowEntryField = new rowEntry[headerRow.Count];
            for (int counter = 0; counter < headerRow.Count; counter++)
            {
                header.row.RowEntryField[counter]      = new rowEntry();
                header.row.RowEntryField[counter].para = headerRow[counter];
            }
            //Add rows
            mamlTable.headerOrRow    = new TableRowOrTableHeader[listOfRows.Count + 1];
            mamlTable.headerOrRow[0] = tableWithHeader[0];
            TableRow      tableRow;
            List <string> listOfRowFields;

            for (int p = 1; p <= listOfRows.Count; p++)
            {
                listOfRowFields          = listOfRows[p - 1];
                tableRow                 = new TableRow();
                mamlTable.headerOrRow[p] = tableRow;
                tableRow.RowEntryField   = new rowEntry[listOfRowFields.Count];
                for (int ix = 0; ix < listOfRowFields.Count; ix++)
                {
                    tableRow.RowEntryField[ix]      = new rowEntry();
                    tableRow.RowEntryField[ix].para = listOfRowFields[ix];
                }
            }
            return(mamlTable);
        }
Exemplo n.º 26
0
        private static Table CreateTable(TableStructure tab)
        {
            Table table = new Table();

            ConfigureTableProperties(table);
            TableRowOpenXML tr;
            TableCell       tc;

            //first row - title
            tr = new TableRowOpenXML();
            tc = new TableCell(new Paragraph(new Run(new Text(tab.Title))));
            TableCellProperties tcp      = new TableCellProperties();
            GridSpan            gridSpan = new GridSpan();

            gridSpan.Val = tab.HeaderRow.Count;
            tcp.Append(gridSpan);
            tc.Append(tcp);
            tr.Append(tc);
            table.Append(tr);
            //second row
            tr = new TableRowOpenXML();
            foreach (string celltab in tab.HeaderRow)
            {
                tr.Append(new TableCell(new Paragraph(new Run(new Text(celltab)))));
            }
            table.Append(tr);
            //rest of the table
            foreach (var tabrow in tab.TableRows)
            {
                tr = new TableRowOpenXML();
                foreach (string celltab in tabrow)
                {
                    tr.Append(new TableCell(new Paragraph(new Run(new Text(celltab)))));
                }
                table.Append(tr);
            }
            return(table);
        }
Exemplo n.º 27
0
 public void SetUp()
 {
     try
     {
         DBTest.RemoveDBFiles();
         DBStructure    database  = new DBStructure("", "MyPal", DatabaseMode.Create);
         TableStructure tblPeople = database.CreateTable("People");
         tblPeople.CreateColumn("Id", ColumnType.Integer, false);
         tblPeople.CreateColumn("Type", ColumnType.Integer, false);
         tblPeople.CreateColumn("Number", ColumnType.Integer, false);
         tblPeople.SetCompoundIndexWithValue("Type", "Id", "Number");
         tblPeople.SetCompoundIndex("Id", "Type");
         database.SaveStructure();
         database.Shutdown();
         database = new DBStructure("", "MyPal");
         database.LoadStructure(  );
         m_database = database.Database;
     }
     catch (Exception exc)
     {
         Assert.Fail(exc.Message);
     }
 }
Exemplo n.º 28
0
        public void CreateDefaultVariableTable()
        {
            AddVersion("1");
            var file = Versions[0].GetFile();
            var dbs  = DatabaseStructure.Load(file);
            var tbl  = new TableStructure();

            dbs.Tables.Add(tbl);
            tbl.FullName = new NameWithSchema("Variables");
            tbl._Columns.Add(new ColumnStructure {
                ColumnName = "Name", DataType = new DbTypeString {
                    Length = 50
                }
            });
            tbl._Columns.Add(new ColumnStructure {
                ColumnName = "Value", DataType = new DbTypeString {
                    Length = 250
                }
            });
            var pk = new PrimaryKey {
                Name = "PK_Variables"
            };

            pk.Columns.Add(new ColumnReference("Name"));
            tbl._Constraints.Add(pk);
            tbl.FixedData = new InMemoryTable(tbl);
            tbl.FixedData.Rows.Add(new ArrayDataRecord(tbl, new object[] { "dbversion", "0" }));
            dbs.Save(file);
            if (String.IsNullOrEmpty(m_props.GetVersionSql))
            {
                m_props.GetVersionSql = DEFAULT_GET_VERSION;
            }
            if (String.IsNullOrEmpty(m_props.SetVersionSql))
            {
                m_props.SetVersionSql = DEFAULT_SET_VERSION;
            }
        }
Exemplo n.º 29
0
        private void LoadIdentityColumns(TableStructure tbl)
        {
            var cols = GetCachedTableColumnsTable("mssql.identity_columns", LoadIdentityColumnsTable, tbl.FullName);

            if (cols == null)
            {
                return;
            }
            bool oldver = cols.Columns.IndexOf("increment_value") < 0;

            foreach (DataRow row in cols.Rows)
            {
                var col = (ColumnStructure)tbl.Columns[row.SafeString("COLUMN_NAME")];
                if (oldver)
                {
                    int colstat = row.SafeString("COLUMN_STAT").SafeIntParse();
                    if ((colstat & 1) != 0)
                    {
                        col.DataType.SetAutoincrement(true);
                        // this is neccessery for correctly set ms_sql attributes
                        col.DataType = m_dialect.GenericTypeToSpecific(col.DataType).ToGenericType();
                    }
                }
                else
                {
                    ISpecificType spec    = m_dialect.GenericTypeToSpecific(col.DataType);
                    var           autoinc = spec as IMsSqlAutoIncrement;
                    if (autoinc != null)
                    {
                        autoinc.IsIdentity        = true;
                        autoinc.IdentityIncrement = row.SafeString("increment_value").SafeIntParse();
                        autoinc.IdentitySeed      = row.SafeString("seed_value").SafeIntParse();
                        col.DataType = spec.ToGenericType();
                    }
                }
            }
        }
Exemplo n.º 30
0
        private static void SnapshotRows(SnapshotBuilder builder, TableStructure table, SqlDataReader reader, Dictionary <string, int> columnIndex)
        {
            while (reader.Read())
            {
                RowBuilder rowBuilder = null;
                foreach (var tableColumn in table.Columns)
                {
                    if (columnIndex == null)
                    {
                        columnIndex = LoadColumnIndex(reader);
                    }

                    if (columnIndex.TryGetValue(tableColumn.Name, out var currentIx))
                    {
                        if (rowBuilder == null)
                        {
                            rowBuilder = builder.AddNewRow(table.Name);
                        }

                        rowBuilder[tableColumn.Name] = reader[currentIx];
                    }
                }
            }
        }
Exemplo n.º 31
0
        protected override void LoadIndexes(TableStructure table)
        {
            base.LoadIndexes(table);

            TableAnalyser tad = new TableAnalyser();

            DataTable idxs = GetDbConn().GetSchema("Indexes");

            foreach (DataRow row in idxs.Rows)
            {
                TableAnalyser.Key key = new TableAnalyser.Key();
                if ((bool)row["PRIMARY_KEY"])
                {
                    continue;
                }
                key.tblname = row["TABLE_NAME"].ToString();
                key.keyname = row["INDEX_NAME"].ToString();
                key.keytype = "INDEX";
                tad.keys.Add(key);
            }

            DataTable idxcols = GetDbConn().GetSchema("IndexColumns");

            foreach (DataRow row in idxcols.Rows)
            {
                TableAnalyser.Col col = new TableAnalyser.Col();
                col.colname = row["COLUMN_NAME"].ToString();
                col.tblname = row["TABLE_NAME"].ToString();
                col.keyname = row["CONSTRAINT_NAME"].ToString();
                col.ordinal = row["ORDINAL_POSITION"].ToString();
                col.keytype = "INDEX";
                tad.cols.Add(col);
            }
            tad.SaveConstraints(table, this);
            table._Constraints.RemoveIf(cnt => cnt.Name != null && cnt.Name.StartsWith("sqlite_"));
        }
Exemplo n.º 32
0
		internal void recordState()
		{
			initialStr = new TableStructure();
			table.saveStructure(initialStr);
		}
Exemplo n.º 33
0
			public TableAccessCallback(ISessionImplementor session, TableStructure owner)
			{
				this.session = session;
				this.owner = owner;
			}