/// <summary> /// Retrieve a generic collection. /// </summary> /// <param name="collectionName">Name of the collection.</param> /// <param name="connection">The connection.</param> /// <param name="tableName">Name of the table.</param> /// <returns></returns> protected DataTable GenericCollection(string collectionName, DbConnection connection, string tableName) { if (SchemaCollectionExists(connection, collectionName)) { return(connection.GetSchema(collectionName, SchemaRestrictions.ForTable(connection, collectionName, tableName))); } return(CreateDataTable(collectionName)); }
/// <summary> /// DataTable of all tables for a specific owner /// </summary> /// <param name="tableName">Name of the table.</param> /// <returns></returns> public DataTable Tables(string tableName) { string collectionName = TablesCollectionName; using (DbConnection conn = Factory.CreateConnection()) { conn.ConnectionString = ConnectionString; conn.Open(); var restrictions = string.IsNullOrEmpty(tableName) ? SchemaRestrictions.ForOwner(conn, collectionName) : SchemaRestrictions.ForTable(conn, TablesCollectionName, tableName); return(conn.GetSchema(collectionName, restrictions)); } }
/// <summary> /// Finds the foreign key columns. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="connection">The connection.</param> /// <returns></returns> protected virtual DataTable ForeignKeyColumns(string tableName, DbConnection connection) { string collectionName = ForeignKeyColumnsCollectionName; if (!SchemaCollectionExists(connection, collectionName)) { return(CreateDataTable(collectionName)); } string[] restrictions = SchemaRestrictions.ForTable(connection, collectionName, tableName); var dt = connection.GetSchema(collectionName, restrictions); if (dt.TableName != collectionName) //devart postgresql returns a table called IndexColumns. { dt.TableName = collectionName; } return(dt); }
/// <summary> /// Does table exist? /// </summary> /// <param name="tableName">Name of the table.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">TableName is null or empty;tableName</exception> public bool TableExists(string tableName) { if (String.IsNullOrEmpty(tableName)) { throw new ArgumentException("TableName is null or empty", "tableName"); } string collectionName = TablesCollectionName; using (DbConnection conn = Factory.CreateConnection()) { conn.ConnectionString = ConnectionString; conn.Open(); string[] restrictions = SchemaRestrictions.ForTable(conn, TablesCollectionName, tableName); var dt = conn.GetSchema(collectionName, restrictions); //could have same name in different schemas return(dt.Rows.Count > 0); } }
/// <summary> /// Gets the primary keys /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="connection">The connection.</param> /// <returns></returns> protected virtual DataTable PrimaryKeys(string tableName, DbConnection connection) { string collectionName = PrimaryKeysCollectionName; if (!SchemaCollectionExists(connection, collectionName)) { return(CreateDataTable(collectionName)); } string[] restrictions = SchemaRestrictions.ForTable(connection, collectionName, tableName); try { return(connection.GetSchema(collectionName, restrictions)); } catch (ArgumentException) { //may not be allowed without tablename return(CreateDataTable(collectionName)); } }
/// <summary> /// Get the columns using GetSchema. Override to get additional stuff from Oracle. /// </summary> protected virtual DataTable Columns(string tableName, DbConnection connection) { string[] restrictions = SchemaRestrictions.ForTable(connection, ColumnsCollectionName, tableName); return(connection.GetSchema(ColumnsCollectionName, restrictions)); }