private static void CleanupTestTableLOB(OleDbConnection conn) { TestCasesOld.ExecuteSQL("drop table if exists t", conn); }
private static void CreateTestTable(OleDbConnection conn) { TestCasesOld.ExecuteSQL("drop table if exists t", conn); TestCasesOld.ExecuteSQL("create table t(a int, b char(10), c string, d float, e double, f date)", conn); }
private static void CreateTestTableLOB(OleDbConnection conn) { TestCasesOld.ExecuteSQL("drop table if exists t", conn); TestCasesOld.ExecuteSQL("create table t(b BLOB, c CLOB)", conn); }
/// <summary> /// Test CUBRID data types Get...() /// </summary> private static void Test_Various_DataTypes() { using (OleDbConnection conn = new OleDbConnection()) { conn.ConnectionString = TestCasesOld.connString; conn.Open(); TestCasesOld.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, "; sql += "c_varchar varchar(4096), "; sql += "c_time time, "; sql += "c_date date, "; sql += "c_timestamp timestamp, "; sql += "c_datetime datetime, "; sql += "c_bit bit(1), "; sql += "c_varbit bit varying(4096), "; sql += "c_monetary monetary, "; sql += "c_string string"; sql += ")"; TestCasesOld.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'0', "; sql += "B'0', "; sql += "123456789, "; sql += "'qwerty'"; sql += ")"; TestCasesOld.ExecuteSQL(sql, conn); sql = "select * from t"; using (OleDbCommand cmd = new OleDbCommand(sql, conn)) { try { OleDbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) //only one row will be available { Debug.Assert(reader.GetInt32(0) == 1); Debug.Assert(reader.GetInt16(1) == 11); Debug.Assert(reader.GetInt32(2) == 111); Debug.Assert(reader.GetInt64(3) == 1111); Debug.Assert(reader.GetDecimal(4) == (decimal)1.1); Debug.Assert(reader.GetFloat(5) == (float)1.11); //"Single" Debug.Assert(reader.GetDecimal(6) == (decimal)1.111); Debug.Assert(reader.GetDouble(7) == (double)1.1111); //We use GetString() because GetChar() is not supported or System.Data.OleDb. //http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader.getchar Debug.Assert(reader.GetString(8) == "a"); //"String" ("Char" in CUBRID) Debug.Assert(reader.GetString(9) == "abcdfghijk"); //"String" ("String in CUBRID) //GetGateTime cannot cast just the time value in a DateTime object, so we use TimeSpan Debug.Assert(reader.GetTimeSpan(10) == new TimeSpan(13, 15, 45)); //"TimeSpan" Debug.Assert(reader.GetDateTime(11) == new DateTime(2000, 10, 31)); //"DateTime" Debug.Assert(reader.GetDateTime(12) == new DateTime(2008, 10, 31, 13, 15, 45)); //"DateTime" Console.WriteLine(reader.GetValue(13)); Debug.Assert(reader.GetDateTime(13) == new DateTime(2008, 10, 31, 13, 15, 45)); //"DateTime" //The GetByte() method does not perform any conversions and the driver does not give tha data as Byte //http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader.getbyte //Use GetValue() or GetBytes() methods to retrieve BIT coulumn value // Debug.Assert((reader.GetValue(14) as byte[])[0] == (byte)0); //"Byte[]" ("bit(1)" in CUBRID) //Or Byte[] value = new Byte[1]; reader.GetBytes(14, 0, value, 0, 1); // Debug.Assert(value[0] == (byte)0);//"Byte[]" ("bit(1)" in CUBRID) //Debug.Assert((reader.GetValue(14) as byte[])[0] == (byte)0); //"Byte[]" ("bit varying(4096)" in CUBRID) //Or // reader.GetBytes(15, 0, value, 0, 1); // Debug.Assert(value[0] == (byte)0);//"Byte[]" ("bit varying(4096)" in CUBRID) Debug.Assert(reader.GetDouble(16) == 123456789.0); //"Double" ("Monetary" in CUBRID) Debug.Assert(reader.GetString(17) == "qwerty"); //"String" } } catch (Exception ex) { Console.WriteLine(ex.Message); } } TestCasesOld.ExecuteSQL("drop table if exists t", conn); } }