public void CUBRIDDataAdapter_ConstructorWithSqlAndConn_Test() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = DBHelper.connString; conn.Open(); DBHelper.ExecuteSQL("drop table if exists t", conn); DBHelper.ExecuteSQL("create table t (id int, name varchar(100))", conn); DBHelper.ExecuteSQL("insert into t values (1, 'Nancy')", conn); DBHelper.ExecuteSQL("insert into t values (2, 'Peter')", conn); string selectCommandText = "select * from t"; CUBRIDDataAdapter adapter = new CUBRIDDataAdapter(selectCommandText, conn); DataTable dt = new DataTable("student"); adapter.Fill(dt); //verify data Assert.AreEqual(1, (int)dt.Rows[0]["id"]); Assert.AreEqual("Nancy", dt.Rows[0]["name"].ToString()); Assert.AreEqual(2, (int)dt.Rows[1]["id"]); Assert.AreEqual("Peter", dt.Rows[1]["name"].ToString()); //revert test db DBHelper.ExecuteSQL("drop table if exists t", conn); } }
/// <summary> /// Test DataTable implicit DELETE /// </summary> private static void Test_DataTable_DeleteImplicit() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); //Insert a new row ExecuteSQL("insert into nation values('ZZZZ', 'Z', 'Z', 'Z')", conn); Debug.Assert(GetTableRowsCount("nation", conn) == 216); String sql = "select * from nation order by `code` desc"; using (CUBRIDDataAdapter da = new CUBRIDDataAdapter(sql, conn)) { CUBRIDDataAdapter daCmd = new CUBRIDDataAdapter(sql, conn); CUBRIDCommandBuilder cmdBuilder = new CUBRIDCommandBuilder(daCmd); da.DeleteCommand = cmdBuilder.GetDeleteCommand(); DataTable dt = new DataTable("nation"); da.Fill(dt); Debug.Assert(dt.Rows[0]["capital"].ToString() == "Z"); dt.Rows[0].Delete(); da.Update(dt); Debug.Assert(dt.Rows.Count == 215); } Debug.Assert(GetTableRowsCount("nation", conn) == 215); } }
/// <summary> /// Test exporting XML from DataSet /// </summary> private static void Test_DataSet_ExportXML() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation order by `code` asc"; CUBRIDDataAdapter da = new CUBRIDDataAdapter(); da.SelectCommand = new CUBRIDCommand(sql, conn); DataSet ds = new DataSet(); da.Fill(ds, "nation"); string filename = @".\Test_DataSet_ExportXML.xml"; ds.WriteXml(filename); if (!System.IO.File.Exists(filename)) { throw new Exception("XML output file not found!"); } else { System.IO.File.Delete(filename); } } }
/// <summary> /// Test SQL statements execution, using DataView /// </summary> private static void Test_DataView_Basic() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation order by `code` asc"; CUBRIDDataAdapter da = new CUBRIDDataAdapter(); da.SelectCommand = new CUBRIDCommand(sql, conn); DataTable dt = new DataTable("nation"); da.Fill(dt); DataView dataView = new DataView(dt); Debug.Assert(dataView.Count == 215); Debug.Assert(dataView.Table.TableName == "nation"); foreach (DataRowView view in dataView) { Debug.Assert(dataView[0][0].ToString() == "AFG"); break; //retrieve just one row } } }
/// <summary> /// Test basic SQL statements execution, using DataSet /// </summary> private static void Test_DataSet_Basic() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation order by `code` asc"; CUBRIDDataAdapter da = new CUBRIDDataAdapter(); da.SelectCommand = new CUBRIDCommand(sql, conn); DataSet ds = new DataSet("nation"); da.Fill(ds); DataTable dt0 = ds.Tables["Table"]; Debug.Assert(dt0 != null); dt0 = ds.Tables[0]; Debug.Assert(dt0.Columns.Count == 4); Debug.Assert(dt0.DefaultView.Count == 215); Debug.Assert(dt0.DefaultView.AllowEdit == true); Debug.Assert(dt0.DefaultView.AllowDelete == true); Debug.Assert(dt0.DefaultView.AllowNew == true); Debug.Assert(dt0.DataSet.DataSetName == "nation"); DataRow[] dataRow = dt0.Select("continent = 'Africa'"); Debug.Assert(dataRow.Length == 54); } }
/// <summary> /// Test BLOB SELECT, using CUBRIDDataAdapter and DataTable /// </summary> private static void Test_Blob_SelectDataAdapter() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); CreateTestTableLOB(conn); string sql1 = "insert into t (b) values(?)"; CUBRIDCommand cmd1 = new CUBRIDCommand(sql1, conn); CUBRIDBlob Blob1 = new CUBRIDBlob(conn); CUBRIDBlob Blob2 = new CUBRIDBlob(conn); byte[] bytes1 = new byte[256]; bytes1[0] = 69; bytes1[1] = 98; bytes1[2] = 99; bytes1[255] = 122; Blob1.SetBytes(1, bytes1); CUBRIDParameter param = new CUBRIDParameter(); param.ParameterName = "?"; param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_BLOB; param.Value = Blob1; cmd1.Parameters.Add(param); cmd1.Parameters[0].DbType = DbType.Binary; cmd1.ExecuteNonQuery(); cmd1.Close(); string sql = "SELECT b from t"; DataTable dt = new DataTable("t"); CUBRIDDataAdapter da = new CUBRIDDataAdapter(); da.SelectCommand = new CUBRIDCommand(sql, conn); da.Fill(dt); for (int j = 0; j < dt.Rows.Count; j++) { CUBRIDBlob bImage = (CUBRIDBlob)dt.Rows[j]["b"]; byte[] bytes = new byte[(int)bImage.BlobLength]; bytes = bImage.GetBytes(1, (int)bImage.BlobLength); Debug.Assert(bytes1.Length == bytes.Length, "The selected length is not valid!"); bool ok = true; for (int i = 0; i < bytes.Length; i++) { if (bytes1[i] != bytes[i]) { ok = false; } } Debug.Assert(ok == true, "The BLOB was not selected correctly!"); } CleanupTestTableLOB(conn); } }
public void CUBRIDCommand_Prepare_Basic_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, name varchar(50))", conn); CUBRIDCommand cmd = new CUBRIDCommand(null, conn); LogTestStep("Test Prepare"); cmd.CommandText = "insert into t (id, name) values (?, ?)"; CUBRIDParameter idParam = new CUBRIDParameter("?", CUBRIDDataType.CCI_U_TYPE_INT, 8); CUBRIDParameter nameParam = new CUBRIDParameter("?", CUBRIDDataType.CCI_U_TYPE_STRING, 20); idParam.Value = 2; nameParam.Value = "Rachel Green"; cmd.Parameters.Add(idParam); cmd.Parameters.Add(nameParam); Log("Call Prepare after setting the Commandtext and Parameters."); cmd.Prepare(); cmd.ExecuteNonQuery(); Log("Change parameter values and call ExecuteNonQuery."); cmd.Parameters[0].Value = 5; cmd.Parameters[1].Value = "Bill Gates"; cmd.ExecuteNonQuery(); Log("Verify the date are inserted by querying them from db"); cmd = new CUBRIDCommand("select * from t", conn); CUBRIDDataAdapter adapter = new CUBRIDDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); Assert.AreEqual(2, dt.Rows.Count); Assert.AreEqual(2, (int)dt.Rows[0][0]); Assert.AreEqual("Rachel Green", dt.Rows[0][1].ToString()); Assert.AreEqual(5, (int)dt.Rows[1][0]); Assert.AreEqual("Bill Gates", dt.Rows[1][1].ToString()); LogStepPass(); cmd.Close(); Log("delete test table"); DBHelper.ExecuteSQL("drop table if exists t", conn); LogTestResult(); } }
//http://msdn.microsoft.com/en-us/library/bbw6zyha%28v=vs.80%29.aspx /// <summary> /// Test DataTable explicit UPDATE /// </summary> private static void Test_DataTable_UpdateExplicit() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation order by `code` asc LIMIT 10"; using (CUBRIDDataAdapter da = new CUBRIDDataAdapter(sql, conn)) { //Initialize the command object that will be used as the UpdateCommand for the DataAdapter. CUBRIDCommand daUpdate = new CUBRIDCommand("update nation set capital = ? where code = ?", conn); //Parameter: capital daUpdate.Parameters.Add(new CUBRIDParameter("?p1", DbType.String)); daUpdate.Parameters[0].SourceVersion = DataRowVersion.Current; daUpdate.Parameters[0].SourceColumn = "capital"; daUpdate.Parameters[0].SourceColumnNullMapping = false; //Parameter: code daUpdate.Parameters.Add(new CUBRIDParameter("?p2", DbType.String)); daUpdate.Parameters[1].SourceVersion = DataRowVersion.Original; daUpdate.Parameters[1].SourceColumn = "code"; daUpdate.Parameters[1].SourceColumnNullMapping = false; daUpdate.UpdatedRowSource = UpdateRowSource.None; //Assign the command to the UpdateCommand property of the DataAdapter. da.UpdateCommand = daUpdate; DataTable dt = new DataTable("nation"); da.Fill(dt); DataRow workRow = dt.Rows[0]; Debug.Assert(workRow["capital"].ToString() == "Kabul"); workRow.BeginEdit(); workRow["capital"] = "MyKabul"; workRow.EndEdit(); da.Update(dt); dt.AcceptChanges(); Debug.Assert(workRow["capital"].ToString() == "MyKabul"); Debug.Assert(workRow.RowState.ToString() != "New"); } Debug.Assert((string)GetSingleValue("select capital from nation where `code` = 'AFG'", conn) == "MyKabul"); //Revert changes ExecuteSQL("update nation set capital = 'Kabul' where capital = 'MyKabul'", conn); Debug.Assert((string)GetSingleValue("select capital from nation where `code` = 'AFG'", conn) == "Kabul"); } }
/// <summary> /// Test CLOB SELECT, using CUBRIDDataAdapter and DataSet /// </summary> private static void Test_Clob_SelectDataAdapter2() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); CreateTestTableLOB(conn); string sql1 = "insert into t (c) values(?)"; CUBRIDCommand cmd1 = new CUBRIDCommand(sql1, conn); CUBRIDClob Clob1 = new CUBRIDClob(conn); String str1 = conn.ConnectionString; //Use ConnectionString content for testing Clob1.SetString(1, str1); CUBRIDParameter param = new CUBRIDParameter(); param.ParameterName = "?"; param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB; param.Value = Clob1; cmd1.Parameters.Add(param); cmd1.ExecuteNonQuery(); cmd1.Close(); string sql = "SELECT c from t"; DataSet ds = new DataSet(); CUBRIDDataAdapter da = new CUBRIDDataAdapter(); da.SelectCommand = new CUBRIDCommand(sql, conn); da.Fill(ds); DataTable dt = ds.Tables[0]; for (int j = 0; j < dt.Rows.Count; j++) { CUBRIDClob cImage = (CUBRIDClob)dt.Rows[j]["c"]; string str = cImage.GetString(1, (int)cImage.ClobLength); Debug.Assert(str.Length == str1.Length, "The selected CLOB length is not valid!"); Debug.Assert(str.Equals(str1), "The CLOB was not selected correctly!"); } CleanupTestTableLOB(conn); } }
//http://msdn.microsoft.com/en-us/library/bbw6zyha%28v=vs.80%29.aspx /// <summary> /// Test DataTable explicit DELETE /// </summary> private static void Test_DataTable_DeleteExplicit() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); //Insert a new row ExecuteSQL("insert into nation values('ZZZZ', 'Z', 'Z', 'Z')", conn); Debug.Assert(GetTableRowsCount("nation", conn) == 216); String sql = "select * from nation order by `code` desc"; using (CUBRIDDataAdapter da = new CUBRIDDataAdapter(sql, conn)) { //Initialize the command object that will be used as the DeleteCommand for the DataAdapter. CUBRIDCommand daDelete = new CUBRIDCommand("delete from nation where code = ?", conn); //Parameter: code daDelete.Parameters.Add(new CUBRIDParameter("?p1", DbType.String)); daDelete.Parameters["?p1"].SourceVersion = DataRowVersion.Original; daDelete.Parameters["?p1"].SourceColumn = "code"; daDelete.Parameters["?p1"].SourceColumnNullMapping = false; daDelete.UpdatedRowSource = UpdateRowSource.OutputParameters; //Assign the command to the DeleteCommand property of the DataAdapter. da.DeleteCommand = daDelete; DataTable dt = new DataTable("nation"); da.Fill(dt); Debug.Assert(dt.Rows[0]["capital"].ToString() == "Z"); dt.Rows[0].Delete(); da.Update(dt); Debug.Assert(dt.Rows.Count == 215); } Debug.Assert(GetTableRowsCount("nation", conn) == 215); } }
/// <summary> /// Test basic SQL Statements execution, using DataTable /// </summary> private static void Test_DataTable_Basic() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation order by `code` asc"; using (DataTable dt = new DataTable("nation")) { CUBRIDDataAdapter da = new CUBRIDDataAdapter(); da.SelectCommand = new CUBRIDCommand(sql, conn); da.Fill(dt); Debug.Assert(dt.Columns.Count == 4); Debug.Assert(dt.Rows.Count == 215); Debug.Assert(dt.Rows[1][1].ToString() == "Netherlands Antilles"); Debug.Assert(dt.Rows[3][2].ToString() == "Africa"); } } }
//http://msdn.microsoft.com/en-us/library/bbw6zyha%28v=vs.80%29.aspx /// <summary> /// Test DataTable implicit UPDATE /// </summary> private static void Test_DataTable_UpdateImplicit() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation order by `code` asc"; using (CUBRIDDataAdapter da = new CUBRIDDataAdapter(sql, conn)) { using (CUBRIDDataAdapter daCmd = new CUBRIDDataAdapter(sql, conn)) { CUBRIDCommandBuilder cmdBuilder = new CUBRIDCommandBuilder(daCmd); da.UpdateCommand = cmdBuilder.GetUpdateCommand(); } DataTable dt = new DataTable("nation"); da.Fill(dt); //Update data DataRow workRow = dt.Rows[0]; Debug.Assert(workRow["code"].ToString() == "AFG"); Debug.Assert(workRow["capital"].ToString() == "Kabul"); workRow.BeginEdit(); workRow["capital"] = "MyKabul"; workRow.EndEdit(); da.Update(dt); Debug.Assert(workRow["capital"].ToString() == "MyKabul"); Debug.Assert(workRow.RowState.ToString() != "New"); } Debug.Assert((string)GetSingleValue("select capital from nation where `code` = 'AFG'", conn) == "MyKabul"); //Revert changes ExecuteSQL("update nation set capital = 'Kabul' where capital = 'MyKabul'", conn); Debug.Assert((string)GetSingleValue("select capital from nation where `code` = 'AFG'", conn) == "Kabul"); } }
//http://msdn.microsoft.com/en-us/library/bbw6zyha%28v=vs.80%29.aspx /// <summary> /// Test DataTable implicit INSERT /// </summary> private static void Test_DataTable_InsertImplicit() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation order by `code` asc"; using (CUBRIDDataAdapter da = new CUBRIDDataAdapter(sql, conn)) { using (CUBRIDDataAdapter daCmd = new CUBRIDDataAdapter(sql, conn)) { CUBRIDCommandBuilder cmdBuilder = new CUBRIDCommandBuilder(daCmd); da.InsertCommand = cmdBuilder.GetInsertCommand(); } DataTable dt = new DataTable("nation"); da.Fill(dt); DataRow newRow = dt.NewRow(); newRow["code"] = "ZZZ"; newRow["name"] = "ABCDEF"; newRow["capital"] = "MyXYZ"; newRow["continent"] = "QWERTY"; dt.Rows.Add(newRow); da.Update(dt); Debug.Assert(dt.Rows.Count == 216); } Debug.Assert(GetTableRowsCount("nation", conn) == 216); //Revert changes ExecuteSQL("delete from nation where `code` = 'ZZZ'", conn); Debug.Assert(GetTableRowsCount("nation", conn) == 215); } }
/// <summary> /// Test DataTable explicit INSERT /// </summary> private static void Test_DataTable_InsertExplicit() { using (CUBRIDConnection conn = new CUBRIDConnection()) { conn.ConnectionString = TestCases.connString; conn.Open(); String sql = "select * from nation order by `code` DESC LIMIT 10"; using (CUBRIDDataAdapter da = new CUBRIDDataAdapter(sql, conn)) { //Initialize the command object that will be used as the UpdateCommand for the DataAdapter. CUBRIDCommand daInsert = new CUBRIDCommand("insert into nation values(?,?,?,?)", conn); daInsert.CommandType = CommandType.Text; //Parameter: code daInsert.Parameters.Add(new CUBRIDParameter("?p1", DbType.String)); daInsert.Parameters["?p1"].SourceVersion = DataRowVersion.Current; daInsert.Parameters["?p1"].SourceColumn = "code"; daInsert.Parameters["?p1"].SourceColumnNullMapping = false; //Parameter: name daInsert.Parameters.Add(new CUBRIDParameter("?p2", DbType.String)); daInsert.Parameters["?p2"].SourceVersion = DataRowVersion.Original; daInsert.Parameters["?p2"].SourceColumn = "name"; daInsert.Parameters["?p2"].SourceColumnNullMapping = false; //Parameter: continent daInsert.Parameters.Add(new CUBRIDParameter("?p3", DbType.String)); daInsert.Parameters["?p3"].SourceVersion = DataRowVersion.Current; daInsert.Parameters["?p3"].SourceColumn = "continent"; daInsert.Parameters["?p3"].SourceColumnNullMapping = false; //Parameter: capital daInsert.Parameters.Add(new CUBRIDParameter("?p4", DbType.String)); daInsert.Parameters["?p4"].SourceVersion = DataRowVersion.Original; daInsert.Parameters["?p4"].SourceColumn = "capital"; daInsert.Parameters["?p4"].SourceColumnNullMapping = false; daInsert.UpdatedRowSource = UpdateRowSource.None; //Assign the command to the InsertCommand property of the DataAdapter. da.InsertCommand = daInsert; DataTable dt = new DataTable("nation"); da.Fill(dt); DataRow newRow = dt.NewRow(); newRow["code"] = "ZZZ"; newRow["name"] = "ABCDEF"; newRow["capital"] = "MyXYZ"; newRow["continent"] = "QWERTY"; dt.Rows.InsertAt(newRow, 0); da.Update(dt); dt.AcceptChanges(); Debug.Assert(dt.Rows[0]["capital"].ToString() == "MyXYZ"); Debug.Assert(newRow.RowState.ToString() != "New"); } Debug.Assert(GetTableRowsCount("nation", conn) == 216); //Revert changes ExecuteSQL("delete from nation where `code` = 'ZZZ'", conn); Debug.Assert(GetTableRowsCount("nation", conn) == 215); } }
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(); }
public void CUBRIDDataAdapter_Command_Test() { CUBRIDConnection conn = new CUBRIDConnection(); conn.ConnectionString = DBHelper.connString; conn.Open(); DBHelper.ExecuteSQL("drop table if exists t", conn); DBHelper.ExecuteSQL("create table t (id int, name varchar(100))", conn); DBHelper.ExecuteSQL("insert into t values (1, 'Nancy')", conn); DBHelper.ExecuteSQL("insert into t values (2, 'Peter')", conn); CUBRIDDataAdapter adapter = new CUBRIDDataAdapter(); //SelectCommand string sql = "select * from t"; CUBRIDCommand cmd = new CUBRIDCommand(sql, conn); adapter.SelectCommand = cmd; DataTable dt = new DataTable("student"); adapter.Fill(dt); //verify data Assert.AreEqual(1, (int)dt.Rows[0]["id"]); Assert.AreEqual("Nancy", dt.Rows[0]["name"].ToString()); Assert.AreEqual(2, (int)dt.Rows[1]["id"]); Assert.AreEqual("Peter", dt.Rows[1]["name"].ToString()); Assert.AreEqual(sql, adapter.SelectCommand.CommandText); //UpdateCommand sql = "update t set name='Mandy' where id=1"; cmd = new CUBRIDCommand(sql, conn); adapter.UpdateCommand = cmd; adapter.UpdateCommand.ExecuteNonQuery(); dt.AcceptChanges(); adapter.Update(dt); Console.WriteLine(dt.Rows[0]["name"]); //dt.AcceptChanges(); //Assert.AreEqual(1, (int)dt.Rows[0]["id"]); //Assert.AreEqual("Mandy", dt.Rows[0]["name"].ToString()); //Assert.AreEqual(2, (int)dt.Rows[1]["id"]); //Assert.AreEqual("Peter", dt.Rows[1]["name"].ToString()); //Assert.AreEqual(sql, adapter.UpdateCommand.CommandText); //DeleteCommand sql = "delete from t where name='Mandy'"; cmd = new CUBRIDCommand(sql, conn); adapter.DeleteCommand = cmd; adapter.DeleteCommand.ExecuteNonQuery(); dt.Rows[0].Delete(); //TODO: Verifcation: might need to 'SqlCommandBuilder'? dt.AcceptChanges(); adapter.Update(dt); Assert.AreEqual(1, dt.Rows.Count); Assert.AreEqual(2, (int)dt.Rows[0]["id"]); Assert.AreEqual("Peter", dt.Rows[0]["name"].ToString()); Assert.AreEqual(sql, adapter.DeleteCommand.CommandText); // -- //InsertCommand //revert test db DBHelper.ExecuteSQL("drop table if exists t", conn); conn.Close(); }