public void ExecuteReader() { var rs = DbExecutor.ExecuteReader(connectionFactory(), "select * from sqlite_master where type=@TypeId ", new { TypeId = "table" }).ToArray(); rs.Length.Is(6); using (var exec = new DbExecutor(connectionFactory())) { //select name from sqlite_master where type='table'; var ri = exec.ExecuteReader("select * from sqlite_master where type=@TypeId ", new { TypeId = "table" }) .Select(dr => { var x = new SqliteMaster(); x.name = (string)dr["name"]; x.rootpage = (int)dr["rootpage"]; x.sql = (string)dr["sql"]; x.tbl_name = (string)dr["tbl_name"]; x.type = (string)dr["type"]; return(x); }) .ToArray(); ri.Length.Is(6); ri.Select(x => x.name).Is("employees", "departments", "dept_emp", "dept_manager", "titles", "salaries"); } }
/// <summary> /// DataTypeの一覧を取得する。 /// </summary> public IEnumerable <string> GetDataTypes(string componentType, string portName) { var conditions = new List <string>(); if (!string.IsNullOrEmpty(componentType) && componentType != "*") { conditions.Add("ComponentType = @ComponentType"); } if (!string.IsNullOrEmpty(portName) && portName != "*") { conditions.Add("PortName = @PortName"); } string condition = ""; if (conditions.Count != 0) { condition = "where " + string.Join(" and ", conditions); } var dataTypes = DbExecutor.ExecuteReader( new SQLiteConnection(_connectionString), @"select distinct DataType from RecordDescriptions " + condition, new { ComponentType = componentType, PortName = portName }); return(dataTypes.Select(dr => (string)dr["DataType"]) .Concat(EnumerableEx.Return("*"))); }
public void ExecuteReader() { var rs = DbExecutor.ExecuteReader(connectionFactory(), "select * from Methods where TypeId = @TypeId", new { TypeId = 2 }) .Select(dr => new Method { Name = (string)dr["Name"], MethodId = (int)dr["MethodId"], }) .ToArray(); rs.Length.Is(3); rs.Select(x => x.Name).Is("StartsWith", "EndsWith", "Contains"); using (var exec = new DbExecutor(connectionFactory())) { var ri = exec.ExecuteReader("select * from Methods where TypeId = @TypeId", new { TypeId = 2 }) .Select(dr => new Method { Name = (string)dr["Name"], MethodId = (int)dr["MethodId"], }) .ToArray(); ri.Length.Is(3); ri.Select(x => x.Name).Is("StartsWith", "EndsWith", "Contains"); } }
public void ExecuteReaderTest() { using(DbExecutor db = new DbExecutor(new SqlConnection(connString))) { var s = db.ExecuteReader("select * from MyTest").Select(dr=>new {Name=dr["Name"],mark=dr["Mark"]}); foreach (var v in s) { Console.WriteLine(v.mark); } } }