Example #1
0
    /// <summary>
    ///   Begins the transaction.
    /// </summary>
    /// <param name="iso"> The isolation level. </param>
    /// <returns> </returns>
    public CUBRIDTransaction BeginTransaction(CUBRIDIsolationLevel iso)
    {
        if (State == ConnectionState.Closed)
        {
            throw new CUBRIDException(Utils.GetStr(MsgId.TheConnectionIsNotOpen));
        }

        SetAutoCommit(false);
        CUBRIDTransaction t = new CUBRIDTransaction(this, iso);

        return t;
    }
Example #2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="CUBRIDCommand" /> class.
 /// </summary>
 /// <param name="sql"> The SQL statement. </param>
 /// <param name="conn"> The connection. </param>
 /// <param name="transaction"> The transaction. </param>
 public CUBRIDCommand(string sql, CUBRIDConnection conn, CUBRIDTransaction transaction)
   : this(sql, conn)
 {
   this.transaction = transaction;
 }
        public void CUBRIDCommand_Constructor_SQLAndConnAndTran_Test()
        {
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = DBHelper.connString;
            conn.Open();
            conn.SetAutoCommit(false);

            string sql = "drop table if exists t";
            CUBRIDTransaction transaction = new CUBRIDTransaction(conn, CUBRIDIsolationLevel.TRAN_DEFAULT_ISOLATION);
            CUBRIDCommand cmd = new CUBRIDCommand(sql, conn, transaction);

            conn.BeginTransaction();
            cmd.ExecuteNonQuery();
            cmd.CommandText = "create table t (id int, name varchar(50))";
            cmd.ExecuteNonQuery();
            cmd.CommandText = "insert into t values(1, 'Nancy')";
            cmd.ExecuteNonQuery();
            conn.Commit();

            cmd.CommandText = "select * from t";
            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();
            reader.Read();
            Assert.AreEqual(2, reader.FieldCount);
            Assert.AreEqual("1", reader.GetString(0));
            Assert.AreEqual("Nancy", reader.GetString(1));

            cmd.Close();
            reader.Close();
            conn.Close();
        }