/// <summary> /// Test CUBRIDCommand column properties /// </summary> private static void Test_Command_ColumnProperties() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation"; CUBRIDCommand cmd = new CUBRIDCommand(sql, conn); CUBRIDCommand cmd2 = cmd.Clone(); try { cmd.Cancel(); } catch (Exception e) { string r = "System.NotSupportedException: Specified method is not supported"; Debug.Assert(e.Message.Substring(0,r.Length) == r); } Debug.Assert(cmd.CommandType == cmd2.CommandType); CUBRIDDataAdapter da = new CUBRIDDataAdapter(); da.SelectCommand = cmd; DataTable dt = new DataTable(""); da.FillSchema(dt, SchemaType.Source);//To retrieve all the column properties you have to use the FillSchema() method Debug.Assert(cmd.ColumnInfos[0].Name == "code"); Debug.Assert(cmd.ColumnInfos[0].IsPrimaryKey == true); Debug.Assert(cmd.ColumnInfos[0].IsForeignKey == false); Debug.Assert(cmd.ColumnInfos[0].IsNullable == false); Debug.Assert(cmd.ColumnInfos[0].RealName == ""); Debug.Assert(cmd.ColumnInfos[0].Precision == 3); Debug.Assert(cmd.ColumnInfos[0].Scale == 0); Debug.Assert(cmd.ColumnInfos[0].IsAutoIncrement == false); Debug.Assert(cmd.ColumnInfos[0].IsReverseIndex == false); Debug.Assert(cmd.ColumnInfos[0].IsReverseUnique == false); Debug.Assert(cmd.ColumnInfos[0].IsShared == false); Debug.Assert(cmd.ColumnInfos[0].Type == CUBRIDDataType.CCI_U_TYPE_CHAR); Debug.Assert(cmd.ColumnInfos[0].Table == "nation"); } }
public void CUBRIDCommand_Clone_Test() { using (CUBRIDConnection conn = new CUBRIDConnection(DBHelper.connString)) { conn.Open(); DBHelper.ExecuteSQL("drop table if exists t", conn); DBHelper.ExecuteSQL("create table t (id int primary key, name varchar(50))", conn); DBHelper.ExecuteSQL("insert into t (id, name) values (2, 'Rachel Green')", conn); DBHelper.ExecuteSQL("insert into t (id, name) values (3, 'Rachel Green')", conn); DBHelper.ExecuteSQL("insert into t (id, name) values (5, 'Bill Gates')", conn); LogTestStep("Clone a CUBRIDCommand which has parameters"); CUBRIDCommand cmd = new CUBRIDCommand(null, conn); cmd.CommandText = "select * from t where id = ?myId and name = ?myName"; CUBRIDParameter idParam = new CUBRIDParameter("?myId", CUBRIDDataType.CCI_U_TYPE_INT, 8); CUBRIDParameter nameParam = new CUBRIDParameter("?myName", CUBRIDDataType.CCI_U_TYPE_STRING, 20); idParam.Value = 2; nameParam.Value = "Rachel Green"; cmd.Parameters.Add(idParam); cmd.Parameters.Add(nameParam); CUBRIDCommand cmdClone = cmd.Clone(); CUBRIDDataAdapter adapter = new CUBRIDDataAdapter(); adapter.SelectCommand = cmdClone; Log("Verify the cloned command"); DataTable dt = new DataTable(""); adapter.Fill(dt); Assert.AreEqual(1, dt.Rows.Count); Assert.AreEqual(2, (int)dt.Rows[0][0]); Assert.AreEqual("Rachel Green", dt.Rows[0][1].ToString()); adapter.FillSchema(dt, SchemaType.Source);//To retrieve all the column properties you have to use the FillSchema() method Assert.AreEqual(cmdClone.ColumnInfos[0].Name, "id"); Assert.AreEqual(cmdClone.ColumnInfos[0].IsPrimaryKey, true); Assert.AreEqual(cmdClone.ColumnInfos[0].IsForeignKey, false); Assert.AreEqual(cmdClone.ColumnInfos[0].IsNullable, false); Assert.AreEqual(cmdClone.ColumnInfos[0].RealName, "t"); Assert.AreEqual(cmdClone.ColumnInfos[0].Precision, 10); Assert.AreEqual(cmdClone.ColumnInfos[0].Scale, 0); Assert.AreEqual(cmdClone.ColumnInfos[0].IsAutoIncrement, false); Assert.AreEqual(cmdClone.ColumnInfos[0].IsReverseIndex, false); Assert.AreEqual(cmdClone.ColumnInfos[0].IsReverseUnique, false); Assert.AreEqual(cmdClone.ColumnInfos[0].IsShared, false); Assert.AreEqual(cmdClone.ColumnInfos[0].Type, CUBRIDDataType.CCI_U_TYPE_INT); Assert.AreEqual(cmdClone.ColumnInfos[0].Table, "t"); LogStepPass(); adapter.Dispose(); cmd.Close(); Log("delete test db"); //DBHelper.ExecuteSQL("drop table if exists t", conn); } LogTestResult(); }