//查询 private DbReader query(Command cmd, DbTran transaction) { if (false == buildCMD(cmd, (transaction == null ? null : transaction.connection), false)) { return(null); } //3.执行 DbReader rst = new DbReader(stmt.ExecuteReader()); //stmt.executeQuery(); //*.监听 WeedConfig.logExecuteAft(cmd); return(rst); }
public List <T> getList <T>(T model, Command cmd, DbTran transaction) where T : IBinder { List <T> list = new List <T>(); try { reader = query(cmd, transaction); while (reader.Read()) { T item = (T)model.clone(); if (WeedConfig.isDebug) { if (item is T) { throw new WeedException(model.GetType() + " clone error(" + item.GetType() + ")"); } } item.bind((key) => { try { return(new Variate(key, reader[key])); } catch (Exception ex) { WeedConfig.logException(cmd, ex); return(new Variate(key, null)); } }); list.Add(item); } if (list.Count > 0) { return(list); } else { return(null); } } catch (Exception ex) { WeedConfig.logException(cmd, ex); throw ex; } finally { tryClose(); } }
public Variate getVariate(Command cmd, DbTran transaction) { try { reader = query(cmd, transaction); if (reader.Read()) { return(new Variate(null, reader[0])); //也可能从1开始 } else { return(null);//new Variate(null, null); } } catch (Exception ex) { WeedConfig.logException(cmd, ex); throw ex; } finally { tryClose(); } }
public DataList getTable(Command cmd, DbTran transaction) { DataList table = new DataList(); try { reader = query(cmd, transaction); while (reader.Read()) { DataItem row = new DataItem(); int len = reader.FieldCount; for (int i = 0; i < len; i++) { row.set(reader.GetName(i), reader[i]); } table.addRow(row); } if (table.getRowCount() > 0) { return(table); } else { return(null); } } catch (Exception ex) { WeedConfig.logException(cmd, ex); throw ex; } finally { tryClose(); } }