public void CUBRIDCommand_Close_Test() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = DBHelper.connString; string sql = "select * from nation order by code asc"; CUBRIDCommand cmd = new CUBRIDCommand(sql, conn); conn.Open(); CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(); reader.Read(); Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AFG", reader.GetString(0)); Assert.AreEqual("Afghanistan", reader.GetString(1)); Assert.AreEqual("Asia", reader.GetString(2)); Assert.AreEqual("Kabul", reader.GetString(3)); cmd.Close(); try { cmd.CommandText = "drop table if exists t"; cmd.ExecuteNonQuery(); } catch (Exception ex) { Assert.AreEqual("Some message about the cmd cannot be used", ex.Message); } } }
private static void Test_apis_669() { String sql = "select s_name from code where f_name = 'Woman';select * from code;"; CUBRIDCommand cmd = new CUBRIDCommand(sql, conn); CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader.GetString(0)); } ; while (reader.NextResult()) { Console.WriteLine("============================="); while (reader.Read()) { Console.WriteLine(reader.GetString(0)); // Console.WriteLine(reader.GetString(1)); } ; } }
public void CUBRIDCommand_Constructor_SQLAndConnAndTran_Test() { CUBRIDConnection conn = new CUBRIDConnection(); conn.ConnectionString = DBHelper.connString; conn.Open(); conn.SetAutoCommit(false); string sql = "drop table if exists t"; CUBRIDTransaction transaction = new CUBRIDTransaction(conn, CUBRIDIsolationLevel.TRAN_DEFAULT_ISOLATION); CUBRIDCommand cmd = new CUBRIDCommand(sql, conn, transaction); conn.BeginTransaction(); cmd.ExecuteNonQuery(); cmd.CommandText = "create table t (id int, name varchar(50))"; cmd.ExecuteNonQuery(); cmd.CommandText = "insert into t values(1, 'Nancy')"; cmd.ExecuteNonQuery(); conn.Commit(); cmd.CommandText = "select * from t"; CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(); reader.Read(); Assert.AreEqual(2, reader.FieldCount); Assert.AreEqual("1", reader.GetString(0)); Assert.AreEqual("Nancy", reader.GetString(1)); cmd.Close(); reader.Close(); conn.Close(); }
public void CUBRIDCommand_Constructor_SQL_Test() { CUBRIDConnection conn = new CUBRIDConnection(); conn.ConnectionString = DBHelper.connString; string sql = "select * from nation order by code asc"; CUBRIDCommand cmd = new CUBRIDCommand(sql); cmd.Connection = conn; conn.Open(); CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(); reader.Read(); Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AFG", reader.GetString(0)); Assert.AreEqual("Afghanistan", reader.GetString(1)); Assert.AreEqual("Asia", reader.GetString(2)); Assert.AreEqual("Kabul", reader.GetString(3)); cmd.Close(); reader.Close(); conn.Close(); }
public void DataReader_MultiQuery_Test2() { string conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"select s_name from code where s_name='X'; select name from nation where name='Algeria';"; CUBRIDCommand cmd = new CUBRIDCommand(sql, conn); CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader.GetString(0)); } ; while (reader.NextResult()) { Console.WriteLine("============================="); while (reader.Read()) { Console.WriteLine(reader.GetString(0)); } ; } conn.Close(); }
public void DataReader_Basic_Test() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = DBHelper.connString; conn.Open(); String sql = "select * from nation order by `code` asc"; LogTestStep("retrieve just one row"); using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn)) { using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader()) { reader.Read(); //retrieve just one row Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AFG", reader.GetString(0)); Assert.AreEqual("Afghanistan", reader.GetString(1)); Assert.AreEqual("Asia", reader.GetString(2)); Assert.AreEqual("Kabul", reader.GetString(3)); LogStepPass(); } } } LogTestResult(); }
public void CUBRIDCommand_ExecuteReader_Test() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = DBHelper.connString; conn.Open(); string sql = "select * from nation order by code asc"; using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn)) { using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader()) { //verify the first two results reader.Read(); Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AFG", reader.GetString(0)); Assert.AreEqual("Afghanistan", reader.GetString(1)); Assert.AreEqual("Asia", reader.GetString(2)); Assert.AreEqual("Kabul", reader.GetString(3)); reader.Read(); Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AHO", reader.GetString(0)); Assert.AreEqual("Netherlands Antilles", reader.GetString(1)); Assert.AreEqual("Americas", reader.GetString(2)); Assert.AreEqual("Willemstad", reader.GetString(3)); } } } }
public void i18n_issue() { CUBRIDConnection conn = new CUBRIDConnection(); conn.ConnectionString = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"utf-8"); cmd.CommandText = "drop table if exists 测试表;"; cmd.ExecuteNonQuery(); cmd.CommandText = "create table 测试表 (名称 varchar);"; cmd.ExecuteNonQuery(); cmd.CommandText = "insert into 测试表 value('小明');"; cmd.ExecuteNonQuery(); cmd.CommandText = "select 名称 from 测试表;"; CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader.GetString(0)); } ; conn.Close(); }
public void CUBRIDCommand_ExecuteReader_CloseConnection_Test() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = DBHelper.connString; conn.Open(); string sql = "select * from nation order by code asc"; CUBRIDCommand cmd = new CUBRIDCommand(sql, conn); LogTestStep("Test CommandBehavior.CloseConnection"); CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(CommandBehavior.CloseConnection); //verify the first two results reader.Read(); Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AFG", reader.GetString(0)); Assert.AreEqual("Afghanistan", reader.GetString(1)); Assert.AreEqual("Asia", reader.GetString(2)); Assert.AreEqual("Kabul", reader.GetString(3)); reader.Read(); Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AHO", reader.GetString(0)); Assert.AreEqual("Netherlands Antilles", reader.GetString(1)); Assert.AreEqual("Americas", reader.GetString(2)); Assert.AreEqual("Willemstad", reader.GetString(3)); reader.Close(); if (reader.IsClosed) { try { cmd = new CUBRIDCommand("create table t(id int)", conn); cmd.ExecuteNonQuery(); LogStepFail(); } catch (Exception ex) { Assert.AreEqual("The connection is not open!", ex.Message); LogStepPass(); } } else { LogStepFail(); } //TODO: Test CommandBehavior.Default, CommandBehavior.SchemaOnly, CommandBehavior.KeyInfo, CommandBehavior.SingleRow, CommandBehavior.SequentialAccess LogTestResult(); } }
public void DataReader_NextResult_Test() { string conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"select * from nation;"; CUBRIDCommand cmd = new CUBRIDCommand(sql, conn); CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(); reader.Read(); Console.WriteLine(reader.GetString(0)); if (reader.NextResult()) { reader.Read(); Console.WriteLine(reader.GetString(0)); } conn.Close(); }
private static void TestGetData() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); ExecuteSQL("drop table if exists t", conn); string sql = "create table t("; sql += "c_integer_ai integer AUTO_INCREMENT, "; sql += "c_smallint smallint, "; sql += "c_integer integer, "; sql += "c_bigint bigint, "; sql += "c_numeric numeric(15,1), "; sql += "c_float float, "; sql += "c_decimal decimal(15,3), "; sql += "c_double double, "; sql += "c_char char(1), "; sql += "c_varchar character varying(4096), "; sql += "c_time time, "; sql += "c_date date, "; sql += "c_timestamp timestamp, "; sql += "c_datetime datetime, "; sql += "c_bit bit(32), "; sql += "c_varbit bit varying(4096), "; sql += "c_monetary monetary, "; sql += "c_string string"; sql += ")"; ExecuteSQL(sql, conn); sql = "insert into t values("; sql += "1, "; sql += "11, "; sql += "111, "; sql += "1111, "; sql += "1.1, "; sql += "1.11, "; sql += "1.111, "; sql += "1.1111, "; sql += "'a', "; sql += "'abcdfghijk', "; sql += "TIME '13:15:45 pm', "; sql += "DATE '00-10-31', "; sql += "TIMESTAMP '13:15:45 10/31/2008', "; sql += "DATETIME '13:15:45 10/31/2008', "; sql += "B'0110011110101001', "; sql += "B'010110110111110000', "; sql += "123456789, "; sql += "'qwerty'"; sql += ")"; ExecuteSQL(sql, conn); sql = "select * from t"; using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn)) { CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); while (reader.Read()) //only one row will be available { int Ordinal = reader.GetOrdinal("c_integer_ai"); Debug.Assert(Ordinal == 0); try { Guid guid = reader.GetGuid(0); } catch (Exception e) { string error = e.ToString(); Debug.Assert(e.Message == "Value does not fall within the expected range."); } try { Guid guid = reader.GetGuid(9); } catch (Exception e) { string error = e.ToString(); Debug.Assert(e.Message == "Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."); } int i = reader.GetInt32(0); Type t = reader.GetColumnType(0); Debug.Assert(i == 1); short s = reader.GetInt16(1); t = reader.GetColumnType(1); Debug.Assert(s == 11); i = reader.GetInt32(2); t = reader.GetColumnType(2); Debug.Assert(i == 111); long i64 = reader.GetInt64(3); t = reader.GetColumnType(3); Debug.Assert(i64 == 1111); decimal d = reader.GetDecimal(4); t = reader.GetColumnType(4); Debug.Assert(d == (decimal)1.1); float f = reader.GetFloat(5); t = reader.GetColumnType(5); Debug.Assert(f == (float)1.11); d = reader.GetDecimal(6); t = reader.GetColumnType(6); Debug.Assert(d == (decimal)1.111); double db = reader.GetDouble(7); t = reader.GetColumnType(7); Debug.Assert(db == (double)1.1111); char c = reader.GetChar(8); t = reader.GetColumnType(8); Debug.Assert(c == 'a'); string str = reader.GetString(9); t = reader.GetColumnType(9); Debug.Assert(str == "abcdfghijk"); DateTime dt = reader.GetDateTime(10); t = reader.GetColumnType(10); Debug.Assert(dt.Second == 45); dt = reader.GetDateTime(11); t = reader.GetColumnType(11); string dt_s = reader.GetDate(11); Debug.Assert(dt == new DateTime(2000, 10, 31)); dt = reader.GetDateTime(12); t = reader.GetColumnType(12); dt_s = reader.GetDate(12, "yyyy-MM-dd"); dt_s = reader.GetTimestamp(12); dt_s = reader.GetTimestamp(12, "yyyy-MM-dd HH:mm:ss.fff"); Debug.Assert(dt == new DateTime(2008, 10, 31, 13, 15, 45)); dt = reader.GetDateTime(13); t = reader.GetColumnType(13); dt_s = reader.GetTime(13); dt_s = reader.GetTime(13, "HH:mm:ss"); Debug.Assert(dt == new DateTime(2008, 10, 31, 13, 15, 45)); byte[] by = new byte[4]; byte[] expected = { 0x67, 0xa9, 0x00, 0x00 }; reader.GetBytes(14, 0, by, 0, 4); Debug.Assert(by.SequenceEqual(expected)); t = reader.GetColumnType(14); expected[0] = 0x5b; expected[1] = 0x7c; expected[2] = 0x00; reader.GetBytes(15, 0, by, 0, 3); Debug.Assert(by.SequenceEqual(expected)); t = reader.GetColumnType(15); Debug.Assert(reader.GetString(16) == "123456789.0000000000000000"); t = reader.GetColumnType(16); char[] buffer = new char[16]; reader.GetChars(16, 0, buffer, 0, 16); Debug.Assert(reader.GetString(17) == "qwerty"); t = reader.GetColumnType(17); } } ExecuteSQL("drop table t", conn); } }
public void DataReader_NextResult_Test() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = DBHelper.connString; conn.Open(); String sql = "select count(*) from nation; select count(*) from athlete"; using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn)) { using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader()) { reader.Read(); Assert.AreEqual(215, reader.GetInt32(0)); if (reader.NextResult()) { reader.Read(); Assert.AreEqual(6677, reader.GetInt32(0)); } } } sql = "select * from nation order by code asc; select * from athlete order by name asc"; using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn)) { using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader()) { //verify the first two results reader.Read(); Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AFG", reader.GetString(0)); Assert.AreEqual("Afghanistan", reader.GetString(1)); Assert.AreEqual("Asia", reader.GetString(2)); Assert.AreEqual("Kabul", reader.GetString(3)); reader.Read(); Assert.AreEqual(4, reader.FieldCount); Assert.AreEqual("AHO", reader.GetString(0)); Assert.AreEqual("Netherlands Antilles", reader.GetString(1)); Assert.AreEqual("Americas", reader.GetString(2)); Assert.AreEqual("Willemstad", reader.GetString(3)); if (reader.NextResult()) { //verify the first two results reader.Read(); Assert.AreEqual(5, reader.FieldCount); Assert.AreEqual(15718, reader.GetInt32(0)); Assert.AreEqual("Aardenburg Willemien", reader.GetString(1)); Assert.AreEqual("W", reader.GetString(2)); Assert.AreEqual("NED", reader.GetString(3)); Assert.AreEqual("Hockey", reader.GetString(4)); reader.Read(); Assert.AreEqual(5, reader.FieldCount); Assert.AreEqual(10000, reader.GetInt32(0)); Assert.AreEqual("Aardewijn Pepijn", reader.GetString(1)); Assert.AreEqual("M", reader.GetString(2)); Assert.AreEqual("NED", reader.GetString(3)); Assert.AreEqual("Rowing", reader.GetString(4)); } } } } }