public void TestInsertSelectChar() // the returned Integers are Uint32 though. { const string DdlDropIfExists = "DROP TABLE IF EXISTS TestInsertSelectChar"; const string DdlCreateTable = "CREATE TABLE TestInsertSelectChar(COL1 CHAR)"; const string SqlInsertInto = "INSERT INTO TestInsertSelectChar(COL1) VALUES (?)"; const string SqlSelect = "SELECT * FROM TestInsertSelectChar ORDER BY COL1 ASC"; using (var connection = new DrdaConnection(new DrdaConnectionOptions { HostName = hostName, Port = port, UserName = userName, Password = password })) { connection.ConnectAsync().Wait(); connection.CreateStatement(DdlDropIfExists).Execute(); connection.CreateStatement(DdlCreateTable).Execute(); var preparedInsert = connection.CreateStatement(SqlInsertInto).Prepare(); preparedInsert.SetParameterValue(0, 'a'); preparedInsert.Execute(); preparedInsert.SetParameterValue(0, 'b'); preparedInsert.Execute(); preparedInsert.SetParameterValue(0, 'c'); preparedInsert.Execute(); connection.Commit(); var selectStatement = connection.CreateStatement(SqlSelect).Prepare(); Assert.IsTrue(selectStatement.Execute()); Assert.IsTrue(selectStatement.Fetch()); Assert.AreEqual("a", selectStatement.GetColumnValue(0)); Assert.IsTrue(selectStatement.Fetch()); Assert.AreEqual("b", selectStatement.GetColumnValue(0)); Assert.IsTrue(selectStatement.Fetch()); Assert.AreEqual("c", selectStatement.GetColumnValue(0)); Assert.IsFalse(selectStatement.Fetch()); } }
public override void Connect( Dictionary <String, Object> connectionSettings) { LogUtilities.LogFunctionEntrance(Log, connectionSettings); Utilities.NullCheck("connectionSettings", connectionSettings); _drdaConnection = new DrdaConnection(new DrdaConnectionOptions { Port = Convert.ToInt32(GetRequiredSetting("PORT", connectionSettings)), HostName = Convert.ToString(GetRequiredSetting("HOST", connectionSettings)), UserName = Convert.ToString(GetRequiredSetting("UID", connectionSettings)), Password = Convert.ToString(GetRequiredSetting("PWD", connectionSettings)) }); _drdaConnection.ConnectAsync().Wait(); }
private static async void TestCreateInsertSelectDrda() { Trace.Listeners.Add(new TextWriterTraceListener(Console.Error)); Trace.AutoFlush = true; using (var connection = new DrdaConnection( new DrdaConnectionOptions { HostName = "localhost", Port = 1527, UserName = "******", Password = "******" })) { await connection.ConnectAsync(); Console.WriteLine(); Console.WriteLine("Try to execute simple SQL"); Console.WriteLine(); connection.CreateStatement(DdlCreateTable).Execute(); // Immediate Console.WriteLine(); Console.WriteLine("Try to execute prepared INSERT SQL"); Console.WriteLine(); var insert = connection.CreateStatement(SqlInsertInto).Prepare(); // Prepared for (var i = 0; i < 10; ++i) { insert.SetParameterValue(0, i); insert.SetParameterValue(1, "Giants"); insert.SetParameterValue(2, "Joe Bojangles"); insert.SetParameterValue(3, "C"); insert.SetParameterValue(4, "Little Joey"); insert.SetParameterValue(5, new DateTime(1911, 11, 07)); insert.Execute(); } connection.Rollback(); Console.WriteLine(); Console.WriteLine("Try to execute prepared SELECT SQL"); Console.WriteLine(); var select = connection.CreateStatement(SqlSelect).Prepare(); // Prepared if (@select.Execute()) { while (@select.Fetch()) { for (var index = 0; index < @select.Columns; ++index) { Console.WriteLine( $"{@select.GetColumnName(index)} = {@select.GetColumnValue(index) ?? "NULL"}"); } Console.WriteLine(); } } } }