Exemple #1
0
        public void TestGetResultMethodNeverThrows () {
            var f = new Future<object>();
            object result;
            Exception error;

            Assert.IsFalse(f.GetResult(out result, out error));

            f.SetResult(5, null);
            Assert.IsTrue(f.GetResult(out result, out error));
            Assert.AreEqual(5, result);

            f = new Future<object>();

            f.SetResult(null, new Exception("earth-shattering kaboom"));
            Assert.IsTrue(f.GetResult(out result, out error));
            Assert.IsTrue(error is Exception);
        }
Exemple #2
0
        public void Cancel()
        {
            Future future = new Future(Service.FreeStmt, GetId(), (int)CLI.FreeStmtOption.SQL_CLOSE);

            try
            {
                connection.futures.Add(future);
                future.SendRequest(connection.Session);
                future.GetResult(connection.Session, connection.futures);
            }
            finally
            {
                connection.futures.Remove(future);
            }
        }
Exemple #3
0
        private void Dispose(bool disposing)
        {
            // TODO: Review command disposing

            /*
             * if (disposing)
             * {
             *      CloseCursor ();
             * }
             */
            Future future = new Future(Service.FreeStmt, GetId(), (int)CLI.FreeStmtOption.SQL_DROP);

            try
            {
                connection.futures.Add(future);
                future.SendRequest(connection.Session);
                future.GetResult(connection.Session, connection.futures);
            }
            finally
            {
                connection.futures.Remove(future);
            }
        }
