Ejemplo n.º 1
0
        private DataTable BuildDataTableDefinition(TableDescriptor table)
        {
            var dataTable = new DataTable();
            foreach (var col in table.Columns)
            {
                dataTable.Columns.Add(new DataColumn(col.Name.GetName()));
            }

            dataTable.AcceptChanges();

            dataTable.RowChanged += (sender, args) =>
            {
                dataTable.ExtendedProperties["Changed"] = true;
            };

            dataTable.TableNewRow += (sender, args) =>
            {
                dataTable.ExtendedProperties["Changed"] = true;
            };

            dataTable.RowDeleting += (sender, args) =>
            {
                dataTable.ExtendedProperties["Changed"] = true;
            };

            return dataTable;
        }
Ejemplo n.º 2
0
 public void uses_sets_identity_on_identity_columns()
 {
     var table = _model.GetObject<TSqlTable>(new ObjectIdentifier("dbo", "TheTable"), DacQueryScopes.UserDefined);
     Assert.IsNotNull(table);
     var descriptor = new TableDescriptor(table);
     Assert.IsTrue(descriptor.Columns.First().IsIdentity);
     Assert.IsFalse(descriptor.Columns.Last().IsIdentity);
 }
Ejemplo n.º 3
0
        public void uses_correct_literal_type()
        {
            var table = _model.GetObject<TSqlTable>(new ObjectIdentifier("dbo", "TheTable"), DacQueryScopes.UserDefined);
            Assert.IsNotNull(table);
            var descriptor = new TableDescriptor(table);
            Assert.AreEqual(LiteralType.Integer, descriptor.Columns.First().DataType);

        }
Ejemplo n.º 4
0
 public void gets_table_name()
 {
     var table = _model.GetObject<TSqlTable>(new ObjectIdentifier("dbo", "TheTable"), DacQueryScopes.UserDefined);
     Assert.IsNotNull(table);
     var descriptor = new TableDescriptor(table);
     Assert.AreEqual("dbo", descriptor.Name.GetSchema());
     Assert.AreEqual("TheTable", descriptor.Name.GetName());
     
 }
Ejemplo n.º 5
0
        public MergeDescriptor.Merge Build(TableDescriptor table, string scriptFile, DataTable data = null)
        {
            
            var merge = new MergeDescriptor.Merge();
            merge.Name = table.Name.ToIdentifier();

            if(data == null)
                merge.Data = BuildDataTableDefinition( table);
            else
            {
                merge.Data = data;
            }
            merge.ScriptDescriptor = new InScriptDescriptor(0,0, scriptFile);
            merge.Statement = new MergeStatement();
            merge.Table = table;

           

            merge.Data.AcceptChanges();

            merge.Option = new MergeOptions(true, true, true, merge.Table.Columns.Any(p=>p.IsKey));
            return merge;
        }
Ejemplo n.º 6
0
        private DataTable GetDataFromMerge(MergeStatement mergeStatement, TableDescriptor table)
        {
            var dataTable = new DataTable();
            foreach (var col in table.Columns)
            {
                dataTable.Columns.Add(new DataColumn(col.Name.GetName()));
            }

            var inlineTable = mergeStatement.MergeSpecification.TableReference as InlineDerivedTable;

            foreach (var row in inlineTable.RowValues)
            {
                var dataTableRow = dataTable.NewRow();
                var index = 0;
                foreach (var col in row.ColumnValues)
                {
                    if (col as NullLiteral != null)
                    {
                        dataTableRow[index++] = DBNull.Value;
                    }
                    else
                    {
                        var value = col as Literal;

                        if (value == null)
                        {
                            Log.WriteInfo("Error Parsing Merge Statement, Could not convert column to Literal: {0}", col);
                            MessageBox.Show("Error we expected to get a literal parsing a merge statement for the " +
                                            table.Name.GetName() + " table but we got a " + col.ToString()
                                            +
                                            "\r\nCheck that you don't have an unquoted string or another impossible type");
                            return null;
                        }

                        dataTableRow[index++] = value.Value;
                    }
                }

                dataTable.Rows.Add(dataTableRow);
            }

            dataTable.AcceptChanges();
           
            dataTable.RowChanged += (sender, args) =>
            {
                dataTable.ExtendedProperties["Changed"] = true;
            };

            dataTable.TableNewRow += (sender, args) =>
            {
                dataTable.ExtendedProperties["Changed"] = true;
            };

            dataTable.RowDeleting += (sender, args) =>
            {
                dataTable.ExtendedProperties["Changed"] = true;
            };

            return dataTable;
        }