Пример #1
0
        public virtual void RecreateTable(ITableStructure oldTable, ITableStructure newTable)
        {
            if (oldTable.GroupId != newTable.GroupId)
            {
                throw new InternalError("DAE-00040 Recreate is not possible: oldTable.GroupId != newTable.GroupId");
            }
            var    columnMap = GetColumnMap(oldTable, newTable);
            int    id        = System.Threading.Interlocked.Increment(ref m_lastAlterTableId);
            string tmptable  = ConnTools.GenerateTempTableName(id);

            // remove constraints
            //DropConstraints(oldTable.GetReferencedFrom(), DropFlags.None);
            DropConstraints(oldTable.Constraints, DropFlags.None);

            RenameTable(oldTable.FullName, tmptable);

            TableStructure old = new TableStructure(oldTable);

            old.FullName = new NameWithSchema(oldTable.FullName.Schema, tmptable);

            CreateTable(newTable);

            var  idcol    = newTable.FindAutoIncrementColumn();
            bool hasident = idcol != null && columnMap[idcol.ColumnOrder] >= 0;

            if (hasident)
            {
                AllowIdentityInsert(newTable.FullName, true);
            }
            PutCmd("^insert ^into %f (%,i) select %,s ^from %f", newTable.FullName,
                   from c in newTable.Columns
                   where columnMap[c.ColumnOrder] >= 0
                   select c.ColumnName,
                   from dstindex in
                   (
                       from i in PyList.Range(newTable.Columns.Count)
                       where columnMap[i] >= 0
                       select i
                   )
                   let srcindex = columnMap[dstindex]
                                  select
                                      (srcindex < 0
                                      // srcindex < 0 should not occur thanks to filtering
                    ? Format("^null ^as %i", newTable.Columns[dstindex].ColumnName)
                    : Format("^%i ^as %i", old.Columns[srcindex].ColumnName, newTable.Columns[dstindex].ColumnName)),
                   old.FullName);
            if (hasident)
            {
                AllowIdentityInsert(newTable.FullName, false);
            }

            // newTable.Constraints are allready created
            //CreateConstraints(newTable.GetReferencedFrom());

            PutCmd("^drop ^table %i", tmptable);
        }
Пример #2
0
 public InMemoryTableOperation(ITableStructure table)
 {
     m_table      = new TableStructure(table);
     m_colIndexes = new List <int>(PyList.Range(m_table.Columns.Count));
 }