Exemplo n.º 1
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));
        }
Exemplo n.º 2
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);
        }