Ejemplo n.º 1
0
 public PqsqlCopyFrom(PqsqlConnection conn)
     : base(conn)
 {
     mColBuf = IntPtr.Zero;
     mExpBuf = PqsqlWrapper.createPQExpBuffer();
     mPos    = 0;
 }
Ejemplo n.º 2
0
        public PqsqlLargeObject(PqsqlConnection conn)
        {
#if CODECONTRACTS
            Contract.Requires <ArgumentNullException>(conn != null);
#else
            if (conn == null)
            {
                throw new ArgumentNullException(nameof(conn));
            }
#endif

            // All large object manipulation using these functions must take place within an SQL transaction block,
            // since large object file descriptors are only valid for the duration of a transaction.
            // https://www.postgresql.org/docs/current/static/lo-interfaces.html
            PGTransactionStatusType transactionStatus = conn.TransactionStatus;
            if (transactionStatus != PGTransactionStatusType.PQTRANS_INTRANS &&
                transactionStatus != PGTransactionStatusType.PQTRANS_ACTIVE)
            {
                throw new PqsqlException("PqsqlLargeObject manipulation must take place within an SQL transaction");
            }

            mConn   = conn;
            mPGConn = conn.PGConnection;
            if (mPGConn == IntPtr.Zero)
            {
                throw new ArgumentNullException("PqsqlConnection is closed: " + mConn.GetErrorMessage());
            }

            mOid  = 0;
            mFd   = -1;
            mMode = 0;
            mPos  = -1;
        }
Ejemplo n.º 3
0
        protected PqsqlCopyBase(PqsqlConnection conn)
        {
            mConn = conn;

            mRowInfo = null;
            mColumns = 0;
        }
Ejemplo n.º 4
0
        public PqsqlCopyTo(PqsqlConnection conn)
            : base(conn)
        {
            if (conn == null)
            {
                throw new ArgumentNullException(nameof(conn));
            }

            mPGConn    = conn.PGConnection;
            mBufferPtr = Marshal.AllocHGlobal(sizeof(IntPtr));
            *((IntPtr *)mBufferPtr) = IntPtr.Zero;
        }
Ejemplo n.º 5
0
        public PqsqlDataAdapter(string selectCommandText, PqsqlConnection selectConnection)
        {
            PqsqlCommand cmd = null;

            try
            {
                cmd           = new PqsqlCommand(selectCommandText, selectConnection);
                SelectCommand = cmd;

                cmd = null;
            }
            finally
            {
                cmd?.Dispose();
            }
        }
Ejemplo n.º 6
0
        //
        // Summary:
        //     Releases the unmanaged resources used by the System.Data.Common.DbTransaction
        //     and optionally releases the managed resources.
        //
        // Parameters:
        //   disposing:
        //     If true, this method releases all resources held by any managed objects that
        //     this System.Data.Common.DbTransaction references.
        protected override void Dispose(bool disposing)
        {
            if (mDisposed)
            {
                return;
            }

            if (disposing)
            {
                SaveTransaction(false);                 // send rollback if we are in a transaction
                mConn = null;
            }

            base.Dispose(disposing);
            mDisposed = true;
        }
Ejemplo n.º 7
0
        protected override void Dispose(bool disposing)
        {
            if (mDisposed)
            {
                return;
            }

            if (disposing)
            {
                // give up references to transaction and connection
                mTransaction = null;
                mConn        = null;
            }

            base.Dispose(disposing);
            mDisposed = true;
        }
Ejemplo n.º 8
0
        private void Dispose(bool disposing)
        {
            if (mDisposed)
            {
                return;
            }

            if (disposing)
            {
                mConn = null;                 // do not close connection
            }

            // always release mColBuf and mExpBuf (must not throw exception)
            Close();

            mDisposed = true;
        }
Ejemplo n.º 9
0
        internal PqsqlTransaction(PqsqlConnection conn, IsolationLevel isolationLevel)
        {
#if CODECONTRACTS
            Contract.Requires <ArgumentNullException>(conn != null);
            Contract.Requires <ArgumentException>(isolationLevel != IsolationLevel.Chaos);
#else
            if (conn == null)
            {
                throw new ArgumentNullException(nameof(conn));
            }

            if (isolationLevel == IsolationLevel.Chaos)
            {
                throw new ArgumentException("unsupported isolation level", nameof(isolationLevel));
            }
#endif

            switch (isolationLevel)
            {
            case IsolationLevel.ReadCommitted:
            case IsolationLevel.Unspecified:
                isolationLevel   = IsolationLevel.ReadCommitted;
                TransactionStart = mBeginReadCommitted;
                break;

            case IsolationLevel.RepeatableRead:
                TransactionStart = mBeginRepeatableRead;
                break;

            case IsolationLevel.Serializable:
            case IsolationLevel.Snapshot:
                TransactionStart = mBeginSerializable;
                break;

            case IsolationLevel.ReadUncommitted:
                TransactionStart = mBeginReadUncommitted;
                break;
            }

            Connection      = conn;
            mIsolationLevel = isolationLevel;
        }
Ejemplo n.º 10
0
        public PqsqlDataAdapter(string selectCommandText, string selectConnectionString)
        {
#if CODECONTRACTS
            Contract.Requires <ArgumentNullException>(selectCommandText != null);
            Contract.Requires <ArgumentNullException>(selectConnectionString != null);
#else
            if (selectCommandText == null)
            {
                throw new ArgumentNullException(nameof(selectCommandText));
            }
            if (selectConnectionString == null)
            {
                throw new ArgumentNullException(nameof(selectConnectionString));
            }
#endif

            PqsqlConnection conn = null;
            PqsqlCommand    cmd  = null;

            try
            {
                conn = new PqsqlConnection(selectConnectionString);

                // ReSharper disable once UseObjectOrCollectionInitializer
                cmd             = new PqsqlCommand();
                cmd.CommandText = selectCommandText;
                cmd.Connection  = conn;

                SelectCommand = cmd;

                cmd  = null;
                conn = null;
            }
            finally
            {
                cmd?.Dispose();
                conn?.Dispose();
            }
        }
Ejemplo n.º 11
0
 public PqsqlCommand(string query, PqsqlConnection conn)
 {
     Init(query);
     mParams = new PqsqlParameterCollection();
     mConn   = conn;
 }
Ejemplo n.º 12
0
 public PqsqlCommand(PqsqlConnection conn)
     : this(string.Empty, conn)
 {
 }