public void IndexerByIndexTest() { BdpTransaction transaction = Connection.BeginTransaction(); BdpCommand command = new BdpCommand("select * from TEST", Connection, transaction); Console.WriteLine(); Console.WriteLine("DataReader - Read Method - Test"); IDataReader reader = command.ExecuteReader(); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { Console.Write(reader[i] + "\t"); } Console.WriteLine(); } reader.Close(); transaction.Rollback(); command.Dispose(); }
public void InvalidParameterFormat() { string sql = "update test set timestamp_field = ? where int_field = ?"; bool failed = false; BdpTransaction transaction = this.Connection.BeginTransaction(); try { BdpCommand command = new BdpCommand(sql, this.Connection, transaction); command.Parameters.Add("@timestamp", BdpType.DateTime).Value = 1; command.Parameters.Add("@integer", BdpType.Int32).Value = 1; command.ExecuteNonQuery(); command.Close(); transaction.Commit(); } catch { failed = true; transaction.Rollback(); } Assert.IsTrue(failed, "Bad parameter not detected"); }
public void GetValuesTest() { BdpTransaction transaction = Connection.BeginTransaction(); BdpCommand command = new BdpCommand("select * from TEST", Connection, transaction); Console.WriteLine(); Console.WriteLine("DataReader - Read Method - Test"); IDataReader reader = command.ExecuteReader(); while (reader.Read()) { object[] values = new object[reader.FieldCount]; reader.GetValues(values); for (int i = 0; i < values.Length; i++) { Console.Write(values[i] + "\t"); } Console.WriteLine(); } reader.Close(); transaction.Rollback(); command.Dispose(); }
public void GetSchemaTableWithExpressionFieldTest() { BdpTransaction transaction = Connection.BeginTransaction(); BdpCommand command = new BdpCommand("select TEST.*, 0 AS VALOR from TEST", Connection, transaction); BdpDataReader reader = command.ExecuteReader(CommandBehavior.SchemaOnly); DataTable schema = reader.GetSchemaTable(); Console.WriteLine(); Console.WriteLine("DataReader - GetSchemaTable Method- Test"); DataRow[] currRows = schema.Select(null, null, DataViewRowState.CurrentRows); foreach (DataColumn myCol in schema.Columns) { Console.Write("{0}\t\t", myCol.ColumnName); } Console.WriteLine(); foreach (DataRow myRow in currRows) { foreach (DataColumn myCol in schema.Columns) { Console.Write("{0}\t\t", myRow[myCol]); } Console.WriteLine(); } reader.Close(); transaction.Rollback(); command.Dispose(); }
public void AbortTransaction() { StringBuilder b1 = new StringBuilder(); b1.AppendFormat("ALTER TABLE \"{0}\" drop \"INT_FIELD\"", "TEST"); BdpTransaction transaction = null; BdpCommand command = null; try { transaction = this.Connection.BeginTransaction(); command = new BdpCommand(b1.ToString(), this.Connection, transaction); command.ExecuteNonQuery(); transaction.Commit(); transaction = null; } catch (Exception) { transaction.Rollback(); transaction = null; } finally { if (command != null) { command.Dispose(); } } }
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(); }
private static void InsertTestData(string connectionString) { BdpConnection connection = new BdpConnection(connectionString); connection.Open(); StringBuilder commandText = new StringBuilder(); commandText.Append("DELETE FROM TEST"); BdpCommand command = new BdpCommand(commandText.ToString(), connection); command.ExecuteNonQuery(); command.Dispose(); commandText = new StringBuilder(); commandText.Append("insert into test (int_field, char_field, varchar_field, bigint_field, smallint_field, float_field, double_field, numeric_field, date_field, time_field, timestamp_field, clob_field, blob_field)"); commandText.Append(" values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); BdpTransaction transaction = connection.BeginTransaction(); command = new BdpCommand(commandText.ToString(), connection, transaction); try { // Add command parameters command.Parameters.Add("@int_field", BdpType.Int32); command.Parameters.Add("@char_field", BdpType.String, BdpType.stFixed); command.Parameters.Add("@varchar_field", BdpType.String); command.Parameters.Add("@bigint_field", BdpType.Int64); command.Parameters.Add("@smallint_field", BdpType.Int16); command.Parameters.Add("@float_field", BdpType.Float); command.Parameters.Add("@double_field", BdpType.Double); command.Parameters.Add("@numeric_field", BdpType.Decimal); command.Parameters.Add("@date_field", BdpType.Date); command.Parameters.Add("@time_Field", BdpType.Time); command.Parameters.Add("@timestamp_field", BdpType.DateTime); command.Parameters.Add("@clob_field", BdpType.Blob, BdpType.stHMemo); command.Parameters.Add("@blob_field", BdpType.Blob, BdpType.stHBinary); command.Prepare(); for (int i = 0; i < 100; i++) { command.Parameters["@int_field"].Value = i; command.Parameters["@char_field"].Value = "IRow " + i.ToString(); command.Parameters["@varchar_field"].Value = "IRow Number " + i.ToString(); command.Parameters["@bigint_field"].Value = i; command.Parameters["@smallint_field"].Value = i; command.Parameters["@float_field"].Value = (float)(i + 10) / 5; command.Parameters["@double_field"].Value = Math.Log(i, 10); command.Parameters["@numeric_field"].Value = (decimal)(i + 10) / 5; command.Parameters["@date_field"].Value = DateTime.Now; command.Parameters["@time_field"].Value = DateTime.Now; command.Parameters["@timestamp_field"].Value = DateTime.Now; command.Parameters["@clob_field"].Value = "IRow Number " + i.ToString(); command.Parameters["@blob_field"].Value = Encoding.Default.GetBytes("IRow Number " + i.ToString()); command.ExecuteNonQuery(); } // Commit transaction transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { command.Dispose(); connection.Close(); } }