public Table MoveDefinition(string withoutIndex) { Table tn = new Table(dDatabase, true, Name, IsCached); for (int i = 0; i < ColumnCount; i++) { tn.AddColumn(GetColumn(i)); } // todo: there should be nothing special with the primary key! if (iVisibleColumns < iColumnCount) { tn.CreatePrimaryKey(); } else { tn.CreatePrimaryKey(PrimaryIndex.Columns[0]); } Index idx = null; while (true) { idx = GetNextIndex(idx); if (idx == null) { break; } if (withoutIndex != null && idx.Name.Equals(withoutIndex)) { continue; } if (idx == PrimaryIndex) { continue; } tn.CreateIndex(idx); } for (int i = 0; i < iConstraintCount; i++) { Constraint c = (Constraint)vConstraint[i]; c.ReplaceTable(this, tn); } tn.vConstraint = vConstraint; return(tn); }
public Table GetSystemTable(string name, Channel channel) { if (name.Equals("SYSTEM_PROCEDURES")) { Table t = CreateTable(name); t.AddColumn("PROCEDURE_" + META_CAT, ColumnType.VarChar); t.AddColumn("PROCEDURE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("PROCEDURE_NAME", ColumnType.VarChar); t.AddColumn("NUM_INPUT_PARAMS", ColumnType.Integer); t.AddColumn("NUM_OUTPUT_PARAMS", ColumnType.Integer); t.AddColumn("NUM_RESULT_SETS", ColumnType.Integer); t.AddColumn("REMARKS", ColumnType.VarChar); t.AddColumn("PROCEDURE_TYPE", ColumnType.SmallInt); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_PROCEDURECOLUMNS")) { Table t = CreateTable(name); t.AddColumn("PROCEDURE_" + META_CAT, ColumnType.VarChar); t.AddColumn("PROCEDURE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("PROCEDURE_NAME", ColumnType.VarChar); t.AddColumn("COLUMN_NAME", ColumnType.VarChar); t.AddColumn("COLUMN_TYPE", ColumnType.SmallInt); t.AddColumn("DATA_TYPE", ColumnType.SmallInt); t.AddColumn("TYPE_NAME", ColumnType.VarChar); t.AddColumn("PRECISION", ColumnType.Integer); t.AddColumn("LENGTH", ColumnType.Integer); t.AddColumn("SCALE", ColumnType.SmallInt); t.AddColumn("RADIX", ColumnType.SmallInt); t.AddColumn("NULLABLE", ColumnType.SmallInt); t.AddColumn("REMARKS", ColumnType.VarChar); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_TABLES")) { Table t = CreateTable(name); t.AddColumn("TABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("TABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("TABLE_NAME", ColumnType.VarChar); t.AddColumn("TABLE_TYPE", ColumnType.VarChar); t.AddColumn("REMARKS", ColumnType.VarChar); t.CreatePrimaryKey(); for (int i = 0; i < tTable.Count; i++) { Table table = (Table)tTable[i]; object[] o = t.NewRow; o[2] = table.Name; o[3] = "TABLE"; t.Insert(o, null); } return(t); } else if (name.Equals("SYSTEM_SCHEMAS")) { Table t = CreateTable(name); t.AddColumn("TABLE_" + META_SCHEM, ColumnType.VarChar); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_CATALOGS")) { Table t = CreateTable(name); t.AddColumn("TABLE_" + META_CAT, ColumnType.VarChar); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_DATABASES")) { Table t = CreateTable(name); t.AddColumn("DATABASE", ColumnType.VarChar); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_TABLETYPES")) { Table t = CreateTable(name); t.AddColumn("TABLE_TYPE", ColumnType.VarChar); t.CreatePrimaryKey(); object[] o = t.NewRow; o[0] = "TABLE"; t.Insert(o, null); return(t); } else if (name.Equals("SYSTEM_COLUMNS")) { Table t = CreateTable(name); t.AddColumn("TABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("TABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("TABLE_NAME", ColumnType.VarChar); t.AddColumn("COLUMN_NAME", ColumnType.VarChar); t.AddColumn("DATA_TYPE", ColumnType.SmallInt); t.AddColumn("TYPE_NAME", ColumnType.VarChar); t.AddColumn(META_COLUMN_SIZE, ColumnType.Integer); t.AddColumn(META_BUFFER_LENGTH, ColumnType.Integer); t.AddColumn(META_DECIMAL_DIGITS, ColumnType.Integer); t.AddColumn(META_NUM_PREC_RADIX, ColumnType.Integer); t.AddColumn("NULLABLE", ColumnType.Integer); t.AddColumn("REMARKS", ColumnType.VarChar); // Access and Intersolv do not return this fields t.AddColumn("COLUMN_DEF", ColumnType.VarChar); t.AddColumn("SQL_DATA_TYPE", ColumnType.VarChar); t.AddColumn("SQL_DATETIME_SUB", ColumnType.Integer); t.AddColumn("CHAR_OCTET_LENGTH", ColumnType.Integer); t.AddColumn("ORDINAL_POSITION", ColumnType.VarChar); t.AddColumn("IS_NULLABLE", ColumnType.VarChar); t.CreatePrimaryKey(); for (int i = 0; i < tTable.Count; i++) { Table table = (Table)tTable[i]; int columns = table.ColumnCount; for (int j = 0; j < columns; j++) { object[] o = t.NewRow; o[2] = table.Name; o[3] = table.GetColumnName(j); o[4] = table.GetColumnType(j); o[5] = Column.GetColumnTypeString(table.GetColumnType(j)); int nullable; if (table.GetColumnIsNullable(j)) { nullable = Convert.ToInt32(true); } else { nullable = Convert.ToInt32(false); } o[10] = nullable; if (table.IdentityColumn == j) { o[11] = "IDENTITY"; } t.Insert(o, null); } } return(t); } else if (name.Equals("SYSTEM_COLUMNPRIVILEGES")) { Table t = CreateTable(name); t.AddColumn("TABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("TABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("TABLE_NAME", ColumnType.VarChar); t.AddColumn("COLUMN_NAME", ColumnType.VarChar); t.AddColumn("GRANTOR", ColumnType.VarChar); t.AddColumn("GRANTEE", ColumnType.VarChar); t.AddColumn("PRIVILEGE", ColumnType.VarChar); t.AddColumn("IS_GRANTABLE", ColumnType.VarChar); t.CreatePrimaryKey(); /* * // todo: get correct info * for(int i=0;i<tTable.size();i++) { * Table table=(Table)tTable.elementAt(i); * int columns=table.ColumnCount; * for(int j=0;j<columns;j++) { * object o[]=t.NewRow; * o[2]=table.Name; * o[3]=table.getColumnName(j); * o[4]="sa"; * o[6]="FULL"; * o[7]="NO"; * t.insert(o,null); * } * } */ return(t); } else if (name.Equals("SYSTEM_TABLEPRIVILEGES")) { Table t = CreateTable(name); t.AddColumn("TABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("TABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("TABLE_NAME", ColumnType.VarChar); t.AddColumn("GRANTOR", ColumnType.VarChar); t.AddColumn("GRANTEE", ColumnType.VarChar); t.AddColumn("PRIVILEGE", ColumnType.VarChar); t.AddColumn("IS_GRANTABLE", ColumnType.VarChar); t.CreatePrimaryKey(); for (int i = 0; i < tTable.Count; i++) { Table table = (Table)tTable[i]; object[] o = t.NewRow; o[2] = table.Name; o[3] = "sa"; o[5] = "FULL"; t.Insert(o, null); } return(t); } else if (name.Equals("SYSTEM_BESTROWIDENTIFIER")) { Table t = CreateTable(name); t.AddColumn("SCOPE", ColumnType.SmallInt); t.AddColumn("COLUMN_NAME", ColumnType.VarChar); t.AddColumn("DATA_TYPE", ColumnType.SmallInt); t.AddColumn("TYPE_NAME", ColumnType.VarChar); t.AddColumn(META_COLUMN_SIZE, ColumnType.Integer); t.AddColumn(META_BUFFER_LENGTH, ColumnType.Integer); t.AddColumn(META_DECIMAL_DIGITS, ColumnType.SmallInt); t.AddColumn("PSEUDO_COLUMN", ColumnType.SmallInt); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_VERSIONCOLUMNS")) { Table t = CreateTable(name); t.AddColumn("SCOPE", ColumnType.Integer); t.AddColumn("COLUMN_NAME", ColumnType.VarChar); t.AddColumn("DATA_TYPE", ColumnType.SmallInt); t.AddColumn("TYPE_NAME", ColumnType.VarChar); t.AddColumn(META_COLUMN_SIZE, ColumnType.SmallInt); t.AddColumn(META_BUFFER_LENGTH, ColumnType.Integer); t.AddColumn(META_DECIMAL_DIGITS, ColumnType.SmallInt); t.AddColumn("PSEUDO_COLUMN", ColumnType.SmallInt); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_PRIMARYKEYS")) { Table t = CreateTable(name); t.AddColumn("TABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("TABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("TABLE_NAME", ColumnType.VarChar); t.AddColumn("COLUMN_NAME", ColumnType.VarChar); t.AddColumn("KEY_SEQ", ColumnType.SmallInt); t.AddColumn("PK_NAME", ColumnType.VarChar); t.CreatePrimaryKey(); for (int i = 0; i < tTable.Count; i++) { Table table = (Table)tTable[i]; Index index = table.GetIndex("SYSTEM_PK"); int[] cols = index.Columns; int len = cols.Length; for (int j = 0; j < len; j++) { object[] o = t.NewRow; o[2] = table.Name; o[3] = table.GetColumnName(cols[j]); o[4] = j + 1; o[5] = "SYSTEM_PK"; t.Insert(o, null); } } return(t); } else if (name.Equals("SYSTEM_IMPORTEDKEYS")) { Table t = CreateTable(name); t.AddColumn("PKTABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("PKTABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("PKTABLE_NAME", ColumnType.VarChar); t.AddColumn("PKCOLUMN_NAME", ColumnType.VarChar); t.AddColumn("FKTABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("FKTABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("FKTABLE_NAME", ColumnType.VarChar); t.AddColumn("FKCOLUMN_NAME", ColumnType.VarChar); t.AddColumn("KEY_SEQ", ColumnType.SmallInt); t.AddColumn("UPDATE_RULE", ColumnType.SmallInt); t.AddColumn("DELETE_RULE", ColumnType.SmallInt); t.AddColumn("FK_NAME", ColumnType.VarChar); t.AddColumn("PK_NAME", ColumnType.VarChar); t.AddColumn("DEFERRABILITY", ColumnType.SmallInt); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_EXPORTEDKEYS")) { Table t = CreateTable(name); t.AddColumn("PKTABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("PKTABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("PKTABLE_NAME", ColumnType.VarChar); t.AddColumn("PKCOLUMN_NAME", ColumnType.VarChar); t.AddColumn("FKTABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("FKTABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("FKTABLE_NAME", ColumnType.VarChar); t.AddColumn("FKCOLUMN_NAME", ColumnType.VarChar); t.AddColumn("KEY_SEQ", ColumnType.SmallInt); t.AddColumn("UPDATE_RULE", ColumnType.SmallInt); t.AddColumn("DELETE_RULE", ColumnType.SmallInt); t.AddColumn("FK_NAME", ColumnType.VarChar); t.AddColumn("PK_NAME", ColumnType.VarChar); t.AddColumn("DEFERRABILITY", ColumnType.SmallInt); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_CROSSREFERENCE")) { Table t = CreateTable(name); t.AddColumn("PKTABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("PKTABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("PKTABLE_NAME", ColumnType.VarChar); t.AddColumn("PKCOLUMN_NAME", ColumnType.VarChar); t.AddColumn("FKTABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("FKTABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("FKTABLE_NAME", ColumnType.VarChar); t.AddColumn("FKCOLUMN_NAME", ColumnType.VarChar); t.AddColumn("KEY_SEQ", ColumnType.Integer); t.AddColumn("UPDATE_RULE", ColumnType.SmallInt); t.AddColumn("DELETE_RULE", ColumnType.SmallInt); t.AddColumn("FK_NAME", ColumnType.VarChar); t.AddColumn("PK_NAME", ColumnType.VarChar); t.AddColumn("DEFERRABILITY", ColumnType.SmallInt); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_TYPEINFO")) { Table t = CreateTable(name); t.AddColumn("TYPE_NAME", ColumnType.VarChar); t.AddColumn("DATA_TYPE", ColumnType.SmallInt); t.AddColumn("PRECISION", ColumnType.Integer); t.AddColumn("LITERAL_PREFIX", ColumnType.VarChar); t.AddColumn("LITERAL_SUFFIX", ColumnType.VarChar); t.AddColumn("CREATE_PARAMS", ColumnType.VarChar); t.AddColumn("NULLABLE", ColumnType.SmallInt); t.AddColumn("CASE_SENSITIVE", ColumnType.VarChar); t.AddColumn("SEARCHABLE", ColumnType.SmallInt); t.AddColumn("UNSIGNED_ATTRIBUTE", ColumnType.Bit); t.AddColumn(META_FIXED_PREC_SCALE, ColumnType.Bit); t.AddColumn("AUTO_INCREMENT", ColumnType.Bit); t.AddColumn("LOCAL_TYPE_NAME", ColumnType.VarChar); t.AddColumn("MINIMUM_SCALE", ColumnType.SmallInt); t.AddColumn("MAXIMUM_SCALE", ColumnType.SmallInt); // this columns are not supported by Access and Intersolv t.AddColumn("SQL_DATE_TYPE", ColumnType.Integer); t.AddColumn("SQL_DATETIME_SUB", ColumnType.Integer); t.AddColumn("NUM_PREC_RADIX", ColumnType.Integer); t.CreatePrimaryKey(); for (int i = 0; i < Column.Types.Length; i++) { object[] o = t.NewRow; ColumnType type = Column.Types[i]; o[0] = Column.GetColumnTypeString(type); o[1] = type; o[2] = 0; // precision o[6] = true; // need Column to track nullable for this o[7] = true; // case sensitive o[8] = true;; o[9] = false; // unsigned o[10] = (type == ColumnType.Numeric || type == ColumnType.DbDecimal); o[11] = (type == ColumnType.Integer); o[12] = o[0]; o[13] = 0; o[14] = 0; // maximum scale o[15] = 0; o[16] = o[15]; o[17] = 10; t.Insert(o, null); } return(t); } else if (name.Equals("SYSTEM_INDEXINFO")) { Table t = CreateTable(name); t.AddColumn("TABLE_" + META_CAT, ColumnType.VarChar); t.AddColumn("TABLE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("TABLE_NAME", ColumnType.VarChar); t.AddColumn("NON_UNIQUE", ColumnType.Bit); t.AddColumn("INDEX_QUALIFIER", ColumnType.VarChar); t.AddColumn("INDEX_NAME", ColumnType.VarChar); t.AddColumn("TYPE", ColumnType.SmallInt); t.AddColumn(META_ORDINAL_POSITON, ColumnType.SmallInt); t.AddColumn("COLUMN_NAME", ColumnType.VarChar); t.AddColumn(META_ASC_OR_DESC, ColumnType.VarChar); t.AddColumn("CARDINALITY", ColumnType.Integer); t.AddColumn("PAGES", ColumnType.Integer); t.AddColumn("FILTER_CONDITION", ColumnType.VarChar); t.CreatePrimaryKey(); for (int i = 0; i < tTable.Count; i++) { Table table = (Table)tTable[i]; Index index = null; while (true) { index = table.GetNextIndex(index); if (index == null) { break; } int[] cols = index.Columns; int len = cols.Length; // this removes the column that makes every index unique if (!index.IsUnique) { len--; } for (int j = 0; j < len; j++) { object[] o = t.NewRow; o[2] = table.Name; o[3] = !index.IsUnique; o[5] = index.Name; o[6] = 1; o[7] = (j + 1); o[8] = table.GetColumnName(cols[j]); o[9] = "A"; t.Insert(o, null); } } } return(t); } else if (name.Equals("SYSTEM_UDTS")) { Table t = CreateTable(name); t.AddColumn("TYPE_" + META_CAT, ColumnType.VarChar); t.AddColumn("TYPE_" + META_SCHEM, ColumnType.VarChar); t.AddColumn("TYPE_NAME", ColumnType.VarChar); t.AddColumn("CLASS_NAME", ColumnType.Bit); t.AddColumn("DATA_TYPE", ColumnType.VarChar); t.AddColumn("REMARKS", ColumnType.VarChar); t.CreatePrimaryKey(); return(t); } else if (name.Equals("SYSTEM_CONNECTIONINFO")) { Table t = CreateTable(name); t.AddColumn("KEY", ColumnType.VarChar); t.AddColumn("VALUE", ColumnType.VarChar); t.CreatePrimaryKey(); object[] o = t.NewRow; o[0] = "USER"; o[1] = channel.UserName; t.Insert(o, null); o = t.NewRow; o[0] = "READONLY"; o[1] = channel.IsReadOnly ? "TRUE" : "FALSE"; t.Insert(o, null); o = t.NewRow; o[0] = "MAXROWS"; o[1] = "" + channel.MaxRows; t.Insert(o, null); o = t.NewRow; o[0] = "DATABASE"; o[1] = "" + channel.Database.Name; t.Insert(o, null); o = t.NewRow; o[0] = "IDENTITY"; o[1] = "" + channel.LastIdentity; t.Insert(o, null); return(t); } else if (name.Equals("SYSTEM_USERS")) { Table t = CreateTable(name); t.AddColumn("USER", ColumnType.VarChar); t.AddColumn("ADMIN", ColumnType.Bit); t.CreatePrimaryKey(); ArrayList v = aAccess.GetUsers(); for (int i = 0; i < v.Count; i++) { User u = (User)v[i]; // todo: this is not a nice implementation if (u == null) { continue; } string user = u.Name; if (!user.Equals("PUBLIC")) { object[] o = t.NewRow; o[0] = user; o[1] = u.IsAdmin; t.Insert(o, null); } } return(t); } return(null); }
public Table MoveDefinition(string withoutIndex) { Table tn = new Table(dDatabase, true, Name, IsCached); for (int i = 0; i < ColumnCount; i++) { tn.AddColumn(GetColumn(i)); } // todo: there should be nothing special with the primary key! if (iVisibleColumns < iColumnCount) { tn.CreatePrimaryKey(); } else { tn.CreatePrimaryKey(PrimaryIndex.Columns[0]); } Index idx = null; while (true) { idx = GetNextIndex(idx); if (idx == null) { break; } if (withoutIndex != null && idx.Name.Equals(withoutIndex)) { continue; } if (idx == PrimaryIndex) { continue; } tn.CreateIndex(idx); } for (int i = 0; i < iConstraintCount; i++) { Constraint c = (Constraint) vConstraint[i]; c.ReplaceTable(this, tn); } tn.vConstraint = vConstraint; return tn; }
/// <summary> /// Process ALTER TABLE statements. /// /// ALTER TABLE tableName ADD COLUMN columnName columnType; /// ALTER TABLE tableName DELETE COLUMN columnName; /// </summary> /// <remarks> /// The only change I've made to Sergio's original code was /// changing the insert's to call insertNoCheck to bypass the trigger /// mechanism that is a part of hsqldb 1.60 and beyond. - Mark Tutt /// </remarks> /// <returns></returns> public Result ProcessAlter() { tTokenizer.GetThis ("TABLE"); string token = tTokenizer.GetString (); cChannel.CheckReadWrite (); // cChannel.check(token,Access.ALTER); --> Accessul nu-l inca controleaza... string tName = token; string swap = tName + "SWAP"; // nimicirea swapului... dDatabase.Execute ("DROP TABLE " + swap, cChannel); Table initialTable = dDatabase.GetTable (token, cChannel); int count = 0; token = tTokenizer.GetString (); if (token.Equals ("ADD")) { token = tTokenizer.GetString (); if (token.Equals ("COLUMN")) { Table swapTable = new Table (dDatabase, true, swap, initialTable.IsCached); // copiem coloanele (fara date) din tabelul initial in swap for (int i = 0; i < initialTable.ColumnCount; i++) { Column aColumn = initialTable.GetColumn (i); swapTable.AddColumn (aColumn); } // end Of copiem coloanele... // aflam daca are PrimaryKey & o cream... string cName = tTokenizer.GetString (); string cType = tTokenizer.GetString (); ColumnType iType = Column.GetColumnType (cType); string sToken = cType; // int primarykeycolumn = -1; bool identity = false; int column = initialTable.ColumnCount + 1; // !-- // stolen from CREATE TABLE... string sColumn = cName; if (iType == ColumnType.VarChar && dDatabase.IsIgnoreCase) { iType = ColumnType.VarCharIgnoreCase; } sToken = tTokenizer.GetString (); if (iType == ColumnType.DbDouble && sToken.Equals ("PRECISION")) { sToken = tTokenizer.GetString (); } if (sToken.Equals ("(")) { // overread length do { sToken = tTokenizer.GetString (); } while (!sToken.Equals (")")); sToken = tTokenizer.GetString (); } // !-- bool nullable = true; if (sToken.Equals ("NULL")) { sToken = tTokenizer.GetString (); } else if (sToken.Equals ("NOT")) { tTokenizer.GetThis ("NULL"); nullable = false; sToken = tTokenizer.GetString (); } /* * if(sToken.Equals("IDENTITY")) { * identity=true; * Trace.check(primarykeycolumn==-1,Trace.SECOND_PRIMARY_KEY,sColumn); * sToken=tTokenizer.getstring(); * primarykeycolumn=column; * } * * if(sToken.Equals("PRIMARY")) { * tTokenizer.getThis("KEY"); * Trace.check(identity || primarykeycolumn==-1, * Trace.SECOND_PRIMARY_KEY,sColumn); * primarykeycolumn=column; * //sToken=tTokenizer.getstring(); * } * //end of STOLEN... */ swapTable.AddColumn (cName, iType, nullable, identity); // under construction... if (initialTable.ColumnCount < initialTable.InternalColumnCount) { swapTable.CreatePrimaryKey (); } else { swapTable.CreatePrimaryKey (initialTable.PrimaryIndex.Columns [0]); } // endof PrimaryKey... // sa ne farimam cu indicii... ;-(( Index idx = null; while (true) { idx = initialTable.GetNextIndex (idx); if (idx == null) { break; } if (idx == initialTable.PrimaryIndex) { continue; } swapTable.CreateIndex (idx); } // end of Index... cChannel.Commit (); dDatabase.LinkTable (swapTable); Tokenizer tmpTokenizer = new Tokenizer ("SELECT * FROM " + tName); Parser pp = new Parser (dDatabase, tmpTokenizer, cChannel); string ff = tmpTokenizer.GetString (); if (!initialTable.IsEmpty) { Record n = ((Result)pp.ProcessSelect ()).Root; do { object[] row = swapTable.NewRow; object[] row1 = n.Data; for (int i = 0; i < initialTable.ColumnCount; i++) { row [i] = row1 [i]; } swapTable.InsertNoCheck (row, cChannel); n = n.Next; } while (n != null); } dDatabase.Execute ("DROP TABLE " + tName, cChannel); // cream tabelul vechi cu proprietatile celui nou... initialTable = new Table (dDatabase, true, tName, swapTable.IsCached); for (int i = 0; i < swapTable.ColumnCount; i++) { Column aColumn = swapTable.GetColumn (i); initialTable.AddColumn (aColumn); } if (swapTable.ColumnCount < swapTable.InternalColumnCount) { initialTable.CreatePrimaryKey (); } else { initialTable.CreatePrimaryKey (swapTable.PrimaryIndex.Columns [0]); } // endof PrimaryKey... // sa ne farimam cu indicii... ;-(( idx = null; while (true) { idx = swapTable.GetNextIndex (idx); if (idx == null) { break; } if (idx == swapTable.PrimaryIndex) { continue; } initialTable.CreateIndex (idx); } // end of Index... cChannel.Commit (); dDatabase.LinkTable (initialTable); // end of cream... // copiem datele din swap in tabel... tmpTokenizer = new Tokenizer ("SELECT * FROM " + swap); pp = new Parser (dDatabase, tmpTokenizer, cChannel); ff = tmpTokenizer.GetString (); if (!swapTable.IsEmpty) { Record n = ((Result)pp.ProcessSelect ()).Root; do { object[] row = initialTable.NewRow; object[] row1 = n.Data; for (int i = 0; i < swapTable.ColumnCount; i++) { row [i] = row1 [i]; } initialTable.InsertNoCheck (row, cChannel); n = n.Next; } while (n != null); // end of copiem... } dDatabase.Execute ("DROP TABLE " + swap, cChannel); count = 4; } else { throw TracingHelper.Error (TracingHelper.UnexpectedToken, token); } } else if (token.Equals ("DELETE")) { token = tTokenizer.GetString (); if (token.Equals ("COLUMN")) { Table swapTable = new Table (dDatabase, true, swap, initialTable.IsCached); string cName = tTokenizer.GetString (); int undesired = initialTable.GetColumnNumber (cName); for (int i = 0; i < initialTable.ColumnCount; i++) { Column aColumn = initialTable.GetColumn (i); if (i != undesired) { swapTable.AddColumn (aColumn); } } int pKey = -1; // !-- if (initialTable.ColumnCount < initialTable.InternalColumnCount) { swapTable.CreatePrimaryKey (); } else { int[] cols = initialTable.PrimaryIndex.Columns; pKey = cols [0]; if ((cols [0] > undesired) || (cols [0] + cols.Length < undesired)) { if (undesired < initialTable.PrimaryIndex.Columns [0]) { // reindexarea... for (int i = 0; i < cols.Length; i++) { cols [i]--; } // endOf reindexarea... } // MT: This initially wouldn't compile, missing the array index on cols[] swapTable.CreatePrimaryKey (cols [0]); } else { swapTable.CreatePrimaryKey (); } } // endof PrimaryKey... // sa ne farimam cu indicii... ;-(( Index idx = null; while (true) { idx = initialTable.GetNextIndex (idx); if (idx == null) { break; } if (idx == initialTable.PrimaryIndex) { continue; } bool flag = true; int[] cols = idx.Columns; for (int i = 0; i < cols.Length; i++) { if (cols [i] == undesired) { flag = false; } } if (flag) { Index tIdx; for (int i = 0; i < cols.Length; i++) { if (cols [i] > undesired) { cols [i]--; } } tIdx = new Index (idx.Name, idx.Columns, idx.ColumnType, idx.IsUnique); swapTable.CreateIndex (tIdx); } } // !-- cChannel.Commit (); dDatabase.LinkTable (swapTable); Tokenizer tmpTokenizer = new Tokenizer ("SELECT * FROM " + tName); Parser pp = new Parser (dDatabase, tmpTokenizer, cChannel); string ff = tmpTokenizer.GetString (); if (!initialTable.IsEmpty) { Record n = ((Result)pp.ProcessSelect ()).Root; do { object[] row = swapTable.NewRow; object[] row1 = n.Data; int j = 0; for (int i = 0; i < initialTable.ColumnCount; i++) { if (i != undesired) { row [j] = row1 [i]; j++; } } swapTable.InsertNoCheck (row, cChannel); n = n.Next; } while (n != null); } dDatabase.Execute ("DROP TABLE " + tName, cChannel); // cream tabelul vechi cu proprietatile celui nou... initialTable = new Table (dDatabase, true, tName, swapTable.IsCached); for (int i = 0; i < swapTable.ColumnCount; i++) { Column aColumn = swapTable.GetColumn (i); initialTable.AddColumn (aColumn); } // !-- if (swapTable.ColumnCount < swapTable.InternalColumnCount) { initialTable.CreatePrimaryKey (); } else { initialTable.CreatePrimaryKey (swapTable.PrimaryIndex.Columns [0]); } // endof PrimaryKey... // sa ne farimam cu indicii... ;-(( idx = null; while (true) { idx = swapTable.GetNextIndex (idx); if (idx == null) { break; } if (idx == swapTable.PrimaryIndex) { continue; } initialTable.CreateIndex (idx); } // end of Index... // !-- cChannel.Commit (); dDatabase.LinkTable (initialTable); // end of cream... // copiem datele din swap in tabel... tmpTokenizer = new Tokenizer ("SELECT * FROM " + swap); pp = new Parser (dDatabase, tmpTokenizer, cChannel); ff = tmpTokenizer.GetString (); if (!swapTable.IsEmpty) { Record n = ((Result)pp.ProcessSelect ()).Root; do { object[] row = initialTable.NewRow; object[] row1 = n.Data; for (int i = 0; i < swapTable.ColumnCount; i++) { row [i] = row1 [i]; } initialTable.InsertNoCheck (row, cChannel); n = n.Next; } while (n != null); // end of copiem... } dDatabase.Execute ("DROP TABLE " + swap, cChannel); count = 3; } else { throw TracingHelper.Error (TracingHelper.UnexpectedToken, token); } count = 3; } Result r = new Result (); r.SetUpdateCount (count); return r; }
public Result ProcessSelect() { Select select = ParseSelect (); if (select.sIntoTable == null) { // [email protected] begin changes from 1.50 // return select.getResult(cChannel.getMaxRows()); return select.GetResult (select.limitStart, select.limitCount, cChannel); // [email protected] end changes from 1.50 } else { Result r = select.GetResult (0, cChannel); Table t = new Table (dDatabase, true, select.sIntoTable, false); t.AddColumns (r); t.CreatePrimaryKey (); // SELECT .. INTO can't fail because of violation of primary key t.Insert (r, cChannel); dDatabase.LinkTable (t); int i = r.Size; r = new Result (); r.SetUpdateCount (i); return r; } }
private TableFilter ParseTableFilter(bool outerjoin) { string token = tTokenizer.GetString (); Table t = null; if (token.Equals ("(")) { tTokenizer.GetThis ("SELECT"); Select s = ParseSelect (); Result r = s.GetResult (0, null); // it's not a problem that this table has not a unique name t = new Table (dDatabase, false, "SYSTEM_SUBQUERY", false); tTokenizer.GetThis (")"); t.AddColumns (r); t.CreatePrimaryKey (); // subquery creation can't fail because of violation of primary key t.Insert (r, cChannel); } else { cChannel.Check (token, AccessType.Select); t = dDatabase.GetTable (token, cChannel); } string sAlias = null; token = tTokenizer.GetString (); if (token.Equals ("AS")) { sAlias = tTokenizer.GetName (); } else if (tTokenizer.WasName) { sAlias = token; } else { tTokenizer.Back (); } return new TableFilter (t, sAlias, outerjoin); }