private void OnSqlQuery(object sender, EventArgs e) { //try { TableLink link = (_ctxtNode.Tag == null) ? null : _ctxtNode.Tag as TableLink; if (link == null) { return; } IDBObjectTree dbTree = link.Tree as IDBObjectTree; if (dbTree == null) { return; } DBObjectIdentifier id = dbTree.GetIdentifier(link.Cell); string selectSql = string.Format("SELECT * FROM {0}", id.FullName); TabPage tp = Zen.UIControls.CtrlBuilder.BuildTabPage(string.Format("Query{0}", _sqlTabCount++), _tabDetailView.Size, _tabDetailView.Controls.Count); SqlControl ctrl = new SqlControl(); ctrl.Dock = DockStyle.Fill; ctrl.SqlText = selectSql; ctrl.DataSource = dbTree.DataSource; tp.Controls.Add(ctrl); _tabDetailView.Controls.Add(tp); } //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} }
public virtual DBObjectIdentifier GetIdentifier(Cell location) { DBObjectIdentifier id = new DBObjectIdentifier(); id.Name = ToString(location); id.Context = _server.DBMSContext; return(id); }
public override DataTable Export(Cell location) { DataTable tbl = null; DBObjectIdentifier id = GetIdentifier(location); _server.Execute(string.Format("SELECT * FROM {0}", id.FullName), out tbl); tbl.TableName = id.Name; return(tbl); }
public override DBObjectIdentifier GetIdentifier(Cell location) { DataRow row = _tblViewer.DataTable.Rows[location.Row]; DBObjectIdentifier id = new DBObjectIdentifier(); id.Context = _server.DBMSContext; id.Type = DBObjectEnum.Table; id.Name = row["TABLE_NAME"].ToString(); id.Owner = row["TABLE_SCHEMA"].ToString(); id.SubType = row["TABLE_TYPE"].ToString(); return(id); }
public static List <ColumnMeta> GetColumnNames(DbConnection conn, DBObjectIdentifier parentTable) { string[] restrictions = new string[] { null, null, parentTable.Name }; DataTable dt = conn.GetSchema(ColumnCollection, restrictions); DataRowCollection rows = dt.Rows; int rowCount = rows.Count; List <ColumnMeta> names = new List <ColumnMeta>(rowCount); for (int i = 0; i < rowCount; i++) { string columnType = rows[i]["DATA_TYPE"].ToString(); ColumnMeta col = new ColumnMeta(rows[i]["COLUMN_NAME"].ToString(), DataTypeEnum.Unspecified, null); //col.DataType.NativeDataType = // no native type exposed from this names.Add(col); } return(names); }
private void OnTableToObj(object sender, EventArgs e) { TableLink link = (_ctxtNode.Tag == null) ? null : _ctxtNode.Tag as TableLink; if (link == null) { return; } IDBObjectTree dbTree = link.Tree as IDBObjectTree; if (dbTree == null) { return; } DBObjectIdentifier id = dbTree.GetIdentifier(link.Cell); TableSchema schema = new TableSchema(dbTree.DataSource, id.FullName); ShowTable(schema.ColumnDefs, id.Name); }
/// <summary> /// Warning: it's caller's responsibility to change the initial catalog (e.g., database) /// before querying table names /// </summary> public static List <DBObjectIdentifier> GetTableList(DbConnection conn, string owner) { // TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE ['BASE TABLE' or 'VIEW'] string[] restrictions = new string[] { null, owner, null, null }; DataTable dt = conn.GetSchema(TableCollection, restrictions); DataRowCollection rows = dt.Rows; int rowCount = rows.Count; List <DBObjectIdentifier> names = new List <DBObjectIdentifier>(rowCount); for (int i = 0; i < rowCount; i++) { DBObjectIdentifier obj = new DBObjectIdentifier(); obj.Type = DBObjectEnum.Table; obj.Name = rows[i]["TABLE_NAME"].ToString(); obj.Database = rows[i]["TABLE_CATALOG"].ToString(); obj.Owner = rows[i]["TABLE_SCHEMA"].ToString(); obj.SubType = rows[i]["TABLE_TYPE"].ToString(); names.Add(obj); } return(names); }