//---------------------------------------------------------------------------------------------------- private static void ASPdb_Table__SyncTablesWithProperties_Helper1__GetAndPopulate(int connectionId, List <ASPdb_Table> tablesList, Dictionary <string, ASPdb_Table> dict) { string sql = "select * from [" + Config.SystemProperties.AppSchema + @"].[ASPdb_Tables] where [ConnectionId] = @ConnectionId order by [TableName]"; using (DbConnectionCommand command = UniversalADO.OpenConnectionCommand(sql)) { command.AddParameter("@ConnectionId", connectionId); using (DbReaderWrapper reader = command.ExecuteReaderWrapper()) { while (reader.Read()) { string db_TableName = reader.Get("TableName", ""); string db_Schema = reader.Get("Schema", ""); string db_UniqueTableNameKey = db_Schema.ToLower() + "." + db_TableName.ToLower(); if (dict.ContainsKey(db_UniqueTableNameKey)) { ASPdb_Table item = dict[db_UniqueTableNameKey]; item.TableId = reader.Get("TableId", -1); item.ConnectionId = reader.Get("ConnectionId", -1); item.TableName = db_TableName; item.Schema = db_Schema; item.Hide = reader.Get("Hide", false); } } } } }
//---------------------------------------------------------------------------------------------------- /// <summary> /// Always uses cache (if already stored in cache). /// Does not perform table sync. /// </summary> public static ASPdb_Table ASPdb_Table__Get(int tableId) { AjaxService.ASPdatabaseService.GetSetVal(); var cache = ASPdatabaseNET.Memory.AppCache.Get(); if (cache.ASPdb_Table_Dictionary2 != null) { if (cache.ASPdb_Table_Dictionary2.ContainsKey(tableId) && cache.ASPdb_Table_Dictionary2[tableId] != null) { return(cache.ASPdb_Table_Dictionary2[tableId]); // return from cache if it's there } } ASPdb_Table rtn = null; int connectionId = -1; string sql = "select [ConnectionId] from [" + Config.SystemProperties.AppSchema + @"].[ASPdb_Tables] where [TableId] = @TableId"; using (DbConnectionCommand command = UniversalADO.OpenConnectionCommand(sql)) { command.AddParameter("@TableId", tableId); using (DbReaderWrapper reader = command.ExecuteReaderWrapper()) { if (reader.Read()) { connectionId = reader.Get("ConnectionId", -1); } if (connectionId < 0) { return(null); } } } var aspdb_Tables = ASPdb_Table__GetAll(connectionId, false); for (int i = 0; i < aspdb_Tables.Count; i++) { if (aspdb_Tables[i].TableId == tableId) { rtn = aspdb_Tables[i]; i = aspdb_Tables.Count + 1; } } // store in cache before returning if (rtn != null) { if (cache.ASPdb_Table_Dictionary2 == null) { cache.ASPdb_Table_Dictionary2 = new Dictionary <int, ASPdb_Table>(); } if (cache.ASPdb_Table_Dictionary2.ContainsKey(tableId)) { cache.ASPdb_Table_Dictionary2[tableId] = rtn; } else { cache.ASPdb_Table_Dictionary2.Add(tableId, rtn); } } return(rtn); }
//---------------------------------------------------------------------------------------------------- private static void ASPdb_Table__SyncTablesWithProperties_Helper2__Insert(ASPdb_Table aspdb_Table) { string sql = String.Format(@" insert into [" + Config.SystemProperties.AppSchema + @"].[ASPdb_Tables] ([ConnectionId], [TableName], [Schema], [Hide]) values (@ConnectionId, @TableName, @Schema, 0) "); using (DbConnectionCommand command = UniversalADO.OpenConnectionCommand(sql)) { command.AddParameter("@ConnectionId", aspdb_Table.ConnectionId); command.AddParameter("@TableName", aspdb_Table.TableName); command.AddParameter("@Schema", aspdb_Table.Schema); command.Command.ExecuteNonQuery(); } }