public void ExecuteReaderTest() { BdpCommand command = Connection.CreateCommand(); command.CommandText = "select * from TEST"; int rows = 0; // Holds number of rows; object rowNum; // Holds row number fetch from DB BdpDataReader reader = command.ExecuteReader(); while (reader.Read()) { // Check INT field for proper value. rowNum = reader["INT_FIELD"]; Assert.IsTrue((int)rowNum == rows, "Invalid row number"); rows++; } reader.Close(); Assert.IsTrue(Connection.State == ConnectionState.Open, "Connection is not open"); command.Close(); }
public void NamedParametersReuseTest() { string sql = "select * from test where int_field >= @lang and int_field <= @lang"; BdpCommand command = new BdpCommand(sql, this.Connection); command.Parameters.Add("@lang", BdpType.Int32).Value = 10; BdpDataReader reader = command.ExecuteReader(); int count = 0; int intValue = 0; while (reader.Read()) { if (count == 0) { intValue = reader.GetInt32(0); } count++; } Assert.AreEqual(1, count, "Invalid number of records fetched."); Assert.AreEqual(10, intValue, "Invalid record fetched."); reader.Close(); command.Close(); }
public void NextResultTest() { string querys = "select * from TEST order by INT_FIELD asc;" + "select * from TEST order by INT_FIELD desc;"; BdpTransaction transaction = Connection.BeginTransaction(); BdpCommand command = new BdpCommand(querys, Connection, transaction); BdpDataReader reader = command.ExecuteReader(); Console.WriteLine(); Console.WriteLine("DataReader - NextResult Method - Test ( First Result )"); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { Console.Write(reader.GetValue(i) + "\t"); } Console.WriteLine(); } if (reader.NextResult()) { Console.WriteLine("DataReader - NextResult Method - Test ( Second Result )"); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { Console.Write(reader.GetValue(i) + "\t"); } Console.WriteLine(); } } reader.Close(); transaction.Rollback(); command.Dispose(); }
public void GetCharsLengthTest() { string sql = "select clob_field from TEST where int_field = ?"; BdpCommand command = new BdpCommand(sql, this.Connection); command.Parameters.Add("@int_field", BdpType.Int32).Value = 50; BdpDataReader reader = command.ExecuteReader(); reader.Read(); long length = reader.GetChars(0, 0, null, 0, 0); reader.Close(); Assert.AreEqual(14, length, "Incorrect clob length"); }
// RPH - Changed parameter names to "?". Parameters are substituted in order. // [Ignore("Named parameters are not support in the Borland Data Provider")] public void NamedParametersTest() { BdpCommand command = Connection.CreateCommand(); // command.CommandText = "select CHAR_FIELD from TEST where INT_FIELD = @int_field or CHAR_FIELD = @char_field"; command.CommandText = "select CHAR_FIELD from TEST where INT_FIELD = ? or CHAR_FIELD = ?"; command.Parameters.Add("@int_field", 2); command.Parameters.Add("@char_field", "TWO"); BdpDataReader reader = command.ExecuteReader(); int count = 0; while (reader.Read()) { count++; } Assert.AreEqual(1, count, "Invalid number of records fetched."); reader.Close(); command.Close(); }
public void PrepareTest() { try { // Drop the table BdpCommand drop = new BdpCommand("drop table PrepareTest", Connection); drop.ExecuteNonQuery(); drop.Close(); } catch { } // Create a new test table BdpCommand create = new BdpCommand("create table PrepareTest(test_field varchar(20));", Connection); create.ExecuteNonQuery(); create.Close(); // Insert data using a prepared statement BdpCommand command = new BdpCommand( "INSERT INTO PrepareTest (test_field) VALUES (?);", Connection); command.Parameters.Add("@test_field", BdpType.String).Value = DBNull.Value; command.Prepare(); for (int i = 0; i < 5; i++) { if (i < 1) { command.Parameters[0].Value = DBNull.Value; } else { command.Parameters[0].Value = i.ToString(); } command.ExecuteNonQuery(); } command.Close(); try { // Check that data is correct BdpCommand select = new BdpCommand("select * from PrepareTest", Connection); BdpDataReader reader = select.ExecuteReader(); int count = 0; while (reader.Read()) { if (count == 0) { Assert.AreEqual(DBNull.Value, reader[0], "Invalid value."); } else { Assert.AreEqual(count.ToString(), reader.GetString(0).Trim(), "Invalid value."); } count++; } reader.Close(); } catch (Exception ex) { throw ex; } finally { // Drop table BdpCommand drop = new BdpCommand("drop table PrepareTest", Connection); drop.ExecuteNonQuery(); drop.Close(); } }