public HowTo_UseTransactions_betweenDOs_operations() { string _testid = DateTime.Now.Ticks.ToString(); bool _constraint; long _iduser; long _idgroup; // we need a shared connection between Data Objects DBConnection _con = DO__utils.DBConnection_createInstance( DO__utils.DBServerType, DO__utils.DBConnectionstring, string.Empty ); // before beginning a transaction we need to open the connection _con.Open(); // beginning transaction _con.Transaction.Begin(); // sharing connection with User Data Object DO_User _user = new DO_User(_con); // performing some operations on User Data Object _user.Fields.Login = _testid; _user.Fields.Password = _testid; _iduser = _user.insObject(true, out _constraint); // handling constraint code should be added here _user.Dispose(); _user = null; // sharing connection with Group Data Object DO_Group _group = new DO_Group(_con); // performing some operations on User Data Object _group.Fields.Name = _testid; _idgroup = _group.insObject(true); _group.Dispose(); _group = null; // sharing connection with Group Data Object DO_UserGroup _usergroup = new DO_UserGroup(_con); // performing some operations on User Data Object _usergroup.Fields.IDGroup = _idgroup; _usergroup.Fields.IDUser = _iduser; _usergroup.Fields.Relationdate = DateTime.Now; _usergroup.Fields.Defaultrelation = false; _usergroup.setObject(false); _usergroup.Dispose(); _usergroup = null; // rollback transaction, we don't need such data in db, this is just an how to sample _con.Transaction.Rollback(); // terminate transaction _con.Transaction.Terminate(); // closing connection _con.Close(); _con.Dispose(); _con = null; }
public void UT_NullableFields() { bool _contraint; long _iduser; long _idgroup; for (int c = 0; c < UT0__utils.DBConnections.Length; c++) { //Console.WriteLine("UT_NullableFields: {0}", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]).ToString()); UT0__utils.DBConnections[c].Open(); UT0__utils.DBConnections[c].Transaction.Begin(); #region _iduser = new DO_User(UT0__utils.DBConnections[c]).insObject(true); DO_User _user = new DO_User(UT0__utils.DBConnections[c]); _user.Fields.Login = testid_; _user.Fields.Password = testid_; _iduser = _user.insObject(true, out _contraint); _user.Dispose(); _user = null; #endregion #region _idgroup = new DO_Group(UT0__utils.DBConnections[c]).insObject(true); DO_Group _group = new DO_Group(UT0__utils.DBConnections[c]); _group.Fields.Name = testid_; _idgroup = _group.insObject(true); _group.Dispose(); _group = null; #endregion DO_UserGroup _usergroup = new DO_UserGroup(UT0__utils.DBConnections[c]); _usergroup.Fields.IDUser = _iduser; _usergroup.Fields.IDGroup = _idgroup; _usergroup.Fields.Relationdate_isNull = true; _usergroup.Fields.Defaultrelation_isNull = true; _usergroup.setObject(true); #region test1... _usergroup.clrObject(); _usergroup.getObject(_iduser, _idgroup); Assert.IsTrue(_usergroup.Fields.Relationdate_isNull, "DO_UserGroup.Relationdate expected to be nullable ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])); Assert.IsTrue(_usergroup.Fields.Defaultrelation_isNull, "DO_UserGroup.Defaultrelation expected to be nullable ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])); #endregion #region test2... _usergroup.Record.Open_byUser_Defaultrelation( _iduser, null ); while (_usergroup.Record.Read()) { Assert.IsTrue(_usergroup.Fields.Relationdate_isNull, "DO_UserGroup.Relationdate expected to be nullable ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])); Assert.IsTrue(_usergroup.Fields.Defaultrelation_isNull, "DO_UserGroup.Defaultrelation expected to be nullable ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])); } _usergroup.Record.Close(); #endregion #region test3... Assert.IsTrue( _usergroup.Record.hasObject_byUser_Defaultrelation( _iduser, _idgroup, _iduser, null ), "test error: 1 ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]) ); Assert.AreEqual( 1L, _usergroup.Record.Count_byUser_Defaultrelation( _iduser, null ), "test error: 2 ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]) ); #endregion #region test4... DateTime _now = DateTime.Now; _usergroup.Record.Update_SomeUpdateTest_byUser_Defaultrelation( _iduser, null, _now ); Assert.IsTrue( _usergroup.Record.hasObject_byUser_Defaultrelation( _iduser, _idgroup, _iduser, _now ), "test error: 3 ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]) ); Assert.AreEqual( 1L, _usergroup.Record.Count_byUser_Defaultrelation( _iduser, _now ), "test error: 4 ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]) ); #endregion _usergroup.Dispose(); _usergroup = null; UT0__utils.DBConnections[c].Transaction.Rollback(); UT0__utils.DBConnections[c].Transaction.Terminate(); UT0__utils.DBConnections[c].Close(); } }
public void UT_bugPostgreSQL_noFunctionMatchesTheGivenNameAndArgumentTypes() { bool _contraint; long _iduser; long _idgroup; for (int c = 0; c < UT0__utils.DBConnections.Length; c++) { //Console.WriteLine("UT_NullableFields: {0}", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]).ToString()); UT0__utils.DBConnections[c].Open(); UT0__utils.DBConnections[c].Transaction.Begin(); #region _iduser = new DO_User(UT0__utils.DBConnections[c]).insObject(true); DO_User _user = new DO_User(UT0__utils.DBConnections[c]); _user.Fields.Login = testid_; _user.Fields.Password = testid_; _iduser = _user.insObject(true, out _contraint); _user.Dispose(); _user = null; #endregion #region _idgroup = new DO_Group(UT0__utils.DBConnections[c]).insObject(true); DO_Group _group = new DO_Group(UT0__utils.DBConnections[c]); _group.Fields.Name = testid_; _idgroup = _group.insObject(true); _group.Dispose(); _group = null; #endregion DO_UserGroup _usergroup = new DO_UserGroup(UT0__utils.DBConnections[c]); _usergroup.Fields.IDUser = _iduser; _usergroup.Fields.IDGroup = _idgroup; _usergroup.Fields.Relationdate_isNull = true; _usergroup.Fields.Defaultrelation_isNull = true; try { _usergroup.setObject(true); } catch { Assert.Fail( "test error: 1 ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]) ); } _usergroup.Dispose(); _usergroup = null; UT0__utils.DBConnections[c].Transaction.Rollback(); UT0__utils.DBConnections[c].Transaction.Terminate(); UT0__utils.DBConnections[c].Close(); } }