public static void SaveToXml(ITableStructure table, IEnumerable records, XmlWriter xw) { List <string> ids = new List <string>(); foreach (IColumnStructure col in table.Columns) { ids.Add(XmlTool.NormalizeIdentifier(col.ColumnName)); } foreach (IBedRecord rec in records) { xw.WriteStartElement("Row"); for (int i = 0; i < rec.FieldCount; i++) { rec.ReadValue(i); string xdata = "", xtype = ""; if (!GetValueAsXml(rec, ref xtype, ref xdata)) { continue; } xw.WriteStartElement(ids[i]); xw.WriteAttributeString("t", xtype); xw.WriteString(xdata); xw.WriteEndElement(); } xw.WriteEndElement(); } }
public static IColumnStructure FindAutoIncrementColumn(this ITableStructure table) { if (table == null || table.Columns == null) { return(null); } foreach (IColumnStructure col in table.Columns) { if (col.DataType is DbTypeInt) { if (((DbTypeInt)col.DataType).Autoincrement) { return(col); } } if (col.DataType is DbTypeNumeric) { if (((DbTypeNumeric)col.DataType).Autoincrement) { return(col); } } } return(null); }
public void GenerateCreateTable(ITableStructure ts, ISqlDumper dmp) { var tbl = new TableStructure(ts); RemoveUnwantedTableFeature(tbl); dmp.CreateTable(tbl); }
public static void GenerateInsertFixedData(ITableSource table, TextWriter tw, ISqlDialect dialect) { ITableStructure ts = table.LoadTableStructure(TableStructureMembers.All); ISqlDumper dmp = dialect.CreateDumper(tw); GenerateInsertFixedData(dmp, ts); }
public void SetBindings(ITabularDataStore source, ITabularDataStore target) { Async.SafeOpen(source.Connection); Async.SafeOpen(target.Connection); //lbsource.Enabled = false; //lbtarget.Enabled = false; lbsource.Items.Clear(); lbtarget.Rows.Clear(); //lbtarget.Items.Clear(); Errors.Assert(source.AvailableRowFormat); //Async.CreateInvokeCallback(m_invoker, GotRowFormat)); m_source = source; m_target = target; //lbsource.Enabled = true; //lbtarget.Enabled = true; try { IAsyncResult async = m_source.BeginGetRowFormat(null); Async.WaitFor(async); m_srcformat = m_source.EndGetRowFormat(async); } catch (Exception err) { throw new BulkCopyInputError("DAE-00184", err); } foreach (IColumnStructure col in m_srcformat.Columns) { lbsource.Items.Add(col.ColumnName); lbtarget.Rows.Add(col.ColumnName, new GenericTransform.ColumnColExprType().ToString(), col.ColumnName); //lbtarget.Items.Add(col.ColumnName); } }
public override void LoadFromXml(XmlElement xml, ITableStructure source, ITableStructure target) { m_source = source; m_target = target; if (xml.SelectSingleNode("Script") != null) { m_script = xml.SelectSingleNode("Script").InnerText; } TableStructure t = new TableStructure(); foreach (XmlElement e in xml.SelectNodes("Column")) { ColExpr ce = ColExpr.Load(e); m_dstcols.Add(ce); t.AddColumn(new ColumnStructure { ColumnName = ce.Name, DataType = ce.GetColType(source) }, true); } m_target = t; UpdateFlags(); }
public void LoadFrom(ITableStructure table) { _Columns.Clear(); _Constraints.Clear(); //_ReferencedFrom.Clear(); FullName = table.FullName; Comment = table.Comment; //Name = table.FullName.Name; //SchemaName = table.FullName.Schema; foreach (IColumnStructure col in table.Columns) { _Columns.Add(new ColumnStructure(col)); } foreach (IConstraint cnt in table.Constraints) { _Constraints.Add(Constraint.CreateCopy(cnt)); } //foreach (IForeignKey fk in table.ReferencedFrom) //{ // _ReferencedFrom.Add(new ForeignKey(fk)); //} SpecificData.AddAll(table.SpecificData); FixedData = table.FixedData; //FilledMembers = table.FilledMembers; }
public void WriteEnd(System.IO.StreamWriter fw, ITableStructure table, object manager) { m_fmt.Writer = fw; m_fmt.EndTable(); m_fmt.EndFile(); m_fmt.Writer = null; }
public static DataTable SchemaFromStructure(this ITableStructure tableStruct) { DataTable schema = CreateEmptySchema(); int index = 1; foreach (IColumnStructure col in tableStruct.Columns) { DataRow row = schema.NewRow(); row[SchemaTableColumn.ColumnName] = col.ColumnName; row[SchemaTableColumn.ColumnOrdinal] = index; row[SchemaTableColumn.ColumnSize] = 0; row[SchemaTableColumn.NumericPrecision] = 0; row[SchemaTableColumn.NumericScale] = 0; row[SchemaTableColumn.DataType] = col.DataType.DotNetType; row[SchemaTableColumn.ProviderType] = (int)TypeTool.GetProviderType(col.DataType.DotNetType); row[SchemaTableColumn.IsLong] = false; row[SchemaTableColumn.AllowDBNull] = true; row[SchemaTableOptionalColumn.IsReadOnly] = false; row[SchemaTableOptionalColumn.IsRowVersion] = false; row[SchemaTableColumn.IsUnique] = false; row[SchemaTableColumn.IsKey] = false; row[SchemaTableOptionalColumn.IsAutoIncrement] = false; row[SchemaTableColumn.BaseSchemaName] = ""; row[SchemaTableOptionalColumn.BaseCatalogName] = ""; row[SchemaTableColumn.BaseTableName] = ""; row[SchemaTableColumn.BaseColumnName] = col.ColumnName; schema.Rows.Add(row); index++; } return(schema); }
public void WriteRecord(StreamWriter fw, ITableStructure table, IBedRecord record, int index, object manager) { var mgr = (Manager)manager; if (index > 0) { fw.Write(ProcessTemplate(RowSeparator)); } fw.Write(ProcessTemplate(RowBegin)); bool was = false; for (int i = 0; i < record.FieldCount; i++) { record.ReadValue(i); mgr.formatter.ReadFrom(record); if (was) { fw.Write(ProcessTemplate(CellSeparator)); } fw.Write(ProcessTemplate(CellBegin)); string val = XmlTool.ObjectToString(mgr.formatter.GetText()); fw.Write(ProcessTemplate(CellValue, "$[VALUE]", val, "$[NAME]", record.GetName(i))); fw.Write(ProcessTemplate(CellEnd)); was = true; } fw.Write(ProcessTemplate(RowEnd)); }
public override void WriteContent(string filename, IDatabaseSource db, Dictionary <string, string> vars, Dictionary <string, object> extnames) { var fw = DataStore as ITabularDataOuputStream; if (fw == null) { throw new InternalError(String.Format("DAE-00060 Cannot write data to {0}", DataStore)); } using (StreamWriter sw = new StreamWriter(filename)) { using (DbCommand cmd = db.Connection.SystemConnection.CreateCommand()) { cmd.CommandText = Sql.ReplaceAll(vars); using (IBedReader reader = db.GetAnyDDA().AdaptReader(cmd.ExecuteReader())) { ITableStructure table = reader.Structure; //Path.GetFileNameWithoutExtension(filename)); object manager = null; fw.WriteStart(sw, table, ref manager); int index = 0; while (reader.Read()) { fw.WriteRecord(sw, table, reader, index, manager); index++; } fw.WriteEnd(sw, table, manager); } } } }
public IRowTransform LoadRowTransform(XmlElement xml, ITableStructure source, ITableStructure target) { IRowTransform res = (IRowTransform)StaticSpace.FindHolder(xml.GetAttribute("type")).CreateInstance(); res.LoadFromXml(xml, source, target); return(res); }
public IRowTransform LoadRowTransform(string filename, ITableStructure source, ITableStructure target) { XmlDocument doc = new XmlDocument(); doc.Load(filename); return(LoadRowTransform(doc.DocumentElement, source, target)); }
public static DialogResult Run(TablePerspective per, ITableStructure table, IDatabaseSource db) { var win = new TablePerspectiveEditorForm(per, table, db); win.ShowDialogEx(); return(win.DialogResult); }
public TableStructure(ITableStructure table) : base(table) { Initialize(); LoadFrom(table); FilledMembers = TableStructureMembers.None; }
public static string[] GetPkColumnNames(this ITableStructure ts) { return((from c in ts.GetPkColumns() select c.ColumnName).ToArray()); //var pk = ts.FindConstraint<IPrimaryKey>(); //if (pk != null) return pk.Columns.GetNames(); //return new string[] { }; }
public static ReferenceViewDefinition Run(ITableStructure table, string activeColumn, List <string> availcols, ISqlDialect dialect) { var win = new SelectReferenceForm(table, activeColumn, availcols, dialect); win.ShowDialogEx(); return(win.m_result); }
//public static BedTable ToBinaryTable(this IDataReader reader, int? maximumRecords) //{ // ITableStructure ts = reader.GetTableStructure(null); // BedTable dt = new BedTable(ts); // int allow_recs = maximumRecords != null ? maximumRecords.Value : -1; // while (reader.Read() && (maximumRecords == null || allow_recs > 0)) // { // dt.AddRow(reader); // allow_recs--; // } // return dt; //} //public static BedTable ToBinaryTable(this IDataReader reader) //{ // return ToBinaryTable(reader, null); //} public static DataTable ToDataTable(this IDataReader reader, int?maximumRecords) { ITableStructure ts = reader.GetTableStructure(null); DataTable dt = ConnTools.DataTableFromStructure(ts); int allow_recs = maximumRecords != null ? maximumRecords.Value : -1; while (reader.Read() && (maximumRecords == null || allow_recs > 0)) { DataRow row = dt.NewRow(); for (int i = 0; i < ts.Columns.Count; i++) { try { row[i] = reader[i]; } catch (Exception) { row[i] = DBNull.Value; } } dt.Rows.Add(row); allow_recs--; } return(dt); }
public static IForeignKey RunFk(ITableStructure table, string activeColumn, ISqlDialect dialect) { var win = new SelectReferenceForm(table, activeColumn, null, dialect); win.ShowDialogEx(); return(win.m_resultFk); }
public GenericTransform(ITableStructure source, ITableStructure target, IEnumerable <ColExpr> dstcols) { m_source = source; m_target = target; m_dstcols.AddRange(dstcols); UpdateFlags(); }
protected override void DoRead(IDataQueue queue) { try { using (CsvReader cr = CreateReader()) { ITableStructure format = GetStructure(cr); IEnumerable <string[]> reader = cr; foreach (string[] row in reader) { queue.PutRecord(new ArrayDataRecord(format, row)); } queue.PutEof(); } } catch (Exception e) { ProgressInfo.LogError(e); queue.PutError(e); } finally { queue.CloseWriting(); } FinalizeBulkCopy(); }
public virtual void FillTable(ITableStructure table, IDataQueue queue, TableCopyOptions opts) { var colnames = from c in queue.GetRowFormat.Columns select c.ColumnName; bool autoinc = queue.GetRowFormat.FindAutoIncrementColumn() != null; if (autoinc) { m_dmp.AllowIdentityInsert(table.FullName, true); } try { while (!queue.IsEof) { IBedRecord row = queue.GetRecord(); m_dmp.PutCmd("^insert ^into %f (%,i) ^values (%,v)", table, colnames, row); } } finally { queue.CloseReading(); } if (autoinc) { m_dmp.AllowIdentityInsert(table.FullName, false); } }
public static bool EqualsColumnRefs(ITableStructure tsrc, ITableStructure tdst, List <IColumnReference> srcRefs, List <IColumnReference> dstRefs) { if (srcRefs.Count != dstRefs.Count) { return(false); } if (tsrc == null || tdst == null) { return(srcRefs.EqualSequence(dstRefs)); } for (int i = 0; i < srcRefs.Count; i++) { var scol = tsrc.Columns.FirstOrDefault(c => c.ColumnName == srcRefs[i].ColumnName); var dcol = tdst.Columns.FirstOrDefault(c => c.ColumnName == dstRefs[i].ColumnName); if (scol == null || dcol == null) { if (srcRefs[i].ColumnName != dstRefs[i].ColumnName) { return(false); } } else { if (scol.GroupId != dcol.GroupId) { return(false); } } } return(true); }
protected void DumpWhere(ITableStructure tbl, ISqlDumper dmp) { if (!GenerateWhere) { return; } dmp.Put("^where&>&n"); bool was = false; foreach (var col in tbl.Columns) { if (was) { dmp.Put("&n^and "); } if (UseWhereParameters) { dmp.Put("%i = '###%s###'", col.ColumnName, col.ColumnName); } else { dmp.Put("%i ^is ^null", col.ColumnName); } was = true; } dmp.Put("&<&n"); }
public static List <IForeignKey> GetReferencedFrom(this ITableStructure table) { var res = new List <IForeignKey>(); if (table.Database == null) { return(res); } foreach (var tbl in table.Database.Tables) { foreach (var cnt in tbl.Constraints) { var fk = cnt as IForeignKey; if (fk == null) { continue; } if (fk.PrimaryKeyTable == table.FullName) { res.Add(fk); } } } return(res); }
private void SaveCurrentCell() { if (m_table == null || dataGridView1.CurrentCell == null || m_programaticallySelectCell) { return; } try { DataState.CurrentCol = dataGridView1.CurrentCell.ColumnIndex; ITableStructure ts = CGetStructure(null); if (ts == null || ts.PrimaryKeyColumnName() == null || dataGridView1.CurrentCell.Value == null) { DataState.CurrentRow = dataGridView1.CurrentCell.RowIndex; DataState.SavedPkCol = null; } else { DataState.CurrentRow = -1; DataState.SavedPkCol = ts.PrimaryKeyColumnName(); DataState.SavedPkValue = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[DataState.SavedPkCol].Value; } DataState.SavedCurrentCell = true; } catch { } }
protected static string[] GetColumns(DataSqlGeneratorColumnSet colset, ITableStructure ts, string[] selcolumns) { switch (colset.Mode) { case DataSqlGeneratorColumnSet.ModeEnum.AllColumns: return(ts.Columns.GetNames()); case DataSqlGeneratorColumnSet.ModeEnum.ExplicitColumns: return(colset.Columns.ToArray()); case DataSqlGeneratorColumnSet.ModeEnum.NoPkCols: return(ts.GetNoPkColumnNames()); case DataSqlGeneratorColumnSet.ModeEnum.PrimaryKey: return(ts.GetPkColumnNames()); case DataSqlGeneratorColumnSet.ModeEnum.SelectedColumns: return(selcolumns); case DataSqlGeneratorColumnSet.ModeEnum.NoSelectedColumns: { var res = new List <string>(); foreach (string col in ts.Columns.GetNames()) { if (Array.IndexOf(selcolumns, col) <= 0) { res.Add(col); } } return(res.ToArray()); } } return(null); }
private void AlterTableOptions(ITableStructure table, string option, string value) { if (value != null) { PutCmd("^alter ^table %f %k=%s", table.FullName, option, value); } }
public override void DropTable(ITableStructure table, DropFlags flags) { bool testIfExist = (flags & DropFlags.TestIfExist) != 0; DropTableReferences(table, flags); PutCmd("^drop ^table%k %f", testIfExist ? " if exists" : "", table.FullName); }
public void GenerateSelectAllWhere(ITableStructure tbl, ISqlDumper dmp, ISqlDialect dialect) { dmp.Put("^select &>&n"); DumpColumns(tbl, dmp); dmp.Put("&<&n"); dmp.Put("^from %f&n", tbl.FullName); DumpWhere(tbl, dmp); }