示例#1
0
        // Summary:
        //     Attempts to cancels the execution of a System.Data.Common.DbCommand.
        public override void Cancel()
        {
            if (mConn == null)
            {
                return;
            }

            ConnectionState s = mConn.State;

            // no cancel possible/necessary if connection is closed / open / connecting / broken
            if (s == ConnectionState.Closed || s == ConnectionState.Open || (s & (ConnectionState.Broken | ConnectionState.Connecting)) > 0)
            {
                return;
            }

            IntPtr cancel = PqsqlWrapper.PQgetCancel(mConn.PGConnection);

            if (cancel != IntPtr.Zero)
            {
                sbyte[] buf = new sbyte[256];

                string err;
                unsafe
                {
                    fixed(sbyte *b = buf)
                    {
                        int cret = PqsqlWrapper.PQcancel(cancel, b, 256);

                        PqsqlWrapper.PQfreeCancel(cancel);

                        if (cret == 1)
                        {
                            return;
                        }

                        err = PqsqlUTF8Statement.CreateStringFromUTF8(new IntPtr(b));
                    }
                }

                throw new PqsqlException("Could not cancel command «" + mCmdText + "»: " + err);
            }
        }