/// <summary> /// Test CUBRIDDataReader getter methods /// </summary> private static void Test_DataReader_Getxxx() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); string sql = "select * from nation;"; using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn)) { using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader()) { reader.Read(); Debug.Assert(reader.GetOrdinal("code") == 0); Debug.Assert(reader.GetName(0) == "code"); Debug.Assert(reader.GetColumnName(0) == "code"); Debug.Assert(reader.GetColumnType(0) == typeof(System.String)); Debug.Assert(reader.GetDataTypeName(0) == "CHAR"); } } } }
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 DataType_MultiSet_Test() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = DBHelper.connString; conn.Open(); DBHelper.ExecuteSQL("drop table if exists testtable", conn); DBHelper.ExecuteSQL("CREATE TABLE testtable(clsid multiset_of(INTEGER));", conn); using (CUBRIDCommand cmd = new CUBRIDCommand("Select * from TestTable", conn)) { using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader()) { reader.Read(); Assert.AreEqual(reader.HasRows, false); Assert.AreEqual(reader.GetColumnType(0), typeof(Object[])); Assert.AreEqual(reader.GetColumnTypeName(0), "MULTISET"); try { reader.GetColumnName(-1); } catch (Exception ex) { Assert.IsTrue((ex as IndexOutOfRangeException) != null); } try { reader.GetColumnTypeName(-1); } catch (Exception ex) { Assert.IsTrue((ex as IndexOutOfRangeException) != null); } try { reader.GetColumnTypeName(2); } catch (Exception ex) { Assert.IsTrue((ex as IndexOutOfRangeException) != null); } try { reader.GetColumnType(-1); } catch (Exception ex) { Assert.IsTrue((ex as IndexOutOfRangeException) != null); } try { reader.GetColumnType(2); } catch (Exception ex) { Assert.IsTrue((ex as IndexOutOfRangeException) != null); } } } DBHelper.ExecuteSQL("drop TestTable;", conn); } }