示例#1
0
        public override void Enlist(object distributedTransaction)
        {
            ITransaction transaction = (ITransaction)distributedTransaction;

            if (transaction == null)
            {
                Future future = new Future(Service.TransactionEnlist, (int)DtpFlags.SQL_TP_UNENLIST, null);
                object result = null;
                try
                {
                    futures.Add(future);
                    future.SendRequest(Session);
                    result = future.GetNextResult(Session, futures);
                }
                finally
                {
                    futures.Remove(future);
                }
                if (result != null && result is object[])
                {
                    object[] results = (object[])result;
                    errors.AddServerError((string)results[1], null, (string)results[2]);
                    Diagnostics.HandleErrors(CLI.ReturnCode.SQL_ERROR, this);
                }
            }
            else
            {
                byte[] whereabouts            = GetServerDtcWhereabouts();
                DTC.ITransactionExport export = DTC.GetTransactionExport(transaction, whereabouts);
                byte[] cookie         = DTC.GetTransactionCookie(transaction, export);
                string cookie_encoded = Encode(cookie);

                ManagedCommand cmd = new ManagedCommand(this);
                cmd.SetParameters(null);
                try
                {
                    cmd.Execute("select mts_enlist_transaction('" + cookie_encoded + "')");
                    if (cmd.Fetch())
                    {
                        autocommit = false;
                    }
                }
                finally
                {
                    cmd.CloseCursor(true);
                    cmd.Dispose();
                }
            }
        }
示例#2
0
        public override void EndTransaction(bool commit)
        {
            Debug.WriteLineIf(CLI.FnTrace.Enabled, String.Format(
                                  "ManagedConnection.EndTransaction ({0})", commit));
            CLI.CompletionType completion = commit ?
                                            CLI.CompletionType.SQL_COMMIT :
                                            CLI.CompletionType.SQL_ROLLBACK;
            Future future = new Future(
                Service.Transaction, (int)completion, null);
            object result = null;

            try
            {
                futures.Add(future);
                future.SendRequest(Session);
                result = future.GetNextResult(Session, futures);
                Debug.WriteLineIf(CLI.FnTrace.Enabled, String.Format(
                                      "ManagedConnection.EndTransaction ({0}) success", commit));
            }
            finally
            {
                futures.Remove(future);
            }
            if (result is object[])
            {
                Debug.WriteLineIf(CLI.FnTrace.Enabled, String.Format(
                                      "ManagedConnection.EndTransaction ({0}) error", commit));
                object[] results = (object[])result;
                errors.AddServerError((string)results[1], null, (string)results[2]);
                Diagnostics.HandleErrors(CLI.ReturnCode.SQL_ERROR, this);
            }

            autocommit = true;
            isolation  = CLI.IsolationLevel.SQL_TXN_READ_COMMITED;
            Debug.WriteLineIf(CLI.FnTrace.Enabled, String.Format(
                                  "ManagedConnection.EndTransaction ({0}) done", commit));
        }
