/// <summary> /// Get the length of a database column /// </summary> /// <param name="owner">Database owner</param> /// <param name="tableName">Table name</param> /// <param name="columnName">Column name</param> /// <param name="useCache">Use column length cache (default is true, use false only to detect changes in the database structure)</param> /// <param name="connection">Database connection (null for a new connection)</param> /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param> /// <returns>The length of the database column; null if the owner, the table or the column does not exist</returns> public static int?GetColumnLength(string owner, string tableName, string columnName, bool useCache = true, DBOracleConnection connection = null, string connectionStringName = null) { if (!useCache) { using (var dbOracleMedatadataDAL = DBOracleMetadataDAL.Create(connection: connection, connectionStringName: connectionStringName)) { return(dbOracleMedatadataDAL.GetColumnLength(owner: owner, tableName: tableName, columnName: columnName)); } } owner = owner.ToUpper(); if (!GetColumnLength_Cache.TryGetValue(owner, out var ownerCache)) { using (var dbOracleMedatadataDAL = DBOracleMetadataDAL.Create(connection: connection, connectionStringName: connectionStringName)) { ownerCache = dbOracleMedatadataDAL.GetColumnLengthTable(owner); } lock (GetColumnLength_Lock) { if (!GetColumnLength_Cache.TryGetValue(owner, out var ownerCacheAux)) { var newCache = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(GetColumnLength_Cache); newCache[owner] = ownerCache; GetColumnLength_Cache = newCache; } } } return(ownerCache.GetOrDefault(tableName.ToUpper()) ?.GetOrDefault(columnName.ToUpper())); }
/// <summary> /// Get the length of a database column /// </summary> /// <param name="owner">Database owner</param> /// <param name="tableName">Table name</param> /// <param name="columnName">Column name</param> /// <param name="useCache">Use column length cache (default is true, use false only to detect changes in the database structure)</param> /// <param name="connection">Database connection (null for a new connection)</param> /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param> /// <returns>The length of the database column; null if the owner, the table or the column does not exist</returns> public static async Task <int?> GetColumnLengthAsync(string owner, string tableName, string columnName, bool useCache = true, DBSqlServerConnection connection = null, string connectionStringName = null) { if (!useCache) { using (var dbSqlServerMedatadataDAL = await DBSqlServerMetadataDAL.CreateAsync(connection: connection, connectionStringName: connectionStringName).ConfigureAwait(false)) { return(await dbSqlServerMedatadataDAL.GetColumnLengthAsync(owner : owner, tableName : tableName, columnName : columnName).ConfigureAwait(false)); } } owner = owner.ToUpper(); if (!GetColumnLength_Cache.TryGetValue(owner, out var ownerCache)) { using (var dbSqlServerMedatadataDAL = await DBSqlServerMetadataDAL.CreateAsync(connection: connection, connectionStringName: connectionStringName).ConfigureAwait(false)) { ownerCache = await dbSqlServerMedatadataDAL.GetColumnLengthTableAsync(owner).ConfigureAwait(false); } lock (GetColumnLength_Lock) { if (!GetColumnLength_Cache.TryGetValue(owner, out var ownerCacheAux)) { var newCache = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(GetColumnLength_Cache); newCache[owner] = ownerCache; GetColumnLength_Cache = newCache; } } } return(ownerCache.GetOrDefault(tableName.ToUpper()) ?.GetOrDefault(columnName.ToUpper())); }