示例#1
0
        // postgres error codes are stored as alphanumeric string of
        // 5 characters. we convert them to an integer of maximum 30 bits;
        // each character is stored within 6 bits of ErrorCode
        private static unsafe int CreateErrorCode(IntPtr result)
        {
            sbyte *sqlState = PqsqlWrapper.PQresultErrorField(result, PqsqlDiag.PG_DIAG_SQLSTATE);

            int code = (int)PqsqlState.SUCCESSFUL_COMPLETION;              // code=0: error code '00000' means successful_completion

            if (sqlState != null)
            {
                for (int j = 0, c = *sqlState; j < 5 && c != 0; j++, c = *(++sqlState))
                {
                    int i = 0;
                    if (c >= 48 && c <= 57)                     // '0' ... '9' =>  0 ...  9
                    {
                        i = c - 48;
                    }
                    else if (c >= 65 && c <= 90)                     // 'A' ... 'Z' => 10 ... 35
                    {
                        i = c - 55;
                    }

                    // store each character in 6 bits from code
                    code |= (i << j * 6);
                }
            }

            return(code);
        }
示例#2
0
        private static unsafe string CreateHint(IntPtr result)
        {
            sbyte *hint = PqsqlWrapper.PQresultErrorField(result, PqsqlDiag.PG_DIAG_MESSAGE_HINT);

            if (hint == null)
            {
                return(string.Empty);
            }
            return(new string(hint));
        }