示例#3
0
        private CLI.ReturnCode ProcessResult(bool needEvl)
        {
            Debug.WriteLineIf(CLI.FnTrace.Enabled, "ManagedCommand.ProcessResult (" + needEvl + ")");
            bool warningPending = false;

            for (;;)
            {
                object result = pendingFuture.GetNextResult(connection.Session, connection.futures);
                if (result is object[])
                {
                    object[]  results = (object[])result;
                    AnswerTag tag     = (AnswerTag)results[0];
                    Debug.WriteLineIf(Switch.Enabled, "QA: " + tag);
                    switch (tag)
                    {
                    case AnswerTag.QA_LOGIN:
                        connection.currentCatalog = (string)results[1];
                        break;

                    case AnswerTag.QA_COMPILED:
                    {
                        object[] compilation = (object[])results[1];
                        queryType = (QueryType)compilation[1];
                        SetColumnMetaData(compilation[0], (int)compilation[4]);
                        if (!needEvl)
                        {
                            return(warningPending ? CLI.ReturnCode.SQL_SUCCESS_WITH_INFO : CLI.ReturnCode.SQL_SUCCESS);
                        }
                        break;
                    }

                    case AnswerTag.QA_ROWS_AFFECTED:
                        affectedRows += (int)results[1];
                        isLastRow     = true;
                        if (queryType == QueryType.QT_PROC_CALL)
                        {
                            return(CLI.ReturnCode.SQL_NO_DATA);
                        }
                        isLastResult = true;
                        if (queryType == QueryType.QT_SELECT)
                        {
                            return(CLI.ReturnCode.SQL_NO_DATA);
                        }
                        return(warningPending ? CLI.ReturnCode.SQL_SUCCESS_WITH_INFO : CLI.ReturnCode.SQL_SUCCESS);

                    case AnswerTag.QA_ROW_LAST_IN_BATCH:
                        isLastInBatch = true;
                        goto case AnswerTag.QA_ROW;

                    case AnswerTag.QA_ROW:
                        prefetchRow = results;
                        isLastRow   = false;
                        return(warningPending ? CLI.ReturnCode.SQL_SUCCESS_WITH_INFO : CLI.ReturnCode.SQL_SUCCESS);

                    case AnswerTag.QA_PROC_RETURN:
                        SetParameterValues(results);
                        isLastResult = isLastRow = true;
                        return(warningPending ? CLI.ReturnCode.SQL_SUCCESS_WITH_INFO : CLI.ReturnCode.SQL_SUCCESS);

                    case AnswerTag.QA_NEED_DATA:
                        needDataParameter = (int)results[1];
                        return(CLI.ReturnCode.SQL_NEED_DATA);

                    case AnswerTag.QA_ERROR:
                        isLastResult = isLastRow = true;
                        errors.AddServerError((string)results[1], null, (string)results[2]);
                        return(CLI.ReturnCode.SQL_ERROR);

                    case AnswerTag.QA_WARNING:
                        errors.AddServerWarning((string)results[1], null, (string)results[2]);
                        warningPending = true;
                        break;
                    }
                }
                else
                {
                    /*
                     * CLI.ReturnCode rc = (CLI.ReturnCode) result;
                     * if (rc == CLI.ReturnCode.SQL_NO_DATA)
                     *      return rc;
                     */

                    isLastRow = true;
                    // proc call. Result set ends, proc not returned.
                    if (queryType == QueryType.QT_PROC_CALL)
                    {
                        return(CLI.ReturnCode.SQL_NO_DATA);
                    }
                    isLastResult = true;
                    if (queryType == QueryType.QT_SELECT)
                    {
                        return(CLI.ReturnCode.SQL_NO_DATA);
                    }
                    return(CLI.ReturnCode.SQL_SUCCESS);
                }
            }
        }
		public override void Enlist (object distributedTransaction)
		{
			ITransaction transaction = (ITransaction) distributedTransaction;
			if (transaction == null)
			{
				Future future = new Future (Service.TransactionEnlist, (int) DtpFlags.SQL_TP_UNENLIST, null);
				object result = null;
				try
				{
					futures.Add (future);
					future.SendRequest (Session);
					result = future.GetNextResult (Session, futures);
				}
				finally
				{
					futures.Remove (future);
				}
				if (result != null && result is object[])
				{
					object[] results = (object[]) result;
					errors.AddServerError ((string) results[1], null, (string) results[2]);
					Diagnostics.HandleErrors (CLI.ReturnCode.SQL_ERROR, this);
				}
			}
			else
			{
				byte[] whereabouts = GetServerDtcWhereabouts ();
				DTC.ITransactionExport export = DTC.GetTransactionExport (transaction, whereabouts);
				byte[] cookie = DTC.GetTransactionCookie (transaction, export);
				string cookie_encoded = Encode (cookie);

				ManagedCommand cmd = new ManagedCommand (this);
				cmd.SetParameters (null);
				try
				{
					cmd.Execute ("select mts_enlist_transaction('" + cookie_encoded + "')");
					if (cmd.Fetch ())
					{
						autocommit = false;
					}
				}
				finally
				{
					cmd.CloseCursor (true);
					cmd.Dispose ();
				}
			}
		}
		public override void EndTransaction (bool commit)
		{
		        Debug.WriteLineIf (CLI.FnTrace.Enabled, String.Format (
			      "ManagedConnection.EndTransaction ({0})", commit));
			  CLI.CompletionType completion = commit ? 
			      CLI.CompletionType.SQL_COMMIT : 
			      CLI.CompletionType.SQL_ROLLBACK;
			  Future future = new Future (
			      Service.Transaction, (int) completion, null);
			  object result = null;
			  try 
			  {
			 	  futures.Add (future);
				  future.SendRequest (Session);
				  result = future.GetNextResult (Session, futures);
				  Debug.WriteLineIf (CLI.FnTrace.Enabled, String.Format (
				      "ManagedConnection.EndTransaction ({0}) success", commit));
			  }
			  finally
			  {
				  futures.Remove (future);
			  }
			  if (result is object[])
			  {
			    Debug.WriteLineIf (CLI.FnTrace.Enabled, String.Format (
				"ManagedConnection.EndTransaction ({0}) error", commit));
				  object[] results = (object[]) result;
				  errors.AddServerError ((string) results[1], null, (string) results[2]);
				  Diagnostics.HandleErrors (CLI.ReturnCode.SQL_ERROR, this);
			  }

			autocommit = true;
			isolation = CLI.IsolationLevel.SQL_TXN_READ_COMMITED;
		        Debug.WriteLineIf (CLI.FnTrace.Enabled, String.Format (
			      "ManagedConnection.EndTransaction ({0}) done", commit));
		}