/// <summary> /// Test SET operations /// </summary> private static void Test_SetOperations() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); TestCases.ExecuteSQL("DROP TABLE IF EXISTS t", conn); //Create a new table with a collection TestCases.ExecuteSQL("CREATE TABLE t(s SET(int))", conn); //Insert some data in the sequence column TestCases.ExecuteSQL("INSERT INTO t(s) VALUES({0,1,2,3,4,5,6})", conn); CUBRIDOid oid = new CUBRIDOid("@0|0|0"); using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT t FROM t", conn)) { using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { oid = (CUBRIDOid)reader[0]; } } } String attributeName = "s"; object value = 7; int SeqSize = conn.GetCollectionSize(oid, attributeName); Debug.Assert(SeqSize == 7); conn.AddElementToSet(oid, attributeName, value); SeqSize = conn.GetCollectionSize(oid, attributeName); Debug.Assert(SeqSize == 8); using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn)) { using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int[] expected = { 0, 1, 2, 3, 4, 5, 6, 7 }; object[] o = (object[])reader[0]; for (int i = 0; i < SeqSize; i++) { Debug.Assert(Convert.ToInt32(o[i]) == expected[i]); } } } } conn.DropElementInSet(oid, attributeName, 5); SeqSize = conn.GetCollectionSize(oid, attributeName); Debug.Assert(SeqSize == 7); using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn)) { using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int[] expected = { 0, 1, 2, 3, 4, 6, 7 }; object[] o = (object[])reader[0]; for (int i = 0; i < SeqSize; i++) { Debug.Assert(Convert.ToInt32(o[i]) == expected[i]); } } } } TestCases.ExecuteSQL("DROP t", conn); } }
public void CollectionSet_Test() { Log("Test GetCollectionSize, AddElementToSet, DropElementInSet"); using (CUBRIDConnection conn = new CUBRIDConnection()) { LogTestStep("Test GetCollectionSize"); conn.ConnectionString = DBHelper.connString; conn.Open(); DBHelper.ExecuteSQL("drop table if exists t", conn); //Create a new table with a sequence DBHelper.ExecuteSQL("CREATE TABLE t(seq SEQUENCE(int))", conn); //Insert some data in the sequence column DBHelper.ExecuteSQL("INSERT INTO t(seq) VALUES({0,1,2,3,4,5,6})", conn); CUBRIDOid oid = new CUBRIDOid("@0|0|0"); using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT t FROM t", conn)) { using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { oid = (CUBRIDOid)reader[0]; } } } String attributeName = "seq"; int SeqSize = conn.GetCollectionSize(oid, attributeName); Assert.AreEqual(7, SeqSize); LogStepPass(); LogTestStep("Test AddElementToSet"); conn.AddElementToSet(oid, attributeName, 10); SeqSize = conn.GetCollectionSize(oid, attributeName); Assert.AreEqual(8, SeqSize); using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn)) { using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int[] expected = { 0, 1, 2, 3, 4, 5, 6, 10 }; object[] o = (object[])reader[0]; for (int i = 0; i < SeqSize; i++) { Assert.AreEqual(expected[i], Convert.ToInt32(o[i])); } } } } LogStepPass(); LogTestStep("Test DropElementInSet"); conn.DropElementInSequence(oid, attributeName, 5); SeqSize = conn.GetCollectionSize(oid, attributeName); Assert.AreEqual(7, SeqSize); using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn)) { using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int[] expected = { 0, 1, 2, 3, 5, 6, 10 }; object[] o = (object[])reader[0]; for (int i = 0; i < SeqSize; i++) { Assert.AreEqual(expected[i], Convert.ToInt32(o[i])); } } } } LogStepPass(); //revert test db DBHelper.ExecuteSQL("drop table t", conn); LogTestResult(); } }