void AddTable(string table) { if (!Tables.Contains(table)) { Tables.Add(table); } }
public override Table GetTable(string name) { if (Tables.Contains(name)) { return(Tables[name]); } if (Tables.Contains("dbo." + name)) { return(Tables["dbo." + name]); } var matchTables = new List <SqlTable>(); foreach (SqlTable table in Tables) { if (string.Equals(table.TableName, name, StringComparison.OrdinalIgnoreCase)) { matchTables.Add(table); } } if (matchTables.Count == 1) { return(matchTables[0]); } if (matchTables.Count > 1) { throw new ApplicationException("Ambiguous table name"); } return(null); }
public void DropTable(Table table, bool recursive) { var dropCmd = conn.CreateCommand(); dropCmd.CommandText = string.Format("DROP TABLE [{0}];", table.Name); if (recursive) { BuildForeignKeysCache(); List<string> exludedCls = new List<string>(); foreach (var col in table.Columns) { if (exludedCls.Contains(col.Name)) continue; string key = string.Format("{0}_{1}", table.Name, col.Name); if (_fkCache.ContainsKey(key)) { var entry = _fkCache[key]; for (int i = 0; i < entry.Constraints.Count; i++) DropConstraint(entry.Owners[i], entry.Constraints[i]); } } } dropCmd.ExecuteNonQuery(); if (Tables.Contains(table)) Tables.Remove(table); }
private void RemoveDataTable() { if (Tables.Contains(TableName)) { Tables.Remove(TableName); } }
public void StoredProceduresSelected(object sender, RoutedEventArgs e) { var parameters = context.GetParametersOfStoredProcedure(SelectedStoredProcedures); var bufAddListBoxCombo = new List <TableField>(); var bufAddListBoxFields = new List <PairTableField>(); foreach (var param in parameters) { var spl = param.Substring(1).Split('_'); if (Tables.Contains(spl[0])) { bufAddListBoxCombo.Add(new TableField() { Text = spl[0], TableFieldName = param, ForeignTable = context.Select(spl[1], spl[0]) }); } else { bufAddListBoxFields.Add(new PairTableField() { Text = spl[0] }); } } AddListBoxCombo = bufAddListBoxCombo; AddListBoxFields = bufAddListBoxFields; }
//---------------------------------------------------------- private CResultAErreur MiseAjour(CMemoryDb sourceDB, bool bUpdateOnly) { foreach (DataTable table in sourceDB.Tables) { if (!bUpdateOnly || Tables[table.TableName] != null) { Type tp = sourceDB.GetTypeForTable(table.TableName); if (tp != null) { GetTable(tp); } } } EnforceConstraints = false; foreach (DataTable table in sourceDB.Tables) { if (Tables.Contains(table.TableName)) { table.BeginLoadData(); Type tp = sourceDB.GetTypeForTable(table.TableName); foreach (DataRow row in table.Rows) { if (!bUpdateOnly || Tables[table.TableName].Rows.Find(row[table.PrimaryKey[0]]) != null) { CEntiteDeMemoryDb entite = Activator.CreateInstance(tp, new object[] { row }) as CEntiteDeMemoryDb; ImporteObjet(entite, false, false); } } table.EndLoadData(); } } EnforceConstraints = true; return(CResultAErreur.True); }
public void AddScreenItem(Table choosenValue) { if (!Tables.Contains(choosenValue)) { Tables.Add(choosenValue); } }
// get relations from schema private void GetRelations(OleDbConnection conn) { var dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, null); foreach (DataRow dr in dt.Rows) { // get primary/foreign table and column names string pkTableName = (string)dr[PK_TABLE_NAME]; string fkTableName = (string)dr[FK_TABLE_NAME]; string pkColumnName = (string)dr[PK_COLUMN_NAME]; string fkColumnName = (string)dr[FK_COLUMN_NAME]; // make sure both tables are in our DataSet if (Tables.Contains(pkTableName) && Tables.Contains(fkTableName)) { // make sure tables are different if (pkTableName != fkTableName) { // get unique relation name string relationName = pkTableName + '_' + fkTableName; if (Relations.Contains(relationName)) { relationName += Relations.Count.ToString(); } // add to collection DataColumn pkColumn = Tables[pkTableName].Columns[pkColumnName]; DataColumn fkColumn = Tables[fkTableName].Columns[fkColumnName]; Relations.Add(relationName, pkColumn, fkColumn, true); } } } }
public virtual Table GetTable(string name) { if (Tables.Contains(name)) { return(Tables[name]); } return(null); }
public ExecutionNode AddTable(TableEntity tableToAdd) { if (!Tables.Contains(tableToAdd)) { _tables.Add(tableToAdd); } return(this); }
/// <summary> /// Determines if the expression is an alias. /// </summary> /// <param name="expression">The expression.</param> /// <returns><see langword="true"/> if the expression is an alias, otherwise, <see langword="false"/>.</returns> public static bool IsAlias(MemberExpression expression) { while (expression.Expression is MemberExpression nextExp) { expression = nextExp; } return(Tables.Contains(expression.Type.FullName)); }
public bool Contains(IEntity entity) { if (entity is ITable) { return(Tables.Contains(entity as ITable)); } return(false); }
private void GetConstraints( OleDbConnection conn) { DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, null); Hashtable uniqueTables = new Hashtable(); foreach (DataRow dr in dt.Rows) { // get primary key info string tableName = dr["TABLE_NAME"].ToString(); string columnName = dr["COLUMN_NAME"].ToString(); // make sure this table is in our DataSet if (!Tables.Contains(tableName)) { continue; } // make sure it's unique if (uniqueTables.Contains(tableName)) { uniqueTables.Remove(tableName); continue; } // save and move on uniqueTables[tableName] = columnName; } // built unique list, now set up primary key columns foreach (string tableName in uniqueTables.Keys) { // set up column string columnName = (string)uniqueTables[tableName]; DataTable table = Tables[tableName]; DataColumn pk = table.Columns[columnName]; pk.Unique = true; pk.AllowDBNull = false; // try setting auto increment this can fail... if (pk.DataType != typeof(string)) { try { pk.AutoIncrement = true; pk.ReadOnly = true; } catch { } } // set primary key on parent table Tables[tableName].PrimaryKey = new DataColumn[] { pk }; } }
/// <summary> /// /// </summary> /// <param name="table"></param> public void RemoveTable(Table table) { if (Tables.Contains <Table>(table)) { if (table.ReservationsThatUseMe.Count == 0) { Tables.Remove(table); table.Delete(); } else { throw new InvalidOperationException("Reservations still exists for this table; cannot delete it."); } } }
/// <summary> /// Add a table to the location. Saves to database. /// </summary> /// <param name="reservable"></param> public void AddTable(Table reservable) { if (Tables.Contains <Table>(reservable, new TableComparer())) { throw new ReservableAlreadyExistsException(); } else { reservable.ParentLocation = this; reservable.Save(); Tables.Add(reservable); this.Save(); //cascade } }
public void GenerateFromSpecificTable(string tableName, Action <Table> parser) { if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentNullException("tableName must not be null"); } if (!Tables.Contains(tableName)) { throw new KeyNotFoundException("Table name not found."); } using (var connection = new TDatabase() { ConnectionString = ConnectionString }) { connection.Open(); var columns = connection.GetTableSchema(TableNameCleanser(tableName)); string primaryKey = null; using (var indexes = connection.GetSchema("IndexColumns", new string[] { null, null, tableName })) { if (indexes != null) { foreach (DataRow rowInfo in indexes.Rows) { primaryKey = rowInfo["column_name"].ToString(); } } } var table = new Table() { Name = tableName, Columns = columns, PrimaryKey = primaryKey }; connection.Close(); parser(table); } }
private void BuildRegexSchemaIntoDataSet() { if ((ContentExpression == null) && !ContentExpressionHasChanged) { return; } RemoveDataTables(); LoadColumnsToTable(DataTable, _regexColumns); foreach (ConditionalRegexParser crp in Parsers) { DataTable crpDT = null; if (!Tables.Contains(crp.TableName)) { crpDT = Tables.Add(crp.TableName); } else { crpDT = Tables[crp.TableName]; } LoadColumnsToTable(crpDT, crp.RegexColumns); } }
public bool ExecuteSqlToServer(string sql, string table) { if (sql.Length <= 6) { return(false); } if (!sql.Substring(0, 6).ToUpper().Equals("SELECT") && !sql.Substring(0, 4).ToUpper().Equals("SHOW")) { if (sqlConnecter.ExecuteCommandToSQLServer(sql, true)) { MessageBox.Show("クエリの実行に成功しました。", "Reseacher"); return(true); } return(false); } else { if (Tables.Contains(table)) { Tables.Remove(table); } return(sqlConnecter.GetDataFromSQLServer(sql, table, true).IsAccess()); } }
public static List <SqlColumn> GetSqlColumns(string sql, IList parameters) { List <SqlColumn> cols = new List <SqlColumn>(); Connection connection = new Connection(@"Data Source=U:\Documentacoes_Equipe_ERP\OpenPOS\database\openpos.db;Version=3;"); connection.Open(); Tables tables = Tables.GetTables(connection); if (tables.Contains(sql)) { cols = new List <SqlColumn>(from c in tables[sql].Fields select new SqlColumn { Name = c.Name, DataType = c.GetFieldType() }); } else { Command cmSQL = null; DataReader dr = null; Cursor saveCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { cmSQL = connection.CreateCommand(); cmSQL.CommandText = sql; AddParameters(cmSQL, parameters); dr = cmSQL.ExecuteReader(CommandBehavior.SchemaOnly); for (int i = 0; i < dr.FieldCount; i++) { SqlColumn sc = new SqlColumn(); sc.Name = dr.GetName(i).TrimEnd('\0'); sc.DataType = dr.GetFieldType(i); cols.Add(sc); } } catch (SqlException sqle) { MessageBox.Show(sqle.Message, Strings.DesignerUtility_Show_SQLError); } catch (Exception e) { MessageBox.Show(e.InnerException == null ? e.Message : e.InnerException.Message, Strings.DesignerUtility_Show_Error); } finally { if (connection != null) { if (cmSQL != null) { cmSQL.Dispose(); if (dr != null) { dr.Close(); } } connection.Close(); connection.Dispose(); } Cursor.Current = saveCursor; } } return(cols); }
private DataTable?MergeSchema(DataTable table) { DataTable?targetTable = null; if (!_isStandAlonetable) { if (_dataSet !.Tables.Contains(table.TableName, true)) { if (_IgnoreNSforTableLookup) { targetTable = _dataSet.Tables[table.TableName]; } else { targetTable = _dataSet.Tables[table.TableName, table.Namespace]; } } } else { targetTable = _dataTable; } if (targetTable == null) { // in case of standalone table, we make sure that targetTable is not null, so if this check passes, it will be when it is called via detaset if (MissingSchemaAction.Add == _missingSchemaAction) { targetTable = table.Clone(table.DataSet); // if we are here mainly we are called from DataSet.Merge at this point we don't set //expression columns, since it might have refer to other columns via relation, so it won't find the table and we get exception; // do it after adding relations. _dataSet !.Tables.Add(targetTable); } else if (MissingSchemaAction.Error == _missingSchemaAction) { throw ExceptionBuilder.MergeMissingDefinition(table.TableName); } } else { if (MissingSchemaAction.Ignore != _missingSchemaAction) { // Do the columns int oldCount = targetTable.Columns.Count; for (int i = 0; i < table.Columns.Count; i++) { DataColumn src = table.Columns[i]; DataColumn?dest = (targetTable.Columns.Contains(src.ColumnName, true)) ? targetTable.Columns[src.ColumnName] : null; if (dest == null) { if (MissingSchemaAction.Add == _missingSchemaAction) { dest = src.Clone(); targetTable.Columns.Add(dest); } else { if (!_isStandAlonetable) { _dataSet !.RaiseMergeFailed(targetTable, SR.Format(SR.DataMerge_MissingColumnDefinition, table.TableName, src.ColumnName), _missingSchemaAction); } else { throw ExceptionBuilder.MergeFailed(SR.Format(SR.DataMerge_MissingColumnDefinition, table.TableName, src.ColumnName)); } } } else { if (dest.DataType != src.DataType || ((dest.DataType == typeof(DateTime)) && (dest.DateTimeMode != src.DateTimeMode) && ((dest.DateTimeMode & src.DateTimeMode) != DataSetDateTime.Unspecified))) { if (!_isStandAlonetable) { _dataSet !.RaiseMergeFailed(targetTable, SR.Format(SR.DataMerge_DataTypeMismatch, src.ColumnName), MissingSchemaAction.Error); } else { throw ExceptionBuilder.MergeFailed(SR.Format(SR.DataMerge_DataTypeMismatch, src.ColumnName)); } } MergeExtendedProperties(src.ExtendedProperties, dest.ExtendedProperties); } } // Set DataExpression if (_isStandAlonetable) { for (int i = oldCount; i < targetTable.Columns.Count; i++) { targetTable.Columns[i].Expression = table.Columns[targetTable.Columns[i].ColumnName] !.Expression; } } // check the PrimaryKey DataColumn[] targetPKey = targetTable.PrimaryKey; DataColumn[] tablePKey = table.PrimaryKey; if (targetPKey.Length != tablePKey.Length) { // special case when the target table does not have the PrimaryKey if (targetPKey.Length == 0) { DataColumn[] key = new DataColumn[tablePKey.Length]; for (int i = 0; i < tablePKey.Length; i++) { key[i] = targetTable.Columns[tablePKey[i].ColumnName] !; } targetTable.PrimaryKey = key; } else if (tablePKey.Length != 0) { _dataSet !.RaiseMergeFailed(targetTable, SR.DataMerge_PrimaryKeyMismatch, _missingSchemaAction); } } else { for (int i = 0; i < targetPKey.Length; i++) { if (string.Compare(targetPKey[i].ColumnName, tablePKey[i].ColumnName, false, targetTable.Locale) != 0) { _dataSet !.RaiseMergeFailed(table, SR.Format(SR.DataMerge_PrimaryKeyColumnsMismatch, targetPKey[i].ColumnName, tablePKey[i].ColumnName), _missingSchemaAction); } } } } MergeExtendedProperties(table.ExtendedProperties, targetTable.ExtendedProperties); } return(targetTable); }