Exemple #4
0
        private long GetData(ColumnData column, BlobHandle blob, int length, object buffer, int bufferOffset)
        {
            Debug.WriteLineIf(CLI.FnTrace.Enabled, "ManagedCommand.GetData()");

            Future future = new Future(Service.GetData,
                                       blob.current_page,
                                       length,
                                       blob.current_position,
                                       blob.keyId,
                                       blob.fragNo,
                                       blob.dirPage,
                                       blob.pages,
                                       blob.tag == BoxTag.DV_BLOB_WIDE_HANDLE ? 1 : 0,
                                       blob.timeStamp);

            object result = null;

            try
            {
                connection.futures.Add(future);
                future.SendRequest(connection.Session, timeout);
                result = future.GetResult(connection.Session, connection.futures);
            }
            finally
            {
                connection.futures.Remove(future);
            }

            if (!(result is object[]))
            {
                return(0);
            }

            object[] results = (object[])result;
            if (results[0] is int && (AnswerTag)results[0] == AnswerTag.QA_ERROR)
            {
                errors.AddServerError((string)results[1], null, (string)results[2]);
                Diagnostics.HandleResult(CLI.ReturnCode.SQL_ERROR, this, connection.OuterConnection);
            }

            int startOffset = column.lobOffset;

            for (int i = 0; i < results.Length; i++)
            {
                if (results[i] is int[])
                {
                    int[] array = (int[])results[i];
                    blob.current_page     = array[1];
                    blob.current_position = array[2];
                    continue;
                }
                else if (results[i] is string)
                {
                    string s = (string)results[i];
                    if (buffer is char[])
                    {
                        char[] chars      = s.ToCharArray();
                        char[] charBuffer = (char[])buffer;

                        Debug.WriteLineIf(Switch.Enabled, "do chars");
                        Debug.WriteLineIf(Switch.Enabled, "buffer length: " +
                                          (charBuffer == null ? "no" : charBuffer.Length.ToString()));
                        Debug.WriteLineIf(Switch.Enabled, "buffer offset: " + bufferOffset);
                        Debug.WriteLineIf(Switch.Enabled, "data length: " + chars.Length);
                        Debug.WriteLineIf(Switch.Enabled, "length: " + length);

                        if (charBuffer != null)
                        {
                            int copyLength = length < chars.Length ? length : chars.Length;
                            Array.Copy(chars, 0, charBuffer, bufferOffset, copyLength);
                        }
                        column.lobOffset += chars.Length;
                        bufferOffset     += chars.Length;
                        length           -= chars.Length;
                    }
                    else
                    {
                        byte[] bytes      = Encoding.GetEncoding("iso-8859-1").GetBytes(s);
                        byte[] byteBuffer = (byte[])buffer;

                        Debug.WriteLineIf(Switch.Enabled, "do bytes");
                        Debug.WriteLineIf(Switch.Enabled, "buffer length: " +
                                          (byteBuffer == null ? "no" : byteBuffer.Length.ToString()));
                        Debug.WriteLineIf(Switch.Enabled, "buffer offset: " + bufferOffset);
                        Debug.WriteLineIf(Switch.Enabled, "data length: " + bytes.Length);
                        Debug.WriteLineIf(Switch.Enabled, "length: " + length);

                        if (byteBuffer != null)
                        {
                            int copyLength = length < bytes.Length ? length : bytes.Length;
                            Array.Copy(bytes, 0, byteBuffer, bufferOffset, copyLength);
                        }
                        column.lobOffset += bytes.Length;
                        bufferOffset     += bytes.Length;
                        length           -= bytes.Length;
                    }
                }
            }
            return(column.lobOffset - startOffset);
        }
		public void Cancel ()
		{
			Future future = new Future (Service.FreeStmt, GetId (), (int) CLI.FreeStmtOption.SQL_CLOSE);
			try
			{
				connection.futures.Add (future);
				future.SendRequest (connection.Session);
				future.GetResult (connection.Session, connection.futures);
			}
			finally
			{
				connection.futures.Remove (future);
			}
		}
		private void Dispose (bool disposing)
		{
			// TODO: Review command disposing
			/*
			if (disposing)
			{
				CloseCursor ();
			}
			*/
			Future future = new Future (Service.FreeStmt, GetId (), (int) CLI.FreeStmtOption.SQL_DROP);
			try
			{
			        connection.futures.Add (future);
			        future.SendRequest (connection.Session);
			        future.GetResult (connection.Session, connection.futures);
			}
			finally
			{
			        connection.futures.Remove (future);
			}
		}
		private long GetData (ColumnData column, BlobHandle blob, int length, object buffer, int bufferOffset)
		{
			Debug.WriteLineIf (CLI.FnTrace.Enabled, "ManagedCommand.GetData()");

			Future future = new Future (Service.GetData,
				blob.current_page,
				length,
				blob.current_position,
				blob.keyId,
				blob.fragNo,
				blob.dirPage,
				blob.pages,
				blob.tag == BoxTag.DV_BLOB_WIDE_HANDLE ? 1 : 0,
				blob.timeStamp);

			object result = null;
			try
			{
				connection.futures.Add (future);
				future.SendRequest (connection.Session, timeout);
				result = future.GetResult (connection.Session, connection.futures);
			}
			finally
			{
				connection.futures.Remove (future);
			}

			if (!(result is object[]))
				return 0;

			object[] results = (object[]) result;
			if (results[0] is int && (AnswerTag) results[0] == AnswerTag.QA_ERROR)
			{
				errors.AddServerError ((string) results[1], null, (string) results[2]);
				Diagnostics.HandleResult (CLI.ReturnCode.SQL_ERROR, this, connection.OuterConnection);
			}

			int startOffset = column.lobOffset;
			for (int i = 0; i < results.Length; i++)
			{
				if (results[i] is int[])
				{
					int[] array = (int[]) results[i];
					blob.current_page = array[1];
					blob.current_position = array[2];
					continue;
				}
				else if (results[i] is string)
				{
					string s = (string) results[i];
					if (buffer is char[])
					{
						char[] chars = s.ToCharArray ();
						char[] charBuffer = (char[]) buffer;

						Debug.WriteLineIf (Switch.Enabled, "do chars");
						Debug.WriteLineIf (Switch.Enabled, "buffer length: " + 
						    (charBuffer == null ? "no" : charBuffer.Length.ToString ()));
						Debug.WriteLineIf (Switch.Enabled, "buffer offset: " + bufferOffset);
						Debug.WriteLineIf (Switch.Enabled, "data length: " + chars.Length);
						Debug.WriteLineIf (Switch.Enabled, "length: " + length);

						if (charBuffer != null)
						{
							int copyLength = length < chars.Length ? length : chars.Length;
							Array.Copy (chars, 0, charBuffer, bufferOffset, copyLength);
						}
						column.lobOffset += chars.Length;
						bufferOffset += chars.Length;
						length -= chars.Length;
					}
					else
					{
						byte[] bytes = Encoding.GetEncoding ("iso-8859-1").GetBytes (s);
						byte[] byteBuffer = (byte[]) buffer;

						Debug.WriteLineIf (Switch.Enabled, "do bytes");
						Debug.WriteLineIf (Switch.Enabled, "buffer length: " + 
						    (byteBuffer == null ? "no" : byteBuffer.Length.ToString ()));
						Debug.WriteLineIf (Switch.Enabled, "buffer offset: " + bufferOffset);
						Debug.WriteLineIf (Switch.Enabled, "data length: " + bytes.Length);
						Debug.WriteLineIf (Switch.Enabled, "length: " + length);

						if (byteBuffer != null)
						{
							int copyLength = length < bytes.Length ? length : bytes.Length;
							Array.Copy (bytes, 0, byteBuffer, bufferOffset, copyLength);
						}
						column.lobOffset += bytes.Length;
						bufferOffset += bytes.Length;
						length -= bytes.Length;
					}
				}
			}
			return column.lobOffset - startOffset;
		}