public virtual SqlQueryResult ExecuteSQL(DbEngines dbEngine, string connectionString, string sqlQuery) { ConfigureDependencies(dbEngine); this.DbConnection.ConnectionString = connectionString; this.DbConnection.Open(); var dataReader = GetDataReader(this.DbConnection, sqlQuery); var sqlResult = new SqlQueryResult(); try { while (dataReader.Read()) { var currentRecord = new Dictionary<string, object>(); for (int i = 0; i < dataReader.FieldCount; i++) { var columnName = dataReader.GetName(i); var columnValue = dataReader[columnName]; currentRecord.Add(columnName, columnValue); } sqlResult.AddRecord(currentRecord); } return sqlResult; } finally { dataReader.Close(); this.DbConnection.Close(); } }
public virtual SqlQueryResult ExecuteSQL(DbEngines dbEngine, string connectionString, string sqlQuery) { ConfigureDependencies(dbEngine); this.DbConnection.ConnectionString = connectionString; this.DbConnection.Open(); var dataReader = GetDataReader(this.DbConnection, sqlQuery); var sqlResult = new SqlQueryResult(); try { while (dataReader.Read()) { var currentRecord = new Dictionary <string, object>(); for (int i = 0; i < dataReader.FieldCount; i++) { var columnName = dataReader.GetName(i); var columnValue = dataReader[columnName]; currentRecord.Add(columnName, columnValue); } sqlResult.AddRecord(currentRecord); } return(sqlResult); } finally { dataReader.Close(); this.DbConnection.Close(); } }
public SqlQueryResultTests() { var fakeColumnNames = new string[] { "name", "id", "enabled" }; var fakeRecord1 = CreateFakeRecord(fakeColumnNames, new object[] { "John Doe", 10, true }); var fakeRecord2 = CreateFakeRecord(fakeColumnNames, new object[] { "Barack Obama", 11, false }); this.FakeSqlQueryResult = new SqlQueryResult(); this.FakeSqlQueryResult.AddRecord(fakeRecord1); this.FakeSqlQueryResult.AddRecord(fakeRecord2); }
public void Should_be_possible_to_transform_a_sqlQueryResult_with_no_result_into_a_list_of_ovalSimpleAnyType() { var emptySqlQueryResult = new SqlQueryResult(); var ovalSimpleTypes = emptySqlQueryResult.ToOvalSimpleTypeList(); Assert.IsNotNull(ovalSimpleTypes); Assert.AreEqual(1, ovalSimpleTypes.Count()); Assert.AreEqual(StatusEnumeration.doesnotexist, ovalSimpleTypes.ElementAt(0).status); }
private BaseObjectCollector CreateSqlObjectCollectorWithBehavior( SqlQueryResult fakeSqlQueryResultToReturn, bool forSql57) { var mocks = new MockRepository(); var fakeSqlQueryProvider = mocks.DynamicMock<SqlQueryProvider>(); Expect.Call( fakeSqlQueryProvider .ExecuteSQL(DbEngines.MsSqlServer, null, null)) .IgnoreArguments() .Return(fakeSqlQueryResultToReturn); mocks.ReplayAll(); if (forSql57) return new Sql57ObjectCollector(fakeSqlQueryProvider); return new SqlObjectCollector(fakeSqlQueryProvider); }
private SqlQueryResult CreateFakeQueryResult() { var fakeColumnNames = new string[] { "name", "id", "enabled" }; var fakeQueryResult = new SqlQueryResult(); fakeQueryResult.AddRecord(CreateFakeRecord(fakeColumnNames, new object[] { "John", 1, true})); fakeQueryResult.AddRecord(CreateFakeRecord(fakeColumnNames, new object[] { "David", 2, false })); return fakeQueryResult; }
public void Should_be_possible_to_transform_a_sqlQueryResult_with_empty_field_into_a_list_of_ovalSimpleAnyType() { var fakeSqlQueryResult = new SqlQueryResult(); fakeSqlQueryResult.AddRecord(CreateFakeRecord(new string[] { "name" }, new object[] { "John" })); fakeSqlQueryResult.AddRecord(CreateFakeRecord(new string[] { "name" }, new object[] { null })); fakeSqlQueryResult.AddRecord(CreateFakeRecord(new string[] { "name" }, new object[] { "Mark" })); var ovalSimpleTypes = fakeSqlQueryResult.ToOvalSimpleTypeList(); Assert.IsNotNull(ovalSimpleTypes); Assert.AreEqual(3, ovalSimpleTypes.Count()); Assert.AreEqual("John", ovalSimpleTypes.ElementAt(0).Value); Assert.AreEqual("Mark", ovalSimpleTypes.ElementAt(2).Value); var nullField = ovalSimpleTypes.ElementAt(1); Assert.IsNull(nullField.Value); Assert.AreEqual(StatusEnumeration.doesnotexist, nullField.status); }
public void Should_be_possible_to_transform_a_sqlQueryResult_with_empty_field_into_a_list_of_ovalRecordType() { var fakeSqlQueryResult = new SqlQueryResult(); fakeSqlQueryResult.AddRecord(CreateFakeRecord(new string[] { "id", "name" }, new object[] { null, null })); fakeSqlQueryResult.AddRecord(CreateFakeRecord(new string[] { "id", "name" }, new object[] { 1, null })); fakeSqlQueryResult.AddRecord(CreateFakeRecord(new string[] { "id", "name" }, new object[] { null, "John" })); fakeSqlQueryResult.AddRecord(CreateFakeRecord(new string[] { "id", "name" }, new object[] { 2, "Michael" })); var ovalRecords = fakeSqlQueryResult.ToOvalRecordTypeList(); Assert.IsNotNull(ovalRecords); Assert.AreEqual(4, ovalRecords.Count()); var firstRecord = ovalRecords.ElementAt(0); AssertField(firstRecord.field.First(), "id", null); AssertField(firstRecord.field.Last(), "name", null); var secondRecord = ovalRecords.ElementAt(1); AssertField(secondRecord.field.First(), "id", "1"); AssertField(secondRecord.field.Last(), "name", null); var thirdRecord = ovalRecords.ElementAt(2); AssertField(thirdRecord.field.First(), "id", null); AssertField(thirdRecord.field.Last(), "name", "John"); var fourthRecord = ovalRecords.ElementAt(3); AssertField(fourthRecord.field.First(), "id", "2"); AssertField(fourthRecord.field.Last(), "name", "Michael"); }