/// <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); } }
public void DoTestTypes(DbTypeParametersCollection row) { testTypesInvocations++; exp = null; string rowId = "43967_" + this.testTypesInvocations.ToString(); OleDbDataReader rdr = null; OleDbConnection con = null; try { row.ExecuteInsert(rowId); row.ExecuteSelectReader(rowId, out rdr, out con); while (rdr.Read()) { //Run over all the columns in the result set row. //For each column, try to read it as a TimeSpan. for (int i = 0; i < row.Count; i++) { if (row[i].Value.GetType() == typeof(TimeSpan)) //The value in the result set should be a TimeSpan. { try { BeginCase(string.Format("Calling GetTimeSpan() on a field of dbtype {0}", row[i].DbTypeName)); TimeSpan retTimeSpan = rdr.GetTimeSpan(i); Compare(row[i].Value, retTimeSpan); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } } else //The value in the result set should NOT be TimeSpan. In this case an Invalid case exception should be thrown. { try { BeginCase(string.Format("Calling GetTimeSpan() on a field of dbtype {0}", row[i].DbTypeName)); TimeSpan retTimeSpan = rdr.GetTimeSpan(i); ExpectedExceptionNotCaught("InvalidCastException"); } catch (InvalidCastException ex) { ExpectedExceptionCaught(ex); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } } } } } finally { row.ExecuteDelete(rowId); if ((rdr != null) && (!rdr.IsClosed)) { rdr.Close(); } if ((con != null) && (con.State != ConnectionState.Closed)) { con.Close(); } } }