/* Generated by Cython 0.24 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_24"
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
  #define CYTHON_USE_PYLONG_INTERNALS 1
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
  #undef SHIFT
  #undef BASE
  #undef MASK
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if PY_VERSION_HEX >= 0x030500B1
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
typedef struct {
    unaryfunc am_await;
    unaryfunc am_aiter;
    unaryfunc am_anext;
} __Pyx_PyAsyncMethodsStruct;
#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
#else
#define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)

#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif


#define __PYX_ERR(f_index, lineno, Ln_error) \
{ \
  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
}

#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE___mssql
#define __PYX_HAVE_API___mssql
#include "string.h"
#include "stdio.h"
#include "pythread.h"
#include "sqlfront.h"
#include "pymssql_version.h"
#include "cpp_helpers.h"
#include "pyerrors.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER) && defined (_M_X64)
    #define __Pyx_sst_abs(value) _abs64(value)
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyObject_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */

static PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "_mssql.pyx",
  "_mssql.pxd",
  "type.pxd",
  "bool.pxd",
  "complex.pxd",
};

/* "sqlfront.pxd":656
 *     RETCODE DBSETLDBNAME(LOGINREC *x, char *y)
 * 
 * ctypedef int LINE_T             # <<<<<<<<<<<<<<
 */
typedef int __pyx_t_8sqlfront_LINE_T;

/*--- Type declarations ---*/
struct __pyx_obj_6_mssql_MSSQLConnection;
struct __pyx_obj_6_mssql_MSSQLRowIterator;
struct __pyx_obj_6_mssql_MSSQLStoredProcedure;
struct __pyx_obj_6_mssql_MSSQLException;
struct __pyx_obj_6_mssql_MSSQLDriverException;
struct __pyx_obj_6_mssql_MSSQLDatabaseException;
struct __pyx_t_6_mssql__mssql_parameter_node;
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_query;
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_non_query;
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_row;
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_scalar;
struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query;
struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_sql_command;
struct __pyx_opt_args_6_mssql_ensure_bytes;
struct __pyx_opt_args_6_mssql__quote_simple_value;
struct __pyx_opt_args_6_mssql__quote_or_flatten;
struct __pyx_opt_args_6_mssql__quote_data;

/* "_mssql.pxd":6
 * cdef void log(char *, ...)
 * 
 * cdef struct _mssql_parameter_node:             # <<<<<<<<<<<<<<
 *     _mssql_parameter_node *next
 *     BYTE                  *value
 */
struct __pyx_t_6_mssql__mssql_parameter_node {
  struct __pyx_t_6_mssql__mssql_parameter_node *next;
  BYTE *value;
};

/* "_mssql.pxd":39
 *     cdef object convert_db_value(self, BYTE *, int, int)
 *     cdef int convert_python_value(self, object value, BYTE **, int*, int*) except -1
 *     cpdef execute_query(self, query, params=?)             # <<<<<<<<<<<<<<
 *     cpdef execute_non_query(self, query, params=?)
 *     cpdef execute_row(self, query, params=?)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_query {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pxd":40
 *     cdef int convert_python_value(self, object value, BYTE **, int*, int*) except -1
 *     cpdef execute_query(self, query, params=?)
 *     cpdef execute_non_query(self, query, params=?)             # <<<<<<<<<<<<<<
 *     cpdef execute_row(self, query, params=?)
 *     cpdef execute_scalar(self, query, params=?)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_non_query {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pxd":41
 *     cpdef execute_query(self, query, params=?)
 *     cpdef execute_non_query(self, query, params=?)
 *     cpdef execute_row(self, query, params=?)             # <<<<<<<<<<<<<<
 *     cpdef execute_scalar(self, query, params=?)
 *     cdef fetch_next_row(self, int, int)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_row {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pxd":42
 *     cpdef execute_non_query(self, query, params=?)
 *     cpdef execute_row(self, query, params=?)
 *     cpdef execute_scalar(self, query, params=?)             # <<<<<<<<<<<<<<
 *     cdef fetch_next_row(self, int, int)
 *     cdef format_and_run_query(self, query_string, params=?)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_scalar {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pxd":44
 *     cpdef execute_scalar(self, query, params=?)
 *     cdef fetch_next_row(self, int, int)
 *     cdef format_and_run_query(self, query_string, params=?)             # <<<<<<<<<<<<<<
 *     cdef format_sql_command(self, format, params=?)
 *     cdef get_result(self)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pxd":45
 *     cdef fetch_next_row(self, int, int)
 *     cdef format_and_run_query(self, query_string, params=?)
 *     cdef format_sql_command(self, format, params=?)             # <<<<<<<<<<<<<<
 *     cdef get_result(self)
 *     cdef get_row(self, int, int)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_sql_command {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pyx":198
 * DEF NUMERIC_BUF_SZ = 45
 * 
 * cdef bytes ensure_bytes(s, encoding='utf-8'):             # <<<<<<<<<<<<<<
 *     try:
 *         decoded = s.decode(encoding)
 */
struct __pyx_opt_args_6_mssql_ensure_bytes {
  int __pyx_n;
  PyObject *encoding;
};

/* "_mssql.pyx":1709
 * ## Quoting Functions ##
 * #######################
 * cdef _quote_simple_value(value, charset='utf8'):             # <<<<<<<<<<<<<<
 * 
 *     if value == None:
 */
struct __pyx_opt_args_6_mssql__quote_simple_value {
  int __pyx_n;
  PyObject *charset;
};

/* "_mssql.pyx":1763
 *     return None
 * 
 * cdef _quote_or_flatten(data, charset='utf8'):             # <<<<<<<<<<<<<<
 *     result = _quote_simple_value(data, charset)
 * 
 */
struct __pyx_opt_args_6_mssql__quote_or_flatten {
  int __pyx_n;
  PyObject *charset;
};

/* "_mssql.pyx":1785
 * # normally passed in via the params argument in the execute_* methods. It
 * # then quotes and flattens the arguments and returns then.
 * cdef _quote_data(data, charset='utf8'):             # <<<<<<<<<<<<<<
 *     result = _quote_simple_value(data)
 * 
 */
struct __pyx_opt_args_6_mssql__quote_data {
  int __pyx_n;
  PyObject *charset;
};

/* "_mssql.pxd":10
 *     BYTE                  *value
 * 
 * cdef class MSSQLConnection:             # <<<<<<<<<<<<<<
 * 
 *     # class property variables
 */
struct __pyx_obj_6_mssql_MSSQLConnection {
  PyObject_HEAD
  struct __pyx_vtabstruct_6_mssql_MSSQLConnection *__pyx_vtab;
  int _connected;
  int _rows_affected;
  int _query_timeout;
  char *_charset;
  DBPROCESS *dbproc;
  int last_msg_no;
  int last_msg_severity;
  int last_msg_state;
  int last_msg_line;
  int last_dbresults;
  int num_columns;
  int debug_queries;
  char *last_msg_str;
  char *last_msg_srv;
  char *last_msg_proc;
  PyObject *column_names;
  PyObject *column_types;
  PyObject *msghandler;
};


/* "_mssql.pxd":51
 *     cpdef set_msghandler(self, object handler)
 * 
 * cdef class MSSQLRowIterator:             # <<<<<<<<<<<<<<
 *     cdef MSSQLConnection conn
 *     cdef int row_format
 */
struct __pyx_obj_6_mssql_MSSQLRowIterator {
  PyObject_HEAD
  struct __pyx_obj_6_mssql_MSSQLConnection *conn;
  int row_format;
};


/* "_mssql.pxd":55
 *     cdef int row_format
 * 
 * cdef class MSSQLStoredProcedure:             # <<<<<<<<<<<<<<
 *     cdef MSSQLConnection conn
 *     cdef DBPROCESS *dbproc
 */
struct __pyx_obj_6_mssql_MSSQLStoredProcedure {
  PyObject_HEAD
  struct __pyx_obj_6_mssql_MSSQLConnection *conn;
  DBPROCESS *dbproc;
  char *procname;
  int param_count;
  PyBoolObject *had_positional;
  PyObject *output_indexes;
  PyObject *params;
  struct __pyx_t_6_mssql__mssql_parameter_node *params_list;
};


/* "_mssql.pyx":146
 *         pass
 * 
 * cdef class MSSQLException(Exception):             # <<<<<<<<<<<<<<
 *     """
 *     Base exception class for the MSSQL driver.
 */
struct __pyx_obj_6_mssql_MSSQLException {
  PyBaseExceptionObject __pyx_base;
};


/* "_mssql.pyx":151
 *     """
 * 
 * cdef class MSSQLDriverException(MSSQLException):             # <<<<<<<<<<<<<<
 *     """
 *     Inherits from the base class and raised when an error is caused within
 */
struct __pyx_obj_6_mssql_MSSQLDriverException {
  struct __pyx_obj_6_mssql_MSSQLException __pyx_base;
};


/* "_mssql.pyx":157
 *     """
 * 
 * cdef class MSSQLDatabaseException(MSSQLException):             # <<<<<<<<<<<<<<
 *     """
 *     Raised when an error occurs within the database.
 */
struct __pyx_obj_6_mssql_MSSQLDatabaseException {
  struct __pyx_obj_6_mssql_MSSQLException __pyx_base;
  int number;
  int severity;
  int state;
  int line;
  char *text;
  char *srvname;
  char *procname;
};



/* "_mssql.pyx":445
 * ## MSSQL Connection Class ##
 * ############################
 * cdef class MSSQLConnection:             # <<<<<<<<<<<<<<
 * 
 *     property charset:
 */

struct __pyx_vtabstruct_6_mssql_MSSQLConnection {
  PyObject *(*cancel)(struct __pyx_obj_6_mssql_MSSQLConnection *, int __pyx_skip_dispatch);
  void (*clear_metadata)(struct __pyx_obj_6_mssql_MSSQLConnection *);
  PyObject *(*convert_db_value)(struct __pyx_obj_6_mssql_MSSQLConnection *, BYTE *, int, int);
  int (*convert_python_value)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, BYTE **, int *, int *);
  PyObject *(*execute_query)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_query *__pyx_optional_args);
  PyObject *(*execute_non_query)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_non_query *__pyx_optional_args);
  PyObject *(*execute_row)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_row *__pyx_optional_args);
  PyObject *(*execute_scalar)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_scalar *__pyx_optional_args);
  PyObject *(*fetch_next_row)(struct __pyx_obj_6_mssql_MSSQLConnection *, int, int);
  PyObject *(*format_and_run_query)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query *__pyx_optional_args);
  PyObject *(*format_sql_command)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_sql_command *__pyx_optional_args);
  PyObject *(*get_result)(struct __pyx_obj_6_mssql_MSSQLConnection *);
  PyObject *(*get_row)(struct __pyx_obj_6_mssql_MSSQLConnection *, int, int);
  PyObject *(*set_msghandler)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_6_mssql_MSSQLConnection *__pyx_vtabptr_6_mssql_MSSQLConnection;

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

/* PyObjectGetAttrStr.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* PyThreadStateGet.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = PyThreadState_GET();
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#endif

/* SaveResetException.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* PyErrExceptionMatches.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* GetException.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* ForceInitThreads.proto */
#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif

/* GetModuleGlobalName.proto */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

/* RaiseArgTupleInvalid.proto */
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

/* ExtTypeTest.proto */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

/* IncludeStringH.proto */
#include <string.h>

/* decode_c_string.proto */
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* KeywordStringCheck.proto */
static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed);

/* PySequenceContains.proto */
static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* BytesEquals.proto */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

/* UnicodeEquals.proto */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

/* StrEquals.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

/* ListAppend.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

/* StringJoin.proto */
#if PY_MAJOR_VERSION < 3
#define __Pyx_PyString_Join __Pyx_PyBytes_Join
#define __Pyx_PyBaseString_Join(s, v) (PyUnicode_CheckExact(s) ? PyUnicode_Join(s, v) : __Pyx_PyBytes_Join(s, v))
#else
#define __Pyx_PyString_Join PyUnicode_Join
#define __Pyx_PyBaseString_Join PyUnicode_Join
#endif
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION < 3
    #define __Pyx_PyBytes_Join _PyString_Join
    #else
    #define __Pyx_PyBytes_Join _PyBytes_Join
    #endif
#else
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values);
#endif

/* PyObjectLookupSpecial.proto */
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) {
    PyObject *res;
    PyTypeObject *tp = Py_TYPE(obj);
#if PY_MAJOR_VERSION < 3
    if (unlikely(PyInstance_Check(obj)))
        return __Pyx_PyObject_GetAttrStr(obj, attr_name);
#endif
    res = _PyType_Lookup(tp, attr_name);
    if (likely(res)) {
        descrgetfunc f = Py_TYPE(res)->tp_descr_get;
        if (!f) {
            Py_INCREF(res);
        } else {
            res = f(res, obj, (PyObject *)tp);
        }
    } else {
        PyErr_SetObject(PyExc_AttributeError, attr_name);
    }
    return res;
}
#else
#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n)
#endif

/* PyObjectSetAttrStr.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o,n,NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

/* PyIntBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_FloorDivideObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceFloorDivide(op1, op2) : PyNumber_FloorDivide(op1, op2))
#endif

/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

/* SwapException.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_ExceptionSwap(type, value, tb)  __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* None.proto */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

/* ArgTypeTest.proto */
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact);

/* PyObjectCallMethod0.proto */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name);

/* RaiseNoneIterError.proto */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

/* UnpackTupleError.proto */
static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index);

/* UnpackTuple2.proto */
static CYTHON_INLINE int __Pyx_unpack_tuple2(PyObject* tuple, PyObject** value1, PyObject** value2,
                                             int is_tuple, int has_known_size, int decref_tuple);

/* dict_iter.proto */
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_is_dict);
static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
                                              PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);

/* PyObjectCallMethod1.proto */
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

/* append.proto */
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x);

/* SliceObject.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

/* PyIntBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* CallNextTpDealloc.proto */
static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc);

/* SetVTable.proto */
static int __Pyx_SetVtable(PyObject *dict, void *vtable);

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_BYTE(BYTE value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_DBINT(DBINT value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE DBINT __Pyx_PyInt_As_DBINT(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *);

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* FunctionExport.proto */
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);

/* PyIdentifierFromString.proto */
#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
  #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
  #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif

/* ModuleImport.proto */
static PyObject *__Pyx_ImportModule(const char *name);

/* TypeImport.proto */
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static PyObject *__pyx_f_6_mssql_15MSSQLConnection_set_msghandler(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_handler, int __pyx_skip_dispatch); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_cancel(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
static void __pyx_f_6_mssql_15MSSQLConnection_clear_metadata(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_convert_db_value(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, BYTE *__pyx_v_data, int __pyx_v_dbtype, int __pyx_v_length); /* proto*/
static int __pyx_f_6_mssql_15MSSQLConnection_convert_python_value(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_value, BYTE **__pyx_v_dbValue, int *__pyx_v_dbtype, int *__pyx_v_length); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_execute_non_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_non_query *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_execute_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_query *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_execute_row(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_row *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_execute_scalar(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_scalar *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_fetch_next_row(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_v_throw, int __pyx_v_row_format); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_format_and_run_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_format_sql_command(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_format, struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_sql_command *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_get_result(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_get_row(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_v_row_info, int __pyx_v_row_format); /* proto*/

/* Module declarations from 'cpython.version' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.type' */
static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;

/* Module declarations from 'libc.string' */

/* Module declarations from 'libc.stdio' */

/* Module declarations from 'cpython.object' */

/* Module declarations from 'cpython.ref' */

/* Module declarations from 'cpython.exc' */

/* Module declarations from 'cpython.module' */

/* Module declarations from 'cpython.mem' */

/* Module declarations from 'cpython.tuple' */

/* Module declarations from 'cpython.list' */

/* Module declarations from 'cpython.sequence' */

/* Module declarations from 'cpython.mapping' */

/* Module declarations from 'cpython.iterator' */

/* Module declarations from 'cpython.number' */

/* Module declarations from 'cpython.int' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.bool' */
static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;

/* Module declarations from 'cpython.long' */

/* Module declarations from 'cpython.float' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.complex' */
static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;

/* Module declarations from 'cpython.string' */

/* Module declarations from 'cpython.unicode' */

/* Module declarations from 'cpython.dict' */

/* Module declarations from 'cpython.instance' */

/* Module declarations from 'cpython.function' */

/* Module declarations from 'cpython.method' */

/* Module declarations from 'cpython.weakref' */

/* Module declarations from 'cpython.getargs' */

/* Module declarations from 'cpython.pythread' */

/* Module declarations from 'cpython.pystate' */

/* Module declarations from 'cpython.cobject' */

/* Module declarations from 'cpython.oldbuffer' */

/* Module declarations from 'cpython.set' */

/* Module declarations from 'cpython.buffer' */

/* Module declarations from 'cpython.bytes' */

/* Module declarations from 'cpython.pycapsule' */

/* Module declarations from 'cpython' */

/* Module declarations from 'sqlfront' */

/* Module declarations from '_mssql' */
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLConnection = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLRowIterator = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLStoredProcedure = 0;
static PyTypeObject *__pyx_ptype_6_mssql_Exception = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLException = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLDriverException = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLDatabaseException = 0;
static int __pyx_v_6_mssql__ROW_FORMAT_TUPLE;
static int __pyx_v_6_mssql__ROW_FORMAT_DICT;
static int __pyx_v_6_mssql__mssql_last_msg_no;
static int __pyx_v_6_mssql__mssql_last_msg_severity;
static int __pyx_v_6_mssql__mssql_last_msg_state;
static int __pyx_v_6_mssql__mssql_last_msg_line;
static char *__pyx_v_6_mssql__mssql_last_msg_str;
static char *__pyx_v_6_mssql__mssql_last_msg_srv;
static char *__pyx_v_6_mssql__mssql_last_msg_proc;
static PyObject *__pyx_v_6_mssql_HOSTNAME = 0;
static PyObject *__pyx_v_6_mssql_connection_object_list = 0;
static int __pyx_v_6_mssql_MAX_INT;
static int __pyx_v_6_mssql_MIN_INT;
static void __pyx_f_6_mssql_log(char *, ...); /*proto*/
static PyObject *__pyx_f_6_mssql_ensure_bytes(PyObject *, struct __pyx_opt_args_6_mssql_ensure_bytes *__pyx_optional_args); /*proto*/
static int __pyx_f_6_mssql_err_handler(DBPROCESS *, int, int, int, char *, char *); /*proto*/
static int __pyx_f_6_mssql_msg_handler(DBPROCESS *, DBINT, int, int, char *, char *, char *, __pyx_t_8sqlfront_LINE_T); /*proto*/
static int __pyx_f_6_mssql_db_sqlexec(DBPROCESS *); /*proto*/
static int __pyx_f_6_mssql_db_sqlok(DBPROCESS *); /*proto*/
static void __pyx_f_6_mssql_clr_err(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static RETCODE __pyx_f_6_mssql_db_cancel(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static int __pyx_f_6_mssql_check_and_raise(RETCODE, struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static int __pyx_f_6_mssql_check_cancel_and_raise(RETCODE, struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static char *__pyx_f_6_mssql_get_last_msg_str(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static char *__pyx_f_6_mssql_get_last_msg_srv(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static char *__pyx_f_6_mssql_get_last_msg_proc(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static int __pyx_f_6_mssql_get_last_msg_no(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static int __pyx_f_6_mssql_get_last_msg_severity(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static int __pyx_f_6_mssql_get_last_msg_state(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static int __pyx_f_6_mssql_get_last_msg_line(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static int __pyx_f_6_mssql_maybe_raise_MSSQLDatabaseException(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static void __pyx_f_6_mssql_assert_connected(struct __pyx_obj_6_mssql_MSSQLConnection *); /*proto*/
static CYTHON_INLINE BYTE *__pyx_f_6_mssql_get_data(DBPROCESS *, int, int); /*proto*/
static CYTHON_INLINE int __pyx_f_6_mssql_get_type(DBPROCESS *, int, int); /*proto*/
static CYTHON_INLINE int __pyx_f_6_mssql_get_length(DBPROCESS *, int, int); /*proto*/
static int __pyx_f_6_mssql_get_api_coltype(int); /*proto*/
static char *__pyx_f_6_mssql__remove_locale(char *, size_t); /*proto*/
static int __pyx_f_6_mssql__tds_ver_str_to_constant(PyObject *); /*proto*/
static PyObject *__pyx_f_6_mssql__quote_simple_value(PyObject *, struct __pyx_opt_args_6_mssql__quote_simple_value *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_6_mssql__quote_or_flatten(PyObject *, struct __pyx_opt_args_6_mssql__quote_or_flatten *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_6_mssql__quote_data(PyObject *, struct __pyx_opt_args_6_mssql__quote_data *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_6_mssql__substitute_params(PyObject *, PyObject *, PyObject *); /*proto*/
static void __pyx_f_6_mssql_init_mssql(void); /*proto*/
#define __Pyx_MODULE_NAME "_mssql"
int __pyx_module_is_main__mssql = 0;

/* Implementation of '_mssql' */
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_StopIteration;
static PyObject *__pyx_builtin_xrange;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_UnicodeDecodeError;
static PyObject *__pyx_builtin_IndexError;
static const char __pyx_k_0[] = "0";
static const char __pyx_k_1[] = "1";
static const char __pyx_k_N[] = "N'";
static const char __pyx_k_l[] = "l";
static const char __pyx_k_s[] = "#%s#\n";
static const char __pyx_k_0x[] = "0x";
static const char __pyx_k__2[] = "";
static const char __pyx_k__3[] = "\\";
static const char __pyx_k__5[] = ".";
static const char __pyx_k_os[] = "os";
static const char __pyx_k_re[] = "re";
static const char __pyx_k_sa[] = "sa";
static const char __pyx_k_sd[] = "(%([sd]))";
static const char __pyx_k_03d[] = "%03d";
static const char __pyx_k_4_2[] = "4.2";
static const char __pyx_k_7_0[] = "7.0";
static const char __pyx_k_7_1[] = "7.1";
static const char __pyx_k_7_2[] = "7.2";
static const char __pyx_k_8_0[] = "8.0";
static const char __pyx_k__10[] = ":";
static const char __pyx_k__15[] = " ";
static const char __pyx_k__31[] = "'";
static const char __pyx_k__32[] = "''";
static const char __pyx_k__34[] = "\000";
static const char __pyx_k__40[] = "(";
static const char __pyx_k__41[] = ",";
static const char __pyx_k__42[] = ")";
static const char __pyx_k_day[] = "day";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_hex[] = "hex";
static const char __pyx_k_s_2[] = "s";
static const char __pyx_k_s_s[] = "%s:%s";
static const char __pyx_k_sys[] = "sys";
static const char __pyx_k_1433[] = "1433";
static const char __pyx_k_NULL[] = "NULL";
static const char __pyx_k_UUID[] = "UUID";
static const char __pyx_k_args[] = "args";
static const char __pyx_k_data[] = "data";
static const char __pyx_k_date[] = "date";
static const char __pyx_k_exit[] = "__exit__";
static const char __pyx_k_hour[] = "hour";
static const char __pyx_k_join[] = "join";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_name[] = "name";
static const char __pyx_k_null[] = "null";
static const char __pyx_k_port[] = "port";
static const char __pyx_k_prec[] = "prec";
static const char __pyx_k_sd_2[] = "(%\\(([^\\)]+)\\)(?:[sd]))";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_user[] = "user";
static const char __pyx_k_utf8[] = "utf8";
static const char __pyx_k_uuid[] = "uuid";
static const char __pyx_k_year[] = "year";
static const char __pyx_k_UTF_8[] = "UTF-8";
static const char __pyx_k_ascii[] = "ascii";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_dberr[] = "dberr";
static const char __pyx_k_enter[] = "__enter__";
static const char __pyx_k_group[] = "group";
static const char __pyx_k_limit[] = "limit";
static const char __pyx_k_local[] = "(local)";
static const char __pyx_k_month[] = "month";
static const char __pyx_k_mssql[] = "_mssql";
static const char __pyx_k_oserr[] = "oserr";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_split[] = "split";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_utf_8[] = "utf-8";
static const char __pyx_k_value[] = "value";
static const char __pyx_k_write[] = "write";
static const char __pyx_k_BINARY[] = "BINARY";
static const char __pyx_k_NUMBER[] = "NUMBER";
static const char __pyx_k_SQLBIT[] = "SQLBIT";
static const char __pyx_k_STRING[] = "STRING";
static const char __pyx_k_append[] = "append";
static const char __pyx_k_cancel[] = "cancel";
static const char __pyx_k_dbproc[] = "dbproc";
static const char __pyx_k_dbtype[] = "dbtype";
static const char __pyx_k_decode[] = "decode";
static const char __pyx_k_encode[] = "encode";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_kwargs[] = "kwargs";
static const char __pyx_k_minute[] = "minute";
static const char __pyx_k_output[] = "output";
static const char __pyx_k_params[] = "params";
static const char __pyx_k_remove[] = "remove";
static const char __pyx_k_second[] = "second";
static const char __pyx_k_server[] = "server";
static const char __pyx_k_socket[] = "socket";
static const char __pyx_k_stderr[] = "stderr";
static const char __pyx_k_xrange[] = "xrange";
static const char __pyx_k_DECIMAL[] = "DECIMAL";
static const char __pyx_k_Decimal[] = "Decimal";
static const char __pyx_k_SQLBITN[] = "SQLBITN";
static const char __pyx_k_SQLCHAR[] = "SQLCHAR";
static const char __pyx_k_SQLFLT4[] = "SQLFLT4";
static const char __pyx_k_SQLFLT8[] = "SQLFLT8";
static const char __pyx_k_SQLFLTN[] = "SQLFLTN";
static const char __pyx_k_SQLINT1[] = "SQLINT1";
static const char __pyx_k_SQLINT2[] = "SQLINT2";
static const char __pyx_k_SQLINT4[] = "SQLINT4";
static const char __pyx_k_SQLINT8[] = "SQLINT8";
static const char __pyx_k_SQLINTN[] = "SQLINTN";
static const char __pyx_k_SQLREAL[] = "SQLREAL";
static const char __pyx_k_SQLTEXT[] = "SQLTEXT";
static const char __pyx_k_SQLUUID[] = "SQLUUID";
static const char __pyx_k_appname[] = "appname";
static const char __pyx_k_charset[] = "charset";
static const char __pyx_k_compile[] = "compile";
static const char __pyx_k_connect[] = "connect";
static const char __pyx_k_decimal[] = "decimal";
static const char __pyx_k_hexlify[] = "hexlify";
static const char __pyx_k_replace[] = "replace";
static const char __pyx_k_results[] = "results";
static const char __pyx_k_version[] = "__version__";
static const char __pyx_k_DATETIME[] = "DATETIME";
static const char __pyx_k_Iterable[] = "Iterable";
static const char __pyx_k_SQLIMAGE[] = "SQLIMAGE";
static const char __pyx_k_SQLMONEY[] = "SQLMONEY";
static const char __pyx_k_as_tuple[] = "as_tuple";
static const char __pyx_k_binascii[] = "binascii";
static const char __pyx_k_bytes_le[] = "bytes_le";
static const char __pyx_k_database[] = "database";
static const char __pyx_k_datetime[] = "datetime";
static const char __pyx_k_dberrstr[] = "dberrstr";
static const char __pyx_k_exc_type[] = "exc_type";
static const char __pyx_k_exponent[] = "exponent";
static const char __pyx_k_finditer[] = "finditer";
static const char __pyx_k_oserrstr[] = "oserrstr";
static const char __pyx_k_password[] = "password";
static const char __pyx_k_severity[] = "severity";
static const char __pyx_k_strftime[] = "strftime";
static const char __pyx_k_toformat[] = "toformat";
static const char __pyx_k_SQLBINARY[] = "SQLBINARY";
static const char __pyx_k_SQLMONEY4[] = "SQLMONEY4";
static const char __pyx_k_SQLMONEYN[] = "SQLMONEYN";
static const char __pyx_k_TypeError[] = "TypeError";
static const char __pyx_k_connected[] = "connected";
static const char __pyx_k_dberrstrc[] = "dberrstrc";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_exc_value[] = "exc_value";
static const char __pyx_k_iteritems[] = "iteritems";
static const char __pyx_k_localhost[] = "localhost";
static const char __pyx_k_oserrstrc[] = "oserrstrc";
static const char __pyx_k_pymssql_s[] = "pymssql=%s";
static const char __pyx_k_select_db[] = "select_db";
static const char __pyx_k_traceback[] = "traceback";
static const char __pyx_k_IndexError[] = "IndexError";
static const char __pyx_k_SQLDECIMAL[] = "SQLDECIMAL";
static const char __pyx_k_SQLNUMERIC[] = "SQLNUMERIC";
static const char __pyx_k_SQLVARCHAR[] = "SQLVARCHAR";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_a_callable[] = "a_callable";
static const char __pyx_k_connection[] = "connection";
static const char __pyx_k_max_length[] = "max_length";
static const char __pyx_k_param_name[] = "param_name";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_quote_data[] = "quote_data";
static const char __pyx_k_row_format[] = "row_format";
static const char __pyx_k_startswith[] = "startswith";
static const char __pyx_k_SQLDATETIM4[] = "SQLDATETIM4";
static const char __pyx_k_SQLDATETIME[] = "SQLDATETIME";
static const char __pyx_k_SQLDATETIMN[] = "SQLDATETIMN";
static const char __pyx_k_Y_m_d_H_M_S[] = "%Y-%m-%d %H:%M:%S.";
static const char __pyx_k_collections[] = "collections";
static const char __pyx_k_execute_row[] = "execute_row";
static const char __pyx_k_gethostname[] = "gethostname";
static const char __pyx_k_microsecond[] = "microsecond";
static const char __pyx_k_tds_version[] = "tds_version";
static const char __pyx_k_SQLVARBINARY[] = "SQLVARBINARY";
static const char __pyx_k_full_version[] = "__full_version__";
static const char __pyx_k_localcontext[] = "localcontext";
static const char __pyx_k_query_string[] = "query_string";
static const char __pyx_k_re_pos_param[] = "_re_pos_param";
static const char __pyx_k_string_types[] = "string_types";
static const char __pyx_k_Out_of_memory[] = "Out of memory";
static const char __pyx_k_StopIteration[] = "StopIteration";
static const char __pyx_k_Unknown_error[] = "Unknown error";
static const char __pyx_k_d_04d_02d_02d[] = "{d '%04d-%02d-%02d'} ";
static const char __pyx_k_dbinit_failed[] = "dbinit() failed";
static const char __pyx_k_execute_query[] = "execute_query";
static const char __pyx_k_login_timeout[] = "login_timeout";
static const char __pyx_k_re_name_param[] = "_re_name_param";
static const char __pyx_k_remove_locale[] = "remove_locale";
static const char __pyx_k_wait_callback[] = "wait_callback";
static const char __pyx_k_AttributeError[] = "AttributeError";
static const char __pyx_k_dblogin_failed[] = "dblogin() failed";
static const char __pyx_k_execute_scalar[] = "execute_scalar";
static const char __pyx_k_set_msghandler[] = "set_msghandler";
static const char __pyx_k_MssqlConnection[] = "MssqlConnection";
static const char __pyx_k_ROW_FORMAT_DICT[] = "ROW_FORMAT_DICT";
static const char __pyx_k_conn_properties[] = "conn_properties";
static const char __pyx_k_ROW_FORMAT_TUPLE[] = "ROW_FORMAT_TUPLE";
static const char __pyx_k_quote_or_flatten[] = "quote_or_flatten";
static const char __pyx_k_test_err_handler[] = "test_err_handler";
static const char __pyx_k_execute_non_query[] = "execute_non_query";
static const char __pyx_k_mark_disconnected[] = "mark_disconnected";
static const char __pyx_k_set_wait_callback[] = "set_wait_callback";
static const char __pyx_k_substitute_params[] = "substitute_params";
static const char __pyx_k_UnicodeDecodeError[] = "UnicodeDecodeError";
static const char __pyx_k_min_error_severity[] = "min_error_severity";
static const char __pyx_k_quote_simple_value[] = "quote_simple_value";
static const char __pyx_k_get_max_connections[] = "get_max_connections";
static const char __pyx_k_set_max_connections[] = "set_max_connections";
static const char __pyx_k_MssqlDriverException[] = "MssqlDriverException";
static const char __pyx_k_dberrstr_byte_string[] = "dberrstr_byte_string";
static const char __pyx_k_oserrstr_byte_string[] = "oserrstr_byte_string";
static const char __pyx_k_SELECT_SCOPE_IDENTITY[] = "SELECT SCOPE_IDENTITY()";
static const char __pyx_k_value_can_only_be_str[] = "value can only be str";
static const char __pyx_k_MssqlDatabaseException[] = "MssqlDatabaseException";
static const char __pyx_k_Unable_to_convert_value[] = "Unable to convert value";
static const char __pyx_k_found_an_unsupported_type[] = "found an unsupported type";
static const char __pyx_k_unrecognized_tds_version_s[] = "unrecognized tds version: %s";
static const char __pyx_k_value_can_only_be_a_Decimal[] = "value can only be a Decimal";
static const char __pyx_k_value_must_be_a_string_type[] = "value must be a string type";
static const char __pyx_k_value_cannot_be_larger_than_d[] = "value cannot be larger than %d";
static const char __pyx_k_ts_04d_02d_02d_02d_02d_02d_03d[] = "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}";
static const char __pyx_k_value_cannot_be_smaller_than_d[] = "value cannot be smaller than %d";
static const char __pyx_k_SQL_Server_message_d_severity_d[] = "SQL Server message %d, severity %d, state %d, procedure %s, line %d:\n%s";
static const char __pyx_k_This_is_an_effort_to_convert_th[] = "\nThis is an effort to convert the pymssql low-level C module to Cython.\n";
static const char __pyx_k_home_travis_build_pymssql_pymss[] = "/home/travis/build/pymssql/pymssql/_mssql.pyx";
static const char __pyx_k_params_arg_r_can_be_only_a_tupl[] = "'params' arg (%r) can be only a tuple or a dictionary.";
static const char __pyx_k_Cannot_bind_named_parameter_afte[] = "Cannot bind named parameter after positional";
static const char __pyx_k_Connection_to_the_database_faile[] = "Connection to the database failed for an unknown reason.";
static const char __pyx_k_Could_not_set_connection_propert[] = "Could not set connection properties";
static const char __pyx_k_Not_connected_to_any_MS_SQL_serv[] = "Not connected to any MS SQL server";
static const char __pyx_k_SET_ARITHABORT_ON_SET_CONCAT_NUL[] = "SET ARITHABORT ON;SET CONCAT_NULL_YIELDS_NULL ON;SET ANSI_NULLS ON;SET ANSI_NULL_DFLT_ON ON;SET ANSI_PADDING ON;SET ANSI_WARNINGS ON;SET ANSI_NULL_DFLT_ON ON;SET CURSOR_CLOSE_ON_COMMIT ON;SET QUOTED_IDENTIFIER ON;SET TEXTSIZE 2147483647;";
static const char __pyx_k_Stored_Procedures_aren_t_support[] = "Stored Procedures aren't supported with a TDS version less than 7.";
static const char __pyx_k_The_query_timeout_attribute_must[] = "The 'query_timeout' attribute must be >= 0.";
static const char __pyx_k_expected_a_simple_type_a_tuple_o[] = "expected a simple type, a tuple or a list";
static const char __pyx_k_more_placeholders_in_sql_than_pa[] = "more placeholders in sql than params available";
static const char __pyx_k_params_dictionary_did_not_contai[] = "params dictionary did not contain value for placeholder: %s";
static const char __pyx_k_value_can_only_be_a_date_or_date[] = "value can only be a date or datetime";
static const char __pyx_k_SQL_Server_message_d_severity_d_2[] = "SQL Server message %d, severity %d, state %d, line %d:\n%s";
static const char __pyx_k_expected_a_simple_type_a_tuple_o_2[] = "expected a simple type, a tuple or a dictionary.";
static PyObject *__pyx_kp_s_0;
static PyObject *__pyx_kp_s_03d;
static PyObject *__pyx_kp_b_0x;
static PyObject *__pyx_kp_s_0x;
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_1433;
static PyObject *__pyx_kp_u_4_2;
static PyObject *__pyx_kp_u_7_0;
static PyObject *__pyx_kp_s_7_1;
static PyObject *__pyx_kp_u_7_1;
static PyObject *__pyx_kp_u_7_2;
static PyObject *__pyx_kp_u_8_0;
static PyObject *__pyx_n_s_AttributeError;
static PyObject *__pyx_n_s_BINARY;
static PyObject *__pyx_kp_s_Cannot_bind_named_parameter_afte;
static PyObject *__pyx_kp_s_Connection_to_the_database_faile;
static PyObject *__pyx_kp_s_Could_not_set_connection_propert;
static PyObject *__pyx_n_s_DATETIME;
static PyObject *__pyx_n_s_DECIMAL;
static PyObject *__pyx_n_s_Decimal;
static PyObject *__pyx_n_s_IndexError;
static PyObject *__pyx_n_s_Iterable;
static PyObject *__pyx_n_s_MssqlConnection;
static PyObject *__pyx_n_s_MssqlDatabaseException;
static PyObject *__pyx_n_s_MssqlDriverException;
static PyObject *__pyx_kp_s_N;
static PyObject *__pyx_n_b_NULL;
static PyObject *__pyx_n_s_NUMBER;
static PyObject *__pyx_kp_s_Not_connected_to_any_MS_SQL_serv;
static PyObject *__pyx_kp_s_Out_of_memory;
static PyObject *__pyx_n_s_ROW_FORMAT_DICT;
static PyObject *__pyx_n_s_ROW_FORMAT_TUPLE;
static PyObject *__pyx_kp_s_SELECT_SCOPE_IDENTITY;
static PyObject *__pyx_kp_s_SET_ARITHABORT_ON_SET_CONCAT_NUL;
static PyObject *__pyx_n_s_SQLBINARY;
static PyObject *__pyx_n_s_SQLBIT;
static PyObject *__pyx_n_s_SQLBITN;
static PyObject *__pyx_n_s_SQLCHAR;
static PyObject *__pyx_n_s_SQLDATETIM4;
static PyObject *__pyx_n_s_SQLDATETIME;
static PyObject *__pyx_n_s_SQLDATETIMN;
static PyObject *__pyx_n_s_SQLDECIMAL;
static PyObject *__pyx_n_s_SQLFLT4;
static PyObject *__pyx_n_s_SQLFLT8;
static PyObject *__pyx_n_s_SQLFLTN;
static PyObject *__pyx_n_s_SQLIMAGE;
static PyObject *__pyx_n_s_SQLINT1;
static PyObject *__pyx_n_s_SQLINT2;
static PyObject *__pyx_n_s_SQLINT4;
static PyObject *__pyx_n_s_SQLINT8;
static PyObject *__pyx_n_s_SQLINTN;
static PyObject *__pyx_n_s_SQLMONEY;
static PyObject *__pyx_n_s_SQLMONEY4;
static PyObject *__pyx_n_s_SQLMONEYN;
static PyObject *__pyx_n_s_SQLNUMERIC;
static PyObject *__pyx_n_s_SQLREAL;
static PyObject *__pyx_n_s_SQLTEXT;
static PyObject *__pyx_n_s_SQLUUID;
static PyObject *__pyx_n_s_SQLVARBINARY;
static PyObject *__pyx_n_s_SQLVARCHAR;
static PyObject *__pyx_kp_s_SQL_Server_message_d_severity_d;
static PyObject *__pyx_kp_s_SQL_Server_message_d_severity_d_2;
static PyObject *__pyx_n_s_STRING;
static PyObject *__pyx_n_s_StopIteration;
static PyObject *__pyx_kp_s_Stored_Procedures_aren_t_support;
static PyObject *__pyx_kp_s_The_query_timeout_attribute_must;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_kp_s_UTF_8;
static PyObject *__pyx_n_s_UUID;
static PyObject *__pyx_kp_s_Unable_to_convert_value;
static PyObject *__pyx_n_s_UnicodeDecodeError;
static PyObject *__pyx_kp_b_Unknown_error;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s_Y_m_d_H_M_S;
static PyObject *__pyx_kp_s__10;
static PyObject *__pyx_kp_s__15;
static PyObject *__pyx_kp_s__2;
static PyObject *__pyx_kp_s__3;
static PyObject *__pyx_kp_b__31;
static PyObject *__pyx_kp_s__31;
static PyObject *__pyx_kp_b__32;
static PyObject *__pyx_kp_s__32;
static PyObject *__pyx_kp_b__34;
static PyObject *__pyx_kp_b__40;
static PyObject *__pyx_kp_b__41;
static PyObject *__pyx_kp_b__42;
static PyObject *__pyx_kp_s__5;
static PyObject *__pyx_n_s_a_callable;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_appname;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_as_tuple;
static PyObject *__pyx_n_s_ascii;
static PyObject *__pyx_n_s_binascii;
static PyObject *__pyx_n_s_bytes_le;
static PyObject *__pyx_n_s_cancel;
static PyObject *__pyx_n_s_charset;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_collections;
static PyObject *__pyx_n_s_compile;
static PyObject *__pyx_n_s_conn_properties;
static PyObject *__pyx_n_s_connect;
static PyObject *__pyx_n_s_connected;
static PyObject *__pyx_n_s_connection;
static PyObject *__pyx_kp_s_d_04d_02d_02d;
static PyObject *__pyx_n_s_data;
static PyObject *__pyx_n_s_database;
static PyObject *__pyx_n_s_date;
static PyObject *__pyx_n_s_datetime;
static PyObject *__pyx_n_s_day;
static PyObject *__pyx_n_s_dberr;
static PyObject *__pyx_n_s_dberrstr;
static PyObject *__pyx_n_s_dberrstr_byte_string;
static PyObject *__pyx_n_s_dberrstrc;
static PyObject *__pyx_kp_s_dbinit_failed;
static PyObject *__pyx_kp_s_dblogin_failed;
static PyObject *__pyx_n_s_dbproc;
static PyObject *__pyx_n_s_dbtype;
static PyObject *__pyx_n_s_decimal;
static PyObject *__pyx_n_s_decode;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_enter;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_exc_type;
static PyObject *__pyx_n_s_exc_value;
static PyObject *__pyx_n_s_execute_non_query;
static PyObject *__pyx_n_s_execute_query;
static PyObject *__pyx_n_s_execute_row;
static PyObject *__pyx_n_s_execute_scalar;
static PyObject *__pyx_n_s_exit;
static PyObject *__pyx_kp_s_expected_a_simple_type_a_tuple_o;
static PyObject *__pyx_kp_s_expected_a_simple_type_a_tuple_o_2;
static PyObject *__pyx_n_s_exponent;
static PyObject *__pyx_n_s_finditer;
static PyObject *__pyx_kp_s_found_an_unsupported_type;
static PyObject *__pyx_n_s_full_version;
static PyObject *__pyx_n_s_get_max_connections;
static PyObject *__pyx_n_s_gethostname;
static PyObject *__pyx_n_s_group;
static PyObject *__pyx_n_s_hex;
static PyObject *__pyx_n_s_hexlify;
static PyObject *__pyx_kp_s_home_travis_build_pymssql_pymss;
static PyObject *__pyx_n_s_hour;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_iteritems;
static PyObject *__pyx_n_s_join;
static PyObject *__pyx_n_s_kwargs;
static PyObject *__pyx_n_s_l;
static PyObject *__pyx_n_s_limit;
static PyObject *__pyx_kp_s_local;
static PyObject *__pyx_n_s_localcontext;
static PyObject *__pyx_n_s_localhost;
static PyObject *__pyx_n_s_login_timeout;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_mark_disconnected;
static PyObject *__pyx_n_s_max_length;
static PyObject *__pyx_n_s_microsecond;
static PyObject *__pyx_n_s_min_error_severity;
static PyObject *__pyx_n_s_minute;
static PyObject *__pyx_n_s_month;
static PyObject *__pyx_kp_s_more_placeholders_in_sql_than_pa;
static PyObject *__pyx_n_s_mssql;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_null;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_oserr;
static PyObject *__pyx_n_s_oserrstr;
static PyObject *__pyx_n_s_oserrstr_byte_string;
static PyObject *__pyx_n_s_oserrstrc;
static PyObject *__pyx_n_s_output;
static PyObject *__pyx_n_s_param_name;
static PyObject *__pyx_n_s_params;
static PyObject *__pyx_kp_s_params_arg_r_can_be_only_a_tupl;
static PyObject *__pyx_kp_s_params_dictionary_did_not_contai;
static PyObject *__pyx_n_s_password;
static PyObject *__pyx_n_s_port;
static PyObject *__pyx_n_s_prec;
static PyObject *__pyx_kp_s_pymssql_s;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_query_string;
static PyObject *__pyx_n_s_quote_data;
static PyObject *__pyx_n_s_quote_or_flatten;
static PyObject *__pyx_n_s_quote_simple_value;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_re;
static PyObject *__pyx_n_s_re_name_param;
static PyObject *__pyx_n_s_re_pos_param;
static PyObject *__pyx_n_s_remove;
static PyObject *__pyx_n_s_remove_locale;
static PyObject *__pyx_n_s_replace;
static PyObject *__pyx_n_s_results;
static PyObject *__pyx_n_s_row_format;
static PyObject *__pyx_kp_s_s;
static PyObject *__pyx_n_s_s_2;
static PyObject *__pyx_kp_s_s_s;
static PyObject *__pyx_n_s_sa;
static PyObject *__pyx_kp_b_sd;
static PyObject *__pyx_kp_b_sd_2;
static PyObject *__pyx_n_s_second;
static PyObject *__pyx_n_s_select_db;
static PyObject *__pyx_n_s_server;
static PyObject *__pyx_n_s_set_max_connections;
static PyObject *__pyx_n_s_set_msghandler;
static PyObject *__pyx_n_s_set_wait_callback;
static PyObject *__pyx_n_s_severity;
static PyObject *__pyx_n_s_socket;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_s_startswith;
static PyObject *__pyx_n_s_stderr;
static PyObject *__pyx_n_s_strftime;
static PyObject *__pyx_n_s_string_types;
static PyObject *__pyx_n_s_substitute_params;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_tds_version;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_test_err_handler;
static PyObject *__pyx_n_s_toformat;
static PyObject *__pyx_n_s_traceback;
static PyObject *__pyx_kp_s_ts_04d_02d_02d_02d_02d_02d_03d;
static PyObject *__pyx_kp_s_unrecognized_tds_version_s;
static PyObject *__pyx_n_s_user;
static PyObject *__pyx_n_s_utf8;
static PyObject *__pyx_kp_s_utf_8;
static PyObject *__pyx_n_s_uuid;
static PyObject *__pyx_n_s_value;
static PyObject *__pyx_kp_s_value_can_only_be_a_Decimal;
static PyObject *__pyx_kp_s_value_can_only_be_a_date_or_date;
static PyObject *__pyx_kp_s_value_can_only_be_str;
static PyObject *__pyx_kp_s_value_cannot_be_larger_than_d;
static PyObject *__pyx_kp_s_value_cannot_be_smaller_than_d;
static PyObject *__pyx_kp_s_value_must_be_a_string_type;
static PyObject *__pyx_n_s_version;
static PyObject *__pyx_n_s_wait_callback;
static PyObject *__pyx_n_s_write;
static PyObject *__pyx_n_s_xrange;
static PyObject *__pyx_n_s_year;
static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_7message___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_6number___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_8severity___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_5state___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_4line___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_4text___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_7srvname___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_8procname___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_set_wait_callback(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a_callable); /* proto */
static int __pyx_pf_6_mssql_16MSSQLRowIterator___init__(struct __pyx_obj_6_mssql_MSSQLRowIterator *__pyx_v_self, PyObject *__pyx_v_connection, int __pyx_v_row_format); /* proto */
static PyObject *__pyx_pf_6_mssql_16MSSQLRowIterator_2__iter__(struct __pyx_obj_6_mssql_MSSQLRowIterator *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_16MSSQLRowIterator_4__next__(struct __pyx_obj_6_mssql_MSSQLRowIterator *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_7charset___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_9connected___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_8identity___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_13query_timeout___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static int __pyx_pf_6_mssql_15MSSQLConnection_13query_timeout_2__set__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_13rows_affected___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_11tds_version___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static int __pyx_pf_6_mssql_15MSSQLConnection___cinit__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static int __pyx_pf_6_mssql_15MSSQLConnection_2__init__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_server, PyObject *__pyx_v_user, PyObject *__pyx_v_password, PyObject *__pyx_v_charset, PyObject *__pyx_v_database, PyObject *__pyx_v_appname, PyObject *__pyx_v_port, PyObject *__pyx_v_tds_version, PyObject *__pyx_v_conn_properties); /* proto */
static void __pyx_pf_6_mssql_15MSSQLConnection_4__dealloc__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_6__enter__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_8__exit__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_10__iter__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_12set_msghandler(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_handler); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_14cancel(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_16close(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_18mark_disconnected(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_20execute_non_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, PyObject *__pyx_v_params); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_22execute_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, PyObject *__pyx_v_params); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_24execute_row(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, PyObject *__pyx_v_params); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_26execute_scalar(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, PyObject *__pyx_v_params); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_28get_header(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_30get_iterator(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_v_row_format); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_32init_procedure(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_procname); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_34nextresult(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_36select_db(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_dbname); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_13debug_queries___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static int __pyx_pf_6_mssql_15MSSQLConnection_13debug_queries_2__set__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_10connection___get__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_4name___get__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_10parameters___get__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self); /* proto */
static int __pyx_pf_6_mssql_20MSSQLStoredProcedure___init__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self, PyObject *__pyx_v_name, struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_connection); /* proto */
static void __pyx_pf_6_mssql_20MSSQLStoredProcedure_2__dealloc__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_4bind(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self, PyObject *__pyx_v_value, int __pyx_v_dbtype, PyObject *__pyx_v_param_name, int __pyx_v_output, int __pyx_v_null, int __pyx_v_max_length); /* proto */
static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_6execute(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_2remove_locale(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_6_mssql_4quote_simple_value(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_6_mssql_6quote_or_flatten(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data); /* proto */
static PyObject *__pyx_pf_6_mssql_8quote_data(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data); /* proto */
static PyObject *__pyx_pf_6_mssql_10substitute_params(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_toformat, PyObject *__pyx_v_params, PyObject *__pyx_v_charset); /* proto */
static PyObject *__pyx_pf_6_mssql_12connect(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_6_mssql_14test_err_handler(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_connection, int __pyx_v_severity, int __pyx_v_dberr, int __pyx_v_oserr, PyObject *__pyx_v_dberrstr, PyObject *__pyx_v_oserrstr); /* proto */
static PyObject *__pyx_pf_6_mssql_16get_max_connections(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6_mssql_18set_max_connections(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_limit); /* proto */
static PyObject *__pyx_tp_new_6_mssql_MSSQLConnection(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6_mssql_MSSQLRowIterator(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6_mssql_MSSQLStoredProcedure(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6_mssql_MSSQLException(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6_mssql_MSSQLDriverException(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6_mssql_MSSQLDatabaseException(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_float_4_2;
static PyObject *__pyx_float_5_0;
static PyObject *__pyx_float_7_0;
static PyObject *__pyx_float_7_2;
static PyObject *__pyx_float_7_3;
static PyObject *__pyx_float_8_0;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_6;
static PyObject *__pyx_int_7;
static PyObject *__pyx_int_36;
static PyObject *__pyx_int_60;
static PyObject *__pyx_int_104;
static PyObject *__pyx_int_1000;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_slice__56;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__47;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__52;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__54;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__62;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__65;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__76;
static PyObject *__pyx_codeobj__58;
static PyObject *__pyx_codeobj__60;
static PyObject *__pyx_codeobj__64;
static PyObject *__pyx_codeobj__66;
static PyObject *__pyx_codeobj__68;
static PyObject *__pyx_codeobj__70;
static PyObject *__pyx_codeobj__72;
static PyObject *__pyx_codeobj__74;
static PyObject *__pyx_codeobj__75;
static PyObject *__pyx_codeobj__77;

/* "_mssql.pyx":172
 *     property message:
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.procname:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_7message_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_7message_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_22MSSQLDatabaseException_7message___get__(((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_7message___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":173
 * 
 *         def __get__(self):
 *             if self.procname:             # <<<<<<<<<<<<<<
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 *                     'procedure %s, line %d:\n%s' % (self.number,
 */
  __pyx_t_1 = (__pyx_v_self->procname != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":174
 *         def __get__(self):
 *             if self.procname:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \             # <<<<<<<<<<<<<<
 *                     'procedure %s, line %d:\n%s' % (self.number,
 *                     self.severity, self.state, self.procname,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "_mssql.pyx":175
 *             if self.procname:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 *                     'procedure %s, line %d:\n%s' % (self.number,             # <<<<<<<<<<<<<<
 *                     self.severity, self.state, self.procname,
 *                     self.line, self.text)
 */
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->number); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 175, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "_mssql.pyx":176
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 *                     'procedure %s, line %d:\n%s' % (self.number,
 *                     self.severity, self.state, self.procname,             # <<<<<<<<<<<<<<
 *                     self.line, self.text)
 *             else:
 */
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->severity); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 176, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->state); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 176, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_self->procname); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 176, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "_mssql.pyx":177
 *                     'procedure %s, line %d:\n%s' % (self.number,
 *                     self.severity, self.state, self.procname,
 *                     self.line, self.text)             # <<<<<<<<<<<<<<
 *             else:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 */
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->line); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 177, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyBytes_FromString(__pyx_v_self->text); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 177, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);

    /* "_mssql.pyx":175
 *             if self.procname:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 *                     'procedure %s, line %d:\n%s' % (self.number,             # <<<<<<<<<<<<<<
 *                     self.severity, self.state, self.procname,
 *                     self.line, self.text)
 */
    __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 175, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_7);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_SQL_Server_message_d_severity_d, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 175, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":173
 * 
 *         def __get__(self):
 *             if self.procname:             # <<<<<<<<<<<<<<
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 *                     'procedure %s, line %d:\n%s' % (self.number,
 */
  }

  /* "_mssql.pyx":179
 *                     self.line, self.text)
 *             else:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \             # <<<<<<<<<<<<<<
 *                     'line %d:\n%s' % (self.number, self.severity,
 *                     self.state, self.line, self.text)
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);

    /* "_mssql.pyx":180
 *             else:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 *                     'line %d:\n%s' % (self.number, self.severity,             # <<<<<<<<<<<<<<
 *                     self.state, self.line, self.text)
 * 
 */
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_self->number); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 180, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_self->severity); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 180, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "_mssql.pyx":181
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 *                     'line %d:\n%s' % (self.number, self.severity,
 *                     self.state, self.line, self.text)             # <<<<<<<<<<<<<<
 * 
 * # Module attributes for configuring _mssql
 */
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->state); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 181, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->line); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 181, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->text); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 181, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "_mssql.pyx":180
 *             else:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 *                     'line %d:\n%s' % (self.number, self.severity,             # <<<<<<<<<<<<<<
 *                     self.state, self.line, self.text)
 * 
 */
    __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_4);
    __pyx_t_7 = 0;
    __pyx_t_8 = 0;
    __pyx_t_6 = 0;
    __pyx_t_5 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_SQL_Server_message_d_severity_d_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 180, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "_mssql.pyx":172
 *     property message:
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.procname:
 *                 return 'SQL Server message %d, severity %d, state %d, ' \
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("_mssql.MSSQLDatabaseException.message.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":162
 *     """
 * 
 *     cdef readonly int number             # <<<<<<<<<<<<<<
 *     cdef readonly int severity
 *     cdef readonly int state
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_6number_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_6number_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_22MSSQLDatabaseException_6number___get__(((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_6number___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->number); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLDatabaseException.number.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":163
 * 
 *     cdef readonly int number
 *     cdef readonly int severity             # <<<<<<<<<<<<<<
 *     cdef readonly int state
 *     cdef readonly int line
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_8severity_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_8severity_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_22MSSQLDatabaseException_8severity___get__(((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_8severity___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->severity); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLDatabaseException.severity.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":164
 *     cdef readonly int number
 *     cdef readonly int severity
 *     cdef readonly int state             # <<<<<<<<<<<<<<
 *     cdef readonly int line
 *     cdef readonly char *text
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_5state_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_5state_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_22MSSQLDatabaseException_5state___get__(((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_5state___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->state); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLDatabaseException.state.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":165
 *     cdef readonly int severity
 *     cdef readonly int state
 *     cdef readonly int line             # <<<<<<<<<<<<<<
 *     cdef readonly char *text
 *     cdef readonly char *srvname
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_4line_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_4line_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_22MSSQLDatabaseException_4line___get__(((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_4line___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLDatabaseException.line.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":166
 *     cdef readonly int state
 *     cdef readonly int line
 *     cdef readonly char *text             # <<<<<<<<<<<<<<
 *     cdef readonly char *srvname
 *     cdef readonly char *procname
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_4text_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_4text_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_22MSSQLDatabaseException_4text___get__(((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_4text___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLDatabaseException.text.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":167
 *     cdef readonly int line
 *     cdef readonly char *text
 *     cdef readonly char *srvname             # <<<<<<<<<<<<<<
 *     cdef readonly char *procname
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_7srvname_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_7srvname_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_22MSSQLDatabaseException_7srvname___get__(((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_7srvname___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->srvname); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLDatabaseException.srvname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":168
 *     cdef readonly char *text
 *     cdef readonly char *srvname
 *     cdef readonly char *procname             # <<<<<<<<<<<<<<
 * 
 *     property message:
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_8procname_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_22MSSQLDatabaseException_8procname_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_22MSSQLDatabaseException_8procname___get__(((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_22MSSQLDatabaseException_8procname___get__(struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->procname); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLDatabaseException.procname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":190
 * wait_callback = None
 * 
 * def set_wait_callback(a_callable):             # <<<<<<<<<<<<<<
 *     global wait_callback
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_1set_wait_callback(PyObject *__pyx_self, PyObject *__pyx_v_a_callable); /*proto*/
static PyMethodDef __pyx_mdef_6_mssql_1set_wait_callback = {"set_wait_callback", (PyCFunction)__pyx_pw_6_mssql_1set_wait_callback, METH_O, 0};
static PyObject *__pyx_pw_6_mssql_1set_wait_callback(PyObject *__pyx_self, PyObject *__pyx_v_a_callable) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_wait_callback (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_set_wait_callback(__pyx_self, ((PyObject *)__pyx_v_a_callable));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_set_wait_callback(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a_callable) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_wait_callback", 0);

  /* "_mssql.pyx":193
 *     global wait_callback
 * 
 *     wait_callback = a_callable             # <<<<<<<<<<<<<<
 * 
 * # Buffer size for large numbers
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_wait_callback, __pyx_v_a_callable) < 0) __PYX_ERR(0, 193, __pyx_L1_error)

  /* "_mssql.pyx":190
 * wait_callback = None
 * 
 * def set_wait_callback(a_callable):             # <<<<<<<<<<<<<<
 *     global wait_callback
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("_mssql.set_wait_callback", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":198
 * DEF NUMERIC_BUF_SZ = 45
 * 
 * cdef bytes ensure_bytes(s, encoding='utf-8'):             # <<<<<<<<<<<<<<
 *     try:
 *         decoded = s.decode(encoding)
 */

static PyObject *__pyx_f_6_mssql_ensure_bytes(PyObject *__pyx_v_s, struct __pyx_opt_args_6_mssql_ensure_bytes *__pyx_optional_args) {
  PyObject *__pyx_v_encoding = ((PyObject *)__pyx_kp_s_utf_8);
  PyObject *__pyx_v_decoded = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  __Pyx_RefNannySetupContext("ensure_bytes", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_encoding = __pyx_optional_args->encoding;
    }
  }

  /* "_mssql.pyx":199
 * 
 * cdef bytes ensure_bytes(s, encoding='utf-8'):
 *     try:             # <<<<<<<<<<<<<<
 *         decoded = s.decode(encoding)
 *         return decoded.encode(encoding)
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "_mssql.pyx":200
 * cdef bytes ensure_bytes(s, encoding='utf-8'):
 *     try:
 *         decoded = s.decode(encoding)             # <<<<<<<<<<<<<<
 *         return decoded.encode(encoding)
 *     except AttributeError:
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_decode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 200, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (!__pyx_t_6) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_encoding); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 200, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
      } else {
        __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 200, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
        __Pyx_INCREF(__pyx_v_encoding);
        __Pyx_GIVEREF(__pyx_v_encoding);
        PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_encoding);
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 200, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_decoded = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":201
 *     try:
 *         decoded = s.decode(encoding)
 *         return decoded.encode(encoding)             # <<<<<<<<<<<<<<
 *     except AttributeError:
 *         return s.encode(encoding)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_decoded, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 201, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (!__pyx_t_7) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_encoding); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
      } else {
        __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 201, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
        __Pyx_INCREF(__pyx_v_encoding);
        __Pyx_GIVEREF(__pyx_v_encoding);
        PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_encoding);
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 201, __pyx_L3_error)
      __pyx_r = ((PyObject*)__pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L7_try_return;

      /* "_mssql.pyx":199
 * 
 * cdef bytes ensure_bytes(s, encoding='utf-8'):
 *     try:             # <<<<<<<<<<<<<<
 *         decoded = s.decode(encoding)
 *         return decoded.encode(encoding)
 */
    }
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "_mssql.pyx":202
 *         decoded = s.decode(encoding)
 *         return decoded.encode(encoding)
 *     except AttributeError:             # <<<<<<<<<<<<<<
 *         return s.encode(encoding)
 * 
 */
    __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_8) {
      __Pyx_AddTraceback("_mssql.ensure_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6) < 0) __PYX_ERR(0, 202, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);

      /* "_mssql.pyx":203
 *         return decoded.encode(encoding)
 *     except AttributeError:
 *         return s.encode(encoding)             # <<<<<<<<<<<<<<
 * 
 * cdef void log(char * message, ...):
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_encode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 203, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      if (!__pyx_t_10) {
        __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_encoding); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 203, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_7);
      } else {
        __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 203, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL;
        __Pyx_INCREF(__pyx_v_encoding);
        __Pyx_GIVEREF(__pyx_v_encoding);
        PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_encoding);
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 203, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (!(likely(PyBytes_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 203, __pyx_L5_except_error)
      __pyx_r = ((PyObject*)__pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L6_except_return;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "_mssql.pyx":199
 * 
 * cdef bytes ensure_bytes(s, encoding='utf-8'):
 *     try:             # <<<<<<<<<<<<<<
 *         decoded = s.decode(encoding)
 *         return decoded.encode(encoding)
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
    __pyx_L6_except_return:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
  }

  /* "_mssql.pyx":198
 * DEF NUMERIC_BUF_SZ = 45
 * 
 * cdef bytes ensure_bytes(s, encoding='utf-8'):             # <<<<<<<<<<<<<<
 *     try:
 *         decoded = s.decode(encoding)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("_mssql.ensure_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_decoded);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":205
 *         return s.encode(encoding)
 * 
 * cdef void log(char * message, ...):             # <<<<<<<<<<<<<<
 *     if PYMSSQL_DEBUG == 1:
 *         fprintf(stderr, "+++ %s\n", message)
 */

static void __pyx_f_6_mssql_log(CYTHON_UNUSED char *__pyx_v_message, ...) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("log", 0);

  /* "_mssql.pyx":206
 * 
 * cdef void log(char * message, ...):
 *     if PYMSSQL_DEBUG == 1:             # <<<<<<<<<<<<<<
 *         fprintf(stderr, "+++ %s\n", message)
 * 
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":217
 * ## Error Handler ##
 * ###################
 * cdef int err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr,             # <<<<<<<<<<<<<<
 *         char *dberrstr, char *oserrstr) with gil:
 *     cdef char *mssql_lastmsgstr
 */

static int __pyx_f_6_mssql_err_handler(DBPROCESS *__pyx_v_dbproc, int __pyx_v_severity, int __pyx_v_dberr, int __pyx_v_oserr, char *__pyx_v_dberrstr, char *__pyx_v_oserrstr) {
  char *__pyx_v_mssql_lastmsgstr;
  int *__pyx_v_mssql_lastmsgno;
  int *__pyx_v_mssql_lastmsgseverity;
  int *__pyx_v_mssql_lastmsgstate;
  int __pyx_v__min_error_severity;
  char __pyx_v_mssql_message[0x2000];
  PyObject *__pyx_v_conn = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  char *__pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("err_handler", 0);

  /* "_mssql.pyx":223
 *     cdef int *mssql_lastmsgseverity
 *     cdef int *mssql_lastmsgstate
 *     cdef int _min_error_severity = min_error_severity             # <<<<<<<<<<<<<<
 *     cdef char mssql_message[PYMSSQL_MSGSIZE]
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_min_error_severity); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 223, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 223, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v__min_error_severity = __pyx_t_2;

  /* "_mssql.pyx":226
 *     cdef char mssql_message[PYMSSQL_MSGSIZE]
 * 
 *     if severity < _min_error_severity:             # <<<<<<<<<<<<<<
 *         return INT_CANCEL
 * 
 */
  __pyx_t_3 = ((__pyx_v_severity < __pyx_v__min_error_severity) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":227
 * 
 *     if severity < _min_error_severity:
 *         return INT_CANCEL             # <<<<<<<<<<<<<<
 * 
 *     if dberrstr == NULL:
 */
    __pyx_r = INT_CANCEL;
    goto __pyx_L0;

    /* "_mssql.pyx":226
 *     cdef char mssql_message[PYMSSQL_MSGSIZE]
 * 
 *     if severity < _min_error_severity:             # <<<<<<<<<<<<<<
 *         return INT_CANCEL
 * 
 */
  }

  /* "_mssql.pyx":229
 *         return INT_CANCEL
 * 
 *     if dberrstr == NULL:             # <<<<<<<<<<<<<<
 *         dberrstr = ''
 *     if oserrstr == NULL:
 */
  __pyx_t_3 = ((__pyx_v_dberrstr == NULL) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":230
 * 
 *     if dberrstr == NULL:
 *         dberrstr = ''             # <<<<<<<<<<<<<<
 *     if oserrstr == NULL:
 *         oserrstr = ''
 */
    __pyx_v_dberrstr = ((char *)"");

    /* "_mssql.pyx":229
 *         return INT_CANCEL
 * 
 *     if dberrstr == NULL:             # <<<<<<<<<<<<<<
 *         dberrstr = ''
 *     if oserrstr == NULL:
 */
  }

  /* "_mssql.pyx":231
 *     if dberrstr == NULL:
 *         dberrstr = ''
 *     if oserrstr == NULL:             # <<<<<<<<<<<<<<
 *         oserrstr = ''
 * 
 */
  __pyx_t_3 = ((__pyx_v_oserrstr == NULL) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":232
 *         dberrstr = ''
 *     if oserrstr == NULL:
 *         oserrstr = ''             # <<<<<<<<<<<<<<
 * 
 *     IF PYMSSQL_DEBUG == 1 or PYMSSQL_DEBUG_ERRORS == 1:
 */
    __pyx_v_oserrstr = ((char *)"");

    /* "_mssql.pyx":231
 *     if dberrstr == NULL:
 *         dberrstr = ''
 *     if oserrstr == NULL:             # <<<<<<<<<<<<<<
 *         oserrstr = ''
 * 
 */
  }

  /* "_mssql.pyx":242
 *             _mssql_last_msg_severity);
 * 
 *     mssql_lastmsgstr = _mssql_last_msg_str             # <<<<<<<<<<<<<<
 *     mssql_lastmsgno = &_mssql_last_msg_no
 *     mssql_lastmsgseverity = &_mssql_last_msg_severity
 */
  __pyx_v_mssql_lastmsgstr = __pyx_v_6_mssql__mssql_last_msg_str;

  /* "_mssql.pyx":243
 * 
 *     mssql_lastmsgstr = _mssql_last_msg_str
 *     mssql_lastmsgno = &_mssql_last_msg_no             # <<<<<<<<<<<<<<
 *     mssql_lastmsgseverity = &_mssql_last_msg_severity
 *     mssql_lastmsgstate = &_mssql_last_msg_state
 */
  __pyx_v_mssql_lastmsgno = (&__pyx_v_6_mssql__mssql_last_msg_no);

  /* "_mssql.pyx":244
 *     mssql_lastmsgstr = _mssql_last_msg_str
 *     mssql_lastmsgno = &_mssql_last_msg_no
 *     mssql_lastmsgseverity = &_mssql_last_msg_severity             # <<<<<<<<<<<<<<
 *     mssql_lastmsgstate = &_mssql_last_msg_state
 * 
 */
  __pyx_v_mssql_lastmsgseverity = (&__pyx_v_6_mssql__mssql_last_msg_severity);

  /* "_mssql.pyx":245
 *     mssql_lastmsgno = &_mssql_last_msg_no
 *     mssql_lastmsgseverity = &_mssql_last_msg_severity
 *     mssql_lastmsgstate = &_mssql_last_msg_state             # <<<<<<<<<<<<<<
 * 
 *     for conn in connection_object_list:
 */
  __pyx_v_mssql_lastmsgstate = (&__pyx_v_6_mssql__mssql_last_msg_state);

  /* "_mssql.pyx":247
 *     mssql_lastmsgstate = &_mssql_last_msg_state
 * 
 *     for conn in connection_object_list:             # <<<<<<<<<<<<<<
 *         if dbproc != (<MSSQLConnection>conn).dbproc:
 *             continue
 */
  if (unlikely(__pyx_v_6_mssql_connection_object_list == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 247, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_6_mssql_connection_object_list; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
  for (;;) {
    if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_5); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 247, __pyx_L1_error)
    #else
    __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 247, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_conn, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":248
 * 
 *     for conn in connection_object_list:
 *         if dbproc != (<MSSQLConnection>conn).dbproc:             # <<<<<<<<<<<<<<
 *             continue
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str
 */
    __pyx_t_3 = ((__pyx_v_dbproc != ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->dbproc) != 0);
    if (__pyx_t_3) {

      /* "_mssql.pyx":249
 *     for conn in connection_object_list:
 *         if dbproc != (<MSSQLConnection>conn).dbproc:
 *             continue             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no
 */
      goto __pyx_L6_continue;

      /* "_mssql.pyx":248
 * 
 *     for conn in connection_object_list:
 *         if dbproc != (<MSSQLConnection>conn).dbproc:             # <<<<<<<<<<<<<<
 *             continue
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str
 */
    }

    /* "_mssql.pyx":250
 *         if dbproc != (<MSSQLConnection>conn).dbproc:
 *             continue
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str             # <<<<<<<<<<<<<<
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 */
    __pyx_t_6 = ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_str;
    __pyx_v_mssql_lastmsgstr = __pyx_t_6;

    /* "_mssql.pyx":251
 *             continue
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no             # <<<<<<<<<<<<<<
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 */
    __pyx_v_mssql_lastmsgno = (&((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_no);

    /* "_mssql.pyx":252
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 *         if DBDEAD(dbproc):
 */
    __pyx_v_mssql_lastmsgseverity = (&((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_severity);

    /* "_mssql.pyx":253
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state             # <<<<<<<<<<<<<<
 *         if DBDEAD(dbproc):
 *             log("+++ err_handler: dbproc is dead; killing conn...\n")
 */
    __pyx_v_mssql_lastmsgstate = (&((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_state);

    /* "_mssql.pyx":254
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 *         if DBDEAD(dbproc):             # <<<<<<<<<<<<<<
 *             log("+++ err_handler: dbproc is dead; killing conn...\n")
 *             conn.mark_disconnected()
 */
    __pyx_t_3 = (DBDEAD(__pyx_v_dbproc) != 0);
    if (__pyx_t_3) {

      /* "_mssql.pyx":255
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 *         if DBDEAD(dbproc):
 *             log("+++ err_handler: dbproc is dead; killing conn...\n")             # <<<<<<<<<<<<<<
 *             conn.mark_disconnected()
 *         break
 */
      __pyx_f_6_mssql_log(((char *)"+++ err_handler: dbproc is dead; killing conn...\n"));

      /* "_mssql.pyx":256
 *         if DBDEAD(dbproc):
 *             log("+++ err_handler: dbproc is dead; killing conn...\n")
 *             conn.mark_disconnected()             # <<<<<<<<<<<<<<
 *         break
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_conn, __pyx_n_s_mark_disconnected); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 256, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      if (__pyx_t_8) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 256, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else {
        __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 256, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "_mssql.pyx":254
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 *         if DBDEAD(dbproc):             # <<<<<<<<<<<<<<
 *             log("+++ err_handler: dbproc is dead; killing conn...\n")
 *             conn.mark_disconnected()
 */
    }

    /* "_mssql.pyx":257
 *             log("+++ err_handler: dbproc is dead; killing conn...\n")
 *             conn.mark_disconnected()
 *         break             # <<<<<<<<<<<<<<
 * 
 *     if severity > mssql_lastmsgseverity[0]:
 */
    goto __pyx_L7_break;

    /* "_mssql.pyx":247
 *     mssql_lastmsgstate = &_mssql_last_msg_state
 * 
 *     for conn in connection_object_list:             # <<<<<<<<<<<<<<
 *         if dbproc != (<MSSQLConnection>conn).dbproc:
 *             continue
 */
    __pyx_L6_continue:;
  }
  __pyx_L7_break:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":259
 *         break
 * 
 *     if severity > mssql_lastmsgseverity[0]:             # <<<<<<<<<<<<<<
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = dberr
 */
  __pyx_t_3 = ((__pyx_v_severity > (__pyx_v_mssql_lastmsgseverity[0])) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":260
 * 
 *     if severity > mssql_lastmsgseverity[0]:
 *         mssql_lastmsgseverity[0] = severity             # <<<<<<<<<<<<<<
 *         mssql_lastmsgno[0] = dberr
 *         mssql_lastmsgstate[0] = oserr
 */
    (__pyx_v_mssql_lastmsgseverity[0]) = __pyx_v_severity;

    /* "_mssql.pyx":261
 *     if severity > mssql_lastmsgseverity[0]:
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = dberr             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstate[0] = oserr
 * 
 */
    (__pyx_v_mssql_lastmsgno[0]) = __pyx_v_dberr;

    /* "_mssql.pyx":262
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = dberr
 *         mssql_lastmsgstate[0] = oserr             # <<<<<<<<<<<<<<
 * 
 *     if oserr != DBNOERR and oserr != 0:
 */
    (__pyx_v_mssql_lastmsgstate[0]) = __pyx_v_oserr;

    /* "_mssql.pyx":259
 *         break
 * 
 *     if severity > mssql_lastmsgseverity[0]:             # <<<<<<<<<<<<<<
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = dberr
 */
  }

  /* "_mssql.pyx":264
 *         mssql_lastmsgstate[0] = oserr
 * 
 *     if oserr != DBNOERR and oserr != 0:             # <<<<<<<<<<<<<<
 *         if severity == EXCOMM:
 *             snprintf(
 */
  __pyx_t_9 = ((__pyx_v_oserr != DBNOERR) != 0);
  if (__pyx_t_9) {
  } else {
    __pyx_t_3 = __pyx_t_9;
    goto __pyx_L12_bool_binop_done;
  }
  __pyx_t_9 = ((__pyx_v_oserr != 0) != 0);
  __pyx_t_3 = __pyx_t_9;
  __pyx_L12_bool_binop_done:;
  if (__pyx_t_3) {

    /* "_mssql.pyx":265
 * 
 *     if oserr != DBNOERR and oserr != 0:
 *         if severity == EXCOMM:             # <<<<<<<<<<<<<<
 *             snprintf(
 *                 mssql_message, sizeof(mssql_message),
 */
    __pyx_t_3 = ((__pyx_v_severity == 9) != 0);
    if (__pyx_t_3) {

      /* "_mssql.pyx":266
 *     if oserr != DBNOERR and oserr != 0:
 *         if severity == EXCOMM:
 *             snprintf(             # <<<<<<<<<<<<<<
 *                 mssql_message, sizeof(mssql_message),
 *                 '%sDB-Lib error message %d, severity %d:\n%s\nNet-Lib error during %s (%d)\n',
 */
      snprintf(__pyx_v_mssql_message, (sizeof(__pyx_v_mssql_message)), ((char const *)"%sDB-Lib error message %d, severity %d:\n%s\nNet-Lib error during %s (%d)\n"), __pyx_v_mssql_lastmsgstr, __pyx_v_dberr, __pyx_v_severity, __pyx_v_dberrstr, __pyx_v_oserrstr, __pyx_v_oserr);

      /* "_mssql.pyx":265
 * 
 *     if oserr != DBNOERR and oserr != 0:
 *         if severity == EXCOMM:             # <<<<<<<<<<<<<<
 *             snprintf(
 *                 mssql_message, sizeof(mssql_message),
 */
      goto __pyx_L14;
    }

    /* "_mssql.pyx":271
 *                 mssql_lastmsgstr, dberr, severity, dberrstr, oserrstr, oserr)
 *         else:
 *             snprintf(             # <<<<<<<<<<<<<<
 *                 mssql_message, sizeof(mssql_message),
 *                 '%sDB-Lib error message %d, severity %d:\n%s\nOperating System error during %s (%d)\n',
 */
    /*else*/ {

      /* "_mssql.pyx":274
 *                 mssql_message, sizeof(mssql_message),
 *                 '%sDB-Lib error message %d, severity %d:\n%s\nOperating System error during %s (%d)\n',
 *                 mssql_lastmsgstr, dberr, severity, dberrstr, oserrstr, oserr)             # <<<<<<<<<<<<<<
 *     else:
 *         snprintf(
 */
      snprintf(__pyx_v_mssql_message, (sizeof(__pyx_v_mssql_message)), ((char const *)"%sDB-Lib error message %d, severity %d:\n%s\nOperating System error during %s (%d)\n"), __pyx_v_mssql_lastmsgstr, __pyx_v_dberr, __pyx_v_severity, __pyx_v_dberrstr, __pyx_v_oserrstr, __pyx_v_oserr);
    }
    __pyx_L14:;

    /* "_mssql.pyx":264
 *         mssql_lastmsgstate[0] = oserr
 * 
 *     if oserr != DBNOERR and oserr != 0:             # <<<<<<<<<<<<<<
 *         if severity == EXCOMM:
 *             snprintf(
 */
    goto __pyx_L11;
  }

  /* "_mssql.pyx":276
 *                 mssql_lastmsgstr, dberr, severity, dberrstr, oserrstr, oserr)
 *     else:
 *         snprintf(             # <<<<<<<<<<<<<<
 *             mssql_message, sizeof(mssql_message),
 *             '%sDB-Lib error message %d, severity %d:\n%s\n',
 */
  /*else*/ {

    /* "_mssql.pyx":279
 *             mssql_message, sizeof(mssql_message),
 *             '%sDB-Lib error message %d, severity %d:\n%s\n',
 *             mssql_lastmsgstr, dberr, severity, dberrstr)             # <<<<<<<<<<<<<<
 * 
 *     strncpy(mssql_lastmsgstr, mssql_message, PYMSSQL_MSGSIZE)
 */
    snprintf(__pyx_v_mssql_message, (sizeof(__pyx_v_mssql_message)), ((char const *)"%sDB-Lib error message %d, severity %d:\n%s\n"), __pyx_v_mssql_lastmsgstr, __pyx_v_dberr, __pyx_v_severity, __pyx_v_dberrstr);
  }
  __pyx_L11:;

  /* "_mssql.pyx":281
 *             mssql_lastmsgstr, dberr, severity, dberrstr)
 * 
 *     strncpy(mssql_lastmsgstr, mssql_message, PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 *     mssql_lastmsgstr[ PYMSSQL_MSGSIZE - 1 ] = '\0'
 * 
 */
  strncpy(__pyx_v_mssql_lastmsgstr, __pyx_v_mssql_message, 0x2000);

  /* "_mssql.pyx":282
 * 
 *     strncpy(mssql_lastmsgstr, mssql_message, PYMSSQL_MSGSIZE)
 *     mssql_lastmsgstr[ PYMSSQL_MSGSIZE - 1 ] = '\0'             # <<<<<<<<<<<<<<
 * 
 *     return INT_CANCEL
 */
  (__pyx_v_mssql_lastmsgstr[0x1FFF]) = '\x00';

  /* "_mssql.pyx":284
 *     mssql_lastmsgstr[ PYMSSQL_MSGSIZE - 1 ] = '\0'
 * 
 *     return INT_CANCEL             # <<<<<<<<<<<<<<
 * 
 * #####################
 */
  __pyx_r = INT_CANCEL;
  goto __pyx_L0;

  /* "_mssql.pyx":217
 * ## Error Handler ##
 * ###################
 * cdef int err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr,             # <<<<<<<<<<<<<<
 *         char *dberrstr, char *oserrstr) with gil:
 *     cdef char *mssql_lastmsgstr
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_WriteUnraisable("_mssql.err_handler", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_conn);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "_mssql.pyx":289
 * ## Message Handler ##
 * #####################
 * cdef int msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,             # <<<<<<<<<<<<<<
 *         int severity, char *msgtext, char *srvname, char *procname,
 *         LINE_T line) with gil:
 */

static int __pyx_f_6_mssql_msg_handler(DBPROCESS *__pyx_v_dbproc, DBINT __pyx_v_msgno, int __pyx_v_msgstate, int __pyx_v_severity, char *__pyx_v_msgtext, char *__pyx_v_srvname, char *__pyx_v_procname, __pyx_t_8sqlfront_LINE_T __pyx_v_line) {
  int *__pyx_v_mssql_lastmsgno;
  int *__pyx_v_mssql_lastmsgseverity;
  int *__pyx_v_mssql_lastmsgstate;
  int *__pyx_v_mssql_lastmsgline;
  char *__pyx_v_mssql_lastmsgstr;
  char *__pyx_v_mssql_lastmsgsrv;
  char *__pyx_v_mssql_lastmsgproc;
  int __pyx_v__min_error_severity;
  struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn = 0;
  PyObject *__pyx_v_cnx = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  char *__pyx_t_16;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("msg_handler", 0);

  /* "_mssql.pyx":300
 *     cdef char *mssql_lastmsgsrv
 *     cdef char *mssql_lastmsgproc
 *     cdef int _min_error_severity = min_error_severity             # <<<<<<<<<<<<<<
 *     cdef MSSQLConnection conn = None
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_min_error_severity); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 300, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 300, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v__min_error_severity = __pyx_t_2;

  /* "_mssql.pyx":301
 *     cdef char *mssql_lastmsgproc
 *     cdef int _min_error_severity = min_error_severity
 *     cdef MSSQLConnection conn = None             # <<<<<<<<<<<<<<
 * 
 *     IF PYMSSQL_DEBUG == 1:
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_conn = ((struct __pyx_obj_6_mssql_MSSQLConnection *)Py_None);

  /* "_mssql.pyx":312
 *             _mssql_last_msg_severity);
 * 
 *     for cnx in connection_object_list:             # <<<<<<<<<<<<<<
 *         if (<MSSQLConnection>cnx).dbproc != dbproc:
 *             continue
 */
  if (unlikely(__pyx_v_6_mssql_connection_object_list == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 312, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_6_mssql_connection_object_list; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
  for (;;) {
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 312, __pyx_L1_error)
    #else
    __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 312, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_cnx, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "_mssql.pyx":313
 * 
 *     for cnx in connection_object_list:
 *         if (<MSSQLConnection>cnx).dbproc != dbproc:             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    __pyx_t_5 = ((((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_cnx)->dbproc != __pyx_v_dbproc) != 0);
    if (__pyx_t_5) {

      /* "_mssql.pyx":314
 *     for cnx in connection_object_list:
 *         if (<MSSQLConnection>cnx).dbproc != dbproc:
 *             continue             # <<<<<<<<<<<<<<
 * 
 *         conn = <MSSQLConnection>cnx
 */
      goto __pyx_L3_continue;

      /* "_mssql.pyx":313
 * 
 *     for cnx in connection_object_list:
 *         if (<MSSQLConnection>cnx).dbproc != dbproc:             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    }

    /* "_mssql.pyx":316
 *             continue
 * 
 *         conn = <MSSQLConnection>cnx             # <<<<<<<<<<<<<<
 *         break
 * 
 */
    __pyx_t_4 = __pyx_v_cnx;
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_DECREF_SET(__pyx_v_conn, ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "_mssql.pyx":317
 * 
 *         conn = <MSSQLConnection>cnx
 *         break             # <<<<<<<<<<<<<<
 * 
 *     if conn is not None and conn.msghandler is not None:
 */
    goto __pyx_L4_break;

    /* "_mssql.pyx":312
 *             _mssql_last_msg_severity);
 * 
 *     for cnx in connection_object_list:             # <<<<<<<<<<<<<<
 *         if (<MSSQLConnection>cnx).dbproc != dbproc:
 *             continue
 */
    __pyx_L3_continue:;
  }
  __pyx_L4_break:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":319
 *         break
 * 
 *     if conn is not None and conn.msghandler is not None:             # <<<<<<<<<<<<<<
 *         conn.msghandler(msgstate, severity, srvname, procname, line, msgtext)
 * 
 */
  __pyx_t_6 = (((PyObject *)__pyx_v_conn) != Py_None);
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_7 = (__pyx_v_conn->msghandler != Py_None);
  __pyx_t_6 = (__pyx_t_7 != 0);
  __pyx_t_5 = __pyx_t_6;
  __pyx_L7_bool_binop_done:;
  if (__pyx_t_5) {

    /* "_mssql.pyx":320
 * 
 *     if conn is not None and conn.msghandler is not None:
 *         conn.msghandler(msgstate, severity, srvname, procname, line, msgtext)             # <<<<<<<<<<<<<<
 * 
 *     if severity < _min_error_severity:
 */
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_msgstate); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_severity); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyBytes_FromString(__pyx_v_srvname); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = __Pyx_PyBytes_FromString(__pyx_v_procname); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_line); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_12 = __Pyx_PyBytes_FromString(__pyx_v_msgtext); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_INCREF(__pyx_v_conn->msghandler);
    __pyx_t_13 = __pyx_v_conn->msghandler; __pyx_t_14 = NULL;
    __pyx_t_3 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_13))) {
      __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_13);
      if (likely(__pyx_t_14)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
        __Pyx_INCREF(__pyx_t_14);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_13, function);
        __pyx_t_3 = 1;
      }
    }
    __pyx_t_15 = PyTuple_New(6+__pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (__pyx_t_14) {
      __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); __pyx_t_14 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_3, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_3, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_15, 2+__pyx_t_3, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_15, 3+__pyx_t_3, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_15, 4+__pyx_t_3, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_15, 5+__pyx_t_3, __pyx_t_12);
    __pyx_t_4 = 0;
    __pyx_t_8 = 0;
    __pyx_t_9 = 0;
    __pyx_t_10 = 0;
    __pyx_t_11 = 0;
    __pyx_t_12 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":319
 *         break
 * 
 *     if conn is not None and conn.msghandler is not None:             # <<<<<<<<<<<<<<
 *         conn.msghandler(msgstate, severity, srvname, procname, line, msgtext)
 * 
 */
  }

  /* "_mssql.pyx":322
 *         conn.msghandler(msgstate, severity, srvname, procname, line, msgtext)
 * 
 *     if severity < _min_error_severity:             # <<<<<<<<<<<<<<
 *         return INT_CANCEL
 * 
 */
  __pyx_t_5 = ((__pyx_v_severity < __pyx_v__min_error_severity) != 0);
  if (__pyx_t_5) {

    /* "_mssql.pyx":323
 * 
 *     if severity < _min_error_severity:
 *         return INT_CANCEL             # <<<<<<<<<<<<<<
 * 
 *     if conn is not None:
 */
    __pyx_r = INT_CANCEL;
    goto __pyx_L0;

    /* "_mssql.pyx":322
 *         conn.msghandler(msgstate, severity, srvname, procname, line, msgtext)
 * 
 *     if severity < _min_error_severity:             # <<<<<<<<<<<<<<
 *         return INT_CANCEL
 * 
 */
  }

  /* "_mssql.pyx":325
 *         return INT_CANCEL
 * 
 *     if conn is not None:             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstr = conn.last_msg_str
 *         mssql_lastmsgsrv = conn.last_msg_srv
 */
  __pyx_t_5 = (((PyObject *)__pyx_v_conn) != Py_None);
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":326
 * 
 *     if conn is not None:
 *         mssql_lastmsgstr = conn.last_msg_str             # <<<<<<<<<<<<<<
 *         mssql_lastmsgsrv = conn.last_msg_srv
 *         mssql_lastmsgproc = conn.last_msg_proc
 */
    __pyx_t_16 = __pyx_v_conn->last_msg_str;
    __pyx_v_mssql_lastmsgstr = __pyx_t_16;

    /* "_mssql.pyx":327
 *     if conn is not None:
 *         mssql_lastmsgstr = conn.last_msg_str
 *         mssql_lastmsgsrv = conn.last_msg_srv             # <<<<<<<<<<<<<<
 *         mssql_lastmsgproc = conn.last_msg_proc
 *         mssql_lastmsgno = &conn.last_msg_no
 */
    __pyx_t_16 = __pyx_v_conn->last_msg_srv;
    __pyx_v_mssql_lastmsgsrv = __pyx_t_16;

    /* "_mssql.pyx":328
 *         mssql_lastmsgstr = conn.last_msg_str
 *         mssql_lastmsgsrv = conn.last_msg_srv
 *         mssql_lastmsgproc = conn.last_msg_proc             # <<<<<<<<<<<<<<
 *         mssql_lastmsgno = &conn.last_msg_no
 *         mssql_lastmsgseverity = &conn.last_msg_severity
 */
    __pyx_t_16 = __pyx_v_conn->last_msg_proc;
    __pyx_v_mssql_lastmsgproc = __pyx_t_16;

    /* "_mssql.pyx":329
 *         mssql_lastmsgsrv = conn.last_msg_srv
 *         mssql_lastmsgproc = conn.last_msg_proc
 *         mssql_lastmsgno = &conn.last_msg_no             # <<<<<<<<<<<<<<
 *         mssql_lastmsgseverity = &conn.last_msg_severity
 *         mssql_lastmsgstate = &conn.last_msg_state
 */
    __pyx_v_mssql_lastmsgno = (&__pyx_v_conn->last_msg_no);

    /* "_mssql.pyx":330
 *         mssql_lastmsgproc = conn.last_msg_proc
 *         mssql_lastmsgno = &conn.last_msg_no
 *         mssql_lastmsgseverity = &conn.last_msg_severity             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstate = &conn.last_msg_state
 *         mssql_lastmsgline = &conn.last_msg_line
 */
    __pyx_v_mssql_lastmsgseverity = (&__pyx_v_conn->last_msg_severity);

    /* "_mssql.pyx":331
 *         mssql_lastmsgno = &conn.last_msg_no
 *         mssql_lastmsgseverity = &conn.last_msg_severity
 *         mssql_lastmsgstate = &conn.last_msg_state             # <<<<<<<<<<<<<<
 *         mssql_lastmsgline = &conn.last_msg_line
 *     else:
 */
    __pyx_v_mssql_lastmsgstate = (&__pyx_v_conn->last_msg_state);

    /* "_mssql.pyx":332
 *         mssql_lastmsgseverity = &conn.last_msg_severity
 *         mssql_lastmsgstate = &conn.last_msg_state
 *         mssql_lastmsgline = &conn.last_msg_line             # <<<<<<<<<<<<<<
 *     else:
 *         mssql_lastmsgstr = _mssql_last_msg_str
 */
    __pyx_v_mssql_lastmsgline = (&__pyx_v_conn->last_msg_line);

    /* "_mssql.pyx":325
 *         return INT_CANCEL
 * 
 *     if conn is not None:             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstr = conn.last_msg_str
 *         mssql_lastmsgsrv = conn.last_msg_srv
 */
    goto __pyx_L10;
  }

  /* "_mssql.pyx":334
 *         mssql_lastmsgline = &conn.last_msg_line
 *     else:
 *         mssql_lastmsgstr = _mssql_last_msg_str             # <<<<<<<<<<<<<<
 *         mssql_lastmsgsrv = _mssql_last_msg_srv
 *         mssql_lastmsgproc = _mssql_last_msg_proc
 */
  /*else*/ {
    __pyx_v_mssql_lastmsgstr = __pyx_v_6_mssql__mssql_last_msg_str;

    /* "_mssql.pyx":335
 *     else:
 *         mssql_lastmsgstr = _mssql_last_msg_str
 *         mssql_lastmsgsrv = _mssql_last_msg_srv             # <<<<<<<<<<<<<<
 *         mssql_lastmsgproc = _mssql_last_msg_proc
 *         mssql_lastmsgno = &_mssql_last_msg_no
 */
    __pyx_v_mssql_lastmsgsrv = __pyx_v_6_mssql__mssql_last_msg_srv;

    /* "_mssql.pyx":336
 *         mssql_lastmsgstr = _mssql_last_msg_str
 *         mssql_lastmsgsrv = _mssql_last_msg_srv
 *         mssql_lastmsgproc = _mssql_last_msg_proc             # <<<<<<<<<<<<<<
 *         mssql_lastmsgno = &_mssql_last_msg_no
 *         mssql_lastmsgseverity = &_mssql_last_msg_severity
 */
    __pyx_v_mssql_lastmsgproc = __pyx_v_6_mssql__mssql_last_msg_proc;

    /* "_mssql.pyx":337
 *         mssql_lastmsgsrv = _mssql_last_msg_srv
 *         mssql_lastmsgproc = _mssql_last_msg_proc
 *         mssql_lastmsgno = &_mssql_last_msg_no             # <<<<<<<<<<<<<<
 *         mssql_lastmsgseverity = &_mssql_last_msg_severity
 *         mssql_lastmsgstate = &_mssql_last_msg_state
 */
    __pyx_v_mssql_lastmsgno = (&__pyx_v_6_mssql__mssql_last_msg_no);

    /* "_mssql.pyx":338
 *         mssql_lastmsgproc = _mssql_last_msg_proc
 *         mssql_lastmsgno = &_mssql_last_msg_no
 *         mssql_lastmsgseverity = &_mssql_last_msg_severity             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstate = &_mssql_last_msg_state
 *         mssql_lastmsgline = &_mssql_last_msg_line
 */
    __pyx_v_mssql_lastmsgseverity = (&__pyx_v_6_mssql__mssql_last_msg_severity);

    /* "_mssql.pyx":339
 *         mssql_lastmsgno = &_mssql_last_msg_no
 *         mssql_lastmsgseverity = &_mssql_last_msg_severity
 *         mssql_lastmsgstate = &_mssql_last_msg_state             # <<<<<<<<<<<<<<
 *         mssql_lastmsgline = &_mssql_last_msg_line
 * 
 */
    __pyx_v_mssql_lastmsgstate = (&__pyx_v_6_mssql__mssql_last_msg_state);

    /* "_mssql.pyx":340
 *         mssql_lastmsgseverity = &_mssql_last_msg_severity
 *         mssql_lastmsgstate = &_mssql_last_msg_state
 *         mssql_lastmsgline = &_mssql_last_msg_line             # <<<<<<<<<<<<<<
 * 
 *     # Calculate the maximum severity of all messages in a row
 */
    __pyx_v_mssql_lastmsgline = (&__pyx_v_6_mssql__mssql_last_msg_line);
  }
  __pyx_L10:;

  /* "_mssql.pyx":344
 *     # Calculate the maximum severity of all messages in a row
 *     # Fill the remaining fields as this is going to raise the exception
 *     if severity > mssql_lastmsgseverity[0]:             # <<<<<<<<<<<<<<
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = msgno
 */
  __pyx_t_6 = ((__pyx_v_severity > (__pyx_v_mssql_lastmsgseverity[0])) != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":345
 *     # Fill the remaining fields as this is going to raise the exception
 *     if severity > mssql_lastmsgseverity[0]:
 *         mssql_lastmsgseverity[0] = severity             # <<<<<<<<<<<<<<
 *         mssql_lastmsgno[0] = msgno
 *         mssql_lastmsgstate[0] = msgstate
 */
    (__pyx_v_mssql_lastmsgseverity[0]) = __pyx_v_severity;

    /* "_mssql.pyx":346
 *     if severity > mssql_lastmsgseverity[0]:
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = msgno             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstate[0] = msgstate
 *         mssql_lastmsgline[0] = line
 */
    (__pyx_v_mssql_lastmsgno[0]) = __pyx_v_msgno;

    /* "_mssql.pyx":347
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = msgno
 *         mssql_lastmsgstate[0] = msgstate             # <<<<<<<<<<<<<<
 *         mssql_lastmsgline[0] = line
 *         strncpy(mssql_lastmsgstr, msgtext, PYMSSQL_MSGSIZE)
 */
    (__pyx_v_mssql_lastmsgstate[0]) = __pyx_v_msgstate;

    /* "_mssql.pyx":348
 *         mssql_lastmsgno[0] = msgno
 *         mssql_lastmsgstate[0] = msgstate
 *         mssql_lastmsgline[0] = line             # <<<<<<<<<<<<<<
 *         strncpy(mssql_lastmsgstr, msgtext, PYMSSQL_MSGSIZE)
 *         strncpy(mssql_lastmsgsrv, srvname, PYMSSQL_MSGSIZE)
 */
    (__pyx_v_mssql_lastmsgline[0]) = __pyx_v_line;

    /* "_mssql.pyx":349
 *         mssql_lastmsgstate[0] = msgstate
 *         mssql_lastmsgline[0] = line
 *         strncpy(mssql_lastmsgstr, msgtext, PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 *         strncpy(mssql_lastmsgsrv, srvname, PYMSSQL_MSGSIZE)
 *         strncpy(mssql_lastmsgproc, procname, PYMSSQL_MSGSIZE)
 */
    strncpy(__pyx_v_mssql_lastmsgstr, __pyx_v_msgtext, 0x2000);

    /* "_mssql.pyx":350
 *         mssql_lastmsgline[0] = line
 *         strncpy(mssql_lastmsgstr, msgtext, PYMSSQL_MSGSIZE)
 *         strncpy(mssql_lastmsgsrv, srvname, PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 *         strncpy(mssql_lastmsgproc, procname, PYMSSQL_MSGSIZE)
 * 
 */
    strncpy(__pyx_v_mssql_lastmsgsrv, __pyx_v_srvname, 0x2000);

    /* "_mssql.pyx":351
 *         strncpy(mssql_lastmsgstr, msgtext, PYMSSQL_MSGSIZE)
 *         strncpy(mssql_lastmsgsrv, srvname, PYMSSQL_MSGSIZE)
 *         strncpy(mssql_lastmsgproc, procname, PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    strncpy(__pyx_v_mssql_lastmsgproc, __pyx_v_procname, 0x2000);

    /* "_mssql.pyx":344
 *     # Calculate the maximum severity of all messages in a row
 *     # Fill the remaining fields as this is going to raise the exception
 *     if severity > mssql_lastmsgseverity[0]:             # <<<<<<<<<<<<<<
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = msgno
 */
  }

  /* "_mssql.pyx":354
 * 
 * 
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * cdef int db_sqlexec(DBPROCESS *dbproc):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":289
 * ## Message Handler ##
 * #####################
 * cdef int msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,             # <<<<<<<<<<<<<<
 *         int severity, char *msgtext, char *srvname, char *procname,
 *         LINE_T line) with gil:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_WriteUnraisable("_mssql.msg_handler", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_conn);
  __Pyx_XDECREF(__pyx_v_cnx);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "_mssql.pyx":356
 *     return 0
 * 
 * cdef int db_sqlexec(DBPROCESS *dbproc):             # <<<<<<<<<<<<<<
 *     cdef RETCODE rtc
 * 
 */

static int __pyx_f_6_mssql_db_sqlexec(DBPROCESS *__pyx_v_dbproc) {
  RETCODE __pyx_v_rtc;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("db_sqlexec", 0);

  /* "_mssql.pyx":368
 *     # accuracy of the command batch. Then dbresults can be called to process
 *     # the results.
 *     with nogil:             # <<<<<<<<<<<<<<
 *         rtc = dbsqlsend(dbproc)
 *         if rtc != SUCCEED:
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":369
 *     # the results.
 *     with nogil:
 *         rtc = dbsqlsend(dbproc)             # <<<<<<<<<<<<<<
 *         if rtc != SUCCEED:
 *             return rtc
 */
        __pyx_v_rtc = dbsqlsend(__pyx_v_dbproc);

        /* "_mssql.pyx":370
 *     with nogil:
 *         rtc = dbsqlsend(dbproc)
 *         if rtc != SUCCEED:             # <<<<<<<<<<<<<<
 *             return rtc
 * 
 */
        __pyx_t_1 = ((__pyx_v_rtc != SUCCEED) != 0);
        if (__pyx_t_1) {

          /* "_mssql.pyx":371
 *         rtc = dbsqlsend(dbproc)
 *         if rtc != SUCCEED:
 *             return rtc             # <<<<<<<<<<<<<<
 * 
 *     # If we've reached here, dbsqlsend didn't fail so the query is in progress.
 */
          __pyx_r = __pyx_v_rtc;
          goto __pyx_L3_return;

          /* "_mssql.pyx":370
 *     with nogil:
 *         rtc = dbsqlsend(dbproc)
 *         if rtc != SUCCEED:             # <<<<<<<<<<<<<<
 *             return rtc
 * 
 */
        }
      }

      /* "_mssql.pyx":368
 *     # accuracy of the command batch. Then dbresults can be called to process
 *     # the results.
 *     with nogil:             # <<<<<<<<<<<<<<
 *         rtc = dbsqlsend(dbproc)
 *         if rtc != SUCCEED:
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L3_return: {
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L0;
        }
        __pyx_L5:;
      }
  }

  /* "_mssql.pyx":377
 *     # Wait for results to come back and return the return code, optionally
 *     # calling wait_callback first...
 *     return db_sqlok(dbproc)             # <<<<<<<<<<<<<<
 * 
 * cdef int db_sqlok(DBPROCESS *dbproc):
 */
  __pyx_r = __pyx_f_6_mssql_db_sqlok(__pyx_v_dbproc);
  goto __pyx_L0;

  /* "_mssql.pyx":356
 *     return 0
 * 
 * cdef int db_sqlexec(DBPROCESS *dbproc):             # <<<<<<<<<<<<<<
 *     cdef RETCODE rtc
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":379
 *     return db_sqlok(dbproc)
 * 
 * cdef int db_sqlok(DBPROCESS *dbproc):             # <<<<<<<<<<<<<<
 *     cdef RETCODE rtc
 * 
 */

static int __pyx_f_6_mssql_db_sqlok(DBPROCESS *__pyx_v_dbproc) {
  RETCODE __pyx_v_rtc;
  int __pyx_v_read_fileno;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_RefNannySetupContext("db_sqlok", 0);

  /* "_mssql.pyx":386
 *     # The wait_callback is a good place to do things like yield to another
 *     # gevent greenlet -- e.g.: gevent.socket.wait_read(read_fileno)
 *     if wait_callback:             # <<<<<<<<<<<<<<
 *         read_fileno = dbiordesc(dbproc)
 *         wait_callback(read_fileno)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_wait_callback); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 386, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":387
 *     # gevent greenlet -- e.g.: gevent.socket.wait_read(read_fileno)
 *     if wait_callback:
 *         read_fileno = dbiordesc(dbproc)             # <<<<<<<<<<<<<<
 *         wait_callback(read_fileno)
 * 
 */
    __pyx_v_read_fileno = dbiordesc(__pyx_v_dbproc);

    /* "_mssql.pyx":388
 *     if wait_callback:
 *         read_fileno = dbiordesc(dbproc)
 *         wait_callback(read_fileno)             # <<<<<<<<<<<<<<
 * 
 *     # dbsqlok following dbsqlsend is the equivalent of dbsqlexec. This function
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_wait_callback); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 388, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_read_fileno); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 388, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 388, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 388, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 388, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":386
 *     # The wait_callback is a good place to do things like yield to another
 *     # gevent greenlet -- e.g.: gevent.socket.wait_read(read_fileno)
 *     if wait_callback:             # <<<<<<<<<<<<<<
 *         read_fileno = dbiordesc(dbproc)
 *         wait_callback(read_fileno)
 */
  }

  /* "_mssql.pyx":393
 *     # must be called after dbsqlsend returns SUCCEED. When dbsqlok returns,
 *     # then dbresults can be called to process the results.
 *     with nogil:             # <<<<<<<<<<<<<<
 *         rtc = dbsqlok(dbproc)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":394
 *     # then dbresults can be called to process the results.
 *     with nogil:
 *         rtc = dbsqlok(dbproc)             # <<<<<<<<<<<<<<
 * 
 *     return rtc
 */
        __pyx_v_rtc = dbsqlok(__pyx_v_dbproc);
      }

      /* "_mssql.pyx":393
 *     # must be called after dbsqlsend returns SUCCEED. When dbsqlok returns,
 *     # then dbresults can be called to process the results.
 *     with nogil:             # <<<<<<<<<<<<<<
 *         rtc = dbsqlok(dbproc)
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L6;
        }
        __pyx_L6:;
      }
  }

  /* "_mssql.pyx":396
 *         rtc = dbsqlok(dbproc)
 * 
 *     return rtc             # <<<<<<<<<<<<<<
 * 
 * cdef void clr_err(MSSQLConnection conn):
 */
  __pyx_r = __pyx_v_rtc;
  goto __pyx_L0;

  /* "_mssql.pyx":379
 *     return db_sqlok(dbproc)
 * 
 * cdef int db_sqlok(DBPROCESS *dbproc):             # <<<<<<<<<<<<<<
 *     cdef RETCODE rtc
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_WriteUnraisable("_mssql.db_sqlok", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":398
 *     return rtc
 * 
 * cdef void clr_err(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     if conn != None:
 *         conn.last_msg_no = 0
 */

static void __pyx_f_6_mssql_clr_err(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  CYTHON_UNUSED long __pyx_v__mssql_last_msg_no;
  CYTHON_UNUSED long __pyx_v__mssql_last_msg_severity;
  CYTHON_UNUSED long __pyx_v__mssql_last_msg_state;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("clr_err", 0);

  /* "_mssql.pyx":399
 * 
 * cdef void clr_err(MSSQLConnection conn):
 *     if conn != None:             # <<<<<<<<<<<<<<
 *         conn.last_msg_no = 0
 *         conn.last_msg_severity = 0
 */
  __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":400
 * cdef void clr_err(MSSQLConnection conn):
 *     if conn != None:
 *         conn.last_msg_no = 0             # <<<<<<<<<<<<<<
 *         conn.last_msg_severity = 0
 *         conn.last_msg_state = 0
 */
    __pyx_v_conn->last_msg_no = 0;

    /* "_mssql.pyx":401
 *     if conn != None:
 *         conn.last_msg_no = 0
 *         conn.last_msg_severity = 0             # <<<<<<<<<<<<<<
 *         conn.last_msg_state = 0
 *         conn.last_msg_str[0] = 0
 */
    __pyx_v_conn->last_msg_severity = 0;

    /* "_mssql.pyx":402
 *         conn.last_msg_no = 0
 *         conn.last_msg_severity = 0
 *         conn.last_msg_state = 0             # <<<<<<<<<<<<<<
 *         conn.last_msg_str[0] = 0
 *     else:
 */
    __pyx_v_conn->last_msg_state = 0;

    /* "_mssql.pyx":403
 *         conn.last_msg_severity = 0
 *         conn.last_msg_state = 0
 *         conn.last_msg_str[0] = 0             # <<<<<<<<<<<<<<
 *     else:
 *         _mssql_last_msg_no = 0
 */
    (__pyx_v_conn->last_msg_str[0]) = 0;

    /* "_mssql.pyx":399
 * 
 * cdef void clr_err(MSSQLConnection conn):
 *     if conn != None:             # <<<<<<<<<<<<<<
 *         conn.last_msg_no = 0
 *         conn.last_msg_severity = 0
 */
    goto __pyx_L3;
  }

  /* "_mssql.pyx":405
 *         conn.last_msg_str[0] = 0
 *     else:
 *         _mssql_last_msg_no = 0             # <<<<<<<<<<<<<<
 *         _mssql_last_msg_severity = 0
 *         _mssql_last_msg_state = 0
 */
  /*else*/ {
    __pyx_v__mssql_last_msg_no = 0;

    /* "_mssql.pyx":406
 *     else:
 *         _mssql_last_msg_no = 0
 *         _mssql_last_msg_severity = 0             # <<<<<<<<<<<<<<
 *         _mssql_last_msg_state = 0
 *         _mssql_last_msg_str[0] = 0
 */
    __pyx_v__mssql_last_msg_severity = 0;

    /* "_mssql.pyx":407
 *         _mssql_last_msg_no = 0
 *         _mssql_last_msg_severity = 0
 *         _mssql_last_msg_state = 0             # <<<<<<<<<<<<<<
 *         _mssql_last_msg_str[0] = 0
 * 
 */
    __pyx_v__mssql_last_msg_state = 0;

    /* "_mssql.pyx":408
 *         _mssql_last_msg_severity = 0
 *         _mssql_last_msg_state = 0
 *         _mssql_last_msg_str[0] = 0             # <<<<<<<<<<<<<<
 * 
 * cdef RETCODE db_cancel(MSSQLConnection conn):
 */
    (__pyx_v_6_mssql__mssql_last_msg_str[0]) = 0;
  }
  __pyx_L3:;

  /* "_mssql.pyx":398
 *     return rtc
 * 
 * cdef void clr_err(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     if conn != None:
 *         conn.last_msg_no = 0
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("_mssql.clr_err", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":410
 *         _mssql_last_msg_str[0] = 0
 * 
 * cdef RETCODE db_cancel(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     cdef RETCODE rtc
 * 
 */

static RETCODE __pyx_f_6_mssql_db_cancel(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  RETCODE __pyx_v_rtc;
  RETCODE __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("db_cancel", 0);

  /* "_mssql.pyx":413
 *     cdef RETCODE rtc
 * 
 *     if conn == None:             # <<<<<<<<<<<<<<
 *         return SUCCEED
 * 
 */
  __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 413, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":414
 * 
 *     if conn == None:
 *         return SUCCEED             # <<<<<<<<<<<<<<
 * 
 *     if conn.dbproc == NULL:
 */
    __pyx_r = SUCCEED;
    goto __pyx_L0;

    /* "_mssql.pyx":413
 *     cdef RETCODE rtc
 * 
 *     if conn == None:             # <<<<<<<<<<<<<<
 *         return SUCCEED
 * 
 */
  }

  /* "_mssql.pyx":416
 *         return SUCCEED
 * 
 *     if conn.dbproc == NULL:             # <<<<<<<<<<<<<<
 *         return SUCCEED
 * 
 */
  __pyx_t_2 = ((__pyx_v_conn->dbproc == NULL) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":417
 * 
 *     if conn.dbproc == NULL:
 *         return SUCCEED             # <<<<<<<<<<<<<<
 * 
 *     with nogil:
 */
    __pyx_r = SUCCEED;
    goto __pyx_L0;

    /* "_mssql.pyx":416
 *         return SUCCEED
 * 
 *     if conn.dbproc == NULL:             # <<<<<<<<<<<<<<
 *         return SUCCEED
 * 
 */
  }

  /* "_mssql.pyx":419
 *         return SUCCEED
 * 
 *     with nogil:             # <<<<<<<<<<<<<<
 *         rtc = dbcancel(conn.dbproc);
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":420
 * 
 *     with nogil:
 *         rtc = dbcancel(conn.dbproc);             # <<<<<<<<<<<<<<
 * 
 *     conn.clear_metadata()
 */
        __pyx_v_rtc = dbcancel(__pyx_v_conn->dbproc);
      }

      /* "_mssql.pyx":419
 *         return SUCCEED
 * 
 *     with nogil:             # <<<<<<<<<<<<<<
 *         rtc = dbcancel(conn.dbproc);
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L7;
        }
        __pyx_L7:;
      }
  }

  /* "_mssql.pyx":422
 *         rtc = dbcancel(conn.dbproc);
 * 
 *     conn.clear_metadata()             # <<<<<<<<<<<<<<
 *     return rtc
 * 
 */
  ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_conn->__pyx_vtab)->clear_metadata(__pyx_v_conn);

  /* "_mssql.pyx":423
 * 
 *     conn.clear_metadata()
 *     return rtc             # <<<<<<<<<<<<<<
 * 
 * ##############################
 */
  __pyx_r = __pyx_v_rtc;
  goto __pyx_L0;

  /* "_mssql.pyx":410
 *         _mssql_last_msg_str[0] = 0
 * 
 * cdef RETCODE db_cancel(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     cdef RETCODE rtc
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("_mssql.db_cancel", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":430
 * cdef class MSSQLRowIterator:
 * 
 *     def __init__(self, connection, int row_format):             # <<<<<<<<<<<<<<
 *         self.conn = connection
 *         self.row_format = row_format
 */

/* Python wrapper */
static int __pyx_pw_6_mssql_16MSSQLRowIterator_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_6_mssql_16MSSQLRowIterator_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_connection = 0;
  int __pyx_v_row_format;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_connection,&__pyx_n_s_row_format,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_connection)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_row_format)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 430, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 430, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_connection = values[0];
    __pyx_v_row_format = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_row_format == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 430, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 430, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLRowIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_16MSSQLRowIterator___init__(((struct __pyx_obj_6_mssql_MSSQLRowIterator *)__pyx_v_self), __pyx_v_connection, __pyx_v_row_format);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6_mssql_16MSSQLRowIterator___init__(struct __pyx_obj_6_mssql_MSSQLRowIterator *__pyx_v_self, PyObject *__pyx_v_connection, int __pyx_v_row_format) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "_mssql.pyx":431
 * 
 *     def __init__(self, connection, int row_format):
 *         self.conn = connection             # <<<<<<<<<<<<<<
 *         self.row_format = row_format
 * 
 */
  if (!(likely(((__pyx_v_connection) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_connection, __pyx_ptype_6_mssql_MSSQLConnection))))) __PYX_ERR(0, 431, __pyx_L1_error)
  __pyx_t_1 = __pyx_v_connection;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->conn);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->conn));
  __pyx_v_self->conn = ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_mssql.pyx":432
 *     def __init__(self, connection, int row_format):
 *         self.conn = connection
 *         self.row_format = row_format             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->row_format = __pyx_v_row_format;

  /* "_mssql.pyx":430
 * cdef class MSSQLRowIterator:
 * 
 *     def __init__(self, connection, int row_format):             # <<<<<<<<<<<<<<
 *         self.conn = connection
 *         self.row_format = row_format
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLRowIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":434
 *         self.row_format = row_format
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_16MSSQLRowIterator_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_16MSSQLRowIterator_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_16MSSQLRowIterator_2__iter__(((struct __pyx_obj_6_mssql_MSSQLRowIterator *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_16MSSQLRowIterator_2__iter__(struct __pyx_obj_6_mssql_MSSQLRowIterator *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);

  /* "_mssql.pyx":435
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "_mssql.pyx":434
 *         self.row_format = row_format
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":437
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         assert_connected(self.conn)
 *         clr_err(self.conn)
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_16MSSQLRowIterator_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_16MSSQLRowIterator_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_16MSSQLRowIterator_4__next__(((struct __pyx_obj_6_mssql_MSSQLRowIterator *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_16MSSQLRowIterator_4__next__(struct __pyx_obj_6_mssql_MSSQLRowIterator *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__next__", 0);

  /* "_mssql.pyx":438
 * 
 *     def __next__(self):
 *         assert_connected(self.conn)             # <<<<<<<<<<<<<<
 *         clr_err(self.conn)
 *         return self.conn.fetch_next_row(1, self.row_format)
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->conn);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_f_6_mssql_assert_connected(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":439
 *     def __next__(self):
 *         assert_connected(self.conn)
 *         clr_err(self.conn)             # <<<<<<<<<<<<<<
 *         return self.conn.fetch_next_row(1, self.row_format)
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->conn);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_f_6_mssql_clr_err(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":440
 *         assert_connected(self.conn)
 *         clr_err(self.conn)
 *         return self.conn.fetch_next_row(1, self.row_format)             # <<<<<<<<<<<<<<
 * 
 * ############################
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->conn->__pyx_vtab)->fetch_next_row(__pyx_v_self->conn, 1, __pyx_v_self->row_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 440, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":437
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         assert_connected(self.conn)
 *         clr_err(self.conn)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLRowIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":452
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if strlen(self._charset):
 *                 return self._charset.decode('ascii') if PY_MAJOR_VERSION == 3 else self._charset
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_7charset_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_7charset_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_7charset___get__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_7charset___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":453
 * 
 *         def __get__(self):
 *             if strlen(self._charset):             # <<<<<<<<<<<<<<
 *                 return self._charset.decode('ascii') if PY_MAJOR_VERSION == 3 else self._charset
 *             return None
 */
  __pyx_t_1 = (strlen(__pyx_v_self->_charset) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":454
 *         def __get__(self):
 *             if strlen(self._charset):
 *                 return self._charset.decode('ascii') if PY_MAJOR_VERSION == 3 else self._charset             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    if (((PY_MAJOR_VERSION == 3) != 0)) {
      __pyx_t_3 = __pyx_v_self->_charset;
      __pyx_t_4 = __Pyx_decode_c_string(__pyx_t_3, 0, strlen(__pyx_t_3), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 454, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_2 = __pyx_t_4;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->_charset); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 454, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __pyx_t_4;
      __pyx_t_4 = 0;
    }
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":453
 * 
 *         def __get__(self):
 *             if strlen(self._charset):             # <<<<<<<<<<<<<<
 *                 return self._charset.decode('ascii') if PY_MAJOR_VERSION == 3 else self._charset
 *             return None
 */
  }

  /* "_mssql.pyx":455
 *             if strlen(self._charset):
 *                 return self._charset.decode('ascii') if PY_MAJOR_VERSION == 3 else self._charset
 *             return None             # <<<<<<<<<<<<<<
 * 
 *     property connected:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  /* "_mssql.pyx":452
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if strlen(self._charset):
 *                 return self._charset.decode('ascii') if PY_MAJOR_VERSION == 3 else self._charset
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.charset.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":462
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._connected
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_9connected_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_9connected_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_9connected___get__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_9connected___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":463
 * 
 *         def __get__(self):
 *             return self._connected             # <<<<<<<<<<<<<<
 * 
 *     property identity:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->_connected); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":462
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._connected
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.connected.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":477
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.execute_scalar('SELECT SCOPE_IDENTITY()')
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_8identity_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_8identity_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_8identity___get__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_8identity___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":478
 * 
 *         def __get__(self):
 *             return self.execute_scalar('SELECT SCOPE_IDENTITY()')             # <<<<<<<<<<<<<<
 * 
 *     property query_timeout:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->execute_scalar(__pyx_v_self, __pyx_kp_s_SELECT_SCOPE_IDENTITY, 0, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":477
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.execute_scalar('SELECT SCOPE_IDENTITY()')
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.identity.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":484
 *         A
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._query_timeout
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13query_timeout_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13query_timeout_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_13query_timeout___get__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_13query_timeout___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":485
 *         """
 *         def __get__(self):
 *             return self._query_timeout             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, value):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_query_timeout); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":484
 *         A
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._query_timeout
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.query_timeout.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":487
 *             return self._query_timeout
 * 
 *         def __set__(self, value):             # <<<<<<<<<<<<<<
 *             cdef int val = int(value)
 *             cdef RETCODE rtc
 */

/* Python wrapper */
static int __pyx_pw_6_mssql_15MSSQLConnection_13query_timeout_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6_mssql_15MSSQLConnection_13query_timeout_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_13query_timeout_2__set__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6_mssql_15MSSQLConnection_13query_timeout_2__set__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_v_val;
  RETCODE __pyx_v_rtc;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("__set__", 0);

  /* "_mssql.pyx":488
 * 
 *         def __set__(self, value):
 *             cdef int val = int(value)             # <<<<<<<<<<<<<<
 *             cdef RETCODE rtc
 *             if val < 0:
 */
  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 488, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_val = __pyx_t_2;

  /* "_mssql.pyx":490
 *             cdef int val = int(value)
 *             cdef RETCODE rtc
 *             if val < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("The 'query_timeout' attribute must be >= 0.")
 * 
 */
  __pyx_t_3 = ((__pyx_v_val < 0) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":491
 *             cdef RETCODE rtc
 *             if val < 0:
 *                 raise ValueError("The 'query_timeout' attribute must be >= 0.")             # <<<<<<<<<<<<<<
 * 
 *             # XXX: Currently this will set it application wide :-(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 491, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 491, __pyx_L1_error)

    /* "_mssql.pyx":490
 *             cdef int val = int(value)
 *             cdef RETCODE rtc
 *             if val < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("The 'query_timeout' attribute must be >= 0.")
 * 
 */
  }

  /* "_mssql.pyx":494
 * 
 *             # XXX: Currently this will set it application wide :-(
 *             rtc = dbsettime(val)             # <<<<<<<<<<<<<<
 *             check_and_raise(rtc, self)
 * 
 */
  __pyx_v_rtc = dbsettime(__pyx_v_val);

  /* "_mssql.pyx":495
 *             # XXX: Currently this will set it application wide :-(
 *             rtc = dbsettime(val)
 *             check_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 * 
 *             # if all is fine then set our attribute
 */
  __pyx_t_2 = __pyx_f_6_mssql_check_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_2 == 1)) __PYX_ERR(0, 495, __pyx_L1_error)

  /* "_mssql.pyx":498
 * 
 *             # if all is fine then set our attribute
 *             self._query_timeout = val             # <<<<<<<<<<<<<<
 * 
 *     property rows_affected:
 */
  __pyx_v_self->_query_timeout = __pyx_v_val;

  /* "_mssql.pyx":487
 *             return self._query_timeout
 * 
 *         def __set__(self, value):             # <<<<<<<<<<<<<<
 *             cdef int val = int(value)
 *             cdef RETCODE rtc
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.query_timeout.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":506
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._rows_affected
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13rows_affected_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13rows_affected_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_13rows_affected___get__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_13rows_affected___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":507
 * 
 *         def __get__(self):
 *             return self._rows_affected             # <<<<<<<<<<<<<<
 * 
 *     property tds_version:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_rows_affected); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":506
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._rows_affected
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.rows_affected.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":513
 *         Returns what TDS version the connection is using.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int version = dbtds(self.dbproc)
 *             if version == 11:
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_11tds_version_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_11tds_version_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_11tds_version___get__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_11tds_version___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  int __pyx_v_version;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":514
 *         """
 *         def __get__(self):
 *             cdef int version = dbtds(self.dbproc)             # <<<<<<<<<<<<<<
 *             if version == 11:
 *                 return 7.3
 */
  __pyx_v_version = dbtds(__pyx_v_self->dbproc);

  /* "_mssql.pyx":515
 *         def __get__(self):
 *             cdef int version = dbtds(self.dbproc)
 *             if version == 11:             # <<<<<<<<<<<<<<
 *                 return 7.3
 *             elif version == 10:
 */
  switch (__pyx_v_version) {
    case 11:

    /* "_mssql.pyx":516
 *             cdef int version = dbtds(self.dbproc)
 *             if version == 11:
 *                 return 7.3             # <<<<<<<<<<<<<<
 *             elif version == 10:
 *                 return 7.2
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_float_7_3);
    __pyx_r = __pyx_float_7_3;
    goto __pyx_L0;

    /* "_mssql.pyx":515
 *         def __get__(self):
 *             cdef int version = dbtds(self.dbproc)
 *             if version == 11:             # <<<<<<<<<<<<<<
 *                 return 7.3
 *             elif version == 10:
 */
    break;

    /* "_mssql.pyx":517
 *             if version == 11:
 *                 return 7.3
 *             elif version == 10:             # <<<<<<<<<<<<<<
 *                 return 7.2
 *             elif version == 9:
 */
    case 10:

    /* "_mssql.pyx":518
 *                 return 7.3
 *             elif version == 10:
 *                 return 7.2             # <<<<<<<<<<<<<<
 *             elif version == 9:
 *                 return 8.0  # Actually 7.1, return 8.0 to keep backward compatibility
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_float_7_2);
    __pyx_r = __pyx_float_7_2;
    goto __pyx_L0;

    /* "_mssql.pyx":517
 *             if version == 11:
 *                 return 7.3
 *             elif version == 10:             # <<<<<<<<<<<<<<
 *                 return 7.2
 *             elif version == 9:
 */
    break;

    /* "_mssql.pyx":519
 *             elif version == 10:
 *                 return 7.2
 *             elif version == 9:             # <<<<<<<<<<<<<<
 *                 return 8.0  # Actually 7.1, return 8.0 to keep backward compatibility
 *             elif version == 8:
 */
    case 9:

    /* "_mssql.pyx":520
 *                 return 7.2
 *             elif version == 9:
 *                 return 8.0  # Actually 7.1, return 8.0 to keep backward compatibility             # <<<<<<<<<<<<<<
 *             elif version == 8:
 *                 return 7.0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_float_8_0);
    __pyx_r = __pyx_float_8_0;
    goto __pyx_L0;

    /* "_mssql.pyx":519
 *             elif version == 10:
 *                 return 7.2
 *             elif version == 9:             # <<<<<<<<<<<<<<
 *                 return 8.0  # Actually 7.1, return 8.0 to keep backward compatibility
 *             elif version == 8:
 */
    break;

    /* "_mssql.pyx":521
 *             elif version == 9:
 *                 return 8.0  # Actually 7.1, return 8.0 to keep backward compatibility
 *             elif version == 8:             # <<<<<<<<<<<<<<
 *                 return 7.0
 *             elif version == 6:
 */
    case 8:

    /* "_mssql.pyx":522
 *                 return 8.0  # Actually 7.1, return 8.0 to keep backward compatibility
 *             elif version == 8:
 *                 return 7.0             # <<<<<<<<<<<<<<
 *             elif version == 6:
 *                 return 5.0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_float_7_0);
    __pyx_r = __pyx_float_7_0;
    goto __pyx_L0;

    /* "_mssql.pyx":521
 *             elif version == 9:
 *                 return 8.0  # Actually 7.1, return 8.0 to keep backward compatibility
 *             elif version == 8:             # <<<<<<<<<<<<<<
 *                 return 7.0
 *             elif version == 6:
 */
    break;

    /* "_mssql.pyx":523
 *             elif version == 8:
 *                 return 7.0
 *             elif version == 6:             # <<<<<<<<<<<<<<
 *                 return 5.0
 *             elif version == 4:
 */
    case 6:

    /* "_mssql.pyx":524
 *                 return 7.0
 *             elif version == 6:
 *                 return 5.0             # <<<<<<<<<<<<<<
 *             elif version == 4:
 *                 return 4.2
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_float_5_0);
    __pyx_r = __pyx_float_5_0;
    goto __pyx_L0;

    /* "_mssql.pyx":523
 *             elif version == 8:
 *                 return 7.0
 *             elif version == 6:             # <<<<<<<<<<<<<<
 *                 return 5.0
 *             elif version == 4:
 */
    break;

    /* "_mssql.pyx":525
 *             elif version == 6:
 *                 return 5.0
 *             elif version == 4:             # <<<<<<<<<<<<<<
 *                 return 4.2
 * 
 */
    case 4:

    /* "_mssql.pyx":526
 *                 return 5.0
 *             elif version == 4:
 *                 return 4.2             # <<<<<<<<<<<<<<
 * 
 *     def __cinit__(self):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_float_4_2);
    __pyx_r = __pyx_float_4_2;
    goto __pyx_L0;

    /* "_mssql.pyx":525
 *             elif version == 6:
 *                 return 5.0
 *             elif version == 4:             # <<<<<<<<<<<<<<
 *                 return 4.2
 * 
 */
    break;
    default: break;
  }

  /* "_mssql.pyx":513
 *         Returns what TDS version the connection is using.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int version = dbtds(self.dbproc)
 *             if version == 11:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":528
 *                 return 4.2
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.__cinit__()")
 *         self._connected = 0
 */

/* Python wrapper */
static int __pyx_pw_6_mssql_15MSSQLConnection_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_6_mssql_15MSSQLConnection_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection___cinit__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6_mssql_15MSSQLConnection___cinit__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "_mssql.pyx":529
 * 
 *     def __cinit__(self):
 *         log("_mssql.MSSQLConnection.__cinit__()")             # <<<<<<<<<<<<<<
 *         self._connected = 0
 *         self._charset = <char *>PyMem_Malloc(PYMSSQL_CHARSETBUFSIZE)
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.__cinit__()"));

  /* "_mssql.pyx":530
 *     def __cinit__(self):
 *         log("_mssql.MSSQLConnection.__cinit__()")
 *         self._connected = 0             # <<<<<<<<<<<<<<
 *         self._charset = <char *>PyMem_Malloc(PYMSSQL_CHARSETBUFSIZE)
 *         self._charset[0] = <char>0
 */
  __pyx_v_self->_connected = 0;

  /* "_mssql.pyx":531
 *         log("_mssql.MSSQLConnection.__cinit__()")
 *         self._connected = 0
 *         self._charset = <char *>PyMem_Malloc(PYMSSQL_CHARSETBUFSIZE)             # <<<<<<<<<<<<<<
 *         self._charset[0] = <char>0
 *         self.last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 */
  __pyx_v_self->_charset = ((char *)PyMem_Malloc(0x64));

  /* "_mssql.pyx":532
 *         self._connected = 0
 *         self._charset = <char *>PyMem_Malloc(PYMSSQL_CHARSETBUFSIZE)
 *         self._charset[0] = <char>0             # <<<<<<<<<<<<<<
 *         self.last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_str[0] = <char>0
 */
  (__pyx_v_self->_charset[0]) = ((char)0);

  /* "_mssql.pyx":533
 *         self._charset = <char *>PyMem_Malloc(PYMSSQL_CHARSETBUFSIZE)
 *         self._charset[0] = <char>0
 *         self.last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 *         self.last_msg_str[0] = <char>0
 *         self.last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 */
  __pyx_v_self->last_msg_str = ((char *)PyMem_Malloc(0x2000));

  /* "_mssql.pyx":534
 *         self._charset[0] = <char>0
 *         self.last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_str[0] = <char>0             # <<<<<<<<<<<<<<
 *         self.last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_srv[0] = <char>0
 */
  (__pyx_v_self->last_msg_str[0]) = ((char)0);

  /* "_mssql.pyx":535
 *         self.last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_str[0] = <char>0
 *         self.last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 *         self.last_msg_srv[0] = <char>0
 *         self.last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 */
  __pyx_v_self->last_msg_srv = ((char *)PyMem_Malloc(0x2000));

  /* "_mssql.pyx":536
 *         self.last_msg_str[0] = <char>0
 *         self.last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_srv[0] = <char>0             # <<<<<<<<<<<<<<
 *         self.last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_proc[0] = <char>0
 */
  (__pyx_v_self->last_msg_srv[0]) = ((char)0);

  /* "_mssql.pyx":537
 *         self.last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_srv[0] = <char>0
 *         self.last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 *         self.last_msg_proc[0] = <char>0
 *         self.column_names = None
 */
  __pyx_v_self->last_msg_proc = ((char *)PyMem_Malloc(0x2000));

  /* "_mssql.pyx":538
 *         self.last_msg_srv[0] = <char>0
 *         self.last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_proc[0] = <char>0             # <<<<<<<<<<<<<<
 *         self.column_names = None
 *         self.column_types = None
 */
  (__pyx_v_self->last_msg_proc[0]) = ((char)0);

  /* "_mssql.pyx":539
 *         self.last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 *         self.last_msg_proc[0] = <char>0
 *         self.column_names = None             # <<<<<<<<<<<<<<
 *         self.column_types = None
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->column_names);
  __Pyx_DECREF(__pyx_v_self->column_names);
  __pyx_v_self->column_names = ((PyObject*)Py_None);

  /* "_mssql.pyx":540
 *         self.last_msg_proc[0] = <char>0
 *         self.column_names = None
 *         self.column_types = None             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, server="localhost", user="sa", password="",
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->column_types);
  __Pyx_DECREF(__pyx_v_self->column_types);
  __pyx_v_self->column_types = ((PyObject*)Py_None);

  /* "_mssql.pyx":528
 *                 return 4.2
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.__cinit__()")
 *         self._connected = 0
 */

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":542
 *         self.column_types = None
 * 
 *     def __init__(self, server="localhost", user="sa", password="",             # <<<<<<<<<<<<<<
 *             charset='UTF-8', database='', appname=None, port='1433', tds_version='7.1', conn_properties=None):
 *         log("_mssql.MSSQLConnection.__init__()")
 */

/* Python wrapper */
static int __pyx_pw_6_mssql_15MSSQLConnection_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_6_mssql_15MSSQLConnection_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_server = 0;
  PyObject *__pyx_v_user = 0;
  PyObject *__pyx_v_password = 0;
  PyObject *__pyx_v_charset = 0;
  PyObject *__pyx_v_database = 0;
  PyObject *__pyx_v_appname = 0;
  PyObject *__pyx_v_port = 0;
  PyObject *__pyx_v_tds_version = 0;
  PyObject *__pyx_v_conn_properties = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_server,&__pyx_n_s_user,&__pyx_n_s_password,&__pyx_n_s_charset,&__pyx_n_s_database,&__pyx_n_s_appname,&__pyx_n_s_port,&__pyx_n_s_tds_version,&__pyx_n_s_conn_properties,0};
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
    values[0] = ((PyObject *)__pyx_n_s_localhost);
    values[1] = ((PyObject *)__pyx_n_s_sa);
    values[2] = ((PyObject *)__pyx_kp_s__2);
    values[3] = ((PyObject *)__pyx_kp_s_UTF_8);
    values[4] = ((PyObject *)__pyx_kp_s__2);

    /* "_mssql.pyx":543
 * 
 *     def __init__(self, server="localhost", user="sa", password="",
 *             charset='UTF-8', database='', appname=None, port='1433', tds_version='7.1', conn_properties=None):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.__init__()")
 * 
 */
    values[5] = ((PyObject *)Py_None);
    values[6] = ((PyObject *)__pyx_kp_s_1433);
    values[7] = ((PyObject *)__pyx_kp_s_7_1);
    values[8] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_server);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_user);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_password);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_charset);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_database);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_appname);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_port);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tds_version);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_conn_properties);
          if (value) { values[8] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 542, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_server = values[0];
    __pyx_v_user = values[1];
    __pyx_v_password = values[2];
    __pyx_v_charset = values[3];
    __pyx_v_database = values[4];
    __pyx_v_appname = values[5];
    __pyx_v_port = values[6];
    __pyx_v_tds_version = values[7];
    __pyx_v_conn_properties = values[8];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 542, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLConnection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_2__init__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_server, __pyx_v_user, __pyx_v_password, __pyx_v_charset, __pyx_v_database, __pyx_v_appname, __pyx_v_port, __pyx_v_tds_version, __pyx_v_conn_properties);

  /* "_mssql.pyx":542
 *         self.column_types = None
 * 
 *     def __init__(self, server="localhost", user="sa", password="",             # <<<<<<<<<<<<<<
 *             charset='UTF-8', database='', appname=None, port='1433', tds_version='7.1', conn_properties=None):
 *         log("_mssql.MSSQLConnection.__init__()")
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6_mssql_15MSSQLConnection_2__init__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_server, PyObject *__pyx_v_user, PyObject *__pyx_v_password, PyObject *__pyx_v_charset, PyObject *__pyx_v_database, PyObject *__pyx_v_appname, PyObject *__pyx_v_port, PyObject *__pyx_v_tds_version, PyObject *__pyx_v_conn_properties) {
  LOGINREC *__pyx_v_login;
  RETCODE __pyx_v_rtc;
  char *__pyx_v__charset;
  PyObject *__pyx_v_instance = NULL;
  PyObject *__pyx_v_user_bytes = 0;
  char *__pyx_v_user_cstr;
  PyObject *__pyx_v_password_bytes = 0;
  char *__pyx_v_password_cstr;
  PyObject *__pyx_v_appname_bytes = 0;
  char *__pyx_v_appname_cstr;
  PyObject *__pyx_v_charset_bytes = 0;
  PyObject *__pyx_v_dbname_bytes = 0;
  char *__pyx_v_dbname_cstr;
  PyObject *__pyx_v_server_bytes = 0;
  char *__pyx_v_server_cstr;
  PyObject *__pyx_v_conn_props_bytes = 0;
  CYTHON_UNUSED char *__pyx_v_conn_props_cstr;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  char *__pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_INCREF(__pyx_v_server);
  __Pyx_INCREF(__pyx_v_appname);
  __Pyx_INCREF(__pyx_v_conn_properties);

  /* "_mssql.pyx":544
 *     def __init__(self, server="localhost", user="sa", password="",
 *             charset='UTF-8', database='', appname=None, port='1433', tds_version='7.1', conn_properties=None):
 *         log("_mssql.MSSQLConnection.__init__()")             # <<<<<<<<<<<<<<
 * 
 *         cdef LOGINREC *login
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.__init__()"));

  /* "_mssql.pyx":551
 * 
 *         # support MS methods of connecting locally
 *         instance = ""             # <<<<<<<<<<<<<<
 *         if "\\" in server:
 *             server, instance = server.split("\\")
 */
  __Pyx_INCREF(__pyx_kp_s__2);
  __pyx_v_instance = __pyx_kp_s__2;

  /* "_mssql.pyx":552
 *         # support MS methods of connecting locally
 *         instance = ""
 *         if "\\" in server:             # <<<<<<<<<<<<<<
 *             server, instance = server.split("\\")
 * 
 */
  __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s__3, __pyx_v_server, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 552, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":553
 *         instance = ""
 *         if "\\" in server:
 *             server, instance = server.split("\\")             # <<<<<<<<<<<<<<
 * 
 *         if server in (".", "(local)"):
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_server, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 553, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 553, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 553, __pyx_L1_error)
      __pyx_t_7 = NULL;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L5_unpacking_done;
      __pyx_L4_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 553, __pyx_L1_error)
      __pyx_L5_unpacking_done:;
    }
    __Pyx_DECREF_SET(__pyx_v_server, __pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_instance, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":552
 *         # support MS methods of connecting locally
 *         instance = ""
 *         if "\\" in server:             # <<<<<<<<<<<<<<
 *             server, instance = server.split("\\")
 * 
 */
  }

  /* "_mssql.pyx":555
 *             server, instance = server.split("\\")
 * 
 *         if server in (".", "(local)"):             # <<<<<<<<<<<<<<
 *             server = "localhost"
 * 
 */
  __Pyx_INCREF(__pyx_v_server);
  __pyx_t_4 = __pyx_v_server;
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_kp_s__5, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 555, __pyx_L1_error)
  if (!__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_kp_s_local, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 555, __pyx_L1_error)
  __pyx_t_2 = __pyx_t_1;
  __pyx_L7_bool_binop_done:;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":556
 * 
 *         if server in (".", "(local)"):
 *             server = "localhost"             # <<<<<<<<<<<<<<
 * 
 *         server = server + "\\" + instance if instance else server
 */
    __Pyx_INCREF(__pyx_n_s_localhost);
    __Pyx_DECREF_SET(__pyx_v_server, __pyx_n_s_localhost);

    /* "_mssql.pyx":555
 *             server, instance = server.split("\\")
 * 
 *         if server in (".", "(local)"):             # <<<<<<<<<<<<<<
 *             server = "localhost"
 * 
 */
  }

  /* "_mssql.pyx":558
 *             server = "localhost"
 * 
 *         server = server + "\\" + instance if instance else server             # <<<<<<<<<<<<<<
 * 
 *         login = dblogin()
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_instance); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 558, __pyx_L1_error)
  if (__pyx_t_1) {
    __pyx_t_5 = PyNumber_Add(__pyx_v_server, __pyx_kp_s__3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyNumber_Add(__pyx_t_5, __pyx_v_instance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_4 = __pyx_t_3;
    __pyx_t_3 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_server);
    __pyx_t_4 = __pyx_v_server;
  }
  __Pyx_DECREF_SET(__pyx_v_server, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "_mssql.pyx":560
 *         server = server + "\\" + instance if instance else server
 * 
 *         login = dblogin()             # <<<<<<<<<<<<<<
 *         if login == NULL:
 *             raise MSSQLDriverException("dblogin() failed")
 */
  __pyx_v_login = dblogin();

  /* "_mssql.pyx":561
 * 
 *         login = dblogin()
 *         if login == NULL:             # <<<<<<<<<<<<<<
 *             raise MSSQLDriverException("dblogin() failed")
 * 
 */
  __pyx_t_1 = ((__pyx_v_login == NULL) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":562
 *         login = dblogin()
 *         if login == NULL:
 *             raise MSSQLDriverException("dblogin() failed")             # <<<<<<<<<<<<<<
 * 
 *         appname = appname or "pymssql=%s" % __full_version__
 */
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 562, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 562, __pyx_L1_error)

    /* "_mssql.pyx":561
 * 
 *         login = dblogin()
 *         if login == NULL:             # <<<<<<<<<<<<<<
 *             raise MSSQLDriverException("dblogin() failed")
 * 
 */
  }

  /* "_mssql.pyx":564
 *             raise MSSQLDriverException("dblogin() failed")
 * 
 *         appname = appname or "pymssql=%s" % __full_version__             # <<<<<<<<<<<<<<
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_appname); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 564, __pyx_L1_error)
  if (!__pyx_t_1) {
  } else {
    __Pyx_INCREF(__pyx_v_appname);
    __pyx_t_4 = __pyx_v_appname;
    goto __pyx_L10_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_full_version); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_pymssql_s, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_INCREF(__pyx_t_5);
  __pyx_t_4 = __pyx_t_5;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_L10_bool_binop_done:;
  __Pyx_DECREF_SET(__pyx_v_appname, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "_mssql.pyx":567
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 *         cdef bytes user_bytes = user.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *user_cstr = user_bytes
 *         cdef bytes password_bytes = password.encode('utf-8')
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_user, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 567, __pyx_L1_error)
  __pyx_v_user_bytes = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "_mssql.pyx":568
 *         # For Python 3, we need to convert unicode to byte strings
 *         cdef bytes user_bytes = user.encode('utf-8')
 *         cdef char *user_cstr = user_bytes             # <<<<<<<<<<<<<<
 *         cdef bytes password_bytes = password.encode('utf-8')
 *         cdef char *password_cstr = password_bytes
 */
  __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_user_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 568, __pyx_L1_error)
  __pyx_v_user_cstr = __pyx_t_8;

  /* "_mssql.pyx":569
 *         cdef bytes user_bytes = user.encode('utf-8')
 *         cdef char *user_cstr = user_bytes
 *         cdef bytes password_bytes = password.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *password_cstr = password_bytes
 *         cdef bytes appname_bytes = appname.encode('utf-8')
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_password, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 569, __pyx_L1_error)
  __pyx_v_password_bytes = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "_mssql.pyx":570
 *         cdef char *user_cstr = user_bytes
 *         cdef bytes password_bytes = password.encode('utf-8')
 *         cdef char *password_cstr = password_bytes             # <<<<<<<<<<<<<<
 *         cdef bytes appname_bytes = appname.encode('utf-8')
 *         cdef char *appname_cstr = appname_bytes
 */
  __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_password_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 570, __pyx_L1_error)
  __pyx_v_password_cstr = __pyx_t_8;

  /* "_mssql.pyx":571
 *         cdef bytes password_bytes = password.encode('utf-8')
 *         cdef char *password_cstr = password_bytes
 *         cdef bytes appname_bytes = appname.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *appname_cstr = appname_bytes
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_appname, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 571, __pyx_L1_error)
  __pyx_v_appname_bytes = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "_mssql.pyx":572
 *         cdef char *password_cstr = password_bytes
 *         cdef bytes appname_bytes = appname.encode('utf-8')
 *         cdef char *appname_cstr = appname_bytes             # <<<<<<<<<<<<<<
 * 
 *         DBSETLUSER(login, user_cstr)
 */
  __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_appname_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 572, __pyx_L1_error)
  __pyx_v_appname_cstr = __pyx_t_8;

  /* "_mssql.pyx":574
 *         cdef char *appname_cstr = appname_bytes
 * 
 *         DBSETLUSER(login, user_cstr)             # <<<<<<<<<<<<<<
 *         DBSETLPWD(login, password_cstr)
 *         DBSETLAPP(login, appname_cstr)
 */
  DBSETLUSER(__pyx_v_login, __pyx_v_user_cstr);

  /* "_mssql.pyx":575
 * 
 *         DBSETLUSER(login, user_cstr)
 *         DBSETLPWD(login, password_cstr)             # <<<<<<<<<<<<<<
 *         DBSETLAPP(login, appname_cstr)
 *         DBSETLVERSION(login, _tds_ver_str_to_constant(tds_version))
 */
  DBSETLPWD(__pyx_v_login, __pyx_v_password_cstr);

  /* "_mssql.pyx":576
 *         DBSETLUSER(login, user_cstr)
 *         DBSETLPWD(login, password_cstr)
 *         DBSETLAPP(login, appname_cstr)             # <<<<<<<<<<<<<<
 *         DBSETLVERSION(login, _tds_ver_str_to_constant(tds_version))
 * 
 */
  DBSETLAPP(__pyx_v_login, __pyx_v_appname_cstr);

  /* "_mssql.pyx":577
 *         DBSETLPWD(login, password_cstr)
 *         DBSETLAPP(login, appname_cstr)
 *         DBSETLVERSION(login, _tds_ver_str_to_constant(tds_version))             # <<<<<<<<<<<<<<
 * 
 *         # add the port to the server string if it doesn't have one already and
 */
  __pyx_t_9 = __pyx_f_6_mssql__tds_ver_str_to_constant(__pyx_v_tds_version); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 577, __pyx_L1_error)
  DBSETLVERSION(__pyx_v_login, __pyx_t_9);

  /* "_mssql.pyx":581
 *         # add the port to the server string if it doesn't have one already and
 *         # if we are not using an instance
 *         if ':' not in server and not instance:             # <<<<<<<<<<<<<<
 *             server = '%s:%s' % (server, port)
 * 
 */
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s__10, __pyx_v_server, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 581, __pyx_L1_error)
  __pyx_t_10 = (__pyx_t_2 != 0);
  if (__pyx_t_10) {
  } else {
    __pyx_t_1 = __pyx_t_10;
    goto __pyx_L13_bool_binop_done;
  }
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_instance); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 581, __pyx_L1_error)
  __pyx_t_2 = ((!__pyx_t_10) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L13_bool_binop_done:;
  if (__pyx_t_1) {

    /* "_mssql.pyx":582
 *         # if we are not using an instance
 *         if ':' not in server and not instance:
 *             server = '%s:%s' % (server, port)             # <<<<<<<<<<<<<<
 * 
 *         # override the HOST to be the portion without the server, otherwise
 */
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 582, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_server);
    __Pyx_GIVEREF(__pyx_v_server);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_server);
    __Pyx_INCREF(__pyx_v_port);
    __Pyx_GIVEREF(__pyx_v_port);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_port);
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 582, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_server, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "_mssql.pyx":581
 *         # add the port to the server string if it doesn't have one already and
 *         # if we are not using an instance
 *         if ':' not in server and not instance:             # <<<<<<<<<<<<<<
 *             server = '%s:%s' % (server, port)
 * 
 */
  }

  /* "_mssql.pyx":597
 * 
 *         # Add ourselves to the global connection list
 *         connection_object_list.append(self)             # <<<<<<<<<<<<<<
 * 
 *         cdef bytes charset_bytes
 */
  if (unlikely(__pyx_v_6_mssql_connection_object_list == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
    __PYX_ERR(0, 597, __pyx_L1_error)
  }
  __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_6_mssql_connection_object_list, ((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 597, __pyx_L1_error)

  /* "_mssql.pyx":602
 * 
 *         # Set the character set name
 *         if charset:             # <<<<<<<<<<<<<<
 *             charset_bytes = charset.encode('utf-8')
 *             _charset = charset_bytes
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_charset); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 602, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":603
 *         # Set the character set name
 *         if charset:
 *             charset_bytes = charset.encode('utf-8')             # <<<<<<<<<<<<<<
 *             _charset = charset_bytes
 *             strncpy(self._charset, _charset, PYMSSQL_CHARSETBUFSIZE)
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_charset, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 603, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 603, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 603, __pyx_L1_error)
    __pyx_v_charset_bytes = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":604
 *         if charset:
 *             charset_bytes = charset.encode('utf-8')
 *             _charset = charset_bytes             # <<<<<<<<<<<<<<
 *             strncpy(self._charset, _charset, PYMSSQL_CHARSETBUFSIZE)
 *             DBSETLCHARSET(login, self._charset)
 */
    __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_charset_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 604, __pyx_L1_error)
    __pyx_v__charset = __pyx_t_8;

    /* "_mssql.pyx":605
 *             charset_bytes = charset.encode('utf-8')
 *             _charset = charset_bytes
 *             strncpy(self._charset, _charset, PYMSSQL_CHARSETBUFSIZE)             # <<<<<<<<<<<<<<
 *             DBSETLCHARSET(login, self._charset)
 * 
 */
    strncpy(__pyx_v_self->_charset, __pyx_v__charset, 0x64);

    /* "_mssql.pyx":606
 *             _charset = charset_bytes
 *             strncpy(self._charset, _charset, PYMSSQL_CHARSETBUFSIZE)
 *             DBSETLCHARSET(login, self._charset)             # <<<<<<<<<<<<<<
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 */
    DBSETLCHARSET(__pyx_v_login, __pyx_v_self->_charset);

    /* "_mssql.pyx":602
 * 
 *         # Set the character set name
 *         if charset:             # <<<<<<<<<<<<<<
 *             charset_bytes = charset.encode('utf-8')
 *             _charset = charset_bytes
 */
  }

  /* "_mssql.pyx":612
 *         cdef char *dbname_cstr
 *         # Put the DB name in the login LOGINREC because it helps with connections to Azure
 *         if database:             # <<<<<<<<<<<<<<
 *             if FREETDS_SUPPORTS_DBSETLDBNAME:
 *                 dbname_bytes = database.encode('ascii')
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_database); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 612, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":613
 *         # Put the DB name in the login LOGINREC because it helps with connections to Azure
 *         if database:
 *             if FREETDS_SUPPORTS_DBSETLDBNAME:             # <<<<<<<<<<<<<<
 *                 dbname_bytes = database.encode('ascii')
 *                 dbname_cstr = dbname_bytes
 */
    __pyx_t_1 = (FREETDS_SUPPORTS_DBSETLDBNAME != 0);
    if (__pyx_t_1) {

      /* "_mssql.pyx":614
 *         if database:
 *             if FREETDS_SUPPORTS_DBSETLDBNAME:
 *                 dbname_bytes = database.encode('ascii')             # <<<<<<<<<<<<<<
 *                 dbname_cstr = dbname_bytes
 *                 DBSETLDBNAME(login, dbname_cstr)
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_database, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 614, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 614, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 614, __pyx_L1_error)
      __pyx_v_dbname_bytes = ((PyObject*)__pyx_t_4);
      __pyx_t_4 = 0;

      /* "_mssql.pyx":615
 *             if FREETDS_SUPPORTS_DBSETLDBNAME:
 *                 dbname_bytes = database.encode('ascii')
 *                 dbname_cstr = dbname_bytes             # <<<<<<<<<<<<<<
 *                 DBSETLDBNAME(login, dbname_cstr)
 *             else:
 */
      __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_dbname_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 615, __pyx_L1_error)
      __pyx_v_dbname_cstr = __pyx_t_8;

      /* "_mssql.pyx":616
 *                 dbname_bytes = database.encode('ascii')
 *                 dbname_cstr = dbname_bytes
 *                 DBSETLDBNAME(login, dbname_cstr)             # <<<<<<<<<<<<<<
 *             else:
 *                 log("_mssql.MSSQLConnection.__init__(): Warning: This version of FreeTDS doesn't support selecting the DB name when setting up the connection. This will keep connections to Azure from working.")
 */
      DBSETLDBNAME(__pyx_v_login, __pyx_v_dbname_cstr);

      /* "_mssql.pyx":613
 *         # Put the DB name in the login LOGINREC because it helps with connections to Azure
 *         if database:
 *             if FREETDS_SUPPORTS_DBSETLDBNAME:             # <<<<<<<<<<<<<<
 *                 dbname_bytes = database.encode('ascii')
 *                 dbname_cstr = dbname_bytes
 */
      goto __pyx_L17;
    }

    /* "_mssql.pyx":618
 *                 DBSETLDBNAME(login, dbname_cstr)
 *             else:
 *                 log("_mssql.MSSQLConnection.__init__(): Warning: This version of FreeTDS doesn't support selecting the DB name when setting up the connection. This will keep connections to Azure from working.")             # <<<<<<<<<<<<<<
 * 
 *         # Set the login timeout
 */
    /*else*/ {
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.__init__(): Warning: This version of FreeTDS doesn't support selecting the DB name when setting up the connection. This will keep connections to Azure from working."));
    }
    __pyx_L17:;

    /* "_mssql.pyx":612
 *         cdef char *dbname_cstr
 *         # Put the DB name in the login LOGINREC because it helps with connections to Azure
 *         if database:             # <<<<<<<<<<<<<<
 *             if FREETDS_SUPPORTS_DBSETLDBNAME:
 *                 dbname_bytes = database.encode('ascii')
 */
  }

  /* "_mssql.pyx":622
 *         # Set the login timeout
 *         # XXX: Currently this will set it application wide :-(
 *         dbsetlogintime(login_timeout)             # <<<<<<<<<<<<<<
 * 
 *         cdef bytes server_bytes = server.encode('utf-8')
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_login_timeout); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 622, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  dbsetlogintime(__pyx_t_9);

  /* "_mssql.pyx":624
 *         dbsetlogintime(login_timeout)
 * 
 *         cdef bytes server_bytes = server.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *server_cstr = server_bytes
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_server, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 624, __pyx_L1_error)
  __pyx_v_server_bytes = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "_mssql.pyx":625
 * 
 *         cdef bytes server_bytes = server.encode('utf-8')
 *         cdef char *server_cstr = server_bytes             # <<<<<<<<<<<<<<
 * 
 *         # Connect to the server
 */
  __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_server_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 625, __pyx_L1_error)
  __pyx_v_server_cstr = __pyx_t_8;

  /* "_mssql.pyx":628
 * 
 *         # Connect to the server
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.dbproc = dbopen(login, server_cstr)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":629
 *         # Connect to the server
 *         with nogil:
 *             self.dbproc = dbopen(login, server_cstr)             # <<<<<<<<<<<<<<
 * 
 *         # Frees the login record, can be called immediately after dbopen.
 */
        __pyx_v_self->dbproc = dbopen(__pyx_v_login, __pyx_v_server_cstr);
      }

      /* "_mssql.pyx":628
 * 
 *         # Connect to the server
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.dbproc = dbopen(login, server_cstr)
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L20;
        }
        __pyx_L20:;
      }
  }

  /* "_mssql.pyx":632
 * 
 *         # Frees the login record, can be called immediately after dbopen.
 *         dbloginfree(login)             # <<<<<<<<<<<<<<
 * 
 *         if self.dbproc == NULL:
 */
  dbloginfree(__pyx_v_login);

  /* "_mssql.pyx":634
 *         dbloginfree(login)
 * 
 *         if self.dbproc == NULL:             # <<<<<<<<<<<<<<
 *             log("_mssql.MSSQLConnection.__init__() -> dbopen() returned NULL")
 *             connection_object_list.remove(self)
 */
  __pyx_t_1 = ((__pyx_v_self->dbproc == NULL) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":635
 * 
 *         if self.dbproc == NULL:
 *             log("_mssql.MSSQLConnection.__init__() -> dbopen() returned NULL")             # <<<<<<<<<<<<<<
 *             connection_object_list.remove(self)
 *             maybe_raise_MSSQLDatabaseException(None)
 */
    __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.__init__() -> dbopen() returned NULL"));

    /* "_mssql.pyx":636
 *         if self.dbproc == NULL:
 *             log("_mssql.MSSQLConnection.__init__() -> dbopen() returned NULL")
 *             connection_object_list.remove(self)             # <<<<<<<<<<<<<<
 *             maybe_raise_MSSQLDatabaseException(None)
 *             raise MSSQLDriverException("Connection to the database failed for an unknown reason.")
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_6_mssql_connection_object_list, __pyx_n_s_remove); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 636, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 636, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 636, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, ((PyObject *)__pyx_v_self));
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 636, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "_mssql.pyx":637
 *             log("_mssql.MSSQLConnection.__init__() -> dbopen() returned NULL")
 *             connection_object_list.remove(self)
 *             maybe_raise_MSSQLDatabaseException(None)             # <<<<<<<<<<<<<<
 *             raise MSSQLDriverException("Connection to the database failed for an unknown reason.")
 * 
 */
    __pyx_t_9 = __pyx_f_6_mssql_maybe_raise_MSSQLDatabaseException(((struct __pyx_obj_6_mssql_MSSQLConnection *)Py_None)); if (unlikely(__pyx_t_9 == 1)) __PYX_ERR(0, 637, __pyx_L1_error)

    /* "_mssql.pyx":638
 *             connection_object_list.remove(self)
 *             maybe_raise_MSSQLDatabaseException(None)
 *             raise MSSQLDriverException("Connection to the database failed for an unknown reason.")             # <<<<<<<<<<<<<<
 * 
 *         self._connected = 1
 */
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 638, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 638, __pyx_L1_error)

    /* "_mssql.pyx":634
 *         dbloginfree(login)
 * 
 *         if self.dbproc == NULL:             # <<<<<<<<<<<<<<
 *             log("_mssql.MSSQLConnection.__init__() -> dbopen() returned NULL")
 *             connection_object_list.remove(self)
 */
  }

  /* "_mssql.pyx":640
 *             raise MSSQLDriverException("Connection to the database failed for an unknown reason.")
 * 
 *         self._connected = 1             # <<<<<<<<<<<<<<
 * 
 *         if conn_properties is None:
 */
  __pyx_v_self->_connected = 1;

  /* "_mssql.pyx":642
 *         self._connected = 1
 * 
 *         if conn_properties is None:             # <<<<<<<<<<<<<<
 *             conn_properties = \
 *                 "SET ARITHABORT ON;"                \
 */
  __pyx_t_1 = (__pyx_v_conn_properties == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":644
 *         if conn_properties is None:
 *             conn_properties = \
 *                 "SET ARITHABORT ON;"                \             # <<<<<<<<<<<<<<
 *                 "SET CONCAT_NULL_YIELDS_NULL ON;"   \
 *                 "SET ANSI_NULLS ON;"                \
 */
    __Pyx_INCREF(__pyx_kp_s_SET_ARITHABORT_ON_SET_CONCAT_NUL);
    __Pyx_DECREF_SET(__pyx_v_conn_properties, __pyx_kp_s_SET_ARITHABORT_ON_SET_CONCAT_NUL);

    /* "_mssql.pyx":642
 *         self._connected = 1
 * 
 *         if conn_properties is None:             # <<<<<<<<<<<<<<
 *             conn_properties = \
 *                 "SET ARITHABORT ON;"                \
 */
    goto __pyx_L22;
  }

  /* "_mssql.pyx":654
 *                 "SET QUOTED_IDENTIFIER ON;"         \
 *                 "SET TEXTSIZE 2147483647;"  # http://msdn.microsoft.com/en-us/library/aa259190%28v=sql.80%29.aspx
 *         elif isinstance(conn_properties, Iterable) and not isinstance(conn_properties, string_types):             # <<<<<<<<<<<<<<
 *             conn_properties = ' '.join(conn_properties)
 *         cdef bytes conn_props_bytes
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_Iterable); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 654, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_conn_properties, __pyx_t_5); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 654, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_10 = (__pyx_t_1 != 0);
  if (__pyx_t_10) {
  } else {
    __pyx_t_2 = __pyx_t_10;
    goto __pyx_L23_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_string_types); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 654, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_10 = PyObject_IsInstance(__pyx_v_conn_properties, __pyx_t_5); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 654, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = ((!(__pyx_t_10 != 0)) != 0);
  __pyx_t_2 = __pyx_t_1;
  __pyx_L23_bool_binop_done:;
  if (__pyx_t_2) {

    /* "_mssql.pyx":655
 *                 "SET TEXTSIZE 2147483647;"  # http://msdn.microsoft.com/en-us/library/aa259190%28v=sql.80%29.aspx
 *         elif isinstance(conn_properties, Iterable) and not isinstance(conn_properties, string_types):
 *             conn_properties = ' '.join(conn_properties)             # <<<<<<<<<<<<<<
 *         cdef bytes conn_props_bytes
 *         cdef char *conn_props_cstr
 */
    __pyx_t_5 = __Pyx_PyString_Join(__pyx_kp_s__15, __pyx_v_conn_properties); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 655, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF_SET(__pyx_v_conn_properties, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":654
 *                 "SET QUOTED_IDENTIFIER ON;"         \
 *                 "SET TEXTSIZE 2147483647;"  # http://msdn.microsoft.com/en-us/library/aa259190%28v=sql.80%29.aspx
 *         elif isinstance(conn_properties, Iterable) and not isinstance(conn_properties, string_types):             # <<<<<<<<<<<<<<
 *             conn_properties = ' '.join(conn_properties)
 *         cdef bytes conn_props_bytes
 */
  }
  __pyx_L22:;

  /* "_mssql.pyx":658
 *         cdef bytes conn_props_bytes
 *         cdef char *conn_props_cstr
 *         if conn_properties:             # <<<<<<<<<<<<<<
 *             log("_mssql.MSSQLConnection.__init__() -> dbcmd() setting connection values")
 *             # Set connection properties, some reasonable values are used by
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_conn_properties); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 658, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "_mssql.pyx":659
 *         cdef char *conn_props_cstr
 *         if conn_properties:
 *             log("_mssql.MSSQLConnection.__init__() -> dbcmd() setting connection values")             # <<<<<<<<<<<<<<
 *             # Set connection properties, some reasonable values are used by
 *             # default but they can be customized
 */
    __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.__init__() -> dbcmd() setting connection values"));

    /* "_mssql.pyx":662
 *             # Set connection properties, some reasonable values are used by
 *             # default but they can be customized
 *             conn_props_bytes = conn_properties.encode(charset)             # <<<<<<<<<<<<<<
 *             conn_props_cstr = conn_props_bytes
 *             dbcmd(self.dbproc, conn_props_bytes)
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_conn_properties, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 662, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_charset); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 662, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 662, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_charset);
      __Pyx_GIVEREF(__pyx_v_charset);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_charset);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 662, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 662, __pyx_L1_error)
    __pyx_v_conn_props_bytes = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":663
 *             # default but they can be customized
 *             conn_props_bytes = conn_properties.encode(charset)
 *             conn_props_cstr = conn_props_bytes             # <<<<<<<<<<<<<<
 *             dbcmd(self.dbproc, conn_props_bytes)
 * 
 */
    __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_conn_props_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 663, __pyx_L1_error)
    __pyx_v_conn_props_cstr = __pyx_t_8;

    /* "_mssql.pyx":664
 *             conn_props_bytes = conn_properties.encode(charset)
 *             conn_props_cstr = conn_props_bytes
 *             dbcmd(self.dbproc, conn_props_bytes)             # <<<<<<<<<<<<<<
 * 
 *             rtc = db_sqlexec(self.dbproc)
 */
    __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_conn_props_bytes); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 664, __pyx_L1_error)
    dbcmd(__pyx_v_self->dbproc, __pyx_t_8);

    /* "_mssql.pyx":666
 *             dbcmd(self.dbproc, conn_props_bytes)
 * 
 *             rtc = db_sqlexec(self.dbproc)             # <<<<<<<<<<<<<<
 *             if (rtc == FAIL):
 *                 raise MSSQLDriverException("Could not set connection properties")
 */
    __pyx_v_rtc = __pyx_f_6_mssql_db_sqlexec(__pyx_v_self->dbproc);

    /* "_mssql.pyx":667
 * 
 *             rtc = db_sqlexec(self.dbproc)
 *             if (rtc == FAIL):             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException("Could not set connection properties")
 * 
 */
    __pyx_t_2 = ((__pyx_v_rtc == FAIL) != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":668
 *             rtc = db_sqlexec(self.dbproc)
 *             if (rtc == FAIL):
 *                 raise MSSQLDriverException("Could not set connection properties")             # <<<<<<<<<<<<<<
 * 
 *         db_cancel(self)
 */
      __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 668, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 668, __pyx_L1_error)

      /* "_mssql.pyx":667
 * 
 *             rtc = db_sqlexec(self.dbproc)
 *             if (rtc == FAIL):             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException("Could not set connection properties")
 * 
 */
    }

    /* "_mssql.pyx":658
 *         cdef bytes conn_props_bytes
 *         cdef char *conn_props_cstr
 *         if conn_properties:             # <<<<<<<<<<<<<<
 *             log("_mssql.MSSQLConnection.__init__() -> dbcmd() setting connection values")
 *             # Set connection properties, some reasonable values are used by
 */
  }

  /* "_mssql.pyx":670
 *                 raise MSSQLDriverException("Could not set connection properties")
 * 
 *         db_cancel(self)             # <<<<<<<<<<<<<<
 *         clr_err(self)
 * 
 */
  __pyx_f_6_mssql_db_cancel(__pyx_v_self);

  /* "_mssql.pyx":671
 * 
 *         db_cancel(self)
 *         clr_err(self)             # <<<<<<<<<<<<<<
 * 
 *         if database:
 */
  __pyx_f_6_mssql_clr_err(__pyx_v_self);

  /* "_mssql.pyx":673
 *         clr_err(self)
 * 
 *         if database:             # <<<<<<<<<<<<<<
 *             self.select_db(database)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_database); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 673, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "_mssql.pyx":674
 * 
 *         if database:
 *             self.select_db(database)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_select_db); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 674, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_database); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 674, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 674, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_database);
      __Pyx_GIVEREF(__pyx_v_database);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_database);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 674, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "_mssql.pyx":673
 *         clr_err(self)
 * 
 *         if database:             # <<<<<<<<<<<<<<
 *             self.select_db(database)
 * 
 */
  }

  /* "_mssql.pyx":542
 *         self.column_types = None
 * 
 *     def __init__(self, server="localhost", user="sa", password="",             # <<<<<<<<<<<<<<
 *             charset='UTF-8', database='', appname=None, port='1433', tds_version='7.1', conn_properties=None):
 *         log("_mssql.MSSQLConnection.__init__()")
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_instance);
  __Pyx_XDECREF(__pyx_v_user_bytes);
  __Pyx_XDECREF(__pyx_v_password_bytes);
  __Pyx_XDECREF(__pyx_v_appname_bytes);
  __Pyx_XDECREF(__pyx_v_charset_bytes);
  __Pyx_XDECREF(__pyx_v_dbname_bytes);
  __Pyx_XDECREF(__pyx_v_server_bytes);
  __Pyx_XDECREF(__pyx_v_conn_props_bytes);
  __Pyx_XDECREF(__pyx_v_server);
  __Pyx_XDECREF(__pyx_v_appname);
  __Pyx_XDECREF(__pyx_v_conn_properties);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":676
 *             self.select_db(database)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.__dealloc__()")
 *         self.close()
 */

/* Python wrapper */
static void __pyx_pw_6_mssql_15MSSQLConnection_5__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_6_mssql_15MSSQLConnection_5__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_6_mssql_15MSSQLConnection_4__dealloc__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_6_mssql_15MSSQLConnection_4__dealloc__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "_mssql.pyx":677
 * 
 *     def __dealloc__(self):
 *         log("_mssql.MSSQLConnection.__dealloc__()")             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.__dealloc__()"));

  /* "_mssql.pyx":678
 *     def __dealloc__(self):
 *         log("_mssql.MSSQLConnection.__dealloc__()")
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     def __enter__(self):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 678, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 678, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":676
 *             self.select_db(database)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.__dealloc__()")
 *         self.close()
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("_mssql.MSSQLConnection.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":680
 *         self.close()
 * 
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_7__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_7__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_6__enter__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_6__enter__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__enter__", 0);

  /* "_mssql.pyx":681
 * 
 *     def __enter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "_mssql.pyx":680
 *         self.close()
 * 
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":683
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_9__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_9__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0;
  CYTHON_UNUSED PyObject *__pyx_v_exc_value = 0;
  CYTHON_UNUSED PyObject *__pyx_v_traceback = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exc_type,&__pyx_n_s_exc_value,&__pyx_n_s_traceback,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_exc_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 683, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 683, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 683, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_exc_type = values[0];
    __pyx_v_exc_value = values[1];
    __pyx_v_traceback = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 683, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLConnection.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_8__exit__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_value, __pyx_v_traceback);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_8__exit__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("__exit__", 0);

  /* "_mssql.pyx":684
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 684, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":683
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":686
 *         self.close()
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         assert_connected(self)
 *         clr_err(self)
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_11__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_11__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_10__iter__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_10__iter__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("__iter__", 0);

  /* "_mssql.pyx":687
 * 
 *     def __iter__(self):
 *         assert_connected(self)             # <<<<<<<<<<<<<<
 *         clr_err(self)
 *         return MSSQLRowIterator(self, ROW_FORMAT_DICT)
 */
  __pyx_f_6_mssql_assert_connected(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 687, __pyx_L1_error)

  /* "_mssql.pyx":688
 *     def __iter__(self):
 *         assert_connected(self)
 *         clr_err(self)             # <<<<<<<<<<<<<<
 *         return MSSQLRowIterator(self, ROW_FORMAT_DICT)
 * 
 */
  __pyx_f_6_mssql_clr_err(__pyx_v_self);

  /* "_mssql.pyx":689
 *         assert_connected(self)
 *         clr_err(self)
 *         return MSSQLRowIterator(self, ROW_FORMAT_DICT)             # <<<<<<<<<<<<<<
 * 
 *     cpdef set_msghandler(self, object handler):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ROW_FORMAT_DICT); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLRowIterator), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":686
 *         self.close()
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         assert_connected(self)
 *         clr_err(self)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":691
 *         return MSSQLRowIterator(self, ROW_FORMAT_DICT)
 * 
 *     cpdef set_msghandler(self, object handler):             # <<<<<<<<<<<<<<
 *         """
 *         set_msghandler(handler) -- set the msghandler for the connection
 */

static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13set_msghandler(PyObject *__pyx_v_self, PyObject *__pyx_v_handler); /*proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_set_msghandler(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_handler, int __pyx_skip_dispatch) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("set_msghandler", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_msghandler); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 691, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_13set_msghandler)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_handler); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 691, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 691, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_INCREF(__pyx_v_handler);
        __Pyx_GIVEREF(__pyx_v_handler);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_handler);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 691, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":699
 *         server.
 *         """
 *         self.msghandler = handler             # <<<<<<<<<<<<<<
 * 
 *     cpdef cancel(self):
 */
  __Pyx_INCREF(__pyx_v_handler);
  __Pyx_GIVEREF(__pyx_v_handler);
  __Pyx_GOTREF(__pyx_v_self->msghandler);
  __Pyx_DECREF(__pyx_v_self->msghandler);
  __pyx_v_self->msghandler = __pyx_v_handler;

  /* "_mssql.pyx":691
 *         return MSSQLRowIterator(self, ROW_FORMAT_DICT)
 * 
 *     cpdef set_msghandler(self, object handler):             # <<<<<<<<<<<<<<
 *         """
 *         set_msghandler(handler) -- set the msghandler for the connection
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.set_msghandler", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13set_msghandler(PyObject *__pyx_v_self, PyObject *__pyx_v_handler); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_12set_msghandler[] = "\n        set_msghandler(handler) -- set the msghandler for the connection\n\n        This function allows setting a msghandler for the connection to\n        allow a client to gain access to the messages returned from the\n        server.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13set_msghandler(PyObject *__pyx_v_self, PyObject *__pyx_v_handler) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_msghandler (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_12set_msghandler(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), ((PyObject *)__pyx_v_handler));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_12set_msghandler(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_handler) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("set_msghandler", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6_mssql_15MSSQLConnection_set_msghandler(__pyx_v_self, __pyx_v_handler, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.set_msghandler", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":701
 *         self.msghandler = handler
 * 
 *     cpdef cancel(self):             # <<<<<<<<<<<<<<
 *         """
 *         cancel() -- cancel all pending results.
 */

static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_15cancel(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_cancel(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_skip_dispatch) {
  RETCODE __pyx_v_rtc;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("cancel", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cancel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 701, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_15cancel)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 701, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 701, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":709
 *         this case.
 *         """
 *         log("_mssql.MSSQLConnection.cancel()")             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 * 
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.cancel()"));

  /* "_mssql.pyx":712
 *         cdef RETCODE rtc
 * 
 *         assert_connected(self)             # <<<<<<<<<<<<<<
 *         clr_err(self)
 * 
 */
  __pyx_f_6_mssql_assert_connected(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 712, __pyx_L1_error)

  /* "_mssql.pyx":713
 * 
 *         assert_connected(self)
 *         clr_err(self)             # <<<<<<<<<<<<<<
 * 
 *         rtc = db_cancel(self)
 */
  __pyx_f_6_mssql_clr_err(__pyx_v_self);

  /* "_mssql.pyx":715
 *         clr_err(self)
 * 
 *         rtc = db_cancel(self)             # <<<<<<<<<<<<<<
 *         check_and_raise(rtc, self)
 * 
 */
  __pyx_v_rtc = __pyx_f_6_mssql_db_cancel(__pyx_v_self);

  /* "_mssql.pyx":716
 * 
 *         rtc = db_cancel(self)
 *         check_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 * 
 *     cdef void clear_metadata(self):
 */
  __pyx_t_5 = __pyx_f_6_mssql_check_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_5 == 1)) __PYX_ERR(0, 716, __pyx_L1_error)

  /* "_mssql.pyx":701
 *         self.msghandler = handler
 * 
 *     cpdef cancel(self):             # <<<<<<<<<<<<<<
 *         """
 *         cancel() -- cancel all pending results.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.cancel", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_15cancel(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_14cancel[] = "\n        cancel() -- cancel all pending results.\n\n        This function cancels all pending results from the last SQL operation.\n        It can be called more than once in a row. No exception is raised in\n        this case.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_15cancel(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cancel (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_14cancel(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_14cancel(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("cancel", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6_mssql_15MSSQLConnection_cancel(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.cancel", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":718
 *         check_and_raise(rtc, self)
 * 
 *     cdef void clear_metadata(self):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.clear_metadata()")
 *         self.column_names = None
 */

static void __pyx_f_6_mssql_15MSSQLConnection_clear_metadata(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("clear_metadata", 0);

  /* "_mssql.pyx":719
 * 
 *     cdef void clear_metadata(self):
 *         log("_mssql.MSSQLConnection.clear_metadata()")             # <<<<<<<<<<<<<<
 *         self.column_names = None
 *         self.column_types = None
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.clear_metadata()"));

  /* "_mssql.pyx":720
 *     cdef void clear_metadata(self):
 *         log("_mssql.MSSQLConnection.clear_metadata()")
 *         self.column_names = None             # <<<<<<<<<<<<<<
 *         self.column_types = None
 *         self.num_columns = 0
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->column_names);
  __Pyx_DECREF(__pyx_v_self->column_names);
  __pyx_v_self->column_names = ((PyObject*)Py_None);

  /* "_mssql.pyx":721
 *         log("_mssql.MSSQLConnection.clear_metadata()")
 *         self.column_names = None
 *         self.column_types = None             # <<<<<<<<<<<<<<
 *         self.num_columns = 0
 *         self.last_dbresults = 0
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->column_types);
  __Pyx_DECREF(__pyx_v_self->column_types);
  __pyx_v_self->column_types = ((PyObject*)Py_None);

  /* "_mssql.pyx":722
 *         self.column_names = None
 *         self.column_types = None
 *         self.num_columns = 0             # <<<<<<<<<<<<<<
 *         self.last_dbresults = 0
 * 
 */
  __pyx_v_self->num_columns = 0;

  /* "_mssql.pyx":723
 *         self.column_types = None
 *         self.num_columns = 0
 *         self.last_dbresults = 0             # <<<<<<<<<<<<<<
 * 
 *     def close(self):
 */
  __pyx_v_self->last_dbresults = 0;

  /* "_mssql.pyx":718
 *         check_and_raise(rtc, self)
 * 
 *     cdef void clear_metadata(self):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.clear_metadata()")
 *         self.column_names = None
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":725
 *         self.last_dbresults = 0
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         """
 *         close() -- close connection to an MS SQL Server.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_17close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_16close[] = "\n        close() -- close connection to an MS SQL Server.\n\n        This function tries to close the connection and free all memory used.\n        It can be called more than once in a row. No exception is raised in\n        this case.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_17close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_16close(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_16close(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("close", 0);

  /* "_mssql.pyx":733
 *         this case.
 *         """
 *         log("_mssql.MSSQLConnection.close()")             # <<<<<<<<<<<<<<
 *         if self == None:
 *             return None
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.close()"));

  /* "_mssql.pyx":734
 *         """
 *         log("_mssql.MSSQLConnection.close()")
 *         if self == None:             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
  __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_self), Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":735
 *         log("_mssql.MSSQLConnection.close()")
 *         if self == None:
 *             return None             # <<<<<<<<<<<<<<
 * 
 *         if not self._connected:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "_mssql.pyx":734
 *         """
 *         log("_mssql.MSSQLConnection.close()")
 *         if self == None:             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
  }

  /* "_mssql.pyx":737
 *             return None
 * 
 *         if not self._connected:             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
  __pyx_t_2 = ((!(__pyx_v_self->_connected != 0)) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":738
 * 
 *         if not self._connected:
 *             return None             # <<<<<<<<<<<<<<
 * 
 *         clr_err(self)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "_mssql.pyx":737
 *             return None
 * 
 *         if not self._connected:             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
  }

  /* "_mssql.pyx":740
 *             return None
 * 
 *         clr_err(self)             # <<<<<<<<<<<<<<
 * 
 *         with nogil:
 */
  __pyx_f_6_mssql_clr_err(__pyx_v_self);

  /* "_mssql.pyx":742
 *         clr_err(self)
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             dbclose(self.dbproc)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":743
 * 
 *         with nogil:
 *             dbclose(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *         self.mark_disconnected()
 */
        dbclose(__pyx_v_self->dbproc);
      }

      /* "_mssql.pyx":742
 *         clr_err(self)
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             dbclose(self.dbproc)
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L7;
        }
        __pyx_L7:;
      }
  }

  /* "_mssql.pyx":745
 *             dbclose(self.dbproc)
 * 
 *         self.mark_disconnected()             # <<<<<<<<<<<<<<
 * 
 *     def mark_disconnected(self):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mark_disconnected); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 745, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":725
 *         self.last_dbresults = 0
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         """
 *         close() -- close connection to an MS SQL Server.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":747
 *         self.mark_disconnected()
 * 
 *     def mark_disconnected(self):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.mark_disconnected()")
 *         self.dbproc = NULL
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_19mark_disconnected(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_19mark_disconnected(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mark_disconnected (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_18mark_disconnected(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_18mark_disconnected(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("mark_disconnected", 0);

  /* "_mssql.pyx":748
 * 
 *     def mark_disconnected(self):
 *         log("_mssql.MSSQLConnection.mark_disconnected()")             # <<<<<<<<<<<<<<
 *         self.dbproc = NULL
 *         self._connected = 0
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.mark_disconnected()"));

  /* "_mssql.pyx":749
 *     def mark_disconnected(self):
 *         log("_mssql.MSSQLConnection.mark_disconnected()")
 *         self.dbproc = NULL             # <<<<<<<<<<<<<<
 *         self._connected = 0
 *         PyMem_Free(self.last_msg_proc)
 */
  __pyx_v_self->dbproc = NULL;

  /* "_mssql.pyx":750
 *         log("_mssql.MSSQLConnection.mark_disconnected()")
 *         self.dbproc = NULL
 *         self._connected = 0             # <<<<<<<<<<<<<<
 *         PyMem_Free(self.last_msg_proc)
 *         PyMem_Free(self.last_msg_srv)
 */
  __pyx_v_self->_connected = 0;

  /* "_mssql.pyx":751
 *         self.dbproc = NULL
 *         self._connected = 0
 *         PyMem_Free(self.last_msg_proc)             # <<<<<<<<<<<<<<
 *         PyMem_Free(self.last_msg_srv)
 *         PyMem_Free(self.last_msg_str)
 */
  PyMem_Free(__pyx_v_self->last_msg_proc);

  /* "_mssql.pyx":752
 *         self._connected = 0
 *         PyMem_Free(self.last_msg_proc)
 *         PyMem_Free(self.last_msg_srv)             # <<<<<<<<<<<<<<
 *         PyMem_Free(self.last_msg_str)
 *         PyMem_Free(self._charset)
 */
  PyMem_Free(__pyx_v_self->last_msg_srv);

  /* "_mssql.pyx":753
 *         PyMem_Free(self.last_msg_proc)
 *         PyMem_Free(self.last_msg_srv)
 *         PyMem_Free(self.last_msg_str)             # <<<<<<<<<<<<<<
 *         PyMem_Free(self._charset)
 *         connection_object_list.remove(self)
 */
  PyMem_Free(__pyx_v_self->last_msg_str);

  /* "_mssql.pyx":754
 *         PyMem_Free(self.last_msg_srv)
 *         PyMem_Free(self.last_msg_str)
 *         PyMem_Free(self._charset)             # <<<<<<<<<<<<<<
 *         connection_object_list.remove(self)
 * 
 */
  PyMem_Free(__pyx_v_self->_charset);

  /* "_mssql.pyx":755
 *         PyMem_Free(self.last_msg_str)
 *         PyMem_Free(self._charset)
 *         connection_object_list.remove(self)             # <<<<<<<<<<<<<<
 * 
 *     cdef object convert_db_value(self, BYTE *data, int dbtype, int length):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_6_mssql_connection_object_list, __pyx_n_s_remove); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_self));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":747
 *         self.mark_disconnected()
 * 
 *     def mark_disconnected(self):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.mark_disconnected()")
 *         self.dbproc = NULL
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.mark_disconnected", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":757
 *         connection_object_list.remove(self)
 * 
 *     cdef object convert_db_value(self, BYTE *data, int dbtype, int length):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.convert_db_value()")
 *         cdef char buf[NUMERIC_BUF_SZ] # buffer in which we store text rep of bug nums
 */

static PyObject *__pyx_f_6_mssql_15MSSQLConnection_convert_db_value(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, BYTE *__pyx_v_data, int __pyx_v_dbtype, int __pyx_v_length) {
  char __pyx_v_buf[45];
  int __pyx_v_converted_length;
  BYTE __pyx_v_precision;
  DBDATEREC __pyx_v_di;
  DBDATETIME __pyx_v_dt;
  DBCOL __pyx_v_dbcol;
  PyObject *__pyx_v_ctx = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  char *__pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  Py_ssize_t __pyx_t_20;
  PyObject *__pyx_t_21 = NULL;
  __Pyx_RefNannySetupContext("convert_db_value", 0);

  /* "_mssql.pyx":758
 * 
 *     cdef object convert_db_value(self, BYTE *data, int dbtype, int length):
 *         log("_mssql.MSSQLConnection.convert_db_value()")             # <<<<<<<<<<<<<<
 *         cdef char buf[NUMERIC_BUF_SZ] # buffer in which we store text rep of bug nums
 *         cdef int converted_length
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.convert_db_value()"));

  /* "_mssql.pyx":770
 *             sys.stderr.write("convert_db_value: dbtype = %d; length = %d\n" % (dbtype, length))
 * 
 *         if dbtype == SQLBIT:             # <<<<<<<<<<<<<<
 *             return bool(<int>(<DBBIT *>data)[0])
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLBIT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":771
 * 
 *         if dbtype == SQLBIT:
 *             return bool(<int>(<DBBIT *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLINT1:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int(((int)(((DBBIT *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 771, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 771, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_4bool_bool), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 771, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":770
 *             sys.stderr.write("convert_db_value: dbtype = %d; length = %d\n" % (dbtype, length))
 * 
 *         if dbtype == SQLBIT:             # <<<<<<<<<<<<<<
 *             return bool(<int>(<DBBIT *>data)[0])
 * 
 */
  }

  /* "_mssql.pyx":773
 *             return bool(<int>(<DBBIT *>data)[0])
 * 
 *         elif dbtype == SQLINT1:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBTINYINT *>data)[0])
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 773, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 773, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":774
 * 
 *         elif dbtype == SQLINT1:
 *             return int(<int>(<DBTINYINT *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLINT2:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyInt_From_int(((int)(((DBTINYINT *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 774, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 774, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyInt_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 774, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":773
 *             return bool(<int>(<DBBIT *>data)[0])
 * 
 *         elif dbtype == SQLINT1:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBTINYINT *>data)[0])
 * 
 */
  }

  /* "_mssql.pyx":776
 *             return int(<int>(<DBTINYINT *>data)[0])
 * 
 *         elif dbtype == SQLINT2:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBSMALLINT *>data)[0])
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":777
 * 
 *         elif dbtype == SQLINT2:
 *             return int(<int>(<DBSMALLINT *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLINT4:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int(((int)(((DBSMALLINT *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)(&PyInt_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":776
 *             return int(<int>(<DBTINYINT *>data)[0])
 * 
 *         elif dbtype == SQLINT2:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBSMALLINT *>data)[0])
 * 
 */
  }

  /* "_mssql.pyx":779
 *             return int(<int>(<DBSMALLINT *>data)[0])
 * 
 *         elif dbtype == SQLINT4:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBINT *>data)[0])
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 779, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 779, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":780
 * 
 *         elif dbtype == SQLINT4:
 *             return int(<int>(<DBINT *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLINT8:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyInt_From_int(((int)(((DBINT *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 780, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 780, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyInt_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 780, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":779
 *             return int(<int>(<DBSMALLINT *>data)[0])
 * 
 *         elif dbtype == SQLINT4:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBINT *>data)[0])
 * 
 */
  }

  /* "_mssql.pyx":782
 *             return int(<int>(<DBINT *>data)[0])
 * 
 *         elif dbtype == SQLINT8:             # <<<<<<<<<<<<<<
 *             return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 782, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 782, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 782, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 782, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":783
 * 
 *         elif dbtype == SQLINT8:
 *             return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLFLT4:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(((PY_LONG_LONG)(((PY_LONG_LONG *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 783, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 783, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)(&PyLong_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 783, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":782
 *             return int(<int>(<DBINT *>data)[0])
 * 
 *         elif dbtype == SQLINT8:             # <<<<<<<<<<<<<<
 *             return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])
 * 
 */
  }

  /* "_mssql.pyx":785
 *             return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])
 * 
 *         elif dbtype == SQLFLT4:             # <<<<<<<<<<<<<<
 *             return float(<float>(<DBREAL *>data)[0])
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 785, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLFLT4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 785, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 785, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 785, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":786
 * 
 *         elif dbtype == SQLFLT4:
 *             return float(<float>(<DBREAL *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLFLT8:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyFloat_FromDouble(((double)((float)(((DBREAL *)__pyx_v_data)[0])))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 786, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":785
 *             return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])
 * 
 *         elif dbtype == SQLFLT4:             # <<<<<<<<<<<<<<
 *             return float(<float>(<DBREAL *>data)[0])
 * 
 */
  }

  /* "_mssql.pyx":788
 *             return float(<float>(<DBREAL *>data)[0])
 * 
 *         elif dbtype == SQLFLT8:             # <<<<<<<<<<<<<<
 *             return float(<double>(<DBFLT8 *>data)[0])
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 788, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLFLT8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 788, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 788, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 788, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":789
 * 
 *         elif dbtype == SQLFLT8:
 *             return float(<double>(<DBFLT8 *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyFloat_FromDouble(((double)(((DBFLT8 *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 789, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":788
 *             return float(<float>(<DBREAL *>data)[0])
 * 
 *         elif dbtype == SQLFLT8:             # <<<<<<<<<<<<<<
 *             return float(<double>(<DBFLT8 *>data)[0])
 * 
 */
  }

  /* "_mssql.pyx":791
 *             return float(<double>(<DBFLT8 *>data)[0])
 * 
 *         elif dbtype in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):             # <<<<<<<<<<<<<<
 *             dbcol.SizeOfStruct = sizeof(dbcol)
 * 
 */
  __pyx_t_5 = __pyx_v_dbtype;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEY); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_4 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEY4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_4 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLNUMERIC); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_4 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDECIMAL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 791, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;
  __pyx_t_6 = (__pyx_t_4 != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":792
 * 
 *         elif dbtype in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):
 *             dbcol.SizeOfStruct = sizeof(dbcol)             # <<<<<<<<<<<<<<
 * 
 *             if dbtype in (SQLMONEY, SQLMONEY4):
 */
    __pyx_v_dbcol.SizeOfStruct = (sizeof(__pyx_v_dbcol));

    /* "_mssql.pyx":794
 *             dbcol.SizeOfStruct = sizeof(dbcol)
 * 
 *             if dbtype in (SQLMONEY, SQLMONEY4):             # <<<<<<<<<<<<<<
 *                 precision = 4
 *             else:
 */
    __pyx_t_5 = __pyx_v_dbtype;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEY); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_4) {
    } else {
      __pyx_t_6 = __pyx_t_4;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEY4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __pyx_t_4;
    __pyx_L9_bool_binop_done:;
    __pyx_t_4 = (__pyx_t_6 != 0);
    if (__pyx_t_4) {

      /* "_mssql.pyx":795
 * 
 *             if dbtype in (SQLMONEY, SQLMONEY4):
 *                 precision = 4             # <<<<<<<<<<<<<<
 *             else:
 *                 precision = 0
 */
      __pyx_v_precision = 4;

      /* "_mssql.pyx":794
 *             dbcol.SizeOfStruct = sizeof(dbcol)
 * 
 *             if dbtype in (SQLMONEY, SQLMONEY4):             # <<<<<<<<<<<<<<
 *                 precision = 4
 *             else:
 */
      goto __pyx_L8;
    }

    /* "_mssql.pyx":797
 *                 precision = 4
 *             else:
 *                 precision = 0             # <<<<<<<<<<<<<<
 * 
 *             converted_length = dbconvert(self.dbproc, dbtype, data, -1, SQLCHAR,
 */
    /*else*/ {
      __pyx_v_precision = 0;
    }
    __pyx_L8:;

    /* "_mssql.pyx":799
 *                 precision = 0
 * 
 *             converted_length = dbconvert(self.dbproc, dbtype, data, -1, SQLCHAR,             # <<<<<<<<<<<<<<
 *                 <BYTE *>buf, NUMERIC_BUF_SZ)
 * 
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 799, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 799, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "_mssql.pyx":800
 * 
 *             converted_length = dbconvert(self.dbproc, dbtype, data, -1, SQLCHAR,
 *                 <BYTE *>buf, NUMERIC_BUF_SZ)             # <<<<<<<<<<<<<<
 * 
 *             with decimal.localcontext() as ctx:
 */
    __pyx_v_converted_length = dbconvert(__pyx_v_self->dbproc, __pyx_v_dbtype, __pyx_v_data, -1, __pyx_t_5, ((BYTE *)__pyx_v_buf), 45);

    /* "_mssql.pyx":802
 *                 <BYTE *>buf, NUMERIC_BUF_SZ)
 * 
 *             with decimal.localcontext() as ctx:             # <<<<<<<<<<<<<<
 *                 # Python 3 doesn't like decimal.localcontext() with prec == 0
 *                 ctx.prec = precision if precision > 0 else 1
 */
    /*with:*/ {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_decimal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 802, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_localcontext); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 802, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      if (__pyx_t_2) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 802, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 802, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_3, __pyx_n_s_exit); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 802, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_2 = __Pyx_PyObject_LookupSpecial(__pyx_t_3, __pyx_n_s_enter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 802, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (__pyx_t_8) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 802, __pyx_L11_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else {
        __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 802, __pyx_L11_error)
      }
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      /*try:*/ {
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
          __Pyx_XGOTREF(__pyx_t_9);
          __Pyx_XGOTREF(__pyx_t_10);
          __Pyx_XGOTREF(__pyx_t_11);
          /*try:*/ {
            __pyx_v_ctx = __pyx_t_2;
            __pyx_t_2 = 0;

            /* "_mssql.pyx":804
 *             with decimal.localcontext() as ctx:
 *                 # Python 3 doesn't like decimal.localcontext() with prec == 0
 *                 ctx.prec = precision if precision > 0 else 1             # <<<<<<<<<<<<<<
 *                 return decimal.Decimal(_remove_locale(buf, converted_length).decode(self._charset))
 * 
 */
            if (((__pyx_v_precision > 0) != 0)) {
              __pyx_t_3 = __Pyx_PyInt_From_BYTE(__pyx_v_precision); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 804, __pyx_L15_error)
              __Pyx_GOTREF(__pyx_t_3);
              __pyx_t_2 = __pyx_t_3;
              __pyx_t_3 = 0;
            } else {
              __Pyx_INCREF(__pyx_int_1);
              __pyx_t_2 = __pyx_int_1;
            }
            if (__Pyx_PyObject_SetAttrStr(__pyx_v_ctx, __pyx_n_s_prec, __pyx_t_2) < 0) __PYX_ERR(0, 804, __pyx_L15_error)
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

            /* "_mssql.pyx":805
 *                 # Python 3 doesn't like decimal.localcontext() with prec == 0
 *                 ctx.prec = precision if precision > 0 else 1
 *                 return decimal.Decimal(_remove_locale(buf, converted_length).decode(self._charset))             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLDATETIM4:
 */
            __Pyx_XDECREF(__pyx_r);
            __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_decimal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 805, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Decimal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 805, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_12 = __pyx_f_6_mssql__remove_locale(__pyx_v_buf, __pyx_v_converted_length);
            __pyx_t_3 = __Pyx_decode_c_string(__pyx_t_12, 0, strlen(__pyx_t_12), __pyx_v_self->_charset, NULL, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 805, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_8 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
              __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
              if (likely(__pyx_t_8)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                __Pyx_INCREF(__pyx_t_8);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_1, function);
              }
            }
            if (!__pyx_t_8) {
              __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 805, __pyx_L15_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_GOTREF(__pyx_t_2);
            } else {
              __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 805, __pyx_L15_error)
              __Pyx_GOTREF(__pyx_t_13);
              __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_8); __pyx_t_8 = NULL;
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_GIVEREF(__pyx_t_3);
              PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_3);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 805, __pyx_L15_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_r = __pyx_t_2;
            __pyx_t_2 = 0;
            goto __pyx_L19_try_return;

            /* "_mssql.pyx":802
 *                 <BYTE *>buf, NUMERIC_BUF_SZ)
 * 
 *             with decimal.localcontext() as ctx:             # <<<<<<<<<<<<<<
 *                 # Python 3 doesn't like decimal.localcontext() with prec == 0
 *                 ctx.prec = precision if precision > 0 else 1
 */
          }
          __pyx_L15_error:;
          __Pyx_PyThreadState_assign
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          /*except:*/ {
            __Pyx_AddTraceback("_mssql.MSSQLConnection.convert_db_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
            if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_13) < 0) __PYX_ERR(0, 802, __pyx_L17_except_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_GOTREF(__pyx_t_13);
            __pyx_t_3 = PyTuple_Pack(3, __pyx_t_2, __pyx_t_1, __pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 802, __pyx_L17_except_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_3, NULL);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 802, __pyx_L17_except_error)
            __Pyx_GOTREF(__pyx_t_14);
            __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_14);
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            if (__pyx_t_4 < 0) __PYX_ERR(0, 802, __pyx_L17_except_error)
            __pyx_t_6 = ((!(__pyx_t_4 != 0)) != 0);
            if (__pyx_t_6) {
              __Pyx_GIVEREF(__pyx_t_2);
              __Pyx_GIVEREF(__pyx_t_1);
              __Pyx_XGIVEREF(__pyx_t_13);
              __Pyx_ErrRestoreWithState(__pyx_t_2, __pyx_t_1, __pyx_t_13);
              __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_13 = 0; 
              __PYX_ERR(0, 802, __pyx_L17_except_error)
            }
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            goto __pyx_L16_exception_handled;
          }
          __pyx_L17_except_error:;
          __Pyx_PyThreadState_assign
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_10);
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
          goto __pyx_L1_error;
          __pyx_L19_try_return:;
          __Pyx_PyThreadState_assign
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_10);
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
          goto __pyx_L12_return;
          __pyx_L16_exception_handled:;
          __Pyx_PyThreadState_assign
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_10);
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        }
      }
      /*finally:*/ {
        /*normal exit:*/{
          if (__pyx_t_7) {
            __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__17, NULL);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 802, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          }
          goto __pyx_L14;
        }
        __pyx_L12_return: {
          __pyx_t_11 = __pyx_r;
          __pyx_r = 0;
          if (__pyx_t_7) {
            __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__18, NULL);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 802, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          }
          __pyx_r = __pyx_t_11;
          __pyx_t_11 = 0;
          goto __pyx_L0;
        }
        __pyx_L14:;
      }
      goto __pyx_L26;
      __pyx_L11_error:;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L1_error;
      __pyx_L26:;
    }

    /* "_mssql.pyx":791
 *             return float(<double>(<DBFLT8 *>data)[0])
 * 
 *         elif dbtype in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):             # <<<<<<<<<<<<<<
 *             dbcol.SizeOfStruct = sizeof(dbcol)
 * 
 */
    goto __pyx_L3;
  }

  /* "_mssql.pyx":807
 *                 return decimal.Decimal(_remove_locale(buf, converted_length).decode(self._charset))
 * 
 *         elif dbtype == SQLDATETIM4:             # <<<<<<<<<<<<<<
 *             dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,
 *                 <BYTE *>&dt, -1)
 */
  __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 807, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDATETIM4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 807, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_13, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 807, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 807, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_6) {

    /* "_mssql.pyx":808
 * 
 *         elif dbtype == SQLDATETIM4:
 *             dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,             # <<<<<<<<<<<<<<
 *                 <BYTE *>&dt, -1)
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDATETIME); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 808, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 808, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "_mssql.pyx":809
 *         elif dbtype == SQLDATETIM4:
 *             dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,
 *                 <BYTE *>&dt, -1)             # <<<<<<<<<<<<<<
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)
 *             return datetime.datetime(di.year, di.month, di.day,
 */
    dbconvert(__pyx_v_self->dbproc, __pyx_v_dbtype, __pyx_v_data, -1, __pyx_t_5, ((BYTE *)(&__pyx_v_dt)), -1);

    /* "_mssql.pyx":810
 *             dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,
 *                 <BYTE *>&dt, -1)
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)             # <<<<<<<<<<<<<<
 *             return datetime.datetime(di.year, di.month, di.day,
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)
 */
    dbdatecrack(__pyx_v_self->dbproc, (&__pyx_v_di), ((DBDATETIME *)((BYTE *)(&__pyx_v_dt))));

    /* "_mssql.pyx":811
 *                 <BYTE *>&dt, -1)
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)
 *             return datetime.datetime(di.year, di.month, di.day,             # <<<<<<<<<<<<<<
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 811, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 811, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyInt_From_DBINT(__pyx_v_di.year); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 811, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_From_DBINT(__pyx_v_di.month); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 811, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = __Pyx_PyInt_From_DBINT(__pyx_v_di.day); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 811, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "_mssql.pyx":812
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)
 *             return datetime.datetime(di.year, di.month, di.day,
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLDATETIME:
 */
    __pyx_t_15 = __Pyx_PyInt_From_DBINT(__pyx_v_di.hour); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_16 = __Pyx_PyInt_From_DBINT(__pyx_v_di.minute); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_17 = __Pyx_PyInt_From_DBINT(__pyx_v_di.second); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __pyx_t_18 = __Pyx_PyInt_From_long((__pyx_v_di.millisecond * 0x3E8)); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_19 = NULL;
    __pyx_t_20 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) {
      __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_13);
      if (likely(__pyx_t_19)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
        __Pyx_INCREF(__pyx_t_19);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_13, function);
        __pyx_t_20 = 1;
      }
    }
    __pyx_t_21 = PyTuple_New(7+__pyx_t_20); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 811, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    if (__pyx_t_19) {
      __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_19); __pyx_t_19 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_21, 0+__pyx_t_20, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_21, 1+__pyx_t_20, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_21, 2+__pyx_t_20, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_21, 3+__pyx_t_20, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_21, 4+__pyx_t_20, __pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_17);
    PyTuple_SET_ITEM(__pyx_t_21, 5+__pyx_t_20, __pyx_t_17);
    __Pyx_GIVEREF(__pyx_t_18);
    PyTuple_SET_ITEM(__pyx_t_21, 6+__pyx_t_20, __pyx_t_18);
    __pyx_t_1 = 0;
    __pyx_t_3 = 0;
    __pyx_t_8 = 0;
    __pyx_t_15 = 0;
    __pyx_t_16 = 0;
    __pyx_t_17 = 0;
    __pyx_t_18 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_21, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 811, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":807
 *                 return decimal.Decimal(_remove_locale(buf, converted_length).decode(self._charset))
 * 
 *         elif dbtype == SQLDATETIM4:             # <<<<<<<<<<<<<<
 *             dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,
 *                 <BYTE *>&dt, -1)
 */
  }

  /* "_mssql.pyx":814
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)
 * 
 *         elif dbtype == SQLDATETIME:             # <<<<<<<<<<<<<<
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *>data)
 *             return datetime.datetime(di.year, di.month, di.day,
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 814, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDATETIME); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 814, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_21 = PyObject_RichCompare(__pyx_t_2, __pyx_t_13, Py_EQ); __Pyx_XGOTREF(__pyx_t_21); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 814, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_21); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 814, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  if (__pyx_t_6) {

    /* "_mssql.pyx":815
 * 
 *         elif dbtype == SQLDATETIME:
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *>data)             # <<<<<<<<<<<<<<
 *             return datetime.datetime(di.year, di.month, di.day,
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)
 */
    dbdatecrack(__pyx_v_self->dbproc, (&__pyx_v_di), ((DBDATETIME *)__pyx_v_data));

    /* "_mssql.pyx":816
 *         elif dbtype == SQLDATETIME:
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *>data)
 *             return datetime.datetime(di.year, di.month, di.day,             # <<<<<<<<<<<<<<
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_datetime); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = __Pyx_PyInt_From_DBINT(__pyx_v_di.year); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_18 = __Pyx_PyInt_From_DBINT(__pyx_v_di.month); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_17 = __Pyx_PyInt_From_DBINT(__pyx_v_di.day); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);

    /* "_mssql.pyx":817
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *>data)
 *             return datetime.datetime(di.year, di.month, di.day,
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 */
    __pyx_t_16 = __Pyx_PyInt_From_DBINT(__pyx_v_di.hour); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 817, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_15 = __Pyx_PyInt_From_DBINT(__pyx_v_di.minute); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 817, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_8 = __Pyx_PyInt_From_DBINT(__pyx_v_di.second); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 817, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_di.millisecond * 0x3E8)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 817, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = NULL;
    __pyx_t_20 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_20 = 1;
      }
    }
    __pyx_t_19 = PyTuple_New(7+__pyx_t_20); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_20, __pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_18);
    PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_20, __pyx_t_18);
    __Pyx_GIVEREF(__pyx_t_17);
    PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_20, __pyx_t_17);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_19, 3+__pyx_t_20, __pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_19, 4+__pyx_t_20, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_19, 5+__pyx_t_20, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_19, 6+__pyx_t_20, __pyx_t_3);
    __pyx_t_13 = 0;
    __pyx_t_18 = 0;
    __pyx_t_17 = 0;
    __pyx_t_16 = 0;
    __pyx_t_15 = 0;
    __pyx_t_8 = 0;
    __pyx_t_3 = 0;
    __pyx_t_21 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_19, NULL); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_21;
    __pyx_t_21 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":814
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)
 * 
 *         elif dbtype == SQLDATETIME:             # <<<<<<<<<<<<<<
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *>data)
 *             return datetime.datetime(di.year, di.month, di.day,
 */
  }

  /* "_mssql.pyx":819
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)
 * 
 *         elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):             # <<<<<<<<<<<<<<
 *             if strlen(self._charset):
 *                 return (<char *>data)[:length].decode(self._charset)
 */
  __pyx_t_5 = __pyx_v_dbtype;
  __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_21);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLVARCHAR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_19 = PyObject_RichCompare(__pyx_t_21, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_19); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_19); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  if (!__pyx_t_4) {
  } else {
    __pyx_t_6 = __pyx_t_4;
    goto __pyx_L27_bool_binop_done;
  }
  __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_21 = PyObject_RichCompare(__pyx_t_19, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_21); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_21); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  if (!__pyx_t_4) {
  } else {
    __pyx_t_6 = __pyx_t_4;
    goto __pyx_L27_bool_binop_done;
  }
  __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_t_5); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_21);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLTEXT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_19 = PyObject_RichCompare(__pyx_t_21, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_19); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_19); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 819, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __pyx_t_6 = __pyx_t_4;
  __pyx_L27_bool_binop_done:;
  __pyx_t_4 = (__pyx_t_6 != 0);
  if (__pyx_t_4) {

    /* "_mssql.pyx":820
 * 
 *         elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *             if strlen(self._charset):             # <<<<<<<<<<<<<<
 *                 return (<char *>data)[:length].decode(self._charset)
 *             else:
 */
    __pyx_t_4 = (strlen(__pyx_v_self->_charset) != 0);
    if (__pyx_t_4) {

      /* "_mssql.pyx":821
 *         elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *             if strlen(self._charset):
 *                 return (<char *>data)[:length].decode(self._charset)             # <<<<<<<<<<<<<<
 *             else:
 *                 return (<char *>data)[:length]
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_19 = __Pyx_decode_c_string(((char *)__pyx_v_data), 0, __pyx_v_length, __pyx_v_self->_charset, NULL, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 821, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_r = __pyx_t_19;
      __pyx_t_19 = 0;
      goto __pyx_L0;

      /* "_mssql.pyx":820
 * 
 *         elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *             if strlen(self._charset):             # <<<<<<<<<<<<<<
 *                 return (<char *>data)[:length].decode(self._charset)
 *             else:
 */
    }

    /* "_mssql.pyx":823
 *                 return (<char *>data)[:length].decode(self._charset)
 *             else:
 *                 return (<char *>data)[:length]             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLUUID:
 */
    /*else*/ {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_19 = __Pyx_PyBytes_FromStringAndSize(((char *)__pyx_v_data) + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 823, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_r = __pyx_t_19;
      __pyx_t_19 = 0;
      goto __pyx_L0;
    }

    /* "_mssql.pyx":819
 *                 di.hour, di.minute, di.second, di.millisecond * 1000)
 * 
 *         elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):             # <<<<<<<<<<<<<<
 *             if strlen(self._charset):
 *                 return (<char *>data)[:length].decode(self._charset)
 */
  }

  /* "_mssql.pyx":825
 *                 return (<char *>data)[:length]
 * 
 *         elif dbtype == SQLUUID:             # <<<<<<<<<<<<<<
 *             return uuid.UUID(bytes_le=(<char *>data)[:length])
 * 
 */
  __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 825, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLUUID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 825, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_21 = PyObject_RichCompare(__pyx_t_19, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_21); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 825, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_21); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 825, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":826
 * 
 *         elif dbtype == SQLUUID:
 *             return uuid.UUID(bytes_le=(<char *>data)[:length])             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_21 = __Pyx_GetModuleGlobalName(__pyx_n_s_uuid); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_UUID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __pyx_t_21 = PyDict_New(); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __pyx_t_19 = __Pyx_PyBytes_FromStringAndSize(((char *)__pyx_v_data) + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    if (PyDict_SetItem(__pyx_t_21, __pyx_n_s_bytes_le, __pyx_t_19) < 0) __PYX_ERR(0, 826, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_21); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __pyx_r = __pyx_t_19;
    __pyx_t_19 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":825
 *                 return (<char *>data)[:length]
 * 
 *         elif dbtype == SQLUUID:             # <<<<<<<<<<<<<<
 *             return uuid.UUID(bytes_le=(<char *>data)[:length])
 * 
 */
  }

  /* "_mssql.pyx":829
 * 
 *         else:
 *             return (<char *>data)[:length]             # <<<<<<<<<<<<<<
 * 
 *     cdef int convert_python_value(self, object value, BYTE **dbValue,
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_19 = __Pyx_PyBytes_FromStringAndSize(((char *)__pyx_v_data) + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 829, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_r = __pyx_t_19;
    __pyx_t_19 = 0;
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "_mssql.pyx":757
 *         connection_object_list.remove(self)
 * 
 *     cdef object convert_db_value(self, BYTE *data, int dbtype, int length):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.convert_db_value()")
 *         cdef char buf[NUMERIC_BUF_SZ] # buffer in which we store text rep of bug nums
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.convert_db_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ctx);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":831
 *             return (<char *>data)[:length]
 * 
 *     cdef int convert_python_value(self, object value, BYTE **dbValue,             # <<<<<<<<<<<<<<
 *             int *dbtype, int *length) except -1:
 *         log("_mssql.MSSQLConnection.convert_python_value()")
 */

static int __pyx_f_6_mssql_15MSSQLConnection_convert_python_value(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_value, BYTE **__pyx_v_dbValue, int *__pyx_v_dbtype, int *__pyx_v_length) {
  int *__pyx_v_intValue;
  double *__pyx_v_dblValue;
  float *__pyx_v_fltValue;
  PY_LONG_LONG *__pyx_v_longValue;
  char *__pyx_v_strValue;
  char *__pyx_v_tmp;
  BYTE *__pyx_v_binValue;
  DBTYPEINFO __pyx_v_decimal_type_info;
  PyObject *__pyx_v_bytes_value = NULL;
  DBDECIMAL *__pyx_v_decValue;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PY_LONG_LONG __pyx_t_7;
  float __pyx_t_8;
  double __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  DBINT __pyx_t_12;
  BYTE *__pyx_t_13;
  int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  char *__pyx_t_16;
  __Pyx_RefNannySetupContext("convert_python_value", 0);
  __Pyx_INCREF(__pyx_v_value);

  /* "_mssql.pyx":833
 *     cdef int convert_python_value(self, object value, BYTE **dbValue,
 *             int *dbtype, int *length) except -1:
 *         log("_mssql.MSSQLConnection.convert_python_value()")             # <<<<<<<<<<<<<<
 *         cdef int *intValue
 *         cdef double *dblValue
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.convert_python_value()"));

  /* "_mssql.pyx":846
 *             sys.stderr.write("convert_python_value: value = %r; dbtype = %d" % (value, dbtype[0]))
 * 
 *         if value is None:             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *>NULL
 *             return 0
 */
  __pyx_t_1 = (__pyx_v_value == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":847
 * 
 *         if value is None:
 *             dbValue[0] = <BYTE *>NULL             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)NULL);

    /* "_mssql.pyx":848
 *         if value is None:
 *             dbValue[0] = <BYTE *>NULL
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLBIT, SQLBITN):
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":846
 *             sys.stderr.write("convert_python_value: value = %r; dbtype = %d" % (value, dbtype[0]))
 * 
 *         if value is None:             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *>NULL
 *             return 0
 */
  }

  /* "_mssql.pyx":850
 *             return 0
 * 
 *         if dbtype[0] in (SQLBIT, SQLBITN):             # <<<<<<<<<<<<<<
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLBIT); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLBITN); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __pyx_t_1;
  __pyx_L5_bool_binop_done:;
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":851
 * 
 *         if dbtype[0] in (SQLBIT, SQLBITN):
 *             intValue = <int *>PyMem_Malloc(sizeof(int))             # <<<<<<<<<<<<<<
 *             intValue[0] = <int>value
 *             dbValue[0] = <BYTE *><DBBIT *>intValue
 */
    __pyx_v_intValue = ((int *)PyMem_Malloc((sizeof(int))));

    /* "_mssql.pyx":852
 *         if dbtype[0] in (SQLBIT, SQLBITN):
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *><DBBIT *>intValue
 *             return 0
 */
    __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 852, __pyx_L1_error)
    (__pyx_v_intValue[0]) = ((int)__pyx_t_3);

    /* "_mssql.pyx":853
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value
 *             dbValue[0] = <BYTE *><DBBIT *>intValue             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)((DBBIT *)__pyx_v_intValue));

    /* "_mssql.pyx":854
 *             intValue[0] = <int>value
 *             dbValue[0] = <BYTE *><DBBIT *>intValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] == SQLINTN:
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":850
 *             return 0
 * 
 *         if dbtype[0] in (SQLBIT, SQLBITN):             # <<<<<<<<<<<<<<
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value
 */
  }

  /* "_mssql.pyx":856
 *             return 0
 * 
 *         if dbtype[0] == SQLINTN:             # <<<<<<<<<<<<<<
 *             dbtype[0] = SQLINT4
 * 
 */
  __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 856, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINTN); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 856, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 856, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 856, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_1) {

    /* "_mssql.pyx":857
 * 
 *         if dbtype[0] == SQLINTN:
 *             dbtype[0] = SQLINT4             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLINT1, SQLINT2, SQLINT4):
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 857, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    (__pyx_v_dbtype[0]) = __pyx_t_3;

    /* "_mssql.pyx":856
 *             return 0
 * 
 *         if dbtype[0] == SQLINTN:             # <<<<<<<<<<<<<<
 *             dbtype[0] = SQLINT4
 * 
 */
  }

  /* "_mssql.pyx":859
 *             dbtype[0] = SQLINT4
 * 
 *         if dbtype[0] in (SQLINT1, SQLINT2, SQLINT4):             # <<<<<<<<<<<<<<
 *             if value > MAX_INT:
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L9_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L9_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __pyx_t_2;
  __pyx_L9_bool_binop_done:;
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":860
 * 
 *         if dbtype[0] in (SQLINT1, SQLINT2, SQLINT4):
 *             if value > MAX_INT:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)
 *             elif value < MIN_INT:
 */
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_6_mssql_MAX_INT); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_v_value, __pyx_t_4, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 860, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 860, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_2) {

      /* "_mssql.pyx":861
 *         if dbtype[0] in (SQLINT1, SQLINT2, SQLINT4):
 *             if value > MAX_INT:
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)             # <<<<<<<<<<<<<<
 *             elif value < MIN_INT:
 *                 raise MSSQLDriverException('value cannot be smaller than %d' % MIN_INT)
 */
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_6_mssql_MAX_INT); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 861, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_value_cannot_be_larger_than_d, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 861, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 861, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 861, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 861, __pyx_L1_error)

      /* "_mssql.pyx":860
 * 
 *         if dbtype[0] in (SQLINT1, SQLINT2, SQLINT4):
 *             if value > MAX_INT:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)
 *             elif value < MIN_INT:
 */
    }

    /* "_mssql.pyx":862
 *             if value > MAX_INT:
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)
 *             elif value < MIN_INT:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('value cannot be smaller than %d' % MIN_INT)
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 */
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_6_mssql_MIN_INT); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 862, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_v_value, __pyx_t_4, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 862, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 862, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_2) {

      /* "_mssql.pyx":863
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)
 *             elif value < MIN_INT:
 *                 raise MSSQLDriverException('value cannot be smaller than %d' % MIN_INT)             # <<<<<<<<<<<<<<
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value
 */
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_6_mssql_MIN_INT); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 863, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_value_cannot_be_smaller_than_d, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 863, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 863, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 863, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 863, __pyx_L1_error)

      /* "_mssql.pyx":862
 *             if value > MAX_INT:
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)
 *             elif value < MIN_INT:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('value cannot be smaller than %d' % MIN_INT)
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 */
    }

    /* "_mssql.pyx":864
 *             elif value < MIN_INT:
 *                 raise MSSQLDriverException('value cannot be smaller than %d' % MIN_INT)
 *             intValue = <int *>PyMem_Malloc(sizeof(int))             # <<<<<<<<<<<<<<
 *             intValue[0] = <int>value
 *             if dbtype[0] == SQLINT1:
 */
    __pyx_v_intValue = ((int *)PyMem_Malloc((sizeof(int))));

    /* "_mssql.pyx":865
 *                 raise MSSQLDriverException('value cannot be smaller than %d' % MIN_INT)
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value             # <<<<<<<<<<<<<<
 *             if dbtype[0] == SQLINT1:
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue
 */
    __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 865, __pyx_L1_error)
    (__pyx_v_intValue[0]) = ((int)__pyx_t_3);

    /* "_mssql.pyx":866
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value
 *             if dbtype[0] == SQLINT1:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue
 *                 return 0
 */
    __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 866, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 866, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 866, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 866, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_2) {

      /* "_mssql.pyx":867
 *             intValue[0] = <int>value
 *             if dbtype[0] == SQLINT1:
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue             # <<<<<<<<<<<<<<
 *                 return 0
 *             if dbtype[0] == SQLINT2:
 */
      (__pyx_v_dbValue[0]) = ((BYTE *)((DBTINYINT *)__pyx_v_intValue));

      /* "_mssql.pyx":868
 *             if dbtype[0] == SQLINT1:
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue
 *                 return 0             # <<<<<<<<<<<<<<
 *             if dbtype[0] == SQLINT2:
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue
 */
      __pyx_r = 0;
      goto __pyx_L0;

      /* "_mssql.pyx":866
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value
 *             if dbtype[0] == SQLINT1:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue
 *                 return 0
 */
    }

    /* "_mssql.pyx":869
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue
 *                 return 0
 *             if dbtype[0] == SQLINT2:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue
 *                 return 0
 */
    __pyx_t_6 = __Pyx_PyInt_From_int((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 869, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 869, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 869, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 869, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_2) {

      /* "_mssql.pyx":870
 *                 return 0
 *             if dbtype[0] == SQLINT2:
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue             # <<<<<<<<<<<<<<
 *                 return 0
 *             if dbtype[0] == SQLINT4:
 */
      (__pyx_v_dbValue[0]) = ((BYTE *)((DBSMALLINT *)__pyx_v_intValue));

      /* "_mssql.pyx":871
 *             if dbtype[0] == SQLINT2:
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue
 *                 return 0             # <<<<<<<<<<<<<<
 *             if dbtype[0] == SQLINT4:
 *                 dbValue[0] = <BYTE *><DBINT *>intValue
 */
      __pyx_r = 0;
      goto __pyx_L0;

      /* "_mssql.pyx":869
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue
 *                 return 0
 *             if dbtype[0] == SQLINT2:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue
 *                 return 0
 */
    }

    /* "_mssql.pyx":872
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue
 *                 return 0
 *             if dbtype[0] == SQLINT4:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBINT *>intValue
 *                 return 0
 */
    __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 872, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 872, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 872, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 872, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_2) {

      /* "_mssql.pyx":873
 *                 return 0
 *             if dbtype[0] == SQLINT4:
 *                 dbValue[0] = <BYTE *><DBINT *>intValue             # <<<<<<<<<<<<<<
 *                 return 0
 * 
 */
      (__pyx_v_dbValue[0]) = ((BYTE *)((DBINT *)__pyx_v_intValue));

      /* "_mssql.pyx":874
 *             if dbtype[0] == SQLINT4:
 *                 dbValue[0] = <BYTE *><DBINT *>intValue
 *                 return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] == SQLINT8:
 */
      __pyx_r = 0;
      goto __pyx_L0;

      /* "_mssql.pyx":872
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue
 *                 return 0
 *             if dbtype[0] == SQLINT4:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBINT *>intValue
 *                 return 0
 */
    }

    /* "_mssql.pyx":859
 *             dbtype[0] = SQLINT4
 * 
 *         if dbtype[0] in (SQLINT1, SQLINT2, SQLINT4):             # <<<<<<<<<<<<<<
 *             if value > MAX_INT:
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)
 */
  }

  /* "_mssql.pyx":876
 *                 return 0
 * 
 *         if dbtype[0] == SQLINT8:             # <<<<<<<<<<<<<<
 *             longValue = <PY_LONG_LONG *>PyMem_Malloc(sizeof(PY_LONG_LONG))
 *             longValue[0] = <PY_LONG_LONG>value
 */
  __pyx_t_6 = __Pyx_PyInt_From_int((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 876, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 876, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 876, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 876, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":877
 * 
 *         if dbtype[0] == SQLINT8:
 *             longValue = <PY_LONG_LONG *>PyMem_Malloc(sizeof(PY_LONG_LONG))             # <<<<<<<<<<<<<<
 *             longValue[0] = <PY_LONG_LONG>value
 *             dbValue[0] = <BYTE *>longValue
 */
    __pyx_v_longValue = ((PY_LONG_LONG *)PyMem_Malloc((sizeof(PY_LONG_LONG))));

    /* "_mssql.pyx":878
 *         if dbtype[0] == SQLINT8:
 *             longValue = <PY_LONG_LONG *>PyMem_Malloc(sizeof(PY_LONG_LONG))
 *             longValue[0] = <PY_LONG_LONG>value             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *>longValue
 *             return 0
 */
    __pyx_t_7 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_value); if (unlikely((__pyx_t_7 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 878, __pyx_L1_error)
    (__pyx_v_longValue[0]) = ((PY_LONG_LONG)__pyx_t_7);

    /* "_mssql.pyx":879
 *             longValue = <PY_LONG_LONG *>PyMem_Malloc(sizeof(PY_LONG_LONG))
 *             longValue[0] = <PY_LONG_LONG>value
 *             dbValue[0] = <BYTE *>longValue             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)__pyx_v_longValue);

    /* "_mssql.pyx":880
 *             longValue[0] = <PY_LONG_LONG>value
 *             dbValue[0] = <BYTE *>longValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLFLT4, SQLREAL):
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":876
 *                 return 0
 * 
 *         if dbtype[0] == SQLINT8:             # <<<<<<<<<<<<<<
 *             longValue = <PY_LONG_LONG *>PyMem_Malloc(sizeof(PY_LONG_LONG))
 *             longValue[0] = <PY_LONG_LONG>value
 */
  }

  /* "_mssql.pyx":882
 *             return 0
 * 
 *         if dbtype[0] in (SQLFLT4, SQLREAL):             # <<<<<<<<<<<<<<
 *             fltValue = <float *>PyMem_Malloc(sizeof(float))
 *             fltValue[0] = <float>value
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLFLT4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L18_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLREAL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __pyx_t_1;
  __pyx_L18_bool_binop_done:;
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":883
 * 
 *         if dbtype[0] in (SQLFLT4, SQLREAL):
 *             fltValue = <float *>PyMem_Malloc(sizeof(float))             # <<<<<<<<<<<<<<
 *             fltValue[0] = <float>value
 *             dbValue[0] = <BYTE *><DBREAL *>fltValue
 */
    __pyx_v_fltValue = ((float *)PyMem_Malloc((sizeof(float))));

    /* "_mssql.pyx":884
 *         if dbtype[0] in (SQLFLT4, SQLREAL):
 *             fltValue = <float *>PyMem_Malloc(sizeof(float))
 *             fltValue[0] = <float>value             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *><DBREAL *>fltValue
 *             return 0
 */
    __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 884, __pyx_L1_error)
    (__pyx_v_fltValue[0]) = ((float)__pyx_t_8);

    /* "_mssql.pyx":885
 *             fltValue = <float *>PyMem_Malloc(sizeof(float))
 *             fltValue[0] = <float>value
 *             dbValue[0] = <BYTE *><DBREAL *>fltValue             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)((DBREAL *)__pyx_v_fltValue));

    /* "_mssql.pyx":886
 *             fltValue[0] = <float>value
 *             dbValue[0] = <BYTE *><DBREAL *>fltValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] == SQLFLT8:
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":882
 *             return 0
 * 
 *         if dbtype[0] in (SQLFLT4, SQLREAL):             # <<<<<<<<<<<<<<
 *             fltValue = <float *>PyMem_Malloc(sizeof(float))
 *             fltValue[0] = <float>value
 */
  }

  /* "_mssql.pyx":888
 *             return 0
 * 
 *         if dbtype[0] == SQLFLT8:             # <<<<<<<<<<<<<<
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))
 *             dblValue[0] = <double>value
 */
  __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLFLT8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 888, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 888, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_1) {

    /* "_mssql.pyx":889
 * 
 *         if dbtype[0] == SQLFLT8:
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))             # <<<<<<<<<<<<<<
 *             dblValue[0] = <double>value
 *             dbValue[0] = <BYTE *><DBFLT8 *>dblValue
 */
    __pyx_v_dblValue = ((double *)PyMem_Malloc((sizeof(double))));

    /* "_mssql.pyx":890
 *         if dbtype[0] == SQLFLT8:
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))
 *             dblValue[0] = <double>value             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *><DBFLT8 *>dblValue
 *             return 0
 */
    __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 890, __pyx_L1_error)
    (__pyx_v_dblValue[0]) = ((double)__pyx_t_9);

    /* "_mssql.pyx":891
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))
 *             dblValue[0] = <double>value
 *             dbValue[0] = <BYTE *><DBFLT8 *>dblValue             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)((DBFLT8 *)__pyx_v_dblValue));

    /* "_mssql.pyx":892
 *             dblValue[0] = <double>value
 *             dbValue[0] = <BYTE *><DBFLT8 *>dblValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLDATETIM4, SQLDATETIME):
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":888
 *             return 0
 * 
 *         if dbtype[0] == SQLFLT8:             # <<<<<<<<<<<<<<
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))
 *             dblValue[0] = <double>value
 */
  }

  /* "_mssql.pyx":894
 *             return 0
 * 
 *         if dbtype[0] in (SQLDATETIM4, SQLDATETIME):             # <<<<<<<<<<<<<<
 *             if type(value) not in (datetime.date, datetime.datetime):
 *                 raise TypeError('value can only be a date or datetime')
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDATETIM4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L22_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDATETIME); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __pyx_t_2;
  __pyx_L22_bool_binop_done:;
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":895
 * 
 *         if dbtype[0] in (SQLDATETIM4, SQLDATETIME):
 *             if type(value) not in (datetime.date, datetime.datetime):             # <<<<<<<<<<<<<<
 *                 raise TypeError('value can only be a date or datetime')
 * 
 */
    __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
    __pyx_t_6 = ((PyObject *)Py_TYPE(__pyx_v_value));
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_datetime); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_date); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_RichCompare(((PyObject *)__pyx_t_6), __pyx_t_4, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L25_bool_binop_done;
    }
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_datetime); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_RichCompare(((PyObject *)__pyx_t_6), __pyx_t_4, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __pyx_t_1;
    __pyx_L25_bool_binop_done:;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "_mssql.pyx":896
 *         if dbtype[0] in (SQLDATETIM4, SQLDATETIME):
 *             if type(value) not in (datetime.date, datetime.datetime):
 *                 raise TypeError('value can only be a date or datetime')             # <<<<<<<<<<<<<<
 * 
 *             value = value.strftime('%Y-%m-%d %H:%M:%S.') + \
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 896, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(0, 896, __pyx_L1_error)

      /* "_mssql.pyx":895
 * 
 *         if dbtype[0] in (SQLDATETIM4, SQLDATETIME):
 *             if type(value) not in (datetime.date, datetime.datetime):             # <<<<<<<<<<<<<<
 *                 raise TypeError('value can only be a date or datetime')
 * 
 */
    }

    /* "_mssql.pyx":898
 *                 raise TypeError('value can only be a date or datetime')
 * 
 *             value = value.strftime('%Y-%m-%d %H:%M:%S.') + \             # <<<<<<<<<<<<<<
 *                 "%03d" % (value.microsecond // 1000)
 *             value = value.encode(self.charset)
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_strftime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 898, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 898, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "_mssql.pyx":899
 * 
 *             value = value.strftime('%Y-%m-%d %H:%M:%S.') + \
 *                 "%03d" % (value.microsecond // 1000)             # <<<<<<<<<<<<<<
 *             value = value.encode(self.charset)
 *             dbtype[0] = SQLCHAR
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_microsecond); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_PyInt_FloorDivideObjC(__pyx_t_6, __pyx_int_1000, 0x3E8, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_03d, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "_mssql.pyx":898
 *                 raise TypeError('value can only be a date or datetime')
 * 
 *             value = value.strftime('%Y-%m-%d %H:%M:%S.') + \             # <<<<<<<<<<<<<<
 *                 "%03d" % (value.microsecond // 1000)
 *             value = value.encode(self.charset)
 */
    __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 898, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "_mssql.pyx":900
 *             value = value.strftime('%Y-%m-%d %H:%M:%S.') + \
 *                 "%03d" % (value.microsecond // 1000)
 *             value = value.encode(self.charset)             # <<<<<<<<<<<<<<
 *             dbtype[0] = SQLCHAR
 * 
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 900, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_charset); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 900, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_10 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (!__pyx_t_10) {
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 900, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 900, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 900, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "_mssql.pyx":901
 *                 "%03d" % (value.microsecond // 1000)
 *             value = value.encode(self.charset)
 *             dbtype[0] = SQLCHAR             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLNUMERIC, SQLDECIMAL):
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 901, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 901, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    (__pyx_v_dbtype[0]) = __pyx_t_3;

    /* "_mssql.pyx":894
 *             return 0
 * 
 *         if dbtype[0] in (SQLDATETIM4, SQLDATETIME):             # <<<<<<<<<<<<<<
 *             if type(value) not in (datetime.date, datetime.datetime):
 *                 raise TypeError('value can only be a date or datetime')
 */
  }

  /* "_mssql.pyx":903
 *             dbtype[0] = SQLCHAR
 * 
 *         if dbtype[0] in (SQLNUMERIC, SQLDECIMAL):             # <<<<<<<<<<<<<<
 *             # There seems to be no harm in setting precision higher than
 *             # necessary
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLNUMERIC); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_11 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L28_bool_binop_done;
  }
  __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDECIMAL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_11, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __pyx_t_2;
  __pyx_L28_bool_binop_done:;
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":906
 *             # There seems to be no harm in setting precision higher than
 *             # necessary
 *             decimal_type_info.precision = 33             # <<<<<<<<<<<<<<
 * 
 *             # Figure out `scale` - number of digits after decimal point
 */
    __pyx_v_decimal_type_info.precision = 33;

    /* "_mssql.pyx":909
 * 
 *             # Figure out `scale` - number of digits after decimal point
 *             decimal_type_info.scale = abs(value.as_tuple().exponent)             # <<<<<<<<<<<<<<
 * 
 *             # Need this to prevent Cython error:
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_as_tuple); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_11 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (__pyx_t_11) {
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 909, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else {
      __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 909, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exponent); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Absolute(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_12 = __Pyx_PyInt_As_DBINT(__pyx_t_4); if (unlikely((__pyx_t_12 == (DBINT)-1) && PyErr_Occurred())) __PYX_ERR(0, 909, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_decimal_type_info.scale = __pyx_t_12;

    /* "_mssql.pyx":914
 *             # "Obtaining 'BYTE *' from temporary Python value"
 *             # bytes_value = bytes(str(value), encoding="ascii")
 *             bytes_value = unicode(value).encode("ascii")             # <<<<<<<<<<<<<<
 * 
 *             decValue = <DBDECIMAL *>PyMem_Malloc(sizeof(DBDECIMAL))
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_value);
    __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)(&PyUnicode_Type)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyUnicode_AsASCIIString(((PyObject*)__pyx_t_6)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_bytes_value = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "_mssql.pyx":916
 *             bytes_value = unicode(value).encode("ascii")
 * 
 *             decValue = <DBDECIMAL *>PyMem_Malloc(sizeof(DBDECIMAL))             # <<<<<<<<<<<<<<
 *             length[0] = dbconvert_ps(
 *                 self.dbproc,
 */
    __pyx_v_decValue = ((DBDECIMAL *)PyMem_Malloc((sizeof(DBDECIMAL))));

    /* "_mssql.pyx":919
 *             length[0] = dbconvert_ps(
 *                 self.dbproc,
 *                 SQLCHAR,             # <<<<<<<<<<<<<<
 *                 bytes_value,
 *                 -1,
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 919, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 919, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "_mssql.pyx":920
 *                 self.dbproc,
 *                 SQLCHAR,
 *                 bytes_value,             # <<<<<<<<<<<<<<
 *                 -1,
 *                 dbtype[0],
 */
    __pyx_t_13 = __Pyx_PyObject_AsUString(__pyx_v_bytes_value); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 920, __pyx_L1_error)

    /* "_mssql.pyx":917
 * 
 *             decValue = <DBDECIMAL *>PyMem_Malloc(sizeof(DBDECIMAL))
 *             length[0] = dbconvert_ps(             # <<<<<<<<<<<<<<
 *                 self.dbproc,
 *                 SQLCHAR,
 */
    (__pyx_v_length[0]) = dbconvert_ps(__pyx_v_self->dbproc, __pyx_t_3, __pyx_t_13, -1, (__pyx_v_dbtype[0]), ((BYTE *)__pyx_v_decValue), (sizeof(DBDECIMAL)), (&__pyx_v_decimal_type_info));

    /* "_mssql.pyx":927
 *                 &decimal_type_info,
 *             )
 *             dbValue[0] = <BYTE *>decValue             # <<<<<<<<<<<<<<
 * 
 *             IF PYMSSQL_DEBUG == 1:
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)__pyx_v_decValue);

    /* "_mssql.pyx":934
 *                     fprintf(stderr, "convert_python_value: dbValue[0][%d] = %d\n", i, dbValue[0][i])
 * 
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":903
 *             dbtype[0] = SQLCHAR
 * 
 *         if dbtype[0] in (SQLNUMERIC, SQLDECIMAL):             # <<<<<<<<<<<<<<
 *             # There seems to be no harm in setting precision higher than
 *             # necessary
 */
  }

  /* "_mssql.pyx":936
 *             return 0
 * 
 *         if dbtype[0] in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):             # <<<<<<<<<<<<<<
 *             if type(value) in (int, long, bytes):
 *                 value = decimal.Decimal(value)
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEY); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_11 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (!__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L31_bool_binop_done;
  }
  __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEY4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_11, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L31_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLNUMERIC); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_11 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (!__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L31_bool_binop_done;
  }
  __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDECIMAL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_11, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __pyx_t_1;
  __pyx_L31_bool_binop_done:;
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":937
 * 
 *         if dbtype[0] in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):
 *             if type(value) in (int, long, bytes):             # <<<<<<<<<<<<<<
 *                 value = decimal.Decimal(value)
 * 
 */
    __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
    __pyx_t_4 = ((PyObject *)Py_TYPE(__pyx_v_value));
    __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_t_4), ((PyObject *)(&PyInt_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 937, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 937, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_t_4), ((PyObject *)(&PyLong_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 937, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 937, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_t_4), ((PyObject *)(&PyBytes_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 937, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 937, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_1 = __pyx_t_2;
    __pyx_L36_bool_binop_done:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":938
 *         if dbtype[0] in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):
 *             if type(value) in (int, long, bytes):
 *                 value = decimal.Decimal(value)             # <<<<<<<<<<<<<<
 * 
 *             if type(value) not in (decimal.Decimal, float):
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_decimal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 938, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_Decimal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 938, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
        }
      }
      if (!__pyx_t_6) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 938, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 938, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
        __Pyx_INCREF(__pyx_v_value);
        __Pyx_GIVEREF(__pyx_v_value);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_value);
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 938, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "_mssql.pyx":937
 * 
 *         if dbtype[0] in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):
 *             if type(value) in (int, long, bytes):             # <<<<<<<<<<<<<<
 *                 value = decimal.Decimal(value)
 * 
 */
    }

    /* "_mssql.pyx":940
 *                 value = decimal.Decimal(value)
 * 
 *             if type(value) not in (decimal.Decimal, float):             # <<<<<<<<<<<<<<
 *                 raise TypeError('value can only be a Decimal')
 * 
 */
    __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
    __pyx_t_4 = ((PyObject *)Py_TYPE(__pyx_v_value));
    __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_decimal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 940, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_Decimal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 940, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_RichCompare(((PyObject *)__pyx_t_4), __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 940, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 940, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    if (__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L40_bool_binop_done;
    }
    __pyx_t_11 = PyObject_RichCompare(((PyObject *)__pyx_t_4), ((PyObject *)(&PyFloat_Type)), Py_NE); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 940, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 940, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_2 = __pyx_t_1;
    __pyx_L40_bool_binop_done:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "_mssql.pyx":941
 * 
 *             if type(value) not in (decimal.Decimal, float):
 *                 raise TypeError('value can only be a Decimal')             # <<<<<<<<<<<<<<
 * 
 *             value = str(value)
 */
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 941, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 941, __pyx_L1_error)

      /* "_mssql.pyx":940
 *                 value = decimal.Decimal(value)
 * 
 *             if type(value) not in (decimal.Decimal, float):             # <<<<<<<<<<<<<<
 *                 raise TypeError('value can only be a Decimal')
 * 
 */
    }

    /* "_mssql.pyx":943
 *                 raise TypeError('value can only be a Decimal')
 * 
 *             value = str(value)             # <<<<<<<<<<<<<<
 *             dbtype[0] = SQLCHAR
 * 
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_value);
    __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)(&PyString_Type)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_11);
    __pyx_t_11 = 0;

    /* "_mssql.pyx":944
 * 
 *             value = str(value)
 *             dbtype[0] = SQLCHAR             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 */
    __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 944, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 944, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    (__pyx_v_dbtype[0]) = __pyx_t_3;

    /* "_mssql.pyx":936
 *             return 0
 * 
 *         if dbtype[0] in (SQLMONEY, SQLMONEY4, SQLNUMERIC, SQLDECIMAL):             # <<<<<<<<<<<<<<
 *             if type(value) in (int, long, bytes):
 *                 value = decimal.Decimal(value)
 */
  }

  /* "_mssql.pyx":946
 *             dbtype[0] = SQLCHAR
 * 
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):             # <<<<<<<<<<<<<<
 *             if not hasattr(value, 'startswith'):
 *                 raise TypeError('value must be a string type')
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLVARCHAR); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_11, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L43_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L43_bool_binop_done;
  }
  __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLTEXT); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_11, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __pyx_t_2;
  __pyx_L43_bool_binop_done:;
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":947
 * 
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *             if not hasattr(value, 'startswith'):             # <<<<<<<<<<<<<<
 *                 raise TypeError('value must be a string type')
 * 
 */
    __pyx_t_2 = PyObject_HasAttr(__pyx_v_value, __pyx_n_s_startswith); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 947, __pyx_L1_error)
    __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0);
    if (__pyx_t_1) {

      /* "_mssql.pyx":948
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *             if not hasattr(value, 'startswith'):
 *                 raise TypeError('value must be a string type')             # <<<<<<<<<<<<<<
 * 
 *             if strlen(self._charset) > 0 and type(value) is unicode:
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 948, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 948, __pyx_L1_error)

      /* "_mssql.pyx":947
 * 
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *             if not hasattr(value, 'startswith'):             # <<<<<<<<<<<<<<
 *                 raise TypeError('value must be a string type')
 * 
 */
    }

    /* "_mssql.pyx":950
 *                 raise TypeError('value must be a string type')
 * 
 *             if strlen(self._charset) > 0 and type(value) is unicode:             # <<<<<<<<<<<<<<
 *                 value = value.encode(self.charset)
 * 
 */
    __pyx_t_2 = ((strlen(__pyx_v_self->_charset) > 0) != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L48_bool_binop_done;
    }
    __pyx_t_2 = (((PyObject *)Py_TYPE(__pyx_v_value)) == ((PyObject *)(&PyUnicode_Type)));
    __pyx_t_14 = (__pyx_t_2 != 0);
    __pyx_t_1 = __pyx_t_14;
    __pyx_L48_bool_binop_done:;
    if (__pyx_t_1) {

      /* "_mssql.pyx":951
 * 
 *             if strlen(self._charset) > 0 and type(value) is unicode:
 *                 value = value.encode(self.charset)             # <<<<<<<<<<<<<<
 * 
 *             strValue = <char *>PyMem_Malloc(len(value) + 1)
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 951, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_charset); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 951, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_6 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (!__pyx_t_6) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 951, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 951, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_6); __pyx_t_6 = NULL;
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_11);
        __pyx_t_11 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 951, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "_mssql.pyx":950
 *                 raise TypeError('value must be a string type')
 * 
 *             if strlen(self._charset) > 0 and type(value) is unicode:             # <<<<<<<<<<<<<<
 *                 value = value.encode(self.charset)
 * 
 */
    }

    /* "_mssql.pyx":953
 *                 value = value.encode(self.charset)
 * 
 *             strValue = <char *>PyMem_Malloc(len(value) + 1)             # <<<<<<<<<<<<<<
 *             tmp = value
 *             strncpy(strValue, tmp, len(value) + 1)
 */
    __pyx_t_15 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 953, __pyx_L1_error)
    __pyx_v_strValue = ((char *)PyMem_Malloc((__pyx_t_15 + 1)));

    /* "_mssql.pyx":954
 * 
 *             strValue = <char *>PyMem_Malloc(len(value) + 1)
 *             tmp = value             # <<<<<<<<<<<<<<
 *             strncpy(strValue, tmp, len(value) + 1)
 *             strValue[ len(value) ] = '\0';
 */
    __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 954, __pyx_L1_error)
    __pyx_v_tmp = __pyx_t_16;

    /* "_mssql.pyx":955
 *             strValue = <char *>PyMem_Malloc(len(value) + 1)
 *             tmp = value
 *             strncpy(strValue, tmp, len(value) + 1)             # <<<<<<<<<<<<<<
 *             strValue[ len(value) ] = '\0';
 *             dbValue[0] = <BYTE *>strValue
 */
    __pyx_t_15 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 955, __pyx_L1_error)
    strncpy(__pyx_v_strValue, __pyx_v_tmp, (__pyx_t_15 + 1));

    /* "_mssql.pyx":956
 *             tmp = value
 *             strncpy(strValue, tmp, len(value) + 1)
 *             strValue[ len(value) ] = '\0';             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *>strValue
 *             return 0
 */
    __pyx_t_15 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 956, __pyx_L1_error)
    (__pyx_v_strValue[__pyx_t_15]) = '\x00';

    /* "_mssql.pyx":957
 *             strncpy(strValue, tmp, len(value) + 1)
 *             strValue[ len(value) ] = '\0';
 *             dbValue[0] = <BYTE *>strValue             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)__pyx_v_strValue);

    /* "_mssql.pyx":958
 *             strValue[ len(value) ] = '\0';
 *             dbValue[0] = <BYTE *>strValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":946
 *             dbtype[0] = SQLCHAR
 * 
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):             # <<<<<<<<<<<<<<
 *             if not hasattr(value, 'startswith'):
 *                 raise TypeError('value must be a string type')
 */
  }

  /* "_mssql.pyx":960
 *             return 0
 * 
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):             # <<<<<<<<<<<<<<
 *             if type(value) is not str:
 *                 raise TypeError('value can only be str')
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLBINARY); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_10 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (!__pyx_t_14) {
  } else {
    __pyx_t_1 = __pyx_t_14;
    goto __pyx_L51_bool_binop_done;
  }
  __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLVARBINARY); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_10, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_14) {
  } else {
    __pyx_t_1 = __pyx_t_14;
    goto __pyx_L51_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLIMAGE); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_10 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 960, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_1 = __pyx_t_14;
  __pyx_L51_bool_binop_done:;
  __pyx_t_14 = (__pyx_t_1 != 0);
  if (__pyx_t_14) {

    /* "_mssql.pyx":961
 * 
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):
 *             if type(value) is not str:             # <<<<<<<<<<<<<<
 *                 raise TypeError('value can only be str')
 * 
 */
    __pyx_t_14 = (((PyObject *)Py_TYPE(__pyx_v_value)) != ((PyObject *)(&PyString_Type)));
    __pyx_t_1 = (__pyx_t_14 != 0);
    if (__pyx_t_1) {

      /* "_mssql.pyx":962
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):
 *             if type(value) is not str:
 *                 raise TypeError('value can only be str')             # <<<<<<<<<<<<<<
 * 
 *             binValue = <BYTE *>PyMem_Malloc(len(value))
 */
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 962, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_Raise(__pyx_t_10, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __PYX_ERR(0, 962, __pyx_L1_error)

      /* "_mssql.pyx":961
 * 
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):
 *             if type(value) is not str:             # <<<<<<<<<<<<<<
 *                 raise TypeError('value can only be str')
 * 
 */
    }

    /* "_mssql.pyx":964
 *                 raise TypeError('value can only be str')
 * 
 *             binValue = <BYTE *>PyMem_Malloc(len(value))             # <<<<<<<<<<<<<<
 *             memcpy(binValue, <char *>value, len(value))
 *             length[0] = len(value)
 */
    __pyx_t_15 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 964, __pyx_L1_error)
    __pyx_v_binValue = ((BYTE *)PyMem_Malloc(__pyx_t_15));

    /* "_mssql.pyx":965
 * 
 *             binValue = <BYTE *>PyMem_Malloc(len(value))
 *             memcpy(binValue, <char *>value, len(value))             # <<<<<<<<<<<<<<
 *             length[0] = len(value)
 *             dbValue[0] = <BYTE *>binValue
 */
    __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 965, __pyx_L1_error)
    __pyx_t_15 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 965, __pyx_L1_error)
    memcpy(__pyx_v_binValue, ((char *)__pyx_t_16), __pyx_t_15);

    /* "_mssql.pyx":966
 *             binValue = <BYTE *>PyMem_Malloc(len(value))
 *             memcpy(binValue, <char *>value, len(value))
 *             length[0] = len(value)             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *>binValue
 *             return 0
 */
    __pyx_t_15 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 966, __pyx_L1_error)
    (__pyx_v_length[0]) = __pyx_t_15;

    /* "_mssql.pyx":967
 *             memcpy(binValue, <char *>value, len(value))
 *             length[0] = len(value)
 *             dbValue[0] = <BYTE *>binValue             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)__pyx_v_binValue);

    /* "_mssql.pyx":968
 *             length[0] = len(value)
 *             dbValue[0] = <BYTE *>binValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] == SQLUUID:
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":960
 *             return 0
 * 
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):             # <<<<<<<<<<<<<<
 *             if type(value) is not str:
 *                 raise TypeError('value can only be str')
 */
  }

  /* "_mssql.pyx":970
 *             return 0
 * 
 *         if dbtype[0] == SQLUUID:             # <<<<<<<<<<<<<<
 *             binValue = <BYTE *>PyMem_Malloc(16)
 *             memcpy(binValue, <char *>value.bytes_le, 16)
 */
  __pyx_t_10 = __Pyx_PyInt_From_int((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLUUID); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_10, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 970, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 970, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_1) {

    /* "_mssql.pyx":971
 * 
 *         if dbtype[0] == SQLUUID:
 *             binValue = <BYTE *>PyMem_Malloc(16)             # <<<<<<<<<<<<<<
 *             memcpy(binValue, <char *>value.bytes_le, 16)
 *             length[0] = 16
 */
    __pyx_v_binValue = ((BYTE *)PyMem_Malloc(16));

    /* "_mssql.pyx":972
 *         if dbtype[0] == SQLUUID:
 *             binValue = <BYTE *>PyMem_Malloc(16)
 *             memcpy(binValue, <char *>value.bytes_le, 16)             # <<<<<<<<<<<<<<
 *             length[0] = 16
 *             dbValue[0] = <BYTE *>binValue
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_bytes_le); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 972, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_t_5); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 972, __pyx_L1_error)
    memcpy(__pyx_v_binValue, ((char *)__pyx_t_16), 16);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "_mssql.pyx":973
 *             binValue = <BYTE *>PyMem_Malloc(16)
 *             memcpy(binValue, <char *>value.bytes_le, 16)
 *             length[0] = 16             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *>binValue
 *             return 0
 */
    (__pyx_v_length[0]) = 16;

    /* "_mssql.pyx":974
 *             memcpy(binValue, <char *>value.bytes_le, 16)
 *             length[0] = 16
 *             dbValue[0] = <BYTE *>binValue             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)__pyx_v_binValue);

    /* "_mssql.pyx":975
 *             length[0] = 16
 *             dbValue[0] = <BYTE *>binValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         # No conversion was possible so raise an error
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":970
 *             return 0
 * 
 *         if dbtype[0] == SQLUUID:             # <<<<<<<<<<<<<<
 *             binValue = <BYTE *>PyMem_Malloc(16)
 *             memcpy(binValue, <char *>value.bytes_le, 16)
 */
  }

  /* "_mssql.pyx":978
 * 
 *         # No conversion was possible so raise an error
 *         raise MSSQLDriverException('Unable to convert value')             # <<<<<<<<<<<<<<
 * 
 *     cpdef execute_non_query(self, query_string, params=None):
 */
  __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 978, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_Raise(__pyx_t_5, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __PYX_ERR(0, 978, __pyx_L1_error)

  /* "_mssql.pyx":831
 *             return (<char *>data)[:length]
 * 
 *     cdef int convert_python_value(self, object value, BYTE **dbValue,             # <<<<<<<<<<<<<<
 *             int *dbtype, int *length) except -1:
 *         log("_mssql.MSSQLConnection.convert_python_value()")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.convert_python_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_bytes_value);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":980
 *         raise MSSQLDriverException('Unable to convert value')
 * 
 *     cpdef execute_non_query(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_non_query(query_string, params=None)
 */

static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_21execute_non_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_execute_non_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_non_query *__pyx_optional_args) {
  PyObject *__pyx_v_params = ((PyObject *)Py_None);
  RETCODE __pyx_v_rtc;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query __pyx_t_7;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("execute_non_query", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_params = __pyx_optional_args->params;
    }
  }
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_execute_non_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 980, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_21execute_non_query)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      __pyx_t_5 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_5 = 1;
        }
      }
      __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 980, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_query_string);
      __Pyx_GIVEREF(__pyx_v_query_string);
      PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_query_string);
      __Pyx_INCREF(__pyx_v_params);
      __Pyx_GIVEREF(__pyx_v_params);
      PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_params);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 980, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":998
 *         rows affected by the last SQL command.
 *         """
 *         log("_mssql.MSSQLConnection.execute_non_query() BEGIN")             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 * 
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.execute_non_query() BEGIN"));

  /* "_mssql.pyx":1001
 *         cdef RETCODE rtc
 * 
 *         self.format_and_run_query(query_string, params)             # <<<<<<<<<<<<<<
 * 
 *         with nogil:
 */
  __pyx_t_7.__pyx_n = 1;
  __pyx_t_7.params = __pyx_v_params;
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->format_and_run_query(__pyx_v_self, __pyx_v_query_string, &__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1001, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1003
 *         self.format_and_run_query(query_string, params)
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             dbresults(self.dbproc)
 *             self._rows_affected = dbcount(self.dbproc)
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":1004
 * 
 *         with nogil:
 *             dbresults(self.dbproc)             # <<<<<<<<<<<<<<
 *             self._rows_affected = dbcount(self.dbproc)
 * 
 */
        dbresults(__pyx_v_self->dbproc);

        /* "_mssql.pyx":1005
 *         with nogil:
 *             dbresults(self.dbproc)
 *             self._rows_affected = dbcount(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *         rtc = db_cancel(self)
 */
        __pyx_v_self->_rows_affected = dbcount(__pyx_v_self->dbproc);
      }

      /* "_mssql.pyx":1003
 *         self.format_and_run_query(query_string, params)
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             dbresults(self.dbproc)
 *             self._rows_affected = dbcount(self.dbproc)
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "_mssql.pyx":1007
 *             self._rows_affected = dbcount(self.dbproc)
 * 
 *         rtc = db_cancel(self)             # <<<<<<<<<<<<<<
 *         check_and_raise(rtc, self)
 *         log("_mssql.MSSQLConnection.execute_non_query() END")
 */
  __pyx_v_rtc = __pyx_f_6_mssql_db_cancel(__pyx_v_self);

  /* "_mssql.pyx":1008
 * 
 *         rtc = db_cancel(self)
 *         check_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.execute_non_query() END")
 * 
 */
  __pyx_t_8 = __pyx_f_6_mssql_check_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_8 == 1)) __PYX_ERR(0, 1008, __pyx_L1_error)

  /* "_mssql.pyx":1009
 *         rtc = db_cancel(self)
 *         check_and_raise(rtc, self)
 *         log("_mssql.MSSQLConnection.execute_non_query() END")             # <<<<<<<<<<<<<<
 * 
 *     cpdef execute_query(self, query_string, params=None):
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.execute_non_query() END"));

  /* "_mssql.pyx":980
 *         raise MSSQLDriverException('Unable to convert value')
 * 
 *     cpdef execute_non_query(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_non_query(query_string, params=None)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_non_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_21execute_non_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_20execute_non_query[] = "\n        execute_non_query(query_string, params=None)\n\n        This method sends a query to the MS SQL Server to which this object\n        instance is connected. After completion, its results (if any) are\n        discarded. An exception is raised on failure. If there are any pending\n        results or rows prior to executing this command, they are silently\n        discarded. This method accepts Python formatting. Please see\n        execute_query() for more details.\n\n        This method is useful for INSERT, UPDATE, DELETE and for Data\n        Definition Language commands, i.e. when you need to alter your database\n        schema.\n\n        After calling this method, rows_affected property contains number of\n        rows affected by the last SQL command.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_21execute_non_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query_string = 0;
  PyObject *__pyx_v_params = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("execute_non_query (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query_string,&__pyx_n_s_params,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query_string)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "execute_non_query") < 0)) __PYX_ERR(0, 980, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_query_string = values[0];
    __pyx_v_params = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("execute_non_query", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 980, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_non_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_20execute_non_query(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_query_string, __pyx_v_params);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_20execute_non_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, PyObject *__pyx_v_params) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_non_query __pyx_t_2;
  __Pyx_RefNannySetupContext("execute_non_query", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.params = __pyx_v_params;
  __pyx_t_1 = __pyx_vtabptr_6_mssql_MSSQLConnection->execute_non_query(__pyx_v_self, __pyx_v_query_string, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 980, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_non_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1011
 *         log("_mssql.MSSQLConnection.execute_non_query() END")
 * 
 *     cpdef execute_query(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_query(query_string, params=None)
 */

static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_23execute_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_execute_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_query *__pyx_optional_args) {
  PyObject *__pyx_v_params = ((PyObject *)Py_None);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query __pyx_t_7;
  __Pyx_RefNannySetupContext("execute_query", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_params = __pyx_optional_args->params;
    }
  }
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_execute_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1011, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_23execute_query)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      __pyx_t_5 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_5 = 1;
        }
      }
      __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1011, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_query_string);
      __Pyx_GIVEREF(__pyx_v_query_string);
      PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_query_string);
      __Pyx_INCREF(__pyx_v_params);
      __Pyx_GIVEREF(__pyx_v_params);
      PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_params);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1011, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":1041
 *         last command (this is how MS SQL returns it).
 *         """
 *         log("_mssql.MSSQLConnection.execute_query() BEGIN")             # <<<<<<<<<<<<<<
 *         self.format_and_run_query(query_string, params)
 *         self.get_result()
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.execute_query() BEGIN"));

  /* "_mssql.pyx":1042
 *         """
 *         log("_mssql.MSSQLConnection.execute_query() BEGIN")
 *         self.format_and_run_query(query_string, params)             # <<<<<<<<<<<<<<
 *         self.get_result()
 *         log("_mssql.MSSQLConnection.execute_query() END")
 */
  __pyx_t_7.__pyx_n = 1;
  __pyx_t_7.params = __pyx_v_params;
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->format_and_run_query(__pyx_v_self, __pyx_v_query_string, &__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1042, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1043
 *         log("_mssql.MSSQLConnection.execute_query() BEGIN")
 *         self.format_and_run_query(query_string, params)
 *         self.get_result()             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.execute_query() END")
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->get_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1043, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1044
 *         self.format_and_run_query(query_string, params)
 *         self.get_result()
 *         log("_mssql.MSSQLConnection.execute_query() END")             # <<<<<<<<<<<<<<
 * 
 *     cpdef execute_row(self, query_string, params=None):
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.execute_query() END"));

  /* "_mssql.pyx":1011
 *         log("_mssql.MSSQLConnection.execute_non_query() END")
 * 
 *     cpdef execute_query(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_query(query_string, params=None)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_23execute_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_22execute_query[] = "\n        execute_query(query_string, params=None)\n\n        This method sends a query to the MS SQL Server to which this object\n        instance is connected. An exception is raised on failure. If there\n        are pending results or rows prior to executing this command, they\n        are silently discarded. After calling this method you may iterate\n        over the connection object to get rows returned by the query.\n\n        You can use Python formatting here and all values get properly\n        quoted:\n            conn.execute_query('SELECT * FROM empl WHERE id=%d', 13)\n            conn.execute_query('SELECT * FROM empl WHERE id IN (%s)', ((5,6),))\n            conn.execute_query('SELECT * FROM empl WHERE name=%s', 'John Doe')\n            conn.execute_query('SELECT * FROM empl WHERE name LIKE %s', 'J%')\n            conn.execute_query('SELECT * FROM empl WHERE name=%(name)s AND                 city=%(city)s', { 'name': 'John Doe', 'city': 'Nowhere' } )\n            conn.execute_query('SELECT * FROM cust WHERE salesrep=%s                 AND id IN (%s)', ('John Doe', (1,2,3)))\n            conn.execute_query('SELECT * FROM empl WHERE id IN (%s)',                (tuple(xrange(4)),))\n            conn.execute_query('SELECT * FROM empl WHERE id IN (%s)',                (tuple([3,5,7,11]),))\n\n        This method is intented to be used on queries that return results,\n        i.e. SELECT. After calling this method AND reading all rows from,\n        result rows_affected property contains number of rows returned by\n        last command (this is how MS SQL returns it).\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_23execute_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query_string = 0;
  PyObject *__pyx_v_params = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("execute_query (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query_string,&__pyx_n_s_params,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query_string)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "execute_query") < 0)) __PYX_ERR(0, 1011, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_query_string = values[0];
    __pyx_v_params = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("execute_query", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1011, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_22execute_query(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_query_string, __pyx_v_params);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_22execute_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, PyObject *__pyx_v_params) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_query __pyx_t_2;
  __Pyx_RefNannySetupContext("execute_query", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.params = __pyx_v_params;
  __pyx_t_1 = __pyx_vtabptr_6_mssql_MSSQLConnection->execute_query(__pyx_v_self, __pyx_v_query_string, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1046
 *         log("_mssql.MSSQLConnection.execute_query() END")
 * 
 *     cpdef execute_row(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_row(query_string, params=None)
 */

static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_25execute_row(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_execute_row(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_row *__pyx_optional_args) {
  PyObject *__pyx_v_params = ((PyObject *)Py_None);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query __pyx_t_7;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("execute_row", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_params = __pyx_optional_args->params;
    }
  }
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_execute_row); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_25execute_row)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      __pyx_t_5 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_5 = 1;
        }
      }
      __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1046, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_query_string);
      __Pyx_GIVEREF(__pyx_v_query_string);
      PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_query_string);
      __Pyx_INCREF(__pyx_v_params);
      __Pyx_GIVEREF(__pyx_v_params);
      PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_params);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1046, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":1067
 *         rows, if any, can still be iterated after calling this method.
 *         """
 *         log("_mssql.MSSQLConnection.execute_row()")             # <<<<<<<<<<<<<<
 *         self.format_and_run_query(query_string, params)
 *         return self.fetch_next_row(0, ROW_FORMAT_DICT)
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.execute_row()"));

  /* "_mssql.pyx":1068
 *         """
 *         log("_mssql.MSSQLConnection.execute_row()")
 *         self.format_and_run_query(query_string, params)             # <<<<<<<<<<<<<<
 *         return self.fetch_next_row(0, ROW_FORMAT_DICT)
 * 
 */
  __pyx_t_7.__pyx_n = 1;
  __pyx_t_7.params = __pyx_v_params;
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->format_and_run_query(__pyx_v_self, __pyx_v_query_string, &__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1068, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1069
 *         log("_mssql.MSSQLConnection.execute_row()")
 *         self.format_and_run_query(query_string, params)
 *         return self.fetch_next_row(0, ROW_FORMAT_DICT)             # <<<<<<<<<<<<<<
 * 
 *     cpdef execute_scalar(self, query_string, params=None):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ROW_FORMAT_DICT); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1069, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1069, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->fetch_next_row(__pyx_v_self, 0, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1069, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1046
 *         log("_mssql.MSSQLConnection.execute_query() END")
 * 
 *     cpdef execute_row(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_row(query_string, params=None)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_row", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_25execute_row(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_24execute_row[] = "\n        execute_row(query_string, params=None)\n\n        This method sends a query to the MS SQL Server to which this object\n        instance is connected, then returns first row of data from result.\n\n        An exception is raised on failure. If there are pending results or\n        rows prior to executing this command, they are silently discarded.\n\n        This method accepts Python formatting. Please see execute_query()\n        for details.\n\n        This method is useful if you want just a single row and don't want\n        or don't need to iterate, as in:\n\n        conn.execute_row('SELECT * FROM employees WHERE id=%d', 13)\n\n        This method works exactly the same as 'iter(conn).next()'. Remaining\n        rows, if any, can still be iterated after calling this method.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_25execute_row(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query_string = 0;
  PyObject *__pyx_v_params = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("execute_row (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query_string,&__pyx_n_s_params,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query_string)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "execute_row") < 0)) __PYX_ERR(0, 1046, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_query_string = values[0];
    __pyx_v_params = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("execute_row", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1046, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_row", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_24execute_row(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_query_string, __pyx_v_params);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_24execute_row(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, PyObject *__pyx_v_params) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_row __pyx_t_2;
  __Pyx_RefNannySetupContext("execute_row", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.params = __pyx_v_params;
  __pyx_t_1 = __pyx_vtabptr_6_mssql_MSSQLConnection->execute_row(__pyx_v_self, __pyx_v_query_string, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1046, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_row", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1071
 *         return self.fetch_next_row(0, ROW_FORMAT_DICT)
 * 
 *     cpdef execute_scalar(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_scalar(query_string, params=None)
 */

static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_27execute_scalar(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6_mssql_15MSSQLConnection_execute_scalar(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_scalar *__pyx_optional_args) {
  PyObject *__pyx_v_params = ((PyObject *)Py_None);
  RETCODE __pyx_v_rtc;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  __Pyx_RefNannySetupContext("execute_scalar", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_params = __pyx_optional_args->params;
    }
  }
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_execute_scalar); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1071, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_27execute_scalar)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      __pyx_t_5 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_5 = 1;
        }
      }
      __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1071, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_query_string);
      __Pyx_GIVEREF(__pyx_v_query_string);
      PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_query_string);
      __Pyx_INCREF(__pyx_v_params);
      __Pyx_GIVEREF(__pyx_v_params);
      PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_params);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1071, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":1093
 *         """
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.execute_scalar()")             # <<<<<<<<<<<<<<
 * 
 *         self.format_and_run_query(query_string, params)
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.execute_scalar()"));

  /* "_mssql.pyx":1095
 *         log("_mssql.MSSQLConnection.execute_scalar()")
 * 
 *         self.format_and_run_query(query_string, params)             # <<<<<<<<<<<<<<
 *         self.get_result()
 * 
 */
  __pyx_t_7.__pyx_n = 1;
  __pyx_t_7.params = __pyx_v_params;
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->format_and_run_query(__pyx_v_self, __pyx_v_query_string, &__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1095, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1096
 * 
 *         self.format_and_run_query(query_string, params)
 *         self.get_result()             # <<<<<<<<<<<<<<
 * 
 *         with nogil:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->get_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1098
 *         self.get_result()
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbnextrow(self.dbproc)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":1099
 * 
 *         with nogil:
 *             rtc = dbnextrow(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *         self._rows_affected = dbcount(self.dbproc)
 */
        __pyx_v_rtc = dbnextrow(__pyx_v_self->dbproc);
      }

      /* "_mssql.pyx":1098
 *         self.get_result()
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbnextrow(self.dbproc)
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "_mssql.pyx":1101
 *             rtc = dbnextrow(self.dbproc)
 * 
 *         self._rows_affected = dbcount(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *         if rtc == NO_MORE_ROWS:
 */
  __pyx_v_self->_rows_affected = dbcount(__pyx_v_self->dbproc);

  /* "_mssql.pyx":1103
 *         self._rows_affected = dbcount(self.dbproc)
 * 
 *         if rtc == NO_MORE_ROWS:             # <<<<<<<<<<<<<<
 *             self.clear_metadata()
 *             self.last_dbresults = 0
 */
  __pyx_t_8 = ((__pyx_v_rtc == NO_MORE_ROWS) != 0);
  if (__pyx_t_8) {

    /* "_mssql.pyx":1104
 * 
 *         if rtc == NO_MORE_ROWS:
 *             self.clear_metadata()             # <<<<<<<<<<<<<<
 *             self.last_dbresults = 0
 *             return None
 */
    ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->clear_metadata(__pyx_v_self);

    /* "_mssql.pyx":1105
 *         if rtc == NO_MORE_ROWS:
 *             self.clear_metadata()
 *             self.last_dbresults = 0             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
    __pyx_v_self->last_dbresults = 0;

    /* "_mssql.pyx":1106
 *             self.clear_metadata()
 *             self.last_dbresults = 0
 *             return None             # <<<<<<<<<<<<<<
 * 
 *         return self.get_row(rtc, ROW_FORMAT_TUPLE)[0]
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "_mssql.pyx":1103
 *         self._rows_affected = dbcount(self.dbproc)
 * 
 *         if rtc == NO_MORE_ROWS:             # <<<<<<<<<<<<<<
 *             self.clear_metadata()
 *             self.last_dbresults = 0
 */
  }

  /* "_mssql.pyx":1108
 *             return None
 * 
 *         return self.get_row(rtc, ROW_FORMAT_TUPLE)[0]             # <<<<<<<<<<<<<<
 * 
 *     cdef fetch_next_row(self, int throw, int row_format):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ROW_FORMAT_TUPLE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1108, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->get_row(__pyx_v_self, __pyx_v_rtc, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1071
 *         return self.fetch_next_row(0, ROW_FORMAT_DICT)
 * 
 *     cpdef execute_scalar(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_scalar(query_string, params=None)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_27execute_scalar(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_26execute_scalar[] = "\n        execute_scalar(query_string, params=None)\n\n        This method sends a query to the MS SQL Server to which this object\n        instance is connected, then returns first column of first row from\n        result. An exception is raised on failure. If there are pending\n\n        results or rows prior to executing this command, they are silently\n        discarded.\n\n        This method accepts Python formatting. Please see execute_query()\n        for details.\n\n        This method is useful if you want just a single value, as in:\n            conn.execute_scalar('SELECT COUNT(*) FROM employees')\n\n        This method works in the same way as 'iter(conn).next()[0]'.\n        Remaining rows, if any, can still be iterated after calling this\n        method.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_27execute_scalar(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query_string = 0;
  PyObject *__pyx_v_params = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("execute_scalar (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query_string,&__pyx_n_s_params,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query_string)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "execute_scalar") < 0)) __PYX_ERR(0, 1071, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_query_string = values[0];
    __pyx_v_params = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("execute_scalar", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1071, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_26execute_scalar(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_query_string, __pyx_v_params);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_26execute_scalar(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, PyObject *__pyx_v_params) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_scalar __pyx_t_2;
  __Pyx_RefNannySetupContext("execute_scalar", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.params = __pyx_v_params;
  __pyx_t_1 = __pyx_vtabptr_6_mssql_MSSQLConnection->execute_scalar(__pyx_v_self, __pyx_v_query_string, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1071, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.execute_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1110
 *         return self.get_row(rtc, ROW_FORMAT_TUPLE)[0]
 * 
 *     cdef fetch_next_row(self, int throw, int row_format):             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.fetch_next_row() BEGIN")
 */

static PyObject *__pyx_f_6_mssql_15MSSQLConnection_fetch_next_row(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_v_throw, int __pyx_v_row_format) {
  RETCODE __pyx_v_rtc;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  char const *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  __Pyx_RefNannySetupContext("fetch_next_row", 0);

  /* "_mssql.pyx":1112
 *     cdef fetch_next_row(self, int throw, int row_format):
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.fetch_next_row() BEGIN")             # <<<<<<<<<<<<<<
 *         try:
 *             self.get_result()
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.fetch_next_row() BEGIN"));

  /* "_mssql.pyx":1113
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.fetch_next_row() BEGIN")
 *         try:             # <<<<<<<<<<<<<<
 *             self.get_result()
 * 
 */
  /*try:*/ {

    /* "_mssql.pyx":1114
 *         log("_mssql.MSSQLConnection.fetch_next_row() BEGIN")
 *         try:
 *             self.get_result()             # <<<<<<<<<<<<<<
 * 
 *             if self.last_dbresults == NO_MORE_RESULTS:
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->get_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1114, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1116
 *             self.get_result()
 * 
 *             if self.last_dbresults == NO_MORE_RESULTS:             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE RESULTS")
 *                 self.clear_metadata()
 */
    __pyx_t_2 = ((__pyx_v_self->last_dbresults == NO_MORE_RESULTS) != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1117
 * 
 *             if self.last_dbresults == NO_MORE_RESULTS:
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE RESULTS")             # <<<<<<<<<<<<<<
 *                 self.clear_metadata()
 *                 if throw:
 */
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.fetch_next_row(): NO MORE RESULTS"));

      /* "_mssql.pyx":1118
 *             if self.last_dbresults == NO_MORE_RESULTS:
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE RESULTS")
 *                 self.clear_metadata()             # <<<<<<<<<<<<<<
 *                 if throw:
 *                     raise StopIteration
 */
      ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->clear_metadata(__pyx_v_self);

      /* "_mssql.pyx":1119
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE RESULTS")
 *                 self.clear_metadata()
 *                 if throw:             # <<<<<<<<<<<<<<
 *                     raise StopIteration
 *                 return None
 */
      __pyx_t_2 = (__pyx_v_throw != 0);
      if (__pyx_t_2) {

        /* "_mssql.pyx":1120
 *                 self.clear_metadata()
 *                 if throw:
 *                     raise StopIteration             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
        __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
        __PYX_ERR(0, 1120, __pyx_L4_error)

        /* "_mssql.pyx":1119
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE RESULTS")
 *                 self.clear_metadata()
 *                 if throw:             # <<<<<<<<<<<<<<
 *                     raise StopIteration
 *                 return None
 */
      }

      /* "_mssql.pyx":1121
 *                 if throw:
 *                     raise StopIteration
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             with nogil:
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L3_return;

      /* "_mssql.pyx":1116
 *             self.get_result()
 * 
 *             if self.last_dbresults == NO_MORE_RESULTS:             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE RESULTS")
 *                 self.clear_metadata()
 */
    }

    /* "_mssql.pyx":1123
 *                 return None
 * 
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 rtc = dbnextrow(self.dbproc)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        #endif
        /*try:*/ {

          /* "_mssql.pyx":1124
 * 
 *             with nogil:
 *                 rtc = dbnextrow(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *             check_cancel_and_raise(rtc, self)
 */
          __pyx_v_rtc = dbnextrow(__pyx_v_self->dbproc);
        }

        /* "_mssql.pyx":1123
 *                 return None
 * 
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 rtc = dbnextrow(self.dbproc)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L10;
          }
          __pyx_L10:;
        }
    }

    /* "_mssql.pyx":1126
 *                 rtc = dbnextrow(self.dbproc)
 * 
 *             check_cancel_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 * 
 *             if rtc == NO_MORE_ROWS:
 */
    __pyx_t_3 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_3 == 1)) __PYX_ERR(0, 1126, __pyx_L4_error)

    /* "_mssql.pyx":1128
 *             check_cancel_and_raise(rtc, self)
 * 
 *             if rtc == NO_MORE_ROWS:             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE ROWS")
 *                 self.clear_metadata()
 */
    __pyx_t_2 = ((__pyx_v_rtc == NO_MORE_ROWS) != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1129
 * 
 *             if rtc == NO_MORE_ROWS:
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE ROWS")             # <<<<<<<<<<<<<<
 *                 self.clear_metadata()
 *                 # 'rows_affected' is nonzero only after all records are read
 */
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.fetch_next_row(): NO MORE ROWS"));

      /* "_mssql.pyx":1130
 *             if rtc == NO_MORE_ROWS:
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE ROWS")
 *                 self.clear_metadata()             # <<<<<<<<<<<<<<
 *                 # 'rows_affected' is nonzero only after all records are read
 *                 self._rows_affected = dbcount(self.dbproc)
 */
      ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->clear_metadata(__pyx_v_self);

      /* "_mssql.pyx":1132
 *                 self.clear_metadata()
 *                 # 'rows_affected' is nonzero only after all records are read
 *                 self._rows_affected = dbcount(self.dbproc)             # <<<<<<<<<<<<<<
 *                 if throw:
 *                     raise StopIteration
 */
      __pyx_v_self->_rows_affected = dbcount(__pyx_v_self->dbproc);

      /* "_mssql.pyx":1133
 *                 # 'rows_affected' is nonzero only after all records are read
 *                 self._rows_affected = dbcount(self.dbproc)
 *                 if throw:             # <<<<<<<<<<<<<<
 *                     raise StopIteration
 *                 return None
 */
      __pyx_t_2 = (__pyx_v_throw != 0);
      if (__pyx_t_2) {

        /* "_mssql.pyx":1134
 *                 self._rows_affected = dbcount(self.dbproc)
 *                 if throw:
 *                     raise StopIteration             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
        __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
        __PYX_ERR(0, 1134, __pyx_L4_error)

        /* "_mssql.pyx":1133
 *                 # 'rows_affected' is nonzero only after all records are read
 *                 self._rows_affected = dbcount(self.dbproc)
 *                 if throw:             # <<<<<<<<<<<<<<
 *                     raise StopIteration
 *                 return None
 */
      }

      /* "_mssql.pyx":1135
 *                 if throw:
 *                     raise StopIteration
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             return self.get_row(rtc, row_format)
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L3_return;

      /* "_mssql.pyx":1128
 *             check_cancel_and_raise(rtc, self)
 * 
 *             if rtc == NO_MORE_ROWS:             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.fetch_next_row(): NO MORE ROWS")
 *                 self.clear_metadata()
 */
    }

    /* "_mssql.pyx":1137
 *                 return None
 * 
 *             return self.get_row(rtc, row_format)             # <<<<<<<<<<<<<<
 *         finally:
 *             log("_mssql.MSSQLConnection.fetch_next_row() END")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->get_row(__pyx_v_self, __pyx_v_rtc, __pyx_v_row_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1137, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L3_return;
  }

  /* "_mssql.pyx":1139
 *             return self.get_row(rtc, row_format)
 *         finally:
 *             log("_mssql.MSSQLConnection.fetch_next_row() END")             # <<<<<<<<<<<<<<
 * 
 *     cdef format_and_run_query(self, query_string, params=None):
 */
  /*finally:*/ {
    /*exception exit:*/{
      __Pyx_PyThreadState_declare
      __pyx_L4_error:;
      __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0;
      __Pyx_PyThreadState_assign
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_11);
      __pyx_t_3 = __pyx_lineno; __pyx_t_4 = __pyx_clineno; __pyx_t_5 = __pyx_filename;
      {
        __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.fetch_next_row() END"));
      }
      __Pyx_PyThreadState_assign
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_ErrRestore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
      __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0;
      __pyx_lineno = __pyx_t_3; __pyx_clineno = __pyx_t_4; __pyx_filename = __pyx_t_5;
      goto __pyx_L1_error;
    }
    __pyx_L3_return: {
      __pyx_t_11 = __pyx_r;
      __pyx_r = 0;
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.fetch_next_row() END"));
      __pyx_r = __pyx_t_11;
      __pyx_t_11 = 0;
      goto __pyx_L0;
    }
  }

  /* "_mssql.pyx":1110
 *         return self.get_row(rtc, ROW_FORMAT_TUPLE)[0]
 * 
 *     cdef fetch_next_row(self, int throw, int row_format):             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.fetch_next_row() BEGIN")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.fetch_next_row", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1141
 *             log("_mssql.MSSQLConnection.fetch_next_row() END")
 * 
 *     cdef format_and_run_query(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         This is a helper function, which does most of the work needed by any
 */

static PyObject *__pyx_f_6_mssql_15MSSQLConnection_format_and_run_query(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_query_string, struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query *__pyx_optional_args) {
  PyObject *__pyx_v_params = ((PyObject *)Py_None);
  RETCODE __pyx_v_rtc;
  PyObject *__pyx_v_query_string_bytes = 0;
  char *__pyx_v_query_string_cstr;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_sql_command __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  struct __pyx_opt_args_6_mssql_ensure_bytes __pyx_t_5;
  char *__pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_t_11;
  char const *__pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  __Pyx_RefNannySetupContext("format_and_run_query", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_params = __pyx_optional_args->params;
    }
  }
  __Pyx_INCREF(__pyx_v_query_string);

  /* "_mssql.pyx":1152
 *         cdef char *query_string_cstr
 * 
 *         log("_mssql.MSSQLConnection.format_and_run_query() BEGIN")             # <<<<<<<<<<<<<<
 * 
 *         try:
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.format_and_run_query() BEGIN"));

  /* "_mssql.pyx":1154
 *         log("_mssql.MSSQLConnection.format_and_run_query() BEGIN")
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             # Cancel any pending results
 *             self.cancel()
 */
  /*try:*/ {

    /* "_mssql.pyx":1156
 *         try:
 *             # Cancel any pending results
 *             self.cancel()             # <<<<<<<<<<<<<<
 * 
 *             if params:
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->cancel(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1156, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1158
 *             self.cancel()
 * 
 *             if params:             # <<<<<<<<<<<<<<
 *                 query_string = self.format_sql_command(query_string, params)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_params); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1158, __pyx_L4_error)
    if (__pyx_t_2) {

      /* "_mssql.pyx":1159
 * 
 *             if params:
 *                 query_string = self.format_sql_command(query_string, params)             # <<<<<<<<<<<<<<
 * 
 *             # For Python 3, we need to convert unicode to byte strings
 */
      __pyx_t_3.__pyx_n = 1;
      __pyx_t_3.params = __pyx_v_params;
      __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->format_sql_command(__pyx_v_self, __pyx_v_query_string, &__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1159, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_query_string, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "_mssql.pyx":1158
 *             self.cancel()
 * 
 *             if params:             # <<<<<<<<<<<<<<
 *                 query_string = self.format_sql_command(query_string, params)
 * 
 */
    }

    /* "_mssql.pyx":1162
 * 
 *             # For Python 3, we need to convert unicode to byte strings
 *             query_string_bytes = ensure_bytes(query_string, self.charset)             # <<<<<<<<<<<<<<
 *             query_string_cstr = query_string_bytes
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_charset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1162, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5.__pyx_n = 1;
    __pyx_t_5.encoding = __pyx_t_1;
    __pyx_t_4 = __pyx_f_6_mssql_ensure_bytes(__pyx_v_query_string, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1162, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_query_string_bytes = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "_mssql.pyx":1163
 *             # For Python 3, we need to convert unicode to byte strings
 *             query_string_bytes = ensure_bytes(query_string, self.charset)
 *             query_string_cstr = query_string_bytes             # <<<<<<<<<<<<<<
 * 
 *             log(query_string_cstr)
 */
    __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_query_string_bytes); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 1163, __pyx_L4_error)
    __pyx_v_query_string_cstr = __pyx_t_6;

    /* "_mssql.pyx":1165
 *             query_string_cstr = query_string_bytes
 * 
 *             log(query_string_cstr)             # <<<<<<<<<<<<<<
 *             if self.debug_queries:
 *                 sys.stderr.write("#%s#\n" % query_string)
 */
    __pyx_f_6_mssql_log(__pyx_v_query_string_cstr);

    /* "_mssql.pyx":1166
 * 
 *             log(query_string_cstr)
 *             if self.debug_queries:             # <<<<<<<<<<<<<<
 *                 sys.stderr.write("#%s#\n" % query_string)
 * 
 */
    __pyx_t_2 = (__pyx_v_self->debug_queries != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1167
 *             log(query_string_cstr)
 *             if self.debug_queries:
 *                 sys.stderr.write("#%s#\n" % query_string)             # <<<<<<<<<<<<<<
 * 
 *             # Prepare the query buffer
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1167, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_stderr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1167, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_write); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1167, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_query_string); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1167, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      if (!__pyx_t_8) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1167, __pyx_L4_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_4);
      } else {
        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1167, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7);
        __pyx_t_7 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1167, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "_mssql.pyx":1166
 * 
 *             log(query_string_cstr)
 *             if self.debug_queries:             # <<<<<<<<<<<<<<
 *                 sys.stderr.write("#%s#\n" % query_string)
 * 
 */
    }

    /* "_mssql.pyx":1170
 * 
 *             # Prepare the query buffer
 *             dbcmd(self.dbproc, query_string_cstr)             # <<<<<<<<<<<<<<
 * 
 *             # Execute the query
 */
    dbcmd(__pyx_v_self->dbproc, __pyx_v_query_string_cstr);

    /* "_mssql.pyx":1173
 * 
 *             # Execute the query
 *             rtc = db_sqlexec(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *             check_cancel_and_raise(rtc, self)
 */
    __pyx_v_rtc = __pyx_f_6_mssql_db_sqlexec(__pyx_v_self->dbproc);

    /* "_mssql.pyx":1175
 *             rtc = db_sqlexec(self.dbproc)
 * 
 *             check_cancel_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 *         finally:
 *             log("_mssql.MSSQLConnection.format_and_run_query() END")
 */
    __pyx_t_10 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_10 == 1)) __PYX_ERR(0, 1175, __pyx_L4_error)
  }

  /* "_mssql.pyx":1177
 *             check_cancel_and_raise(rtc, self)
 *         finally:
 *             log("_mssql.MSSQLConnection.format_and_run_query() END")             # <<<<<<<<<<<<<<
 * 
 *     cdef format_sql_command(self, format, params=None):
 */
  /*finally:*/ {
    /*normal exit:*/{
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.format_and_run_query() END"));
      goto __pyx_L5;
    }
    /*exception exit:*/{
      __Pyx_PyThreadState_declare
      __pyx_L4_error:;
      __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0;
      __Pyx_PyThreadState_assign
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15) < 0)) __Pyx_ErrFetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
      __Pyx_XGOTREF(__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_14);
      __Pyx_XGOTREF(__pyx_t_15);
      __Pyx_XGOTREF(__pyx_t_16);
      __Pyx_XGOTREF(__pyx_t_17);
      __Pyx_XGOTREF(__pyx_t_18);
      __pyx_t_10 = __pyx_lineno; __pyx_t_11 = __pyx_clineno; __pyx_t_12 = __pyx_filename;
      {
        __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.format_and_run_query() END"));
      }
      __Pyx_PyThreadState_assign
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_XGIVEREF(__pyx_t_17);
        __Pyx_XGIVEREF(__pyx_t_18);
        __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
      }
      __Pyx_XGIVEREF(__pyx_t_13);
      __Pyx_XGIVEREF(__pyx_t_14);
      __Pyx_XGIVEREF(__pyx_t_15);
      __Pyx_ErrRestore(__pyx_t_13, __pyx_t_14, __pyx_t_15);
      __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0;
      __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_11; __pyx_filename = __pyx_t_12;
      goto __pyx_L1_error;
    }
    __pyx_L5:;
  }

  /* "_mssql.pyx":1141
 *             log("_mssql.MSSQLConnection.fetch_next_row() END")
 * 
 *     cdef format_and_run_query(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         This is a helper function, which does most of the work needed by any
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.format_and_run_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_query_string_bytes);
  __Pyx_XDECREF(__pyx_v_query_string);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1179
 *             log("_mssql.MSSQLConnection.format_and_run_query() END")
 * 
 *     cdef format_sql_command(self, format, params=None):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.format_sql_command()")
 *         return _substitute_params(format, params, self.charset)
 */

static PyObject *__pyx_f_6_mssql_15MSSQLConnection_format_sql_command(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_format, struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_sql_command *__pyx_optional_args) {
  PyObject *__pyx_v_params = ((PyObject *)Py_None);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("format_sql_command", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_params = __pyx_optional_args->params;
    }
  }

  /* "_mssql.pyx":1180
 * 
 *     cdef format_sql_command(self, format, params=None):
 *         log("_mssql.MSSQLConnection.format_sql_command()")             # <<<<<<<<<<<<<<
 *         return _substitute_params(format, params, self.charset)
 * 
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.format_sql_command()"));

  /* "_mssql.pyx":1181
 *     cdef format_sql_command(self, format, params=None):
 *         log("_mssql.MSSQLConnection.format_sql_command()")
 *         return _substitute_params(format, params, self.charset)             # <<<<<<<<<<<<<<
 * 
 *     def get_header(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_charset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_f_6_mssql__substitute_params(__pyx_v_format, __pyx_v_params, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1179
 *             log("_mssql.MSSQLConnection.format_and_run_query() END")
 * 
 *     cdef format_sql_command(self, format, params=None):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.format_sql_command()")
 *         return _substitute_params(format, params, self.charset)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.format_sql_command", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1183
 *         return _substitute_params(format, params, self.charset)
 * 
 *     def get_header(self):             # <<<<<<<<<<<<<<
 *         """
 *         get_header() -- get the Python DB-API compliant header information.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_29get_header(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_28get_header[] = "\n        get_header() -- get the Python DB-API compliant header information.\n\n        This method is infrastructure and doesn't need to be called by your\n        code. It returns a list of 7-element tuples describing the current\n        result header. Only name and DB-API compliant type is filled, rest\n        of the data is None, as permitted by the specs.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_29get_header(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_header (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_28get_header(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_28get_header(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  int __pyx_v_col;
  PyObject *__pyx_v_header_tuple = NULL;
  PyObject *__pyx_v_col_name = NULL;
  PyObject *__pyx_v_col_type = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  long __pyx_t_3;
  int __pyx_t_4;
  long __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  char const *__pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_RefNannySetupContext("get_header", 0);

  /* "_mssql.pyx":1193
 *         """
 *         cdef int col
 *         log("_mssql.MSSQLConnection.get_header() BEGIN")             # <<<<<<<<<<<<<<
 *         try:
 *             self.get_result()
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_header() BEGIN"));

  /* "_mssql.pyx":1194
 *         cdef int col
 *         log("_mssql.MSSQLConnection.get_header() BEGIN")
 *         try:             # <<<<<<<<<<<<<<
 *             self.get_result()
 * 
 */
  /*try:*/ {

    /* "_mssql.pyx":1195
 *         log("_mssql.MSSQLConnection.get_header() BEGIN")
 *         try:
 *             self.get_result()             # <<<<<<<<<<<<<<
 * 
 *             if self.num_columns == 0:
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->get_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1195, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1197
 *             self.get_result()
 * 
 *             if self.num_columns == 0:             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.get_header(): num_columns == 0")
 *                 return None
 */
    __pyx_t_2 = ((__pyx_v_self->num_columns == 0) != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1198
 * 
 *             if self.num_columns == 0:
 *                 log("_mssql.MSSQLConnection.get_header(): num_columns == 0")             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_header(): num_columns == 0"));

      /* "_mssql.pyx":1199
 *             if self.num_columns == 0:
 *                 log("_mssql.MSSQLConnection.get_header(): num_columns == 0")
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             header_tuple = []
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L3_return;

      /* "_mssql.pyx":1197
 *             self.get_result()
 * 
 *             if self.num_columns == 0:             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.get_header(): num_columns == 0")
 *                 return None
 */
    }

    /* "_mssql.pyx":1201
 *                 return None
 * 
 *             header_tuple = []             # <<<<<<<<<<<<<<
 *             for col in xrange(1, self.num_columns + 1):
 *                 col_name = self.column_names[col - 1]
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1201, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_header_tuple = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "_mssql.pyx":1202
 * 
 *             header_tuple = []
 *             for col in xrange(1, self.num_columns + 1):             # <<<<<<<<<<<<<<
 *                 col_name = self.column_names[col - 1]
 *                 col_type = self.column_types[col - 1]
 */
    __pyx_t_3 = (__pyx_v_self->num_columns + 1);
    for (__pyx_t_4 = 1; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_v_col = __pyx_t_4;

      /* "_mssql.pyx":1203
 *             header_tuple = []
 *             for col in xrange(1, self.num_columns + 1):
 *                 col_name = self.column_names[col - 1]             # <<<<<<<<<<<<<<
 *                 col_type = self.column_types[col - 1]
 *                 header_tuple.append((col_name, col_type, None, None, None, None, None))
 */
      if (unlikely(__pyx_v_self->column_names == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 1203, __pyx_L4_error)
      }
      __pyx_t_5 = (__pyx_v_col - 1);
      __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_self->column_names, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1203, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_col_name, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "_mssql.pyx":1204
 *             for col in xrange(1, self.num_columns + 1):
 *                 col_name = self.column_names[col - 1]
 *                 col_type = self.column_types[col - 1]             # <<<<<<<<<<<<<<
 *                 header_tuple.append((col_name, col_type, None, None, None, None, None))
 *             return tuple(header_tuple)
 */
      if (unlikely(__pyx_v_self->column_types == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 1204, __pyx_L4_error)
      }
      __pyx_t_5 = (__pyx_v_col - 1);
      __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_self->column_types, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1204, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_col_type, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "_mssql.pyx":1205
 *                 col_name = self.column_names[col - 1]
 *                 col_type = self.column_types[col - 1]
 *                 header_tuple.append((col_name, col_type, None, None, None, None, None))             # <<<<<<<<<<<<<<
 *             return tuple(header_tuple)
 *         finally:
 */
      __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1205, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_col_name);
      __Pyx_GIVEREF(__pyx_v_col_name);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_col_name);
      __Pyx_INCREF(__pyx_v_col_type);
      __Pyx_GIVEREF(__pyx_v_col_type);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_col_type);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 3, Py_None);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 4, Py_None);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 5, Py_None);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 6, Py_None);
      __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_header_tuple, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 1205, __pyx_L4_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }

    /* "_mssql.pyx":1206
 *                 col_type = self.column_types[col - 1]
 *                 header_tuple.append((col_name, col_type, None, None, None, None, None))
 *             return tuple(header_tuple)             # <<<<<<<<<<<<<<
 *         finally:
 *             log("_mssql.MSSQLConnection.get_header() END")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_AsTuple(__pyx_v_header_tuple); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1206, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L3_return;
  }

  /* "_mssql.pyx":1208
 *             return tuple(header_tuple)
 *         finally:
 *             log("_mssql.MSSQLConnection.get_header() END")             # <<<<<<<<<<<<<<
 * 
 *     def get_iterator(self, int row_format):
 */
  /*finally:*/ {
    /*exception exit:*/{
      __Pyx_PyThreadState_declare
      __pyx_L4_error:;
      __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;
      __Pyx_PyThreadState_assign
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_12);
      __Pyx_XGOTREF(__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_14);
      __pyx_t_4 = __pyx_lineno; __pyx_t_7 = __pyx_clineno; __pyx_t_8 = __pyx_filename;
      {
        __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_header() END"));
      }
      __Pyx_PyThreadState_assign
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
      }
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_ErrRestore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;
      __pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_7; __pyx_filename = __pyx_t_8;
      goto __pyx_L1_error;
    }
    __pyx_L3_return: {
      __pyx_t_14 = __pyx_r;
      __pyx_r = 0;
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_header() END"));
      __pyx_r = __pyx_t_14;
      __pyx_t_14 = 0;
      goto __pyx_L0;
    }
  }

  /* "_mssql.pyx":1183
 *         return _substitute_params(format, params, self.charset)
 * 
 *     def get_header(self):             # <<<<<<<<<<<<<<
 *         """
 *         get_header() -- get the Python DB-API compliant header information.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.get_header", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_header_tuple);
  __Pyx_XDECREF(__pyx_v_col_name);
  __Pyx_XDECREF(__pyx_v_col_type);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1210
 *             log("_mssql.MSSQLConnection.get_header() END")
 * 
 *     def get_iterator(self, int row_format):             # <<<<<<<<<<<<<<
 *         """
 *         get_iterator(row_format) -- allows the format of the iterator to be specified
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_31get_iterator(PyObject *__pyx_v_self, PyObject *__pyx_arg_row_format); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_30get_iterator[] = "\n        get_iterator(row_format) -- allows the format of the iterator to be specified\n\n        While the iter(conn) call will always return a dictionary, this\n        method allows the return type of the row to be specified.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_31get_iterator(PyObject *__pyx_v_self, PyObject *__pyx_arg_row_format) {
  int __pyx_v_row_format;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_iterator (wrapper)", 0);
  assert(__pyx_arg_row_format); {
    __pyx_v_row_format = __Pyx_PyInt_As_int(__pyx_arg_row_format); if (unlikely((__pyx_v_row_format == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1210, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLConnection.get_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_30get_iterator(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), ((int)__pyx_v_row_format));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_30get_iterator(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_v_row_format) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_iterator", 0);

  /* "_mssql.pyx":1217
 *         method allows the return type of the row to be specified.
 *         """
 *         assert_connected(self)             # <<<<<<<<<<<<<<
 *         clr_err(self)
 *         return MSSQLRowIterator(self, row_format)
 */
  __pyx_f_6_mssql_assert_connected(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1217, __pyx_L1_error)

  /* "_mssql.pyx":1218
 *         """
 *         assert_connected(self)
 *         clr_err(self)             # <<<<<<<<<<<<<<
 *         return MSSQLRowIterator(self, row_format)
 * 
 */
  __pyx_f_6_mssql_clr_err(__pyx_v_self);

  /* "_mssql.pyx":1219
 *         assert_connected(self)
 *         clr_err(self)
 *         return MSSQLRowIterator(self, row_format)             # <<<<<<<<<<<<<<
 * 
 *     cdef get_result(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_row_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLRowIterator), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1210
 *             log("_mssql.MSSQLConnection.get_header() END")
 * 
 *     def get_iterator(self, int row_format):             # <<<<<<<<<<<<<<
 *         """
 *         get_iterator(row_format) -- allows the format of the iterator to be specified
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.get_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1221
 *         return MSSQLRowIterator(self, row_format)
 * 
 *     cdef get_result(self):             # <<<<<<<<<<<<<<
 *         cdef int coltype
 *         cdef char log_message[200]
 */

static PyObject *__pyx_f_6_mssql_15MSSQLConnection_get_result(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  int __pyx_v_coltype;
  char __pyx_v_log_message[0xC8];
  PyObject *__pyx_v_column_names = NULL;
  PyObject *__pyx_v_column_types = NULL;
  long __pyx_v_col;
  char *__pyx_v_col_name;
  PyObject *__pyx_v_column_name = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  long __pyx_t_5;
  long __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  char const *__pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  __Pyx_RefNannySetupContext("get_result", 0);

  /* "_mssql.pyx":1225
 *         cdef char log_message[200]
 * 
 *         log("_mssql.MSSQLConnection.get_result() BEGIN")             # <<<<<<<<<<<<<<
 * 
 *         try:
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_result() BEGIN"));

  /* "_mssql.pyx":1227
 *         log("_mssql.MSSQLConnection.get_result() BEGIN")
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             if self.last_dbresults:
 *                 log("_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None")
 */
  /*try:*/ {

    /* "_mssql.pyx":1228
 * 
 *         try:
 *             if self.last_dbresults:             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None")
 *                 return None
 */
    __pyx_t_1 = (__pyx_v_self->last_dbresults != 0);
    if (__pyx_t_1) {

      /* "_mssql.pyx":1229
 *         try:
 *             if self.last_dbresults:
 *                 log("_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None")             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None"));

      /* "_mssql.pyx":1230
 *             if self.last_dbresults:
 *                 log("_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None")
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             self.clear_metadata()
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L3_return;

      /* "_mssql.pyx":1228
 * 
 *         try:
 *             if self.last_dbresults:             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None")
 *                 return None
 */
    }

    /* "_mssql.pyx":1232
 *                 return None
 * 
 *             self.clear_metadata()             # <<<<<<<<<<<<<<
 * 
 *             # Since python doesn't have a do/while loop do it this way
 */
    ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->clear_metadata(__pyx_v_self);

    /* "_mssql.pyx":1235
 * 
 *             # Since python doesn't have a do/while loop do it this way
 *             while True:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     self.last_dbresults = dbresults(self.dbproc)
 */
    while (1) {

      /* "_mssql.pyx":1236
 *             # Since python doesn't have a do/while loop do it this way
 *             while True:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     self.last_dbresults = dbresults(self.dbproc)
 *                 self.num_columns = dbnumcols(self.dbproc)
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          #endif
          /*try:*/ {

            /* "_mssql.pyx":1237
 *             while True:
 *                 with nogil:
 *                     self.last_dbresults = dbresults(self.dbproc)             # <<<<<<<<<<<<<<
 *                 self.num_columns = dbnumcols(self.dbproc)
 *                 if self.last_dbresults != SUCCEED or self.num_columns > 0:
 */
            __pyx_v_self->last_dbresults = dbresults(__pyx_v_self->dbproc);
          }

          /* "_mssql.pyx":1236
 *             # Since python doesn't have a do/while loop do it this way
 *             while True:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     self.last_dbresults = dbresults(self.dbproc)
 *                 self.num_columns = dbnumcols(self.dbproc)
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L13;
            }
            __pyx_L13:;
          }
      }

      /* "_mssql.pyx":1238
 *                 with nogil:
 *                     self.last_dbresults = dbresults(self.dbproc)
 *                 self.num_columns = dbnumcols(self.dbproc)             # <<<<<<<<<<<<<<
 *                 if self.last_dbresults != SUCCEED or self.num_columns > 0:
 *                     break
 */
      __pyx_v_self->num_columns = dbnumcols(__pyx_v_self->dbproc);

      /* "_mssql.pyx":1239
 *                     self.last_dbresults = dbresults(self.dbproc)
 *                 self.num_columns = dbnumcols(self.dbproc)
 *                 if self.last_dbresults != SUCCEED or self.num_columns > 0:             # <<<<<<<<<<<<<<
 *                     break
 *             check_cancel_and_raise(self.last_dbresults, self)
 */
      __pyx_t_2 = ((__pyx_v_self->last_dbresults != SUCCEED) != 0);
      if (!__pyx_t_2) {
      } else {
        __pyx_t_1 = __pyx_t_2;
        goto __pyx_L15_bool_binop_done;
      }
      __pyx_t_2 = ((__pyx_v_self->num_columns > 0) != 0);
      __pyx_t_1 = __pyx_t_2;
      __pyx_L15_bool_binop_done:;
      if (__pyx_t_1) {

        /* "_mssql.pyx":1240
 *                 self.num_columns = dbnumcols(self.dbproc)
 *                 if self.last_dbresults != SUCCEED or self.num_columns > 0:
 *                     break             # <<<<<<<<<<<<<<
 *             check_cancel_and_raise(self.last_dbresults, self)
 * 
 */
        goto __pyx_L8_break;

        /* "_mssql.pyx":1239
 *                     self.last_dbresults = dbresults(self.dbproc)
 *                 self.num_columns = dbnumcols(self.dbproc)
 *                 if self.last_dbresults != SUCCEED or self.num_columns > 0:             # <<<<<<<<<<<<<<
 *                     break
 *             check_cancel_and_raise(self.last_dbresults, self)
 */
      }
    }
    __pyx_L8_break:;

    /* "_mssql.pyx":1241
 *                 if self.last_dbresults != SUCCEED or self.num_columns > 0:
 *                     break
 *             check_cancel_and_raise(self.last_dbresults, self)             # <<<<<<<<<<<<<<
 * 
 *             self._rows_affected = dbcount(self.dbproc)
 */
    __pyx_t_3 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_self->last_dbresults, __pyx_v_self); if (unlikely(__pyx_t_3 == 1)) __PYX_ERR(0, 1241, __pyx_L4_error)

    /* "_mssql.pyx":1243
 *             check_cancel_and_raise(self.last_dbresults, self)
 * 
 *             self._rows_affected = dbcount(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *             if self.last_dbresults == NO_MORE_RESULTS:
 */
    __pyx_v_self->_rows_affected = dbcount(__pyx_v_self->dbproc);

    /* "_mssql.pyx":1245
 *             self._rows_affected = dbcount(self.dbproc)
 * 
 *             if self.last_dbresults == NO_MORE_RESULTS:             # <<<<<<<<<<<<<<
 *                 self.num_columns = 0
 *                 log("_mssql.MSSQLConnection.get_result(): NO_MORE_RESULTS, return None")
 */
    __pyx_t_1 = ((__pyx_v_self->last_dbresults == NO_MORE_RESULTS) != 0);
    if (__pyx_t_1) {

      /* "_mssql.pyx":1246
 * 
 *             if self.last_dbresults == NO_MORE_RESULTS:
 *                 self.num_columns = 0             # <<<<<<<<<<<<<<
 *                 log("_mssql.MSSQLConnection.get_result(): NO_MORE_RESULTS, return None")
 *                 return None
 */
      __pyx_v_self->num_columns = 0;

      /* "_mssql.pyx":1247
 *             if self.last_dbresults == NO_MORE_RESULTS:
 *                 self.num_columns = 0
 *                 log("_mssql.MSSQLConnection.get_result(): NO_MORE_RESULTS, return None")             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_result(): NO_MORE_RESULTS, return None"));

      /* "_mssql.pyx":1248
 *                 self.num_columns = 0
 *                 log("_mssql.MSSQLConnection.get_result(): NO_MORE_RESULTS, return None")
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             self.num_columns = dbnumcols(self.dbproc)
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L3_return;

      /* "_mssql.pyx":1245
 *             self._rows_affected = dbcount(self.dbproc)
 * 
 *             if self.last_dbresults == NO_MORE_RESULTS:             # <<<<<<<<<<<<<<
 *                 self.num_columns = 0
 *                 log("_mssql.MSSQLConnection.get_result(): NO_MORE_RESULTS, return None")
 */
    }

    /* "_mssql.pyx":1250
 *                 return None
 * 
 *             self.num_columns = dbnumcols(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *             snprintf(log_message, sizeof(log_message), "_mssql.MSSQLConnection.get_result(): num_columns = %d", self.num_columns)
 */
    __pyx_v_self->num_columns = dbnumcols(__pyx_v_self->dbproc);

    /* "_mssql.pyx":1252
 *             self.num_columns = dbnumcols(self.dbproc)
 * 
 *             snprintf(log_message, sizeof(log_message), "_mssql.MSSQLConnection.get_result(): num_columns = %d", self.num_columns)             # <<<<<<<<<<<<<<
 *             log_message[ sizeof(log_message) - 1 ] = '\0'
 *             log(log_message)
 */
    snprintf(__pyx_v_log_message, (sizeof(__pyx_v_log_message)), ((char const *)"_mssql.MSSQLConnection.get_result(): num_columns = %d"), __pyx_v_self->num_columns);

    /* "_mssql.pyx":1253
 * 
 *             snprintf(log_message, sizeof(log_message), "_mssql.MSSQLConnection.get_result(): num_columns = %d", self.num_columns)
 *             log_message[ sizeof(log_message) - 1 ] = '\0'             # <<<<<<<<<<<<<<
 *             log(log_message)
 * 
 */
    (__pyx_v_log_message[((sizeof(__pyx_v_log_message)) - 1)]) = '\x00';

    /* "_mssql.pyx":1254
 *             snprintf(log_message, sizeof(log_message), "_mssql.MSSQLConnection.get_result(): num_columns = %d", self.num_columns)
 *             log_message[ sizeof(log_message) - 1 ] = '\0'
 *             log(log_message)             # <<<<<<<<<<<<<<
 * 
 *             column_names = list()
 */
    __pyx_f_6_mssql_log(__pyx_v_log_message);

    /* "_mssql.pyx":1256
 *             log(log_message)
 * 
 *             column_names = list()             # <<<<<<<<<<<<<<
 *             column_types = list()
 * 
 */
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1256, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_column_names = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "_mssql.pyx":1257
 * 
 *             column_names = list()
 *             column_types = list()             # <<<<<<<<<<<<<<
 * 
 *             for col in xrange(1, self.num_columns + 1):
 */
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1257, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_column_types = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "_mssql.pyx":1259
 *             column_types = list()
 * 
 *             for col in xrange(1, self.num_columns + 1):             # <<<<<<<<<<<<<<
 *                 col_name = dbcolname(self.dbproc, col)
 *                 if not col_name:
 */
    __pyx_t_5 = (__pyx_v_self->num_columns + 1);
    for (__pyx_t_6 = 1; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_col = __pyx_t_6;

      /* "_mssql.pyx":1260
 * 
 *             for col in xrange(1, self.num_columns + 1):
 *                 col_name = dbcolname(self.dbproc, col)             # <<<<<<<<<<<<<<
 *                 if not col_name:
 *                     self.num_columns -= 1
 */
      __pyx_v_col_name = dbcolname(__pyx_v_self->dbproc, __pyx_v_col);

      /* "_mssql.pyx":1261
 *             for col in xrange(1, self.num_columns + 1):
 *                 col_name = dbcolname(self.dbproc, col)
 *                 if not col_name:             # <<<<<<<<<<<<<<
 *                     self.num_columns -= 1
 *                     return None
 */
      __pyx_t_1 = ((!(__pyx_v_col_name != 0)) != 0);
      if (__pyx_t_1) {

        /* "_mssql.pyx":1262
 *                 col_name = dbcolname(self.dbproc, col)
 *                 if not col_name:
 *                     self.num_columns -= 1             # <<<<<<<<<<<<<<
 *                     return None
 * 
 */
        __pyx_v_self->num_columns = (__pyx_v_self->num_columns - 1);

        /* "_mssql.pyx":1263
 *                 if not col_name:
 *                     self.num_columns -= 1
 *                     return None             # <<<<<<<<<<<<<<
 * 
 *                 column_name = col_name.decode(self._charset)
 */
        __Pyx_XDECREF(__pyx_r);
        __Pyx_INCREF(Py_None);
        __pyx_r = Py_None;
        goto __pyx_L3_return;

        /* "_mssql.pyx":1261
 *             for col in xrange(1, self.num_columns + 1):
 *                 col_name = dbcolname(self.dbproc, col)
 *                 if not col_name:             # <<<<<<<<<<<<<<
 *                     self.num_columns -= 1
 *                     return None
 */
      }

      /* "_mssql.pyx":1265
 *                     return None
 * 
 *                 column_name = col_name.decode(self._charset)             # <<<<<<<<<<<<<<
 *                 column_names.append(column_name)
 *                 coltype = dbcoltype(self.dbproc, col)
 */
      __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_col_name, 0, strlen(__pyx_v_col_name), __pyx_v_self->_charset, NULL, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1265, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_column_name, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1266
 * 
 *                 column_name = col_name.decode(self._charset)
 *                 column_names.append(column_name)             # <<<<<<<<<<<<<<
 *                 coltype = dbcoltype(self.dbproc, col)
 *                 column_types.append(get_api_coltype(coltype))
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_column_names, __pyx_v_column_name); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 1266, __pyx_L4_error)

      /* "_mssql.pyx":1267
 *                 column_name = col_name.decode(self._charset)
 *                 column_names.append(column_name)
 *                 coltype = dbcoltype(self.dbproc, col)             # <<<<<<<<<<<<<<
 *                 column_types.append(get_api_coltype(coltype))
 * 
 */
      __pyx_v_coltype = dbcoltype(__pyx_v_self->dbproc, __pyx_v_col);

      /* "_mssql.pyx":1268
 *                 column_names.append(column_name)
 *                 coltype = dbcoltype(self.dbproc, col)
 *                 column_types.append(get_api_coltype(coltype))             # <<<<<<<<<<<<<<
 * 
 *             self.column_names = tuple(column_names)
 */
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_f_6_mssql_get_api_coltype(__pyx_v_coltype)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1268, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_column_types, __pyx_t_4); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 1268, __pyx_L4_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }

    /* "_mssql.pyx":1270
 *                 column_types.append(get_api_coltype(coltype))
 * 
 *             self.column_names = tuple(column_names)             # <<<<<<<<<<<<<<
 *             self.column_types = tuple(column_types)
 *         finally:
 */
    __pyx_t_4 = PyList_AsTuple(__pyx_v_column_names); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1270, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_GOTREF(__pyx_v_self->column_names);
    __Pyx_DECREF(__pyx_v_self->column_names);
    __pyx_v_self->column_names = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "_mssql.pyx":1271
 * 
 *             self.column_names = tuple(column_names)
 *             self.column_types = tuple(column_types)             # <<<<<<<<<<<<<<
 *         finally:
 *             log("_mssql.MSSQLConnection.get_result() END")
 */
    __pyx_t_4 = PyList_AsTuple(__pyx_v_column_types); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1271, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_GOTREF(__pyx_v_self->column_types);
    __Pyx_DECREF(__pyx_v_self->column_types);
    __pyx_v_self->column_types = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;
  }

  /* "_mssql.pyx":1273
 *             self.column_types = tuple(column_types)
 *         finally:
 *             log("_mssql.MSSQLConnection.get_result() END")             # <<<<<<<<<<<<<<
 * 
 *     cdef get_row(self, int row_info, int row_format):
 */
  /*finally:*/ {
    /*normal exit:*/{
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_result() END"));
      goto __pyx_L5;
    }
    /*exception exit:*/{
      __Pyx_PyThreadState_declare
      __pyx_L4_error:;
      __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
      __Pyx_PyThreadState_assign
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12) < 0)) __Pyx_ErrFetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_12);
      __Pyx_XGOTREF(__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_14);
      __Pyx_XGOTREF(__pyx_t_15);
      __pyx_t_3 = __pyx_lineno; __pyx_t_8 = __pyx_clineno; __pyx_t_9 = __pyx_filename;
      {
        __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_result() END"));
      }
      __Pyx_PyThreadState_assign
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
      }
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_XGIVEREF(__pyx_t_12);
      __Pyx_ErrRestore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
      __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
      __pyx_lineno = __pyx_t_3; __pyx_clineno = __pyx_t_8; __pyx_filename = __pyx_t_9;
      goto __pyx_L1_error;
    }
    __pyx_L3_return: {
      __pyx_t_15 = __pyx_r;
      __pyx_r = 0;
      __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_result() END"));
      __pyx_r = __pyx_t_15;
      __pyx_t_15 = 0;
      goto __pyx_L0;
    }
    __pyx_L5:;
  }

  /* "_mssql.pyx":1221
 *         return MSSQLRowIterator(self, row_format)
 * 
 *     cdef get_result(self):             # <<<<<<<<<<<<<<
 *         cdef int coltype
 *         cdef char log_message[200]
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.get_result", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_column_names);
  __Pyx_XDECREF(__pyx_v_column_types);
  __Pyx_XDECREF(__pyx_v_column_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1275
 *             log("_mssql.MSSQLConnection.get_result() END")
 * 
 *     cdef get_row(self, int row_info, int row_format):             # <<<<<<<<<<<<<<
 *         cdef DBPROCESS *dbproc = self.dbproc
 *         cdef int col
 */

static PyObject *__pyx_f_6_mssql_15MSSQLConnection_get_row(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_v_row_info, int __pyx_v_row_format) {
  DBPROCESS *__pyx_v_dbproc;
  int __pyx_v_col;
  int __pyx_v_col_type;
  int __pyx_v_len;
  BYTE *__pyx_v_data;
  PyObject *__pyx_v_trecord = 0;
  PyObject *__pyx_v_drecord = 0;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  DBPROCESS *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  long __pyx_t_4;
  int __pyx_t_5;
  long __pyx_t_6;
  __Pyx_RefNannySetupContext("get_row", 0);

  /* "_mssql.pyx":1276
 * 
 *     cdef get_row(self, int row_info, int row_format):
 *         cdef DBPROCESS *dbproc = self.dbproc             # <<<<<<<<<<<<<<
 *         cdef int col
 *         cdef int col_type
 */
  __pyx_t_1 = __pyx_v_self->dbproc;
  __pyx_v_dbproc = __pyx_t_1;

  /* "_mssql.pyx":1283
 *         cdef tuple trecord
 *         cdef dict drecord
 *         log("_mssql.MSSQLConnection.get_row()")             # <<<<<<<<<<<<<<
 * 
 *         if PYMSSQL_DEBUG == 1:
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.get_row()"));

  /* "_mssql.pyx":1289
 *             _row_count += 1
 * 
 *         if row_format == _ROW_FORMAT_TUPLE:             # <<<<<<<<<<<<<<
 *             trecord = PyTuple_New(self.num_columns)
 *         elif row_format == _ROW_FORMAT_DICT:
 */
  __pyx_t_2 = ((__pyx_v_row_format == __pyx_v_6_mssql__ROW_FORMAT_TUPLE) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1290
 * 
 *         if row_format == _ROW_FORMAT_TUPLE:
 *             trecord = PyTuple_New(self.num_columns)             # <<<<<<<<<<<<<<
 *         elif row_format == _ROW_FORMAT_DICT:
 *             drecord = dict()
 */
    __pyx_t_3 = PyTuple_New(__pyx_v_self->num_columns); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1290, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_trecord = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "_mssql.pyx":1289
 *             _row_count += 1
 * 
 *         if row_format == _ROW_FORMAT_TUPLE:             # <<<<<<<<<<<<<<
 *             trecord = PyTuple_New(self.num_columns)
 *         elif row_format == _ROW_FORMAT_DICT:
 */
    goto __pyx_L3;
  }

  /* "_mssql.pyx":1291
 *         if row_format == _ROW_FORMAT_TUPLE:
 *             trecord = PyTuple_New(self.num_columns)
 *         elif row_format == _ROW_FORMAT_DICT:             # <<<<<<<<<<<<<<
 *             drecord = dict()
 * 
 */
  __pyx_t_2 = ((__pyx_v_row_format == __pyx_v_6_mssql__ROW_FORMAT_DICT) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1292
 *             trecord = PyTuple_New(self.num_columns)
 *         elif row_format == _ROW_FORMAT_DICT:
 *             drecord = dict()             # <<<<<<<<<<<<<<
 * 
 *         for col in xrange(1, self.num_columns + 1):
 */
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1292, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_drecord = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "_mssql.pyx":1291
 *         if row_format == _ROW_FORMAT_TUPLE:
 *             trecord = PyTuple_New(self.num_columns)
 *         elif row_format == _ROW_FORMAT_DICT:             # <<<<<<<<<<<<<<
 *             drecord = dict()
 * 
 */
  }
  __pyx_L3:;

  /* "_mssql.pyx":1294
 *             drecord = dict()
 * 
 *         for col in xrange(1, self.num_columns + 1):             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 data = get_data(dbproc, row_info, col)
 */
  __pyx_t_4 = (__pyx_v_self->num_columns + 1);
  for (__pyx_t_5 = 1; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
    __pyx_v_col = __pyx_t_5;

    /* "_mssql.pyx":1295
 * 
 *         for col in xrange(1, self.num_columns + 1):
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 data = get_data(dbproc, row_info, col)
 *                 col_type = get_type(dbproc, row_info, col)
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        #endif
        /*try:*/ {

          /* "_mssql.pyx":1296
 *         for col in xrange(1, self.num_columns + 1):
 *             with nogil:
 *                 data = get_data(dbproc, row_info, col)             # <<<<<<<<<<<<<<
 *                 col_type = get_type(dbproc, row_info, col)
 *                 len = get_length(dbproc, row_info, col)
 */
          __pyx_v_data = __pyx_f_6_mssql_get_data(__pyx_v_dbproc, __pyx_v_row_info, __pyx_v_col);

          /* "_mssql.pyx":1297
 *             with nogil:
 *                 data = get_data(dbproc, row_info, col)
 *                 col_type = get_type(dbproc, row_info, col)             # <<<<<<<<<<<<<<
 *                 len = get_length(dbproc, row_info, col)
 * 
 */
          __pyx_v_col_type = __pyx_f_6_mssql_get_type(__pyx_v_dbproc, __pyx_v_row_info, __pyx_v_col);

          /* "_mssql.pyx":1298
 *                 data = get_data(dbproc, row_info, col)
 *                 col_type = get_type(dbproc, row_info, col)
 *                 len = get_length(dbproc, row_info, col)             # <<<<<<<<<<<<<<
 * 
 *             if data == NULL:
 */
          __pyx_v_len = __pyx_f_6_mssql_get_length(__pyx_v_dbproc, __pyx_v_row_info, __pyx_v_col);
        }

        /* "_mssql.pyx":1295
 * 
 *         for col in xrange(1, self.num_columns + 1):
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 data = get_data(dbproc, row_info, col)
 *                 col_type = get_type(dbproc, row_info, col)
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L10;
          }
          __pyx_L10:;
        }
    }

    /* "_mssql.pyx":1300
 *                 len = get_length(dbproc, row_info, col)
 * 
 *             if data == NULL:             # <<<<<<<<<<<<<<
 *                 value = None
 *             else:
 */
    __pyx_t_2 = ((__pyx_v_data == NULL) != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1301
 * 
 *             if data == NULL:
 *                 value = None             # <<<<<<<<<<<<<<
 *             else:
 *                 IF PYMSSQL_DEBUG == 1:
 */
      __Pyx_INCREF(Py_None);
      __Pyx_XDECREF_SET(__pyx_v_value, Py_None);

      /* "_mssql.pyx":1300
 *                 len = get_length(dbproc, row_info, col)
 * 
 *             if data == NULL:             # <<<<<<<<<<<<<<
 *                 value = None
 *             else:
 */
      goto __pyx_L11;
    }

    /* "_mssql.pyx":1308
 *                         'Got data=%x, coltype=%d, len=%d\n', _row_count, col,
 *                         data, col_type, len)
 *                 value = self.convert_db_value(data, col_type, len)             # <<<<<<<<<<<<<<
 * 
 *             if row_format == _ROW_FORMAT_TUPLE:
 */
    /*else*/ {
      __pyx_t_3 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->convert_db_value(__pyx_v_self, __pyx_v_data, __pyx_v_col_type, __pyx_v_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1308, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;
    }
    __pyx_L11:;

    /* "_mssql.pyx":1310
 *                 value = self.convert_db_value(data, col_type, len)
 * 
 *             if row_format == _ROW_FORMAT_TUPLE:             # <<<<<<<<<<<<<<
 *                 Py_INCREF(value)
 *                 PyTuple_SetItem(trecord, col - 1, value)
 */
    __pyx_t_2 = ((__pyx_v_row_format == __pyx_v_6_mssql__ROW_FORMAT_TUPLE) != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1311
 * 
 *             if row_format == _ROW_FORMAT_TUPLE:
 *                 Py_INCREF(value)             # <<<<<<<<<<<<<<
 *                 PyTuple_SetItem(trecord, col - 1, value)
 *             elif row_format == _ROW_FORMAT_DICT:
 */
      Py_INCREF(__pyx_v_value);

      /* "_mssql.pyx":1312
 *             if row_format == _ROW_FORMAT_TUPLE:
 *                 Py_INCREF(value)
 *                 PyTuple_SetItem(trecord, col - 1, value)             # <<<<<<<<<<<<<<
 *             elif row_format == _ROW_FORMAT_DICT:
 *                 name = self.column_names[col - 1]
 */
      if (unlikely(!__pyx_v_trecord)) { __Pyx_RaiseUnboundLocalError("trecord"); __PYX_ERR(0, 1312, __pyx_L1_error) }
      PyTuple_SetItem(__pyx_v_trecord, (__pyx_v_col - 1), __pyx_v_value);

      /* "_mssql.pyx":1310
 *                 value = self.convert_db_value(data, col_type, len)
 * 
 *             if row_format == _ROW_FORMAT_TUPLE:             # <<<<<<<<<<<<<<
 *                 Py_INCREF(value)
 *                 PyTuple_SetItem(trecord, col - 1, value)
 */
      goto __pyx_L12;
    }

    /* "_mssql.pyx":1313
 *                 Py_INCREF(value)
 *                 PyTuple_SetItem(trecord, col - 1, value)
 *             elif row_format == _ROW_FORMAT_DICT:             # <<<<<<<<<<<<<<
 *                 name = self.column_names[col - 1]
 *                 drecord[col - 1] = value
 */
    __pyx_t_2 = ((__pyx_v_row_format == __pyx_v_6_mssql__ROW_FORMAT_DICT) != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1314
 *                 PyTuple_SetItem(trecord, col - 1, value)
 *             elif row_format == _ROW_FORMAT_DICT:
 *                 name = self.column_names[col - 1]             # <<<<<<<<<<<<<<
 *                 drecord[col - 1] = value
 *                 if name:
 */
      if (unlikely(__pyx_v_self->column_names == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 1314, __pyx_L1_error)
      }
      __pyx_t_6 = (__pyx_v_col - 1);
      __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_self->column_names, __pyx_t_6, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1314, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1315
 *             elif row_format == _ROW_FORMAT_DICT:
 *                 name = self.column_names[col - 1]
 *                 drecord[col - 1] = value             # <<<<<<<<<<<<<<
 *                 if name:
 *                     drecord[name] = value
 */
      if (unlikely(!__pyx_v_drecord)) { __Pyx_RaiseUnboundLocalError("drecord"); __PYX_ERR(0, 1315, __pyx_L1_error) }
      __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_col - 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1315, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (unlikely(PyDict_SetItem(__pyx_v_drecord, __pyx_t_3, __pyx_v_value) < 0)) __PYX_ERR(0, 1315, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "_mssql.pyx":1316
 *                 name = self.column_names[col - 1]
 *                 drecord[col - 1] = value
 *                 if name:             # <<<<<<<<<<<<<<
 *                     drecord[name] = value
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_name); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1316, __pyx_L1_error)
      if (__pyx_t_2) {

        /* "_mssql.pyx":1317
 *                 drecord[col - 1] = value
 *                 if name:
 *                     drecord[name] = value             # <<<<<<<<<<<<<<
 * 
 *         if row_format == _ROW_FORMAT_TUPLE:
 */
        if (unlikely(!__pyx_v_drecord)) { __Pyx_RaiseUnboundLocalError("drecord"); __PYX_ERR(0, 1317, __pyx_L1_error) }
        if (unlikely(PyDict_SetItem(__pyx_v_drecord, __pyx_v_name, __pyx_v_value) < 0)) __PYX_ERR(0, 1317, __pyx_L1_error)

        /* "_mssql.pyx":1316
 *                 name = self.column_names[col - 1]
 *                 drecord[col - 1] = value
 *                 if name:             # <<<<<<<<<<<<<<
 *                     drecord[name] = value
 * 
 */
      }

      /* "_mssql.pyx":1313
 *                 Py_INCREF(value)
 *                 PyTuple_SetItem(trecord, col - 1, value)
 *             elif row_format == _ROW_FORMAT_DICT:             # <<<<<<<<<<<<<<
 *                 name = self.column_names[col - 1]
 *                 drecord[col - 1] = value
 */
    }
    __pyx_L12:;
  }

  /* "_mssql.pyx":1319
 *                     drecord[name] = value
 * 
 *         if row_format == _ROW_FORMAT_TUPLE:             # <<<<<<<<<<<<<<
 *             return trecord
 *         elif row_format == _ROW_FORMAT_DICT:
 */
  __pyx_t_2 = ((__pyx_v_row_format == __pyx_v_6_mssql__ROW_FORMAT_TUPLE) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1320
 * 
 *         if row_format == _ROW_FORMAT_TUPLE:
 *             return trecord             # <<<<<<<<<<<<<<
 *         elif row_format == _ROW_FORMAT_DICT:
 *             return drecord
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_trecord)) { __Pyx_RaiseUnboundLocalError("trecord"); __PYX_ERR(0, 1320, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_trecord);
    __pyx_r = __pyx_v_trecord;
    goto __pyx_L0;

    /* "_mssql.pyx":1319
 *                     drecord[name] = value
 * 
 *         if row_format == _ROW_FORMAT_TUPLE:             # <<<<<<<<<<<<<<
 *             return trecord
 *         elif row_format == _ROW_FORMAT_DICT:
 */
  }

  /* "_mssql.pyx":1321
 *         if row_format == _ROW_FORMAT_TUPLE:
 *             return trecord
 *         elif row_format == _ROW_FORMAT_DICT:             # <<<<<<<<<<<<<<
 *             return drecord
 * 
 */
  __pyx_t_2 = ((__pyx_v_row_format == __pyx_v_6_mssql__ROW_FORMAT_DICT) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1322
 *             return trecord
 *         elif row_format == _ROW_FORMAT_DICT:
 *             return drecord             # <<<<<<<<<<<<<<
 * 
 *     def init_procedure(self, procname):
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_drecord)) { __Pyx_RaiseUnboundLocalError("drecord"); __PYX_ERR(0, 1322, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_drecord);
    __pyx_r = __pyx_v_drecord;
    goto __pyx_L0;

    /* "_mssql.pyx":1321
 *         if row_format == _ROW_FORMAT_TUPLE:
 *             return trecord
 *         elif row_format == _ROW_FORMAT_DICT:             # <<<<<<<<<<<<<<
 *             return drecord
 * 
 */
  }

  /* "_mssql.pyx":1275
 *             log("_mssql.MSSQLConnection.get_result() END")
 * 
 *     cdef get_row(self, int row_info, int row_format):             # <<<<<<<<<<<<<<
 *         cdef DBPROCESS *dbproc = self.dbproc
 *         cdef int col
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.get_row", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_trecord);
  __Pyx_XDECREF(__pyx_v_drecord);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1324
 *             return drecord
 * 
 *     def init_procedure(self, procname):             # <<<<<<<<<<<<<<
 *         """
 *         init_procedure(procname) -- creates and returns a MSSQLStoredProcedure
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_33init_procedure(PyObject *__pyx_v_self, PyObject *__pyx_v_procname); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_32init_procedure[] = "\n        init_procedure(procname) -- creates and returns a MSSQLStoredProcedure\n        object.\n\n        This methods initializes a stored procedure or function on the server\n        and creates a MSSQLStoredProcedure object that allows parameters to\n        be bound.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_33init_procedure(PyObject *__pyx_v_self, PyObject *__pyx_v_procname) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("init_procedure (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_32init_procedure(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), ((PyObject *)__pyx_v_procname));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_32init_procedure(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_procname) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("init_procedure", 0);

  /* "_mssql.pyx":1333
 *         be bound.
 *         """
 *         log("_mssql.MSSQLConnection.init_procedure()")             # <<<<<<<<<<<<<<
 *         return MSSQLStoredProcedure(procname.encode(self.charset), self)
 * 
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.init_procedure()"));

  /* "_mssql.pyx":1334
 *         """
 *         log("_mssql.MSSQLConnection.init_procedure()")
 *         return MSSQLStoredProcedure(procname.encode(self.charset), self)             # <<<<<<<<<<<<<<
 * 
 *     def nextresult(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_procname, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_charset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1334, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self));
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLStoredProcedure), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1324
 *             return drecord
 * 
 *     def init_procedure(self, procname):             # <<<<<<<<<<<<<<
 *         """
 *         init_procedure(procname) -- creates and returns a MSSQLStoredProcedure
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.init_procedure", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1336
 *         return MSSQLStoredProcedure(procname.encode(self.charset), self)
 * 
 *     def nextresult(self):             # <<<<<<<<<<<<<<
 *         """
 *         nextresult() -- move to the next result, skipping all pending rows.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_35nextresult(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_34nextresult[] = "\n        nextresult() -- move to the next result, skipping all pending rows.\n\n        This method fetches and discards any rows remaining from the current\n        resultset, then it advances to the next (if any) resultset. Returns\n        True if the next resultset is available, otherwise None.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_35nextresult(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("nextresult (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_34nextresult(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_34nextresult(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  RETCODE __pyx_v_rtc;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("nextresult", 0);

  /* "_mssql.pyx":1346
 * 
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.nextresult()")             # <<<<<<<<<<<<<<
 * 
 *         assert_connected(self)
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.nextresult()"));

  /* "_mssql.pyx":1348
 *         log("_mssql.MSSQLConnection.nextresult()")
 * 
 *         assert_connected(self)             # <<<<<<<<<<<<<<
 *         clr_err(self)
 * 
 */
  __pyx_f_6_mssql_assert_connected(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1348, __pyx_L1_error)

  /* "_mssql.pyx":1349
 * 
 *         assert_connected(self)
 *         clr_err(self)             # <<<<<<<<<<<<<<
 * 
 *         rtc = dbnextrow(self.dbproc)
 */
  __pyx_f_6_mssql_clr_err(__pyx_v_self);

  /* "_mssql.pyx":1351
 *         clr_err(self)
 * 
 *         rtc = dbnextrow(self.dbproc)             # <<<<<<<<<<<<<<
 *         check_cancel_and_raise(rtc, self)
 * 
 */
  __pyx_v_rtc = dbnextrow(__pyx_v_self->dbproc);

  /* "_mssql.pyx":1352
 * 
 *         rtc = dbnextrow(self.dbproc)
 *         check_cancel_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 * 
 *         while rtc != NO_MORE_ROWS:
 */
  __pyx_t_1 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_1 == 1)) __PYX_ERR(0, 1352, __pyx_L1_error)

  /* "_mssql.pyx":1354
 *         check_cancel_and_raise(rtc, self)
 * 
 *         while rtc != NO_MORE_ROWS:             # <<<<<<<<<<<<<<
 *             rtc = dbnextrow(self.dbproc)
 *             check_cancel_and_raise(rtc, self)
 */
  while (1) {
    __pyx_t_2 = ((__pyx_v_rtc != NO_MORE_ROWS) != 0);
    if (!__pyx_t_2) break;

    /* "_mssql.pyx":1355
 * 
 *         while rtc != NO_MORE_ROWS:
 *             rtc = dbnextrow(self.dbproc)             # <<<<<<<<<<<<<<
 *             check_cancel_and_raise(rtc, self)
 * 
 */
    __pyx_v_rtc = dbnextrow(__pyx_v_self->dbproc);

    /* "_mssql.pyx":1356
 *         while rtc != NO_MORE_ROWS:
 *             rtc = dbnextrow(self.dbproc)
 *             check_cancel_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 * 
 *         self.last_dbresults = 0
 */
    __pyx_t_1 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_1 == 1)) __PYX_ERR(0, 1356, __pyx_L1_error)
  }

  /* "_mssql.pyx":1358
 *             check_cancel_and_raise(rtc, self)
 * 
 *         self.last_dbresults = 0             # <<<<<<<<<<<<<<
 *         self.get_result()
 * 
 */
  __pyx_v_self->last_dbresults = 0;

  /* "_mssql.pyx":1359
 * 
 *         self.last_dbresults = 0
 *         self.get_result()             # <<<<<<<<<<<<<<
 * 
 *         if self.last_dbresults != NO_MORE_RESULTS:
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->get_result(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1361
 *         self.get_result()
 * 
 *         if self.last_dbresults != NO_MORE_RESULTS:             # <<<<<<<<<<<<<<
 *             return 1
 * 
 */
  __pyx_t_2 = ((__pyx_v_self->last_dbresults != NO_MORE_RESULTS) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1362
 * 
 *         if self.last_dbresults != NO_MORE_RESULTS:
 *             return 1             # <<<<<<<<<<<<<<
 * 
 *     def select_db(self, dbname):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_1);
    __pyx_r = __pyx_int_1;
    goto __pyx_L0;

    /* "_mssql.pyx":1361
 *         self.get_result()
 * 
 *         if self.last_dbresults != NO_MORE_RESULTS:             # <<<<<<<<<<<<<<
 *             return 1
 * 
 */
  }

  /* "_mssql.pyx":1336
 *         return MSSQLStoredProcedure(procname.encode(self.charset), self)
 * 
 *     def nextresult(self):             # <<<<<<<<<<<<<<
 *         """
 *         nextresult() -- move to the next result, skipping all pending rows.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.nextresult", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1364
 *             return 1
 * 
 *     def select_db(self, dbname):             # <<<<<<<<<<<<<<
 *         """
 *         select_db(dbname) -- Select the current database.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_37select_db(PyObject *__pyx_v_self, PyObject *__pyx_v_dbname); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_36select_db[] = "\n        select_db(dbname) -- Select the current database.\n\n        This function selects the given database. An exception is raised on\n        failure.\n        ";
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_37select_db(PyObject *__pyx_v_self, PyObject *__pyx_v_dbname) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("select_db (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_36select_db(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), ((PyObject *)__pyx_v_dbname));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_36select_db(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_dbname) {
  PyObject *__pyx_v_dbname_bytes = 0;
  char *__pyx_v_dbname_cstr;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  __Pyx_RefNannySetupContext("select_db", 0);

  /* "_mssql.pyx":1372
 *         """
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.select_db()")             # <<<<<<<<<<<<<<
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLConnection.select_db()"));

  /* "_mssql.pyx":1375
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 *         cdef bytes dbname_bytes = dbname.encode('ascii')             # <<<<<<<<<<<<<<
 *         cdef char *dbname_cstr = dbname_bytes
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dbname, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1375, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1375, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1375, __pyx_L1_error)
  __pyx_v_dbname_bytes = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1376
 *         # For Python 3, we need to convert unicode to byte strings
 *         cdef bytes dbname_bytes = dbname.encode('ascii')
 *         cdef char *dbname_cstr = dbname_bytes             # <<<<<<<<<<<<<<
 * 
 *         dbuse(self.dbproc, dbname_cstr)
 */
  __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_dbname_bytes); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1376, __pyx_L1_error)
  __pyx_v_dbname_cstr = __pyx_t_3;

  /* "_mssql.pyx":1378
 *         cdef char *dbname_cstr = dbname_bytes
 * 
 *         dbuse(self.dbproc, dbname_cstr)             # <<<<<<<<<<<<<<
 * 
 * ##################################
 */
  dbuse(__pyx_v_self->dbproc, __pyx_v_dbname_cstr);

  /* "_mssql.pyx":1364
 *             return 1
 * 
 *     def select_db(self, dbname):             # <<<<<<<<<<<<<<
 *         """
 *         select_db(dbname) -- Select the current database.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.select_db", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_dbname_bytes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pxd":26
 *     cdef int last_dbresults
 *     cdef int num_columns
 *     cdef public bint debug_queries             # <<<<<<<<<<<<<<
 *     cdef char *last_msg_str
 *     cdef char *last_msg_srv
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13debug_queries_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_13debug_queries_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_13debug_queries___get__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_13debug_queries___get__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->debug_queries); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.debug_queries.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6_mssql_15MSSQLConnection_13debug_queries_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6_mssql_15MSSQLConnection_13debug_queries_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_13debug_queries_2__set__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6_mssql_15MSSQLConnection_13debug_queries_2__set__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 26, __pyx_L1_error)
  __pyx_v_self->debug_queries = __pyx_t_1;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("_mssql.MSSQLConnection.debug_queries.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1387
 *     property connection:
 *         """The underlying MSSQLConnection object."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.conn
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_10connection_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_10connection_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_20MSSQLStoredProcedure_10connection___get__(((struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_10connection___get__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":1388
 *         """The underlying MSSQLConnection object."""
 *         def __get__(self):
 *             return self.conn             # <<<<<<<<<<<<<<
 * 
 *     property name:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->conn));
  __pyx_r = ((PyObject *)__pyx_v_self->conn);
  goto __pyx_L0;

  /* "_mssql.pyx":1387
 *     property connection:
 *         """The underlying MSSQLConnection object."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.conn
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1392
 *     property name:
 *         """The name of the procedure that this object represents."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.procname
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_4name_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_4name_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_20MSSQLStoredProcedure_4name___get__(((struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_4name___get__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":1393
 *         """The name of the procedure that this object represents."""
 *         def __get__(self):
 *             return self.procname             # <<<<<<<<<<<<<<
 * 
 *     property parameters:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->procname); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1392
 *     property name:
 *         """The name of the procedure that this object represents."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.procname
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLStoredProcedure.name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1397
 *     property parameters:
 *         """The parameters that have been bound to this procedure."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.params
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_10parameters_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_10parameters_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_20MSSQLStoredProcedure_10parameters___get__(((struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_10parameters___get__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":1398
 *         """The parameters that have been bound to this procedure."""
 *         def __get__(self):
 *             return self.params             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, bytes name, MSSQLConnection connection):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->params);
  __pyx_r = __pyx_v_self->params;
  goto __pyx_L0;

  /* "_mssql.pyx":1397
 *     property parameters:
 *         """The parameters that have been bound to this procedure."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.params
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1400
 *             return self.params
 * 
 *     def __init__(self, bytes name, MSSQLConnection connection):             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLStoredProcedure.__init__()")
 */

/* Python wrapper */
static int __pyx_pw_6_mssql_20MSSQLStoredProcedure_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_6_mssql_20MSSQLStoredProcedure_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_name = 0;
  struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_connection = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_connection,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_connection)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 1400, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1400, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_name = ((PyObject*)values[0]);
    __pyx_v_connection = ((struct __pyx_obj_6_mssql_MSSQLConnection *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1400, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLStoredProcedure.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_name), (&PyBytes_Type), 1, "name", 1))) __PYX_ERR(0, 1400, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_connection), __pyx_ptype_6_mssql_MSSQLConnection, 1, "connection", 0))) __PYX_ERR(0, 1400, __pyx_L1_error)
  __pyx_r = __pyx_pf_6_mssql_20MSSQLStoredProcedure___init__(((struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)__pyx_v_self), __pyx_v_name, __pyx_v_connection);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6_mssql_20MSSQLStoredProcedure___init__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self, PyObject *__pyx_v_name, struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_connection) {
  RETCODE __pyx_v_rtc;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  DBPROCESS *__pyx_t_4;
  char *__pyx_t_5;
  int __pyx_t_6;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "_mssql.pyx":1402
 *     def __init__(self, bytes name, MSSQLConnection connection):
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLStoredProcedure.__init__()")             # <<<<<<<<<<<<<<
 * 
 *         # We firstly want to check if tdsver is >= 7 as anything less
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLStoredProcedure.__init__()"));

  /* "_mssql.pyx":1406
 *         # We firstly want to check if tdsver is >= 7 as anything less
 *         # doesn't support remote procedure calls.
 *         if connection.tds_version < 7:             # <<<<<<<<<<<<<<
 *             raise MSSQLDriverException("Stored Procedures aren't "
 *                 "supported with a TDS version less than 7.")
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_connection), __pyx_n_s_tds_version); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_7, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1406, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1406, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "_mssql.pyx":1407
 *         # doesn't support remote procedure calls.
 *         if connection.tds_version < 7:
 *             raise MSSQLDriverException("Stored Procedures aren't "             # <<<<<<<<<<<<<<
 *                 "supported with a TDS version less than 7.")
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1407, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1407, __pyx_L1_error)

    /* "_mssql.pyx":1406
 *         # We firstly want to check if tdsver is >= 7 as anything less
 *         # doesn't support remote procedure calls.
 *         if connection.tds_version < 7:             # <<<<<<<<<<<<<<
 *             raise MSSQLDriverException("Stored Procedures aren't "
 *                 "supported with a TDS version less than 7.")
 */
  }

  /* "_mssql.pyx":1410
 *                 "supported with a TDS version less than 7.")
 * 
 *         self.conn = connection             # <<<<<<<<<<<<<<
 *         self.dbproc = connection.dbproc
 *         self.procname = name
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_connection));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_connection));
  __Pyx_GOTREF(__pyx_v_self->conn);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->conn));
  __pyx_v_self->conn = __pyx_v_connection;

  /* "_mssql.pyx":1411
 * 
 *         self.conn = connection
 *         self.dbproc = connection.dbproc             # <<<<<<<<<<<<<<
 *         self.procname = name
 *         self.params = dict()
 */
  __pyx_t_4 = __pyx_v_connection->dbproc;
  __pyx_v_self->dbproc = __pyx_t_4;

  /* "_mssql.pyx":1412
 *         self.conn = connection
 *         self.dbproc = connection.dbproc
 *         self.procname = name             # <<<<<<<<<<<<<<
 *         self.params = dict()
 *         self.output_indexes = list()
 */
  __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_name); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1412, __pyx_L1_error)
  __pyx_v_self->procname = __pyx_t_5;

  /* "_mssql.pyx":1413
 *         self.dbproc = connection.dbproc
 *         self.procname = name
 *         self.params = dict()             # <<<<<<<<<<<<<<
 *         self.output_indexes = list()
 *         self.param_count = 0
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->params);
  __Pyx_DECREF(__pyx_v_self->params);
  __pyx_v_self->params = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1414
 *         self.procname = name
 *         self.params = dict()
 *         self.output_indexes = list()             # <<<<<<<<<<<<<<
 *         self.param_count = 0
 *         self.had_positional = False
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->output_indexes);
  __Pyx_DECREF(__pyx_v_self->output_indexes);
  __pyx_v_self->output_indexes = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1415
 *         self.params = dict()
 *         self.output_indexes = list()
 *         self.param_count = 0             # <<<<<<<<<<<<<<
 *         self.had_positional = False
 * 
 */
  __pyx_v_self->param_count = 0;

  /* "_mssql.pyx":1416
 *         self.output_indexes = list()
 *         self.param_count = 0
 *         self.had_positional = False             # <<<<<<<<<<<<<<
 * 
 *         with nogil:
 */
  __Pyx_INCREF(Py_False);
  __Pyx_GIVEREF(Py_False);
  __Pyx_GOTREF(__pyx_v_self->had_positional);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->had_positional));
  __pyx_v_self->had_positional = ((PyBoolObject *)Py_False);

  /* "_mssql.pyx":1418
 *         self.had_positional = False
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcinit(self.dbproc, self.procname, 0)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":1419
 * 
 *         with nogil:
 *             rtc = dbrpcinit(self.dbproc, self.procname, 0)             # <<<<<<<<<<<<<<
 * 
 *         check_cancel_and_raise(rtc, self.conn)
 */
        __pyx_v_rtc = dbrpcinit(__pyx_v_self->dbproc, __pyx_v_self->procname, 0);
      }

      /* "_mssql.pyx":1418
 *         self.had_positional = False
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcinit(self.dbproc, self.procname, 0)
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L6;
        }
        __pyx_L6:;
      }
  }

  /* "_mssql.pyx":1421
 *             rtc = dbrpcinit(self.dbproc, self.procname, 0)
 * 
 *         check_cancel_and_raise(rtc, self.conn)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_t_2 = ((PyObject *)__pyx_v_self->conn);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_6 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_2)); if (unlikely(__pyx_t_6 == 1)) __PYX_ERR(0, 1421, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "_mssql.pyx":1400
 *             return self.params
 * 
 *     def __init__(self, bytes name, MSSQLConnection connection):             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLStoredProcedure.__init__()")
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_mssql.MSSQLStoredProcedure.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1423
 *         check_cancel_and_raise(rtc, self.conn)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef _mssql_parameter_node *n
 *         cdef _mssql_parameter_node *p
 */

/* Python wrapper */
static void __pyx_pw_6_mssql_20MSSQLStoredProcedure_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_6_mssql_20MSSQLStoredProcedure_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_6_mssql_20MSSQLStoredProcedure_2__dealloc__(((struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_6_mssql_20MSSQLStoredProcedure_2__dealloc__(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self) {
  struct __pyx_t_6_mssql__mssql_parameter_node *__pyx_v_n;
  struct __pyx_t_6_mssql__mssql_parameter_node *__pyx_v_p;
  __Pyx_RefNannyDeclarations
  struct __pyx_t_6_mssql__mssql_parameter_node *__pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "_mssql.pyx":1426
 *         cdef _mssql_parameter_node *n
 *         cdef _mssql_parameter_node *p
 *         log("_mssql.MSSQLStoredProcedure.__dealloc__()")             # <<<<<<<<<<<<<<
 * 
 *         n = self.params_list
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLStoredProcedure.__dealloc__()"));

  /* "_mssql.pyx":1428
 *         log("_mssql.MSSQLStoredProcedure.__dealloc__()")
 * 
 *         n = self.params_list             # <<<<<<<<<<<<<<
 *         p = NULL
 * 
 */
  __pyx_t_1 = __pyx_v_self->params_list;
  __pyx_v_n = __pyx_t_1;

  /* "_mssql.pyx":1429
 * 
 *         n = self.params_list
 *         p = NULL             # <<<<<<<<<<<<<<
 * 
 *         while n != NULL:
 */
  __pyx_v_p = NULL;

  /* "_mssql.pyx":1431
 *         p = NULL
 * 
 *         while n != NULL:             # <<<<<<<<<<<<<<
 *             PyMem_Free(n.value)
 *             p = n
 */
  while (1) {
    __pyx_t_2 = ((__pyx_v_n != NULL) != 0);
    if (!__pyx_t_2) break;

    /* "_mssql.pyx":1432
 * 
 *         while n != NULL:
 *             PyMem_Free(n.value)             # <<<<<<<<<<<<<<
 *             p = n
 *             n = n.next
 */
    PyMem_Free(__pyx_v_n->value);

    /* "_mssql.pyx":1433
 *         while n != NULL:
 *             PyMem_Free(n.value)
 *             p = n             # <<<<<<<<<<<<<<
 *             n = n.next
 *             PyMem_Free(p)
 */
    __pyx_v_p = __pyx_v_n;

    /* "_mssql.pyx":1434
 *             PyMem_Free(n.value)
 *             p = n
 *             n = n.next             # <<<<<<<<<<<<<<
 *             PyMem_Free(p)
 * 
 */
    __pyx_t_1 = __pyx_v_n->next;
    __pyx_v_n = __pyx_t_1;

    /* "_mssql.pyx":1435
 *             p = n
 *             n = n.next
 *             PyMem_Free(p)             # <<<<<<<<<<<<<<
 * 
 *     def bind(self, object value, int dbtype, str param_name=None,
 */
    PyMem_Free(__pyx_v_p);
  }

  /* "_mssql.pyx":1423
 *         check_cancel_and_raise(rtc, self.conn)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef _mssql_parameter_node *n
 *         cdef _mssql_parameter_node *p
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":1437
 *             PyMem_Free(p)
 * 
 *     def bind(self, object value, int dbtype, str param_name=None,             # <<<<<<<<<<<<<<
 *             int output=False, int null=False, int max_length=-1):
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_5bind(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_20MSSQLStoredProcedure_4bind[] = "\n        bind(value, data_type, param_name = None, output = False,\n            null = False, max_length = -1) -- bind a parameter\n\n        This method binds a parameter to the stored procedure.\n        ";
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_5bind(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_value = 0;
  int __pyx_v_dbtype;
  PyObject *__pyx_v_param_name = 0;
  int __pyx_v_output;
  int __pyx_v_null;
  int __pyx_v_max_length;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("bind (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_dbtype,&__pyx_n_s_param_name,&__pyx_n_s_output,&__pyx_n_s_null,&__pyx_n_s_max_length,0};
    PyObject* values[6] = {0,0,0,0,0,0};
    values[2] = ((PyObject*)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_dbtype)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("bind", 0, 2, 6, 1); __PYX_ERR(0, 1437, __pyx_L3_error)
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_param_name);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_output);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_null);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_length);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bind") < 0)) __PYX_ERR(0, 1437, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_value = values[0];
    __pyx_v_dbtype = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_dbtype == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1437, __pyx_L3_error)
    __pyx_v_param_name = ((PyObject*)values[2]);
    if (values[3]) {
      __pyx_v_output = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_output == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1438, __pyx_L3_error)
    } else {

      /* "_mssql.pyx":1438
 * 
 *     def bind(self, object value, int dbtype, str param_name=None,
 *             int output=False, int null=False, int max_length=-1):             # <<<<<<<<<<<<<<
 *         """
 *         bind(value, data_type, param_name = None, output = False,
 */
      __pyx_v_output = ((int)0);
    }
    if (values[4]) {
      __pyx_v_null = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_null == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1438, __pyx_L3_error)
    } else {
      __pyx_v_null = ((int)0);
    }
    if (values[5]) {
      __pyx_v_max_length = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_max_length == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1438, __pyx_L3_error)
    } else {
      __pyx_v_max_length = ((int)-1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bind", 0, 2, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1437, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.MSSQLStoredProcedure.bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_param_name), (&PyString_Type), 1, "param_name", 1))) __PYX_ERR(0, 1437, __pyx_L1_error)
  __pyx_r = __pyx_pf_6_mssql_20MSSQLStoredProcedure_4bind(((struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)__pyx_v_self), __pyx_v_value, __pyx_v_dbtype, __pyx_v_param_name, __pyx_v_output, __pyx_v_null, __pyx_v_max_length);

  /* "_mssql.pyx":1437
 *             PyMem_Free(p)
 * 
 *     def bind(self, object value, int dbtype, str param_name=None,             # <<<<<<<<<<<<<<
 *             int output=False, int null=False, int max_length=-1):
 *         """
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_4bind(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self, PyObject *__pyx_v_value, int __pyx_v_dbtype, PyObject *__pyx_v_param_name, int __pyx_v_output, int __pyx_v_null, int __pyx_v_max_length) {
  int __pyx_v_length;
  RETCODE __pyx_v_rtc;
  BYTE __pyx_v_status;
  BYTE *__pyx_v_data;
  PyObject *__pyx_v_param_name_bytes = 0;
  char *__pyx_v_param_name_cstr;
  struct __pyx_t_6_mssql__mssql_parameter_node *__pyx_v_pn;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  struct __pyx_t_6_mssql__mssql_parameter_node *__pyx_t_8;
  char *__pyx_t_9;
  int __pyx_t_10;
  __Pyx_RefNannySetupContext("bind", 0);

  /* "_mssql.pyx":1445
 *         This method binds a parameter to the stored procedure.
 *         """
 *         cdef int length = -1             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         cdef BYTE status
 */
  __pyx_v_length = -1;

  /* "_mssql.pyx":1452
 *         cdef char *param_name_cstr
 *         cdef _mssql_parameter_node *pn
 *         log("_mssql.MSSQLStoredProcedure.bind()")             # <<<<<<<<<<<<<<
 * 
 *         # Set status according to output being True or False
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLStoredProcedure.bind()"));

  /* "_mssql.pyx":1455
 * 
 *         # Set status according to output being True or False
 *         status = DBRPCRETURN if output else <BYTE>0             # <<<<<<<<<<<<<<
 * 
 *         # Convert the PyObject to the db type
 */
  if ((__pyx_v_output != 0)) {
    __pyx_t_1 = DBRPCRETURN;
  } else {
    __pyx_t_1 = ((BYTE)0);
  }
  __pyx_v_status = __pyx_t_1;

  /* "_mssql.pyx":1458
 * 
 *         # Convert the PyObject to the db type
 *         self.conn.convert_python_value(value, &data, &dbtype, &length)             # <<<<<<<<<<<<<<
 * 
 *         # We support nullable parameters by just not binding them
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->conn->__pyx_vtab)->convert_python_value(__pyx_v_self->conn, __pyx_v_value, (&__pyx_v_data), (&__pyx_v_dbtype), (&__pyx_v_length)); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 1458, __pyx_L1_error)

  /* "_mssql.pyx":1461
 * 
 *         # We support nullable parameters by just not binding them
 *         if dbtype in (SQLINTN, SQLBITN) and data == NULL:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = __pyx_v_dbtype;
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINTN); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_3 = __pyx_t_7;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLBITN); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_3 = __pyx_t_7;
  __pyx_L6_bool_binop_done:;
  __pyx_t_7 = (__pyx_t_3 != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_2 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_7 = ((__pyx_v_data == NULL) != 0);
  __pyx_t_2 = __pyx_t_7;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1462
 *         # We support nullable parameters by just not binding them
 *         if dbtype in (SQLINTN, SQLBITN) and data == NULL:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         # Store the converted parameter in our parameter list so we can
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "_mssql.pyx":1461
 * 
 *         # We support nullable parameters by just not binding them
 *         if dbtype in (SQLINTN, SQLBITN) and data == NULL:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  }

  /* "_mssql.pyx":1466
 *         # Store the converted parameter in our parameter list so we can
 *         # free() it later.
 *         if data != NULL:             # <<<<<<<<<<<<<<
 *             pn = <_mssql_parameter_node *>PyMem_Malloc(sizeof(_mssql_parameter_node))
 *             if pn == NULL:
 */
  __pyx_t_2 = ((__pyx_v_data != NULL) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1467
 *         # free() it later.
 *         if data != NULL:
 *             pn = <_mssql_parameter_node *>PyMem_Malloc(sizeof(_mssql_parameter_node))             # <<<<<<<<<<<<<<
 *             if pn == NULL:
 *                 raise MSSQLDriverException('Out of memory')
 */
    __pyx_v_pn = ((struct __pyx_t_6_mssql__mssql_parameter_node *)PyMem_Malloc((sizeof(struct __pyx_t_6_mssql__mssql_parameter_node))));

    /* "_mssql.pyx":1468
 *         if data != NULL:
 *             pn = <_mssql_parameter_node *>PyMem_Malloc(sizeof(_mssql_parameter_node))
 *             if pn == NULL:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('Out of memory')
 *             pn.next = self.params_list
 */
    __pyx_t_2 = ((__pyx_v_pn == NULL) != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1469
 *             pn = <_mssql_parameter_node *>PyMem_Malloc(sizeof(_mssql_parameter_node))
 *             if pn == NULL:
 *                 raise MSSQLDriverException('Out of memory')             # <<<<<<<<<<<<<<
 *             pn.next = self.params_list
 *             pn.value = data
 */
      __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1469, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 1469, __pyx_L1_error)

      /* "_mssql.pyx":1468
 *         if data != NULL:
 *             pn = <_mssql_parameter_node *>PyMem_Malloc(sizeof(_mssql_parameter_node))
 *             if pn == NULL:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('Out of memory')
 *             pn.next = self.params_list
 */
    }

    /* "_mssql.pyx":1470
 *             if pn == NULL:
 *                 raise MSSQLDriverException('Out of memory')
 *             pn.next = self.params_list             # <<<<<<<<<<<<<<
 *             pn.value = data
 *             self.params_list = pn
 */
    __pyx_t_8 = __pyx_v_self->params_list;
    __pyx_v_pn->next = __pyx_t_8;

    /* "_mssql.pyx":1471
 *                 raise MSSQLDriverException('Out of memory')
 *             pn.next = self.params_list
 *             pn.value = data             # <<<<<<<<<<<<<<
 *             self.params_list = pn
 * 
 */
    __pyx_v_pn->value = __pyx_v_data;

    /* "_mssql.pyx":1472
 *             pn.next = self.params_list
 *             pn.value = data
 *             self.params_list = pn             # <<<<<<<<<<<<<<
 * 
 *         # We may need to set the data length depending on the type being
 */
    __pyx_v_self->params_list = __pyx_v_pn;

    /* "_mssql.pyx":1466
 *         # Store the converted parameter in our parameter list so we can
 *         # free() it later.
 *         if data != NULL:             # <<<<<<<<<<<<<<
 *             pn = <_mssql_parameter_node *>PyMem_Malloc(sizeof(_mssql_parameter_node))
 *             if pn == NULL:
 */
  }

  /* "_mssql.pyx":1476
 *         # We may need to set the data length depending on the type being
 *         # passed to the server here.
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,             # <<<<<<<<<<<<<<
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:
 */
  __pyx_t_1 = __pyx_v_dbtype;
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLVARCHAR); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_2 = __pyx_t_7;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_2 = __pyx_t_7;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLTEXT); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_2 = __pyx_t_7;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLBINARY); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_2 = __pyx_t_7;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "_mssql.pyx":1477
 *         # passed to the server here.
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,
 *             SQLVARBINARY, SQLIMAGE):             # <<<<<<<<<<<<<<
 *             if null or data == NULL:
 *                 length = 0
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLVARBINARY); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1477, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "_mssql.pyx":1476
 *         # We may need to set the data length depending on the type being
 *         # passed to the server here.
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,             # <<<<<<<<<<<<<<
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:
 */
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_2 = __pyx_t_7;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "_mssql.pyx":1477
 *         # passed to the server here.
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,
 *             SQLVARBINARY, SQLIMAGE):             # <<<<<<<<<<<<<<
 *             if null or data == NULL:
 *                 length = 0
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLIMAGE); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1477, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "_mssql.pyx":1476
 *         # We may need to set the data length depending on the type being
 *         # passed to the server here.
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,             # <<<<<<<<<<<<<<
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:
 */
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __pyx_t_7;
  __pyx_L11_bool_binop_done:;
  __pyx_t_7 = (__pyx_t_2 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1478
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:             # <<<<<<<<<<<<<<
 *                 length = 0
 *                 if not output:
 */
    __pyx_t_2 = (__pyx_v_null != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_7 = __pyx_t_2;
      goto __pyx_L18_bool_binop_done;
    }
    __pyx_t_2 = ((__pyx_v_data == NULL) != 0);
    __pyx_t_7 = __pyx_t_2;
    __pyx_L18_bool_binop_done:;
    if (__pyx_t_7) {

      /* "_mssql.pyx":1479
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:
 *                 length = 0             # <<<<<<<<<<<<<<
 *                 if not output:
 *                     max_length = -1
 */
      __pyx_v_length = 0;

      /* "_mssql.pyx":1480
 *             if null or data == NULL:
 *                 length = 0
 *                 if not output:             # <<<<<<<<<<<<<<
 *                     max_length = -1
 *             # only set the length for strings, binary may contain NULLs
 */
      __pyx_t_7 = ((!(__pyx_v_output != 0)) != 0);
      if (__pyx_t_7) {

        /* "_mssql.pyx":1481
 *                 length = 0
 *                 if not output:
 *                     max_length = -1             # <<<<<<<<<<<<<<
 *             # only set the length for strings, binary may contain NULLs
 *             elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 */
        __pyx_v_max_length = -1;

        /* "_mssql.pyx":1480
 *             if null or data == NULL:
 *                 length = 0
 *                 if not output:             # <<<<<<<<<<<<<<
 *                     max_length = -1
 *             # only set the length for strings, binary may contain NULLs
 */
      }

      /* "_mssql.pyx":1478
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:             # <<<<<<<<<<<<<<
 *                 length = 0
 *                 if not output:
 */
      goto __pyx_L17;
    }

    /* "_mssql.pyx":1483
 *                     max_length = -1
 *             # only set the length for strings, binary may contain NULLs
 *             elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):             # <<<<<<<<<<<<<<
 *                 length = strlen(<char *>data)
 *         else:
 */
    __pyx_t_1 = __pyx_v_dbtype;
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLVARCHAR); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!__pyx_t_2) {
    } else {
      __pyx_t_7 = __pyx_t_2;
      goto __pyx_L21_bool_binop_done;
    }
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!__pyx_t_2) {
    } else {
      __pyx_t_7 = __pyx_t_2;
      goto __pyx_L21_bool_binop_done;
    }
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLTEXT); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = __pyx_t_2;
    __pyx_L21_bool_binop_done:;
    __pyx_t_2 = (__pyx_t_7 != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1484
 *             # only set the length for strings, binary may contain NULLs
 *             elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *                 length = strlen(<char *>data)             # <<<<<<<<<<<<<<
 *         else:
 *             # Fixed length data type
 */
      __pyx_v_length = strlen(((char *)__pyx_v_data));

      /* "_mssql.pyx":1483
 *                     max_length = -1
 *             # only set the length for strings, binary may contain NULLs
 *             elif dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT):             # <<<<<<<<<<<<<<
 *                 length = strlen(<char *>data)
 *         else:
 */
    }
    __pyx_L17:;

    /* "_mssql.pyx":1476
 *         # We may need to set the data length depending on the type being
 *         # passed to the server here.
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,             # <<<<<<<<<<<<<<
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:
 */
    goto __pyx_L10;
  }

  /* "_mssql.pyx":1487
 *         else:
 *             # Fixed length data type
 *             if null or (output and dbtype not in (SQLDECIMAL, SQLNUMERIC)):             # <<<<<<<<<<<<<<
 *                 length = 0
 *             max_length = -1
 */
  /*else*/ {
    __pyx_t_7 = (__pyx_v_null != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_2 = __pyx_t_7;
      goto __pyx_L25_bool_binop_done;
    }
    __pyx_t_7 = (__pyx_v_output != 0);
    if (__pyx_t_7) {
    } else {
      __pyx_t_2 = __pyx_t_7;
      goto __pyx_L25_bool_binop_done;
    }
    __pyx_t_1 = __pyx_v_dbtype;
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1487, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDECIMAL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1487, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1487, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1487, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_3) {
    } else {
      __pyx_t_7 = __pyx_t_3;
      goto __pyx_L28_bool_binop_done;
    }
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1487, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLNUMERIC); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1487, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1487, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1487, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = __pyx_t_3;
    __pyx_L28_bool_binop_done:;
    __pyx_t_3 = (__pyx_t_7 != 0);
    __pyx_t_2 = __pyx_t_3;
    __pyx_L25_bool_binop_done:;
    if (__pyx_t_2) {

      /* "_mssql.pyx":1488
 *             # Fixed length data type
 *             if null or (output and dbtype not in (SQLDECIMAL, SQLNUMERIC)):
 *                 length = 0             # <<<<<<<<<<<<<<
 *             max_length = -1
 * 
 */
      __pyx_v_length = 0;

      /* "_mssql.pyx":1487
 *         else:
 *             # Fixed length data type
 *             if null or (output and dbtype not in (SQLDECIMAL, SQLNUMERIC)):             # <<<<<<<<<<<<<<
 *                 length = 0
 *             max_length = -1
 */
    }

    /* "_mssql.pyx":1489
 *             if null or (output and dbtype not in (SQLDECIMAL, SQLNUMERIC)):
 *                 length = 0
 *             max_length = -1             # <<<<<<<<<<<<<<
 * 
 *         # Add some monkey fixing for nullable bit types
 */
    __pyx_v_max_length = -1;
  }
  __pyx_L10:;

  /* "_mssql.pyx":1492
 * 
 *         # Add some monkey fixing for nullable bit types
 *         if dbtype == SQLBITN:             # <<<<<<<<<<<<<<
 *             if output:
 *                 max_length = 1
 */
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_dbtype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLBITN); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1492, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1492, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1493
 *         # Add some monkey fixing for nullable bit types
 *         if dbtype == SQLBITN:
 *             if output:             # <<<<<<<<<<<<<<
 *                 max_length = 1
 *                 length = 0
 */
    __pyx_t_2 = (__pyx_v_output != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1494
 *         if dbtype == SQLBITN:
 *             if output:
 *                 max_length = 1             # <<<<<<<<<<<<<<
 *                 length = 0
 *             else:
 */
      __pyx_v_max_length = 1;

      /* "_mssql.pyx":1495
 *             if output:
 *                 max_length = 1
 *                 length = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 length = 1
 */
      __pyx_v_length = 0;

      /* "_mssql.pyx":1493
 *         # Add some monkey fixing for nullable bit types
 *         if dbtype == SQLBITN:
 *             if output:             # <<<<<<<<<<<<<<
 *                 max_length = 1
 *                 length = 0
 */
      goto __pyx_L31;
    }

    /* "_mssql.pyx":1497
 *                 length = 0
 *             else:
 *                 length = 1             # <<<<<<<<<<<<<<
 * 
 *         if status != DBRPCRETURN:
 */
    /*else*/ {
      __pyx_v_length = 1;
    }
    __pyx_L31:;

    /* "_mssql.pyx":1492
 * 
 *         # Add some monkey fixing for nullable bit types
 *         if dbtype == SQLBITN:             # <<<<<<<<<<<<<<
 *             if output:
 *                 max_length = 1
 */
  }

  /* "_mssql.pyx":1499
 *                 length = 1
 * 
 *         if status != DBRPCRETURN:             # <<<<<<<<<<<<<<
 *             max_length = -1
 * 
 */
  __pyx_t_2 = ((__pyx_v_status != DBRPCRETURN) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1500
 * 
 *         if status != DBRPCRETURN:
 *             max_length = -1             # <<<<<<<<<<<<<<
 * 
 *         if param_name:
 */
    __pyx_v_max_length = -1;

    /* "_mssql.pyx":1499
 *                 length = 1
 * 
 *         if status != DBRPCRETURN:             # <<<<<<<<<<<<<<
 *             max_length = -1
 * 
 */
  }

  /* "_mssql.pyx":1502
 *             max_length = -1
 * 
 *         if param_name:             # <<<<<<<<<<<<<<
 *             param_name_bytes = param_name.encode('ascii')
 *             param_name_cstr = param_name_bytes
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_param_name); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1502, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "_mssql.pyx":1503
 * 
 *         if param_name:
 *             param_name_bytes = param_name.encode('ascii')             # <<<<<<<<<<<<<<
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_param_name, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1503, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1503, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 1503, __pyx_L1_error)
    __pyx_v_param_name_bytes = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":1504
 *         if param_name:
 *             param_name_bytes = param_name.encode('ascii')
 *             param_name_cstr = param_name_bytes             # <<<<<<<<<<<<<<
 *             if self.had_positional:
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')
 */
    __pyx_t_9 = __Pyx_PyObject_AsString(__pyx_v_param_name_bytes); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 1504, __pyx_L1_error)
    __pyx_v_param_name_cstr = __pyx_t_9;

    /* "_mssql.pyx":1505
 *             param_name_bytes = param_name.encode('ascii')
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')
 *         else:
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->had_positional)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1505, __pyx_L1_error)
    if (__pyx_t_2) {

      /* "_mssql.pyx":1506
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')             # <<<<<<<<<<<<<<
 *         else:
 *             param_name_cstr = ''
 */
      __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1506, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 1506, __pyx_L1_error)

      /* "_mssql.pyx":1505
 *             param_name_bytes = param_name.encode('ascii')
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')
 *         else:
 */
    }

    /* "_mssql.pyx":1502
 *             max_length = -1
 * 
 *         if param_name:             # <<<<<<<<<<<<<<
 *             param_name_bytes = param_name.encode('ascii')
 *             param_name_cstr = param_name_bytes
 */
    goto __pyx_L33;
  }

  /* "_mssql.pyx":1508
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')
 *         else:
 *             param_name_cstr = ''             # <<<<<<<<<<<<<<
 *             self.had_positional = True
 * 
 */
  /*else*/ {
    __pyx_v_param_name_cstr = ((char *)"");

    /* "_mssql.pyx":1509
 *         else:
 *             param_name_cstr = ''
 *             self.had_positional = True             # <<<<<<<<<<<<<<
 * 
 *         IF PYMSSQL_DEBUG == 1:
 */
    __Pyx_INCREF(Py_True);
    __Pyx_GIVEREF(Py_True);
    __Pyx_GOTREF(__pyx_v_self->had_positional);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->had_positional));
    __pyx_v_self->had_positional = ((PyBoolObject *)Py_True);
  }
  __pyx_L33:;

  /* "_mssql.pyx":1518
 *             )
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcparam(self.dbproc, param_name_cstr, status, dbtype,
 *                 max_length, length, data)
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":1519
 * 
 *         with nogil:
 *             rtc = dbrpcparam(self.dbproc, param_name_cstr, status, dbtype,             # <<<<<<<<<<<<<<
 *                 max_length, length, data)
 *         check_cancel_and_raise(rtc, self.conn)
 */
        __pyx_v_rtc = dbrpcparam(__pyx_v_self->dbproc, __pyx_v_param_name_cstr, __pyx_v_status, __pyx_v_dbtype, __pyx_v_max_length, __pyx_v_length, __pyx_v_data);
      }

      /* "_mssql.pyx":1518
 *             )
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcparam(self.dbproc, param_name_cstr, status, dbtype,
 *                 max_length, length, data)
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L37;
        }
        __pyx_L37:;
      }
  }

  /* "_mssql.pyx":1521
 *             rtc = dbrpcparam(self.dbproc, param_name_cstr, status, dbtype,
 *                 max_length, length, data)
 *         check_cancel_and_raise(rtc, self.conn)             # <<<<<<<<<<<<<<
 * 
 *         # Store the value in the parameters dictionary for returning
 */
  __pyx_t_5 = ((PyObject *)__pyx_v_self->conn);
  __Pyx_INCREF(__pyx_t_5);
  __pyx_t_1 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_5)); if (unlikely(__pyx_t_1 == 1)) __PYX_ERR(0, 1521, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "_mssql.pyx":1525
 *         # Store the value in the parameters dictionary for returning
 *         # later, by name if that has been supplied.
 *         if param_name:             # <<<<<<<<<<<<<<
 *             self.params[param_name] = value
 *         self.params[self.param_count] = value
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_param_name); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1525, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "_mssql.pyx":1526
 *         # later, by name if that has been supplied.
 *         if param_name:
 *             self.params[param_name] = value             # <<<<<<<<<<<<<<
 *         self.params[self.param_count] = value
 *         if output:
 */
    if (unlikely(__pyx_v_self->params == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 1526, __pyx_L1_error)
    }
    if (unlikely(PyDict_SetItem(__pyx_v_self->params, __pyx_v_param_name, __pyx_v_value) < 0)) __PYX_ERR(0, 1526, __pyx_L1_error)

    /* "_mssql.pyx":1525
 *         # Store the value in the parameters dictionary for returning
 *         # later, by name if that has been supplied.
 *         if param_name:             # <<<<<<<<<<<<<<
 *             self.params[param_name] = value
 *         self.params[self.param_count] = value
 */
  }

  /* "_mssql.pyx":1527
 *         if param_name:
 *             self.params[param_name] = value
 *         self.params[self.param_count] = value             # <<<<<<<<<<<<<<
 *         if output:
 *             self.output_indexes.append(self.param_count)
 */
  if (unlikely(__pyx_v_self->params == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 1527, __pyx_L1_error)
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->param_count); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1527, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (unlikely(PyDict_SetItem(__pyx_v_self->params, __pyx_t_5, __pyx_v_value) < 0)) __PYX_ERR(0, 1527, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "_mssql.pyx":1528
 *             self.params[param_name] = value
 *         self.params[self.param_count] = value
 *         if output:             # <<<<<<<<<<<<<<
 *             self.output_indexes.append(self.param_count)
 *         self.param_count += 1
 */
  __pyx_t_2 = (__pyx_v_output != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1529
 *         self.params[self.param_count] = value
 *         if output:
 *             self.output_indexes.append(self.param_count)             # <<<<<<<<<<<<<<
 *         self.param_count += 1
 * 
 */
    if (unlikely(__pyx_v_self->output_indexes == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
      __PYX_ERR(0, 1529, __pyx_L1_error)
    }
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->param_count); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1529, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_self->output_indexes, __pyx_t_5); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 1529, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "_mssql.pyx":1528
 *             self.params[param_name] = value
 *         self.params[self.param_count] = value
 *         if output:             # <<<<<<<<<<<<<<
 *             self.output_indexes.append(self.param_count)
 *         self.param_count += 1
 */
  }

  /* "_mssql.pyx":1530
 *         if output:
 *             self.output_indexes.append(self.param_count)
 *         self.param_count += 1             # <<<<<<<<<<<<<<
 * 
 *     def execute(self):
 */
  __pyx_v_self->param_count = (__pyx_v_self->param_count + 1);

  /* "_mssql.pyx":1437
 *             PyMem_Free(p)
 * 
 *     def bind(self, object value, int dbtype, str param_name=None,             # <<<<<<<<<<<<<<
 *             int output=False, int null=False, int max_length=-1):
 *         """
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_mssql.MSSQLStoredProcedure.bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_param_name_bytes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1532
 *         self.param_count += 1
 * 
 *     def execute(self):             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         cdef int output_count, i, type, length
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_7execute(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_6_mssql_20MSSQLStoredProcedure_7execute(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("execute (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_20MSSQLStoredProcedure_6execute(((struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_20MSSQLStoredProcedure_6execute(struct __pyx_obj_6_mssql_MSSQLStoredProcedure *__pyx_v_self) {
  RETCODE __pyx_v_rtc;
  int __pyx_v_output_count;
  int __pyx_v_i;
  int __pyx_v_type;
  int __pyx_v_length;
  char *__pyx_v_param_name_bytes;
  BYTE *__pyx_v_data;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_param_name = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  long __pyx_t_4;
  long __pyx_t_5;
  __Pyx_RefNannySetupContext("execute", 0);

  /* "_mssql.pyx":1537
 *         cdef char *param_name_bytes
 *         cdef BYTE *data
 *         log("_mssql.MSSQLStoredProcedure.execute()")             # <<<<<<<<<<<<<<
 * 
 *         # Cancel any pending results as this throws a server error
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.MSSQLStoredProcedure.execute()"));

  /* "_mssql.pyx":1541
 *         # Cancel any pending results as this throws a server error
 *         # otherwise.
 *         db_cancel(self.conn)             # <<<<<<<<<<<<<<
 * 
 *         # Send the RPC request
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->conn);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_f_6_mssql_db_cancel(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1544
 * 
 *         # Send the RPC request
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcsend(self.dbproc)
 *         check_cancel_and_raise(rtc, self.conn)
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":1545
 *         # Send the RPC request
 *         with nogil:
 *             rtc = dbrpcsend(self.dbproc)             # <<<<<<<<<<<<<<
 *         check_cancel_and_raise(rtc, self.conn)
 * 
 */
        __pyx_v_rtc = dbrpcsend(__pyx_v_self->dbproc);
      }

      /* "_mssql.pyx":1544
 * 
 *         # Send the RPC request
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcsend(self.dbproc)
 *         check_cancel_and_raise(rtc, self.conn)
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "_mssql.pyx":1546
 *         with nogil:
 *             rtc = dbrpcsend(self.dbproc)
 *         check_cancel_and_raise(rtc, self.conn)             # <<<<<<<<<<<<<<
 * 
 *         # Wait for results to come back and return the return code, optionally
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->conn);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_1)); if (unlikely(__pyx_t_2 == 1)) __PYX_ERR(0, 1546, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1550
 *         # Wait for results to come back and return the return code, optionally
 *         # calling wait_callback first...
 *         rtc = db_sqlok(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *         check_cancel_and_raise(rtc, self.conn)
 */
  __pyx_v_rtc = __pyx_f_6_mssql_db_sqlok(__pyx_v_self->dbproc);

  /* "_mssql.pyx":1552
 *         rtc = db_sqlok(self.dbproc)
 * 
 *         check_cancel_and_raise(rtc, self.conn)             # <<<<<<<<<<<<<<
 * 
 *         # Need to call this regardless of whether or not there are output
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->conn);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_1)); if (unlikely(__pyx_t_2 == 1)) __PYX_ERR(0, 1552, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1556
 *         # Need to call this regardless of whether or not there are output
 *         # parameters in order for the return status to be correct.
 *         output_count = dbnumrets(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *         # If there are any output parameters then we are going to want to
 */
  __pyx_v_output_count = dbnumrets(__pyx_v_self->dbproc);

  /* "_mssql.pyx":1560
 *         # If there are any output parameters then we are going to want to
 *         # set the values in the parameters dictionary.
 *         if output_count:             # <<<<<<<<<<<<<<
 *             for i in xrange(1, output_count + 1):
 *                 with nogil:
 */
  __pyx_t_3 = (__pyx_v_output_count != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1561
 *         # set the values in the parameters dictionary.
 *         if output_count:
 *             for i in xrange(1, output_count + 1):             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     type = dbrettype(self.dbproc, i)
 */
    __pyx_t_4 = (__pyx_v_output_count + 1);
    for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_4; __pyx_t_2+=1) {
      __pyx_v_i = __pyx_t_2;

      /* "_mssql.pyx":1562
 *         if output_count:
 *             for i in xrange(1, output_count + 1):
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     type = dbrettype(self.dbproc, i)
 *                     param_name_bytes = dbretname(self.dbproc, i)
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          #endif
          /*try:*/ {

            /* "_mssql.pyx":1563
 *             for i in xrange(1, output_count + 1):
 *                 with nogil:
 *                     type = dbrettype(self.dbproc, i)             # <<<<<<<<<<<<<<
 *                     param_name_bytes = dbretname(self.dbproc, i)
 *                     length = dbretlen(self.dbproc, i)
 */
            __pyx_v_type = dbrettype(__pyx_v_self->dbproc, __pyx_v_i);

            /* "_mssql.pyx":1564
 *                 with nogil:
 *                     type = dbrettype(self.dbproc, i)
 *                     param_name_bytes = dbretname(self.dbproc, i)             # <<<<<<<<<<<<<<
 *                     length = dbretlen(self.dbproc, i)
 *                     data = dbretdata(self.dbproc, i)
 */
            __pyx_v_param_name_bytes = dbretname(__pyx_v_self->dbproc, __pyx_v_i);

            /* "_mssql.pyx":1565
 *                     type = dbrettype(self.dbproc, i)
 *                     param_name_bytes = dbretname(self.dbproc, i)
 *                     length = dbretlen(self.dbproc, i)             # <<<<<<<<<<<<<<
 *                     data = dbretdata(self.dbproc, i)
 * 
 */
            __pyx_v_length = dbretlen(__pyx_v_self->dbproc, __pyx_v_i);

            /* "_mssql.pyx":1566
 *                     param_name_bytes = dbretname(self.dbproc, i)
 *                     length = dbretlen(self.dbproc, i)
 *                     data = dbretdata(self.dbproc, i)             # <<<<<<<<<<<<<<
 * 
 *                 value = self.conn.convert_db_value(data, type, length)
 */
            __pyx_v_data = dbretdata(__pyx_v_self->dbproc, __pyx_v_i);
          }

          /* "_mssql.pyx":1562
 *         if output_count:
 *             for i in xrange(1, output_count + 1):
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     type = dbrettype(self.dbproc, i)
 *                     param_name_bytes = dbretname(self.dbproc, i)
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L13;
            }
            __pyx_L13:;
          }
      }

      /* "_mssql.pyx":1568
 *                     data = dbretdata(self.dbproc, i)
 * 
 *                 value = self.conn.convert_db_value(data, type, length)             # <<<<<<<<<<<<<<
 *                 if strlen(param_name_bytes):
 *                     param_name = param_name_bytes.decode('utf-8')
 */
      __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->conn->__pyx_vtab)->convert_db_value(__pyx_v_self->conn, __pyx_v_data, __pyx_v_type, __pyx_v_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1568, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "_mssql.pyx":1569
 * 
 *                 value = self.conn.convert_db_value(data, type, length)
 *                 if strlen(param_name_bytes):             # <<<<<<<<<<<<<<
 *                     param_name = param_name_bytes.decode('utf-8')
 *                     self.params[param_name] = value
 */
      __pyx_t_3 = (strlen(__pyx_v_param_name_bytes) != 0);
      if (__pyx_t_3) {

        /* "_mssql.pyx":1570
 *                 value = self.conn.convert_db_value(data, type, length)
 *                 if strlen(param_name_bytes):
 *                     param_name = param_name_bytes.decode('utf-8')             # <<<<<<<<<<<<<<
 *                     self.params[param_name] = value
 *                 self.params[self.output_indexes[i-1]] = value
 */
        __pyx_t_1 = __Pyx_decode_c_string(__pyx_v_param_name_bytes, 0, strlen(__pyx_v_param_name_bytes), NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1570, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_XDECREF_SET(__pyx_v_param_name, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "_mssql.pyx":1571
 *                 if strlen(param_name_bytes):
 *                     param_name = param_name_bytes.decode('utf-8')
 *                     self.params[param_name] = value             # <<<<<<<<<<<<<<
 *                 self.params[self.output_indexes[i-1]] = value
 * 
 */
        if (unlikely(__pyx_v_self->params == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 1571, __pyx_L1_error)
        }
        if (unlikely(PyDict_SetItem(__pyx_v_self->params, __pyx_v_param_name, __pyx_v_value) < 0)) __PYX_ERR(0, 1571, __pyx_L1_error)

        /* "_mssql.pyx":1569
 * 
 *                 value = self.conn.convert_db_value(data, type, length)
 *                 if strlen(param_name_bytes):             # <<<<<<<<<<<<<<
 *                     param_name = param_name_bytes.decode('utf-8')
 *                     self.params[param_name] = value
 */
      }

      /* "_mssql.pyx":1572
 *                     param_name = param_name_bytes.decode('utf-8')
 *                     self.params[param_name] = value
 *                 self.params[self.output_indexes[i-1]] = value             # <<<<<<<<<<<<<<
 * 
 *         # Get the return value from the procedure ready for return.
 */
      if (unlikely(__pyx_v_self->params == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 1572, __pyx_L1_error)
      }
      if (unlikely(__pyx_v_self->output_indexes == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 1572, __pyx_L1_error)
      }
      __pyx_t_5 = (__pyx_v_i - 1);
      __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_self->output_indexes, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1572, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (unlikely(PyDict_SetItem(__pyx_v_self->params, __pyx_t_1, __pyx_v_value) < 0)) __PYX_ERR(0, 1572, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }

    /* "_mssql.pyx":1560
 *         # If there are any output parameters then we are going to want to
 *         # set the values in the parameters dictionary.
 *         if output_count:             # <<<<<<<<<<<<<<
 *             for i in xrange(1, output_count + 1):
 *                 with nogil:
 */
  }

  /* "_mssql.pyx":1575
 * 
 *         # Get the return value from the procedure ready for return.
 *         return dbretstatus(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 * cdef int check_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_DBINT(dbretstatus(__pyx_v_self->dbproc)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1575, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1532
 *         self.param_count += 1
 * 
 *     def execute(self):             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         cdef int output_count, i, type, length
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLStoredProcedure.execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_param_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1577
 *         return dbretstatus(self.dbproc)
 * 
 * cdef int check_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:             # <<<<<<<<<<<<<<
 *     if rtc == FAIL:
 *         return maybe_raise_MSSQLDatabaseException(conn)
 */

static int __pyx_f_6_mssql_check_and_raise(RETCODE __pyx_v_rtc, struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("check_and_raise", 0);

  /* "_mssql.pyx":1578
 * 
 * cdef int check_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:
 *     if rtc == FAIL:             # <<<<<<<<<<<<<<
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):
 */
  __pyx_t_1 = ((__pyx_v_rtc == FAIL) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1579
 * cdef int check_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:
 *     if rtc == FAIL:
 *         return maybe_raise_MSSQLDatabaseException(conn)             # <<<<<<<<<<<<<<
 *     elif get_last_msg_str(conn):
 *         return maybe_raise_MSSQLDatabaseException(conn)
 */
    __pyx_t_2 = __pyx_f_6_mssql_maybe_raise_MSSQLDatabaseException(__pyx_v_conn); if (unlikely(__pyx_t_2 == 1)) __PYX_ERR(0, 1579, __pyx_L1_error)
    __pyx_r = __pyx_t_2;
    goto __pyx_L0;

    /* "_mssql.pyx":1578
 * 
 * cdef int check_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:
 *     if rtc == FAIL:             # <<<<<<<<<<<<<<
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):
 */
  }

  /* "_mssql.pyx":1580
 *     if rtc == FAIL:
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):             # <<<<<<<<<<<<<<
 *         return maybe_raise_MSSQLDatabaseException(conn)
 * 
 */
  __pyx_t_1 = (__pyx_f_6_mssql_get_last_msg_str(__pyx_v_conn) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1581
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):
 *         return maybe_raise_MSSQLDatabaseException(conn)             # <<<<<<<<<<<<<<
 * 
 * cdef int check_cancel_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:
 */
    __pyx_t_2 = __pyx_f_6_mssql_maybe_raise_MSSQLDatabaseException(__pyx_v_conn); if (unlikely(__pyx_t_2 == 1)) __PYX_ERR(0, 1581, __pyx_L1_error)
    __pyx_r = __pyx_t_2;
    goto __pyx_L0;

    /* "_mssql.pyx":1580
 *     if rtc == FAIL:
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):             # <<<<<<<<<<<<<<
 *         return maybe_raise_MSSQLDatabaseException(conn)
 * 
 */
  }

  /* "_mssql.pyx":1577
 *         return dbretstatus(self.dbproc)
 * 
 * cdef int check_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:             # <<<<<<<<<<<<<<
 *     if rtc == FAIL:
 *         return maybe_raise_MSSQLDatabaseException(conn)
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("_mssql.check_and_raise", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1583
 *         return maybe_raise_MSSQLDatabaseException(conn)
 * 
 * cdef int check_cancel_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:             # <<<<<<<<<<<<<<
 *     if rtc == FAIL:
 *         db_cancel(conn)
 */

static int __pyx_f_6_mssql_check_cancel_and_raise(RETCODE __pyx_v_rtc, struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("check_cancel_and_raise", 0);

  /* "_mssql.pyx":1584
 * 
 * cdef int check_cancel_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:
 *     if rtc == FAIL:             # <<<<<<<<<<<<<<
 *         db_cancel(conn)
 *         return maybe_raise_MSSQLDatabaseException(conn)
 */
  __pyx_t_1 = ((__pyx_v_rtc == FAIL) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1585
 * cdef int check_cancel_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:
 *     if rtc == FAIL:
 *         db_cancel(conn)             # <<<<<<<<<<<<<<
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):
 */
    __pyx_f_6_mssql_db_cancel(__pyx_v_conn);

    /* "_mssql.pyx":1586
 *     if rtc == FAIL:
 *         db_cancel(conn)
 *         return maybe_raise_MSSQLDatabaseException(conn)             # <<<<<<<<<<<<<<
 *     elif get_last_msg_str(conn):
 *         return maybe_raise_MSSQLDatabaseException(conn)
 */
    __pyx_t_2 = __pyx_f_6_mssql_maybe_raise_MSSQLDatabaseException(__pyx_v_conn); if (unlikely(__pyx_t_2 == 1)) __PYX_ERR(0, 1586, __pyx_L1_error)
    __pyx_r = __pyx_t_2;
    goto __pyx_L0;

    /* "_mssql.pyx":1584
 * 
 * cdef int check_cancel_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:
 *     if rtc == FAIL:             # <<<<<<<<<<<<<<
 *         db_cancel(conn)
 *         return maybe_raise_MSSQLDatabaseException(conn)
 */
  }

  /* "_mssql.pyx":1587
 *         db_cancel(conn)
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):             # <<<<<<<<<<<<<<
 *         return maybe_raise_MSSQLDatabaseException(conn)
 * 
 */
  __pyx_t_1 = (__pyx_f_6_mssql_get_last_msg_str(__pyx_v_conn) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1588
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):
 *         return maybe_raise_MSSQLDatabaseException(conn)             # <<<<<<<<<<<<<<
 * 
 * cdef char *get_last_msg_str(MSSQLConnection conn):
 */
    __pyx_t_2 = __pyx_f_6_mssql_maybe_raise_MSSQLDatabaseException(__pyx_v_conn); if (unlikely(__pyx_t_2 == 1)) __PYX_ERR(0, 1588, __pyx_L1_error)
    __pyx_r = __pyx_t_2;
    goto __pyx_L0;

    /* "_mssql.pyx":1587
 *         db_cancel(conn)
 *         return maybe_raise_MSSQLDatabaseException(conn)
 *     elif get_last_msg_str(conn):             # <<<<<<<<<<<<<<
 *         return maybe_raise_MSSQLDatabaseException(conn)
 * 
 */
  }

  /* "_mssql.pyx":1583
 *         return maybe_raise_MSSQLDatabaseException(conn)
 * 
 * cdef int check_cancel_and_raise(RETCODE rtc, MSSQLConnection conn) except 1:             # <<<<<<<<<<<<<<
 *     if rtc == FAIL:
 *         db_cancel(conn)
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("_mssql.check_cancel_and_raise", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1590
 *         return maybe_raise_MSSQLDatabaseException(conn)
 * 
 * cdef char *get_last_msg_str(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_str if conn != None else _mssql_last_msg_str
 * 
 */

static char *__pyx_f_6_mssql_get_last_msg_str(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  char *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("get_last_msg_str", 0);

  /* "_mssql.pyx":1591
 * 
 * cdef char *get_last_msg_str(MSSQLConnection conn):
 *     return conn.last_msg_str if conn != None else _mssql_last_msg_str             # <<<<<<<<<<<<<<
 * 
 * cdef char *get_last_msg_srv(MSSQLConnection conn):
 */
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1591, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1591, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_1 = __pyx_v_conn->last_msg_str;
  } else {
    __pyx_t_1 = __pyx_v_6_mssql__mssql_last_msg_str;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1590
 *         return maybe_raise_MSSQLDatabaseException(conn)
 * 
 * cdef char *get_last_msg_str(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_str if conn != None else _mssql_last_msg_str
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_str", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1593
 *     return conn.last_msg_str if conn != None else _mssql_last_msg_str
 * 
 * cdef char *get_last_msg_srv(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_srv if conn != None else _mssql_last_msg_srv
 * 
 */

static char *__pyx_f_6_mssql_get_last_msg_srv(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  char *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("get_last_msg_srv", 0);

  /* "_mssql.pyx":1594
 * 
 * cdef char *get_last_msg_srv(MSSQLConnection conn):
 *     return conn.last_msg_srv if conn != None else _mssql_last_msg_srv             # <<<<<<<<<<<<<<
 * 
 * cdef char *get_last_msg_proc(MSSQLConnection conn):
 */
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1594, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1594, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_1 = __pyx_v_conn->last_msg_srv;
  } else {
    __pyx_t_1 = __pyx_v_6_mssql__mssql_last_msg_srv;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1593
 *     return conn.last_msg_str if conn != None else _mssql_last_msg_str
 * 
 * cdef char *get_last_msg_srv(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_srv if conn != None else _mssql_last_msg_srv
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_srv", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1596
 *     return conn.last_msg_srv if conn != None else _mssql_last_msg_srv
 * 
 * cdef char *get_last_msg_proc(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_proc if conn != None else _mssql_last_msg_proc
 * 
 */

static char *__pyx_f_6_mssql_get_last_msg_proc(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  char *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("get_last_msg_proc", 0);

  /* "_mssql.pyx":1597
 * 
 * cdef char *get_last_msg_proc(MSSQLConnection conn):
 *     return conn.last_msg_proc if conn != None else _mssql_last_msg_proc             # <<<<<<<<<<<<<<
 * 
 * cdef int get_last_msg_no(MSSQLConnection conn):
 */
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1597, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1597, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_1 = __pyx_v_conn->last_msg_proc;
  } else {
    __pyx_t_1 = __pyx_v_6_mssql__mssql_last_msg_proc;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1596
 *     return conn.last_msg_srv if conn != None else _mssql_last_msg_srv
 * 
 * cdef char *get_last_msg_proc(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_proc if conn != None else _mssql_last_msg_proc
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_proc", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1599
 *     return conn.last_msg_proc if conn != None else _mssql_last_msg_proc
 * 
 * cdef int get_last_msg_no(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_no if conn != None else _mssql_last_msg_no
 * 
 */

static int __pyx_f_6_mssql_get_last_msg_no(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("get_last_msg_no", 0);

  /* "_mssql.pyx":1600
 * 
 * cdef int get_last_msg_no(MSSQLConnection conn):
 *     return conn.last_msg_no if conn != None else _mssql_last_msg_no             # <<<<<<<<<<<<<<
 * 
 * cdef int get_last_msg_severity(MSSQLConnection conn):
 */
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1600, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1600, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_1 = __pyx_v_conn->last_msg_no;
  } else {
    __pyx_t_1 = __pyx_v_6_mssql__mssql_last_msg_no;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1599
 *     return conn.last_msg_proc if conn != None else _mssql_last_msg_proc
 * 
 * cdef int get_last_msg_no(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_no if conn != None else _mssql_last_msg_no
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_no", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1602
 *     return conn.last_msg_no if conn != None else _mssql_last_msg_no
 * 
 * cdef int get_last_msg_severity(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_severity if conn != None else _mssql_last_msg_severity
 * 
 */

static int __pyx_f_6_mssql_get_last_msg_severity(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("get_last_msg_severity", 0);

  /* "_mssql.pyx":1603
 * 
 * cdef int get_last_msg_severity(MSSQLConnection conn):
 *     return conn.last_msg_severity if conn != None else _mssql_last_msg_severity             # <<<<<<<<<<<<<<
 * 
 * cdef int get_last_msg_state(MSSQLConnection conn):
 */
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1603, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1603, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_1 = __pyx_v_conn->last_msg_severity;
  } else {
    __pyx_t_1 = __pyx_v_6_mssql__mssql_last_msg_severity;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1602
 *     return conn.last_msg_no if conn != None else _mssql_last_msg_no
 * 
 * cdef int get_last_msg_severity(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_severity if conn != None else _mssql_last_msg_severity
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_severity", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1605
 *     return conn.last_msg_severity if conn != None else _mssql_last_msg_severity
 * 
 * cdef int get_last_msg_state(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_state if conn != None else _mssql_last_msg_state
 * 
 */

static int __pyx_f_6_mssql_get_last_msg_state(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("get_last_msg_state", 0);

  /* "_mssql.pyx":1606
 * 
 * cdef int get_last_msg_state(MSSQLConnection conn):
 *     return conn.last_msg_state if conn != None else _mssql_last_msg_state             # <<<<<<<<<<<<<<
 * 
 * cdef int get_last_msg_line(MSSQLConnection conn):
 */
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1606, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1606, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_1 = __pyx_v_conn->last_msg_state;
  } else {
    __pyx_t_1 = __pyx_v_6_mssql__mssql_last_msg_state;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1605
 *     return conn.last_msg_severity if conn != None else _mssql_last_msg_severity
 * 
 * cdef int get_last_msg_state(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_state if conn != None else _mssql_last_msg_state
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_state", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1608
 *     return conn.last_msg_state if conn != None else _mssql_last_msg_state
 * 
 * cdef int get_last_msg_line(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_line if conn != None else _mssql_last_msg_line
 * 
 */

static int __pyx_f_6_mssql_get_last_msg_line(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("get_last_msg_line", 0);

  /* "_mssql.pyx":1609
 * 
 * cdef int get_last_msg_line(MSSQLConnection conn):
 *     return conn.last_msg_line if conn != None else _mssql_last_msg_line             # <<<<<<<<<<<<<<
 * 
 * cdef int maybe_raise_MSSQLDatabaseException(MSSQLConnection conn) except 1:
 */
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_conn), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1609, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1609, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_1 = __pyx_v_conn->last_msg_line;
  } else {
    __pyx_t_1 = __pyx_v_6_mssql__mssql_last_msg_line;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1608
 *     return conn.last_msg_state if conn != None else _mssql_last_msg_state
 * 
 * cdef int get_last_msg_line(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     return conn.last_msg_line if conn != None else _mssql_last_msg_line
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_line", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1611
 *     return conn.last_msg_line if conn != None else _mssql_last_msg_line
 * 
 * cdef int maybe_raise_MSSQLDatabaseException(MSSQLConnection conn) except 1:             # <<<<<<<<<<<<<<
 * 
 *     if get_last_msg_severity(conn) < min_error_severity:
 */

static int __pyx_f_6_mssql_maybe_raise_MSSQLDatabaseException(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  PyObject *__pyx_v_error_msg = NULL;
  struct __pyx_obj_6_mssql_MSSQLDatabaseException *__pyx_v_ex = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  char *__pyx_t_6;
  __Pyx_RefNannySetupContext("maybe_raise_MSSQLDatabaseException", 0);

  /* "_mssql.pyx":1613
 * cdef int maybe_raise_MSSQLDatabaseException(MSSQLConnection conn) except 1:
 * 
 *     if get_last_msg_severity(conn) < min_error_severity:             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_6_mssql_get_last_msg_severity(__pyx_v_conn)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_min_error_severity); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":1614
 * 
 *     if get_last_msg_severity(conn) < min_error_severity:
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     error_msg = get_last_msg_str(conn)
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1613
 * cdef int maybe_raise_MSSQLDatabaseException(MSSQLConnection conn) except 1:
 * 
 *     if get_last_msg_severity(conn) < min_error_severity:             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
  }

  /* "_mssql.pyx":1616
 *         return 0
 * 
 *     error_msg = get_last_msg_str(conn)             # <<<<<<<<<<<<<<
 *     if len(error_msg) == 0:
 *         error_msg = b"Unknown error"
 */
  __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_f_6_mssql_get_last_msg_str(__pyx_v_conn)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_error_msg = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "_mssql.pyx":1617
 * 
 *     error_msg = get_last_msg_str(conn)
 *     if len(error_msg) == 0:             # <<<<<<<<<<<<<<
 *         error_msg = b"Unknown error"
 * 
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_error_msg); if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(0, 1617, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_5 == 0) != 0);
  if (__pyx_t_4) {

    /* "_mssql.pyx":1618
 *     error_msg = get_last_msg_str(conn)
 *     if len(error_msg) == 0:
 *         error_msg = b"Unknown error"             # <<<<<<<<<<<<<<
 * 
 *     ex = MSSQLDatabaseException((get_last_msg_no(conn), error_msg))
 */
    __Pyx_INCREF(__pyx_kp_b_Unknown_error);
    __Pyx_DECREF_SET(__pyx_v_error_msg, __pyx_kp_b_Unknown_error);

    /* "_mssql.pyx":1617
 * 
 *     error_msg = get_last_msg_str(conn)
 *     if len(error_msg) == 0:             # <<<<<<<<<<<<<<
 *         error_msg = b"Unknown error"
 * 
 */
  }

  /* "_mssql.pyx":1620
 *         error_msg = b"Unknown error"
 * 
 *     ex = MSSQLDatabaseException((get_last_msg_no(conn), error_msg))             # <<<<<<<<<<<<<<
 *     (<MSSQLDatabaseException>ex).text = error_msg
 *     (<MSSQLDatabaseException>ex).srvname = get_last_msg_srv(conn)
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_f_6_mssql_get_last_msg_no(__pyx_v_conn)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_INCREF(__pyx_v_error_msg);
  __Pyx_GIVEREF(__pyx_v_error_msg);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_error_msg);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDatabaseException), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_ex = ((struct __pyx_obj_6_mssql_MSSQLDatabaseException *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1621
 * 
 *     ex = MSSQLDatabaseException((get_last_msg_no(conn), error_msg))
 *     (<MSSQLDatabaseException>ex).text = error_msg             # <<<<<<<<<<<<<<
 *     (<MSSQLDatabaseException>ex).srvname = get_last_msg_srv(conn)
 *     (<MSSQLDatabaseException>ex).procname = get_last_msg_proc(conn)
 */
  __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_error_msg); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 1621, __pyx_L1_error)
  __pyx_v_ex->text = __pyx_t_6;

  /* "_mssql.pyx":1622
 *     ex = MSSQLDatabaseException((get_last_msg_no(conn), error_msg))
 *     (<MSSQLDatabaseException>ex).text = error_msg
 *     (<MSSQLDatabaseException>ex).srvname = get_last_msg_srv(conn)             # <<<<<<<<<<<<<<
 *     (<MSSQLDatabaseException>ex).procname = get_last_msg_proc(conn)
 *     (<MSSQLDatabaseException>ex).number = get_last_msg_no(conn)
 */
  __pyx_v_ex->srvname = __pyx_f_6_mssql_get_last_msg_srv(__pyx_v_conn);

  /* "_mssql.pyx":1623
 *     (<MSSQLDatabaseException>ex).text = error_msg
 *     (<MSSQLDatabaseException>ex).srvname = get_last_msg_srv(conn)
 *     (<MSSQLDatabaseException>ex).procname = get_last_msg_proc(conn)             # <<<<<<<<<<<<<<
 *     (<MSSQLDatabaseException>ex).number = get_last_msg_no(conn)
 *     (<MSSQLDatabaseException>ex).severity = get_last_msg_severity(conn)
 */
  __pyx_v_ex->procname = __pyx_f_6_mssql_get_last_msg_proc(__pyx_v_conn);

  /* "_mssql.pyx":1624
 *     (<MSSQLDatabaseException>ex).srvname = get_last_msg_srv(conn)
 *     (<MSSQLDatabaseException>ex).procname = get_last_msg_proc(conn)
 *     (<MSSQLDatabaseException>ex).number = get_last_msg_no(conn)             # <<<<<<<<<<<<<<
 *     (<MSSQLDatabaseException>ex).severity = get_last_msg_severity(conn)
 *     (<MSSQLDatabaseException>ex).state = get_last_msg_state(conn)
 */
  __pyx_v_ex->number = __pyx_f_6_mssql_get_last_msg_no(__pyx_v_conn);

  /* "_mssql.pyx":1625
 *     (<MSSQLDatabaseException>ex).procname = get_last_msg_proc(conn)
 *     (<MSSQLDatabaseException>ex).number = get_last_msg_no(conn)
 *     (<MSSQLDatabaseException>ex).severity = get_last_msg_severity(conn)             # <<<<<<<<<<<<<<
 *     (<MSSQLDatabaseException>ex).state = get_last_msg_state(conn)
 *     (<MSSQLDatabaseException>ex).line = get_last_msg_line(conn)
 */
  __pyx_v_ex->severity = __pyx_f_6_mssql_get_last_msg_severity(__pyx_v_conn);

  /* "_mssql.pyx":1626
 *     (<MSSQLDatabaseException>ex).number = get_last_msg_no(conn)
 *     (<MSSQLDatabaseException>ex).severity = get_last_msg_severity(conn)
 *     (<MSSQLDatabaseException>ex).state = get_last_msg_state(conn)             # <<<<<<<<<<<<<<
 *     (<MSSQLDatabaseException>ex).line = get_last_msg_line(conn)
 *     db_cancel(conn)
 */
  __pyx_v_ex->state = __pyx_f_6_mssql_get_last_msg_state(__pyx_v_conn);

  /* "_mssql.pyx":1627
 *     (<MSSQLDatabaseException>ex).severity = get_last_msg_severity(conn)
 *     (<MSSQLDatabaseException>ex).state = get_last_msg_state(conn)
 *     (<MSSQLDatabaseException>ex).line = get_last_msg_line(conn)             # <<<<<<<<<<<<<<
 *     db_cancel(conn)
 *     clr_err(conn)
 */
  __pyx_v_ex->line = __pyx_f_6_mssql_get_last_msg_line(__pyx_v_conn);

  /* "_mssql.pyx":1628
 *     (<MSSQLDatabaseException>ex).state = get_last_msg_state(conn)
 *     (<MSSQLDatabaseException>ex).line = get_last_msg_line(conn)
 *     db_cancel(conn)             # <<<<<<<<<<<<<<
 *     clr_err(conn)
 *     raise ex
 */
  __pyx_f_6_mssql_db_cancel(__pyx_v_conn);

  /* "_mssql.pyx":1629
 *     (<MSSQLDatabaseException>ex).line = get_last_msg_line(conn)
 *     db_cancel(conn)
 *     clr_err(conn)             # <<<<<<<<<<<<<<
 *     raise ex
 * 
 */
  __pyx_f_6_mssql_clr_err(__pyx_v_conn);

  /* "_mssql.pyx":1630
 *     db_cancel(conn)
 *     clr_err(conn)
 *     raise ex             # <<<<<<<<<<<<<<
 * 
 * cdef void assert_connected(MSSQLConnection conn) except *:
 */
  __Pyx_Raise(((PyObject *)__pyx_v_ex), 0, 0, 0);
  __PYX_ERR(0, 1630, __pyx_L1_error)

  /* "_mssql.pyx":1611
 *     return conn.last_msg_line if conn != None else _mssql_last_msg_line
 * 
 * cdef int maybe_raise_MSSQLDatabaseException(MSSQLConnection conn) except 1:             # <<<<<<<<<<<<<<
 * 
 *     if get_last_msg_severity(conn) < min_error_severity:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("_mssql.maybe_raise_MSSQLDatabaseException", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_error_msg);
  __Pyx_XDECREF((PyObject *)__pyx_v_ex);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1632
 *     raise ex
 * 
 * cdef void assert_connected(MSSQLConnection conn) except *:             # <<<<<<<<<<<<<<
 *     log("_mssql.assert_connected()")
 *     if not conn.connected:
 */

static void __pyx_f_6_mssql_assert_connected(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_conn) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("assert_connected", 0);

  /* "_mssql.pyx":1633
 * 
 * cdef void assert_connected(MSSQLConnection conn) except *:
 *     log("_mssql.assert_connected()")             # <<<<<<<<<<<<<<
 *     if not conn.connected:
 *         raise MSSQLDriverException("Not connected to any MS SQL server")
 */
  __pyx_f_6_mssql_log(((char *)"_mssql.assert_connected()"));

  /* "_mssql.pyx":1634
 * cdef void assert_connected(MSSQLConnection conn) except *:
 *     log("_mssql.assert_connected()")
 *     if not conn.connected:             # <<<<<<<<<<<<<<
 *         raise MSSQLDriverException("Not connected to any MS SQL server")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_conn), __pyx_n_s_connected); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1634, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1634, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1635
 *     log("_mssql.assert_connected()")
 *     if not conn.connected:
 *         raise MSSQLDriverException("Not connected to any MS SQL server")             # <<<<<<<<<<<<<<
 * 
 * cdef inline BYTE *get_data(DBPROCESS *dbproc, int row_info, int col) nogil:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1635, __pyx_L1_error)

    /* "_mssql.pyx":1634
 * cdef void assert_connected(MSSQLConnection conn) except *:
 *     log("_mssql.assert_connected()")
 *     if not conn.connected:             # <<<<<<<<<<<<<<
 *         raise MSSQLDriverException("Not connected to any MS SQL server")
 * 
 */
  }

  /* "_mssql.pyx":1632
 *     raise ex
 * 
 * cdef void assert_connected(MSSQLConnection conn) except *:             # <<<<<<<<<<<<<<
 *     log("_mssql.assert_connected()")
 *     if not conn.connected:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.assert_connected", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":1637
 *         raise MSSQLDriverException("Not connected to any MS SQL server")
 * 
 * cdef inline BYTE *get_data(DBPROCESS *dbproc, int row_info, int col) nogil:             # <<<<<<<<<<<<<<
 *     return dbdata(dbproc, col) if row_info == REG_ROW else \
 *         dbadata(dbproc, row_info, col)
 */

static CYTHON_INLINE BYTE *__pyx_f_6_mssql_get_data(DBPROCESS *__pyx_v_dbproc, int __pyx_v_row_info, int __pyx_v_col) {
  BYTE *__pyx_r;
  BYTE *__pyx_t_1;

  /* "_mssql.pyx":1638
 * 
 * cdef inline BYTE *get_data(DBPROCESS *dbproc, int row_info, int col) nogil:
 *     return dbdata(dbproc, col) if row_info == REG_ROW else \             # <<<<<<<<<<<<<<
 *         dbadata(dbproc, row_info, col)
 * 
 */
  if (((__pyx_v_row_info == REG_ROW) != 0)) {
    __pyx_t_1 = dbdata(__pyx_v_dbproc, __pyx_v_col);
  } else {

    /* "_mssql.pyx":1639
 * cdef inline BYTE *get_data(DBPROCESS *dbproc, int row_info, int col) nogil:
 *     return dbdata(dbproc, col) if row_info == REG_ROW else \
 *         dbadata(dbproc, row_info, col)             # <<<<<<<<<<<<<<
 * 
 * cdef inline int get_type(DBPROCESS *dbproc, int row_info, int col) nogil:
 */
    __pyx_t_1 = dbadata(__pyx_v_dbproc, __pyx_v_row_info, __pyx_v_col);
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1637
 *         raise MSSQLDriverException("Not connected to any MS SQL server")
 * 
 * cdef inline BYTE *get_data(DBPROCESS *dbproc, int row_info, int col) nogil:             # <<<<<<<<<<<<<<
 *     return dbdata(dbproc, col) if row_info == REG_ROW else \
 *         dbadata(dbproc, row_info, col)
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "_mssql.pyx":1641
 *         dbadata(dbproc, row_info, col)
 * 
 * cdef inline int get_type(DBPROCESS *dbproc, int row_info, int col) nogil:             # <<<<<<<<<<<<<<
 *     return dbcoltype(dbproc, col) if row_info == REG_ROW else \
 *         dbalttype(dbproc, row_info, col)
 */

static CYTHON_INLINE int __pyx_f_6_mssql_get_type(DBPROCESS *__pyx_v_dbproc, int __pyx_v_row_info, int __pyx_v_col) {
  int __pyx_r;
  int __pyx_t_1;

  /* "_mssql.pyx":1642
 * 
 * cdef inline int get_type(DBPROCESS *dbproc, int row_info, int col) nogil:
 *     return dbcoltype(dbproc, col) if row_info == REG_ROW else \             # <<<<<<<<<<<<<<
 *         dbalttype(dbproc, row_info, col)
 * 
 */
  if (((__pyx_v_row_info == REG_ROW) != 0)) {
    __pyx_t_1 = dbcoltype(__pyx_v_dbproc, __pyx_v_col);
  } else {

    /* "_mssql.pyx":1643
 * cdef inline int get_type(DBPROCESS *dbproc, int row_info, int col) nogil:
 *     return dbcoltype(dbproc, col) if row_info == REG_ROW else \
 *         dbalttype(dbproc, row_info, col)             # <<<<<<<<<<<<<<
 * 
 * cdef inline int get_length(DBPROCESS *dbproc, int row_info, int col) nogil:
 */
    __pyx_t_1 = dbalttype(__pyx_v_dbproc, __pyx_v_row_info, __pyx_v_col);
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1641
 *         dbadata(dbproc, row_info, col)
 * 
 * cdef inline int get_type(DBPROCESS *dbproc, int row_info, int col) nogil:             # <<<<<<<<<<<<<<
 *     return dbcoltype(dbproc, col) if row_info == REG_ROW else \
 *         dbalttype(dbproc, row_info, col)
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "_mssql.pyx":1645
 *         dbalttype(dbproc, row_info, col)
 * 
 * cdef inline int get_length(DBPROCESS *dbproc, int row_info, int col) nogil:             # <<<<<<<<<<<<<<
 *     return dbdatlen(dbproc, col) if row_info == REG_ROW else \
 *         dbadlen(dbproc, row_info, col)
 */

static CYTHON_INLINE int __pyx_f_6_mssql_get_length(DBPROCESS *__pyx_v_dbproc, int __pyx_v_row_info, int __pyx_v_col) {
  int __pyx_r;
  DBINT __pyx_t_1;

  /* "_mssql.pyx":1646
 * 
 * cdef inline int get_length(DBPROCESS *dbproc, int row_info, int col) nogil:
 *     return dbdatlen(dbproc, col) if row_info == REG_ROW else \             # <<<<<<<<<<<<<<
 *         dbadlen(dbproc, row_info, col)
 * 
 */
  if (((__pyx_v_row_info == REG_ROW) != 0)) {
    __pyx_t_1 = dbdatlen(__pyx_v_dbproc, __pyx_v_col);
  } else {

    /* "_mssql.pyx":1647
 * cdef inline int get_length(DBPROCESS *dbproc, int row_info, int col) nogil:
 *     return dbdatlen(dbproc, col) if row_info == REG_ROW else \
 *         dbadlen(dbproc, row_info, col)             # <<<<<<<<<<<<<<
 * 
 * ######################
 */
    __pyx_t_1 = dbadlen(__pyx_v_dbproc, __pyx_v_row_info, __pyx_v_col);
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "_mssql.pyx":1645
 *         dbalttype(dbproc, row_info, col)
 * 
 * cdef inline int get_length(DBPROCESS *dbproc, int row_info, int col) nogil:             # <<<<<<<<<<<<<<
 *     return dbdatlen(dbproc, col) if row_info == REG_ROW else \
 *         dbadlen(dbproc, row_info, col)
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "_mssql.pyx":1652
 * ## Helper Functions ##
 * ######################
 * cdef int get_api_coltype(int coltype):             # <<<<<<<<<<<<<<
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 */

static int __pyx_f_6_mssql_get_api_coltype(int __pyx_v_coltype) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  __Pyx_RefNannySetupContext("get_api_coltype", 0);

  /* "_mssql.pyx":1653
 * ######################
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,             # <<<<<<<<<<<<<<
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 */
  __pyx_t_1 = __pyx_v_coltype;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLBIT); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINT8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLINTN); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "_mssql.pyx":1654
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,
 *             SQLFLT4, SQLFLT8, SQLFLTN):             # <<<<<<<<<<<<<<
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLFLT4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1654, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1653
 * ######################
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,             # <<<<<<<<<<<<<<
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "_mssql.pyx":1654
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,
 *             SQLFLT4, SQLFLT8, SQLFLTN):             # <<<<<<<<<<<<<<
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLFLT8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1654, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1653
 * ######################
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,             # <<<<<<<<<<<<<<
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "_mssql.pyx":1654
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,
 *             SQLFLT4, SQLFLT8, SQLFLTN):             # <<<<<<<<<<<<<<
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLFLTN); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1654, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1653
 * ######################
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,             # <<<<<<<<<<<<<<
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;
  __pyx_t_6 = (__pyx_t_2 != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":1655
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER             # <<<<<<<<<<<<<<
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 *             SQLDECIMAL):
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_NUMBER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1655, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1655, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;

    /* "_mssql.pyx":1653
 * ######################
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,             # <<<<<<<<<<<<<<
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 */
  }

  /* "_mssql.pyx":1656
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,             # <<<<<<<<<<<<<<
 *             SQLDECIMAL):
 *         return DECIMAL
 */
  __pyx_t_1 = __pyx_v_coltype;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEY); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_6 = __pyx_t_2;
    goto __pyx_L13_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEY4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_6 = __pyx_t_2;
    goto __pyx_L13_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLMONEYN); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_6 = __pyx_t_2;
    goto __pyx_L13_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLNUMERIC); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_6 = __pyx_t_2;
    goto __pyx_L13_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "_mssql.pyx":1657
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 *             SQLDECIMAL):             # <<<<<<<<<<<<<<
 *         return DECIMAL
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDECIMAL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1657, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1656
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,             # <<<<<<<<<<<<<<
 *             SQLDECIMAL):
 *         return DECIMAL
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __pyx_t_2;
  __pyx_L13_bool_binop_done:;
  __pyx_t_2 = (__pyx_t_6 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1658
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 *             SQLDECIMAL):
 *         return DECIMAL             # <<<<<<<<<<<<<<
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):
 *         return DATETIME
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_DECIMAL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1658, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1658, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;

    /* "_mssql.pyx":1656
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,             # <<<<<<<<<<<<<<
 *             SQLDECIMAL):
 *         return DECIMAL
 */
  }

  /* "_mssql.pyx":1659
 *             SQLDECIMAL):
 *         return DECIMAL
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):             # <<<<<<<<<<<<<<
 *         return DATETIME
 *     elif coltype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 */
  __pyx_t_1 = __pyx_v_coltype;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDATETIME); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L18_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDATETIM4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L18_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLDATETIMN); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __pyx_t_6;
  __pyx_L18_bool_binop_done:;
  __pyx_t_6 = (__pyx_t_2 != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":1660
 *         return DECIMAL
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):
 *         return DATETIME             # <<<<<<<<<<<<<<
 *     elif coltype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *         return STRING
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_DATETIME); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1660, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1660, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;

    /* "_mssql.pyx":1659
 *             SQLDECIMAL):
 *         return DECIMAL
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):             # <<<<<<<<<<<<<<
 *         return DATETIME
 *     elif coltype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 */
  }

  /* "_mssql.pyx":1661
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):
 *         return DATETIME
 *     elif coltype in (SQLVARCHAR, SQLCHAR, SQLTEXT):             # <<<<<<<<<<<<<<
 *         return STRING
 *     else:
 */
  __pyx_t_1 = __pyx_v_coltype;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLVARCHAR); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_6 = __pyx_t_2;
    goto __pyx_L21_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLCHAR); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_6 = __pyx_t_2;
    goto __pyx_L21_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_SQLTEXT); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1661, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __pyx_t_2;
  __pyx_L21_bool_binop_done:;
  __pyx_t_2 = (__pyx_t_6 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1662
 *         return DATETIME
 *     elif coltype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *         return STRING             # <<<<<<<<<<<<<<
 *     else:
 *         return BINARY
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_STRING); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1662, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1662, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;

    /* "_mssql.pyx":1661
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):
 *         return DATETIME
 *     elif coltype in (SQLVARCHAR, SQLCHAR, SQLTEXT):             # <<<<<<<<<<<<<<
 *         return STRING
 *     else:
 */
  }

  /* "_mssql.pyx":1664
 *         return STRING
 *     else:
 *         return BINARY             # <<<<<<<<<<<<<<
 * 
 * cdef char *_remove_locale(char *s, size_t buflen):
 */
  /*else*/ {
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_BINARY); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1664, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1664, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;
  }

  /* "_mssql.pyx":1652
 * ## Helper Functions ##
 * ######################
 * cdef int get_api_coltype(int coltype):             # <<<<<<<<<<<<<<
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_WriteUnraisable("_mssql.get_api_coltype", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1666
 *         return BINARY
 * 
 * cdef char *_remove_locale(char *s, size_t buflen):             # <<<<<<<<<<<<<<
 *     cdef char c
 *     cdef char *stripped = s
 */

static char *__pyx_f_6_mssql__remove_locale(char *__pyx_v_s, size_t __pyx_v_buflen) {
  char __pyx_v_c;
  char *__pyx_v_stripped;
  int __pyx_v_i;
  int __pyx_v_x;
  int __pyx_v_last_sep;
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  char *__pyx_t_4;
  char *__pyx_t_5;
  char *__pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  __Pyx_RefNannySetupContext("_remove_locale", 0);

  /* "_mssql.pyx":1668
 * cdef char *_remove_locale(char *s, size_t buflen):
 *     cdef char c
 *     cdef char *stripped = s             # <<<<<<<<<<<<<<
 *     cdef int i, x = 0, last_sep = -1
 * 
 */
  __pyx_v_stripped = __pyx_v_s;

  /* "_mssql.pyx":1669
 *     cdef char c
 *     cdef char *stripped = s
 *     cdef int i, x = 0, last_sep = -1             # <<<<<<<<<<<<<<
 * 
 *     for i, c in enumerate(s[0:buflen]):
 */
  __pyx_v_x = 0;
  __pyx_v_last_sep = -1;

  /* "_mssql.pyx":1671
 *     cdef int i, x = 0, last_sep = -1
 * 
 *     for i, c in enumerate(s[0:buflen]):             # <<<<<<<<<<<<<<
 *         if c in (',', '.'):
 *             last_sep = i
 */
  __pyx_t_1 = 0;
  __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_buflen - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1671, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyBytes_AS_STRING(__pyx_t_2);
  __pyx_t_5 = (__pyx_t_4 + PyBytes_GET_SIZE(__pyx_t_2));
  for (__pyx_t_6 = __pyx_t_4; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) {
    __pyx_t_3 = __pyx_t_6;
    __pyx_v_c = (__pyx_t_3[0]);

    /* "_mssql.pyx":1672
 * 
 *     for i, c in enumerate(s[0:buflen]):
 *         if c in (',', '.'):             # <<<<<<<<<<<<<<
 *             last_sep = i
 * 
 */
    __pyx_v_i = __pyx_t_1;

    /* "_mssql.pyx":1671
 *     cdef int i, x = 0, last_sep = -1
 * 
 *     for i, c in enumerate(s[0:buflen]):             # <<<<<<<<<<<<<<
 *         if c in (',', '.'):
 *             last_sep = i
 */
    __pyx_t_1 = (__pyx_t_1 + 1);

    /* "_mssql.pyx":1672
 * 
 *     for i, c in enumerate(s[0:buflen]):
 *         if c in (',', '.'):             # <<<<<<<<<<<<<<
 *             last_sep = i
 * 
 */
    switch (__pyx_v_c) {
      case ',':
      case '.':

      /* "_mssql.pyx":1673
 *     for i, c in enumerate(s[0:buflen]):
 *         if c in (',', '.'):
 *             last_sep = i             # <<<<<<<<<<<<<<
 * 
 *     for i, c in enumerate(s[0:buflen]):
 */
      __pyx_v_last_sep = __pyx_v_i;

      /* "_mssql.pyx":1672
 * 
 *     for i, c in enumerate(s[0:buflen]):
 *         if c in (',', '.'):             # <<<<<<<<<<<<<<
 *             last_sep = i
 * 
 */
      break;
      default: break;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "_mssql.pyx":1675
 *             last_sep = i
 * 
 *     for i, c in enumerate(s[0:buflen]):             # <<<<<<<<<<<<<<
 *         if (c >= '0' and c <= '9') or c in ('+', '-'):
 *             stripped[x] = c
 */
  __pyx_t_1 = 0;
  __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_buflen - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1675, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyBytes_AS_STRING(__pyx_t_2);
  __pyx_t_4 = (__pyx_t_5 + PyBytes_GET_SIZE(__pyx_t_2));
  for (__pyx_t_6 = __pyx_t_5; __pyx_t_6 < __pyx_t_4; __pyx_t_6++) {
    __pyx_t_3 = __pyx_t_6;
    __pyx_v_c = (__pyx_t_3[0]);

    /* "_mssql.pyx":1676
 * 
 *     for i, c in enumerate(s[0:buflen]):
 *         if (c >= '0' and c <= '9') or c in ('+', '-'):             # <<<<<<<<<<<<<<
 *             stripped[x] = c
 *             x += 1
 */
    __pyx_v_i = __pyx_t_1;

    /* "_mssql.pyx":1675
 *             last_sep = i
 * 
 *     for i, c in enumerate(s[0:buflen]):             # <<<<<<<<<<<<<<
 *         if (c >= '0' and c <= '9') or c in ('+', '-'):
 *             stripped[x] = c
 */
    __pyx_t_1 = (__pyx_t_1 + 1);

    /* "_mssql.pyx":1676
 * 
 *     for i, c in enumerate(s[0:buflen]):
 *         if (c >= '0' and c <= '9') or c in ('+', '-'):             # <<<<<<<<<<<<<<
 *             stripped[x] = c
 *             x += 1
 */
    __pyx_t_8 = ((__pyx_v_c >= '0') != 0);
    if (!__pyx_t_8) {
      goto __pyx_L9_next_or;
    } else {
    }
    __pyx_t_8 = ((__pyx_v_c <= '9') != 0);
    if (!__pyx_t_8) {
    } else {
      __pyx_t_7 = __pyx_t_8;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_L9_next_or:;
    switch (__pyx_v_c) {
      case '+':
      case '-':
      __pyx_t_8 = 1;
      break;
      default:
      __pyx_t_8 = 0;
      break;
    }
    __pyx_t_9 = (__pyx_t_8 != 0);
    __pyx_t_7 = __pyx_t_9;
    __pyx_L8_bool_binop_done:;
    if (__pyx_t_7) {

      /* "_mssql.pyx":1677
 *     for i, c in enumerate(s[0:buflen]):
 *         if (c >= '0' and c <= '9') or c in ('+', '-'):
 *             stripped[x] = c             # <<<<<<<<<<<<<<
 *             x += 1
 *         elif i == last_sep:
 */
      (__pyx_v_stripped[__pyx_v_x]) = __pyx_v_c;

      /* "_mssql.pyx":1678
 *         if (c >= '0' and c <= '9') or c in ('+', '-'):
 *             stripped[x] = c
 *             x += 1             # <<<<<<<<<<<<<<
 *         elif i == last_sep:
 *             stripped[x] = c
 */
      __pyx_v_x = (__pyx_v_x + 1);

      /* "_mssql.pyx":1676
 * 
 *     for i, c in enumerate(s[0:buflen]):
 *         if (c >= '0' and c <= '9') or c in ('+', '-'):             # <<<<<<<<<<<<<<
 *             stripped[x] = c
 *             x += 1
 */
      goto __pyx_L7;
    }

    /* "_mssql.pyx":1679
 *             stripped[x] = c
 *             x += 1
 *         elif i == last_sep:             # <<<<<<<<<<<<<<
 *             stripped[x] = c
 *             x += 1
 */
    __pyx_t_7 = ((__pyx_v_i == __pyx_v_last_sep) != 0);
    if (__pyx_t_7) {

      /* "_mssql.pyx":1680
 *             x += 1
 *         elif i == last_sep:
 *             stripped[x] = c             # <<<<<<<<<<<<<<
 *             x += 1
 *     stripped[x] = 0
 */
      (__pyx_v_stripped[__pyx_v_x]) = __pyx_v_c;

      /* "_mssql.pyx":1681
 *         elif i == last_sep:
 *             stripped[x] = c
 *             x += 1             # <<<<<<<<<<<<<<
 *     stripped[x] = 0
 *     return stripped
 */
      __pyx_v_x = (__pyx_v_x + 1);

      /* "_mssql.pyx":1679
 *             stripped[x] = c
 *             x += 1
 *         elif i == last_sep:             # <<<<<<<<<<<<<<
 *             stripped[x] = c
 *             x += 1
 */
    }
    __pyx_L7:;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "_mssql.pyx":1682
 *             stripped[x] = c
 *             x += 1
 *     stripped[x] = 0             # <<<<<<<<<<<<<<
 *     return stripped
 * 
 */
  (__pyx_v_stripped[__pyx_v_x]) = 0;

  /* "_mssql.pyx":1683
 *             x += 1
 *     stripped[x] = 0
 *     return stripped             # <<<<<<<<<<<<<<
 * 
 * def remove_locale(bytes value):
 */
  __pyx_r = __pyx_v_stripped;
  goto __pyx_L0;

  /* "_mssql.pyx":1666
 *         return BINARY
 * 
 * cdef char *_remove_locale(char *s, size_t buflen):             # <<<<<<<<<<<<<<
 *     cdef char c
 *     cdef char *stripped = s
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql._remove_locale", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1685
 *     return stripped
 * 
 * def remove_locale(bytes value):             # <<<<<<<<<<<<<<
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_3remove_locale(PyObject *__pyx_self, PyObject *__pyx_v_value); /*proto*/
static PyMethodDef __pyx_mdef_6_mssql_3remove_locale = {"remove_locale", (PyCFunction)__pyx_pw_6_mssql_3remove_locale, METH_O, 0};
static PyObject *__pyx_pw_6_mssql_3remove_locale(PyObject *__pyx_self, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("remove_locale (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_value), (&PyBytes_Type), 1, "value", 1))) __PYX_ERR(0, 1685, __pyx_L1_error)
  __pyx_r = __pyx_pf_6_mssql_2remove_locale(__pyx_self, ((PyObject*)__pyx_v_value));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_2remove_locale(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value) {
  char *__pyx_v_s;
  size_t __pyx_v_l;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  char *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("remove_locale", 0);

  /* "_mssql.pyx":1686
 * 
 * def remove_locale(bytes value):
 *     cdef char *s = <char*>value             # <<<<<<<<<<<<<<
 *     cdef size_t l = strlen(s)
 *     return _remove_locale(s, l)
 */
  __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 1686, __pyx_L1_error)
  __pyx_v_s = ((char *)__pyx_t_1);

  /* "_mssql.pyx":1687
 * def remove_locale(bytes value):
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)             # <<<<<<<<<<<<<<
 *     return _remove_locale(s, l)
 * 
 */
  __pyx_v_l = strlen(__pyx_v_s);

  /* "_mssql.pyx":1688
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)
 *     return _remove_locale(s, l)             # <<<<<<<<<<<<<<
 * 
 * cdef int _tds_ver_str_to_constant(verstr) except -1:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_f_6_mssql__remove_locale(__pyx_v_s, __pyx_v_l)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1688, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1685
 *     return stripped
 * 
 * def remove_locale(bytes value):             # <<<<<<<<<<<<<<
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_mssql.remove_locale", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1690
 *     return _remove_locale(s, l)
 * 
 * cdef int _tds_ver_str_to_constant(verstr) except -1:             # <<<<<<<<<<<<<<
 *     """
 *         http://www.freetds.org/userguide/choosingtdsprotocol.htm
 */

static int __pyx_f_6_mssql__tds_ver_str_to_constant(PyObject *__pyx_v_verstr) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("_tds_ver_str_to_constant", 0);

  /* "_mssql.pyx":1694
 *         http://www.freetds.org/userguide/choosingtdsprotocol.htm
 *     """
 *     if verstr == u'4.2':             # <<<<<<<<<<<<<<
 *         return DBVERSION_42
 *     if verstr == u'7.0':
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_verstr, __pyx_kp_u_4_2, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1694, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1695
 *     """
 *     if verstr == u'4.2':
 *         return DBVERSION_42             # <<<<<<<<<<<<<<
 *     if verstr == u'7.0':
 *         return DBVERSION_70
 */
    __pyx_r = DBVERSION_42;
    goto __pyx_L0;

    /* "_mssql.pyx":1694
 *         http://www.freetds.org/userguide/choosingtdsprotocol.htm
 *     """
 *     if verstr == u'4.2':             # <<<<<<<<<<<<<<
 *         return DBVERSION_42
 *     if verstr == u'7.0':
 */
  }

  /* "_mssql.pyx":1696
 *     if verstr == u'4.2':
 *         return DBVERSION_42
 *     if verstr == u'7.0':             # <<<<<<<<<<<<<<
 *         return DBVERSION_70
 *     if verstr == u'7.1':
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_verstr, __pyx_kp_u_7_0, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1696, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1697
 *         return DBVERSION_42
 *     if verstr == u'7.0':
 *         return DBVERSION_70             # <<<<<<<<<<<<<<
 *     if verstr == u'7.1':
 *         return DBVERSION_71
 */
    __pyx_r = DBVERSION_70;
    goto __pyx_L0;

    /* "_mssql.pyx":1696
 *     if verstr == u'4.2':
 *         return DBVERSION_42
 *     if verstr == u'7.0':             # <<<<<<<<<<<<<<
 *         return DBVERSION_70
 *     if verstr == u'7.1':
 */
  }

  /* "_mssql.pyx":1698
 *     if verstr == u'7.0':
 *         return DBVERSION_70
 *     if verstr == u'7.1':             # <<<<<<<<<<<<<<
 *         return DBVERSION_71
 *     if verstr == u'7.2':
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_verstr, __pyx_kp_u_7_1, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1698, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1699
 *         return DBVERSION_70
 *     if verstr == u'7.1':
 *         return DBVERSION_71             # <<<<<<<<<<<<<<
 *     if verstr == u'7.2':
 *         return DBVERSION_72
 */
    __pyx_r = 5;
    goto __pyx_L0;

    /* "_mssql.pyx":1698
 *     if verstr == u'7.0':
 *         return DBVERSION_70
 *     if verstr == u'7.1':             # <<<<<<<<<<<<<<
 *         return DBVERSION_71
 *     if verstr == u'7.2':
 */
  }

  /* "_mssql.pyx":1700
 *     if verstr == u'7.1':
 *         return DBVERSION_71
 *     if verstr == u'7.2':             # <<<<<<<<<<<<<<
 *         return DBVERSION_72
 *     if verstr == u'8.0':
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_verstr, __pyx_kp_u_7_2, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1700, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1701
 *         return DBVERSION_71
 *     if verstr == u'7.2':
 *         return DBVERSION_72             # <<<<<<<<<<<<<<
 *     if verstr == u'8.0':
 *         return DBVERSION_80
 */
    __pyx_r = 6;
    goto __pyx_L0;

    /* "_mssql.pyx":1700
 *     if verstr == u'7.1':
 *         return DBVERSION_71
 *     if verstr == u'7.2':             # <<<<<<<<<<<<<<
 *         return DBVERSION_72
 *     if verstr == u'8.0':
 */
  }

  /* "_mssql.pyx":1702
 *     if verstr == u'7.2':
 *         return DBVERSION_72
 *     if verstr == u'8.0':             # <<<<<<<<<<<<<<
 *         return DBVERSION_80
 *     raise MSSQLException('unrecognized tds version: %s' % verstr)
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_verstr, __pyx_kp_u_8_0, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1702, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1703
 *         return DBVERSION_72
 *     if verstr == u'8.0':
 *         return DBVERSION_80             # <<<<<<<<<<<<<<
 *     raise MSSQLException('unrecognized tds version: %s' % verstr)
 * 
 */
    __pyx_r = DBVERSION_80;
    goto __pyx_L0;

    /* "_mssql.pyx":1702
 *     if verstr == u'7.2':
 *         return DBVERSION_72
 *     if verstr == u'8.0':             # <<<<<<<<<<<<<<
 *         return DBVERSION_80
 *     raise MSSQLException('unrecognized tds version: %s' % verstr)
 */
  }

  /* "_mssql.pyx":1704
 *     if verstr == u'8.0':
 *         return DBVERSION_80
 *     raise MSSQLException('unrecognized tds version: %s' % verstr)             # <<<<<<<<<<<<<<
 * 
 * #######################
 */
  __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_unrecognized_tds_version_s, __pyx_v_verstr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1704, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1704, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLException), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1704, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_Raise(__pyx_t_2, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __PYX_ERR(0, 1704, __pyx_L1_error)

  /* "_mssql.pyx":1690
 *     return _remove_locale(s, l)
 * 
 * cdef int _tds_ver_str_to_constant(verstr) except -1:             # <<<<<<<<<<<<<<
 *     """
 *         http://www.freetds.org/userguide/choosingtdsprotocol.htm
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("_mssql._tds_ver_str_to_constant", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1709
 * ## Quoting Functions ##
 * #######################
 * cdef _quote_simple_value(value, charset='utf8'):             # <<<<<<<<<<<<<<
 * 
 *     if value == None:
 */

static PyObject *__pyx_f_6_mssql__quote_simple_value(PyObject *__pyx_v_value, struct __pyx_opt_args_6_mssql__quote_simple_value *__pyx_optional_args) {
  PyObject *__pyx_v_charset = ((PyObject *)__pyx_n_s_utf8);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  __Pyx_RefNannySetupContext("_quote_simple_value", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_charset = __pyx_optional_args->charset;
    }
  }

  /* "_mssql.pyx":1711
 * cdef _quote_simple_value(value, charset='utf8'):
 * 
 *     if value == None:             # <<<<<<<<<<<<<<
 *         return b'NULL'
 * 
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_value, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1711, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1711, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1712
 * 
 *     if value == None:
 *         return b'NULL'             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, bool):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_n_b_NULL);
    __pyx_r = __pyx_n_b_NULL;
    goto __pyx_L0;

    /* "_mssql.pyx":1711
 * cdef _quote_simple_value(value, charset='utf8'):
 * 
 *     if value == None:             # <<<<<<<<<<<<<<
 *         return b'NULL'
 * 
 */
  }

  /* "_mssql.pyx":1714
 *         return b'NULL'
 * 
 *     if isinstance(value, bool):             # <<<<<<<<<<<<<<
 *         return '1' if value else '0'
 * 
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_value, __pyx_ptype_7cpython_4bool_bool); 
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1715
 * 
 *     if isinstance(value, bool):
 *         return '1' if value else '0'             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, float):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1715, __pyx_L1_error)
    if (__pyx_t_3) {
      __Pyx_INCREF(__pyx_kp_s_1);
      __pyx_t_1 = __pyx_kp_s_1;
    } else {
      __Pyx_INCREF(__pyx_kp_s_0);
      __pyx_t_1 = __pyx_kp_s_0;
    }
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1714
 *         return b'NULL'
 * 
 *     if isinstance(value, bool):             # <<<<<<<<<<<<<<
 *         return '1' if value else '0'
 * 
 */
  }

  /* "_mssql.pyx":1717
 *         return '1' if value else '0'
 * 
 *     if isinstance(value, float):             # <<<<<<<<<<<<<<
 *         return repr(value).encode(charset)
 * 
 */
  __pyx_t_3 = PyFloat_Check(__pyx_v_value); 
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1718
 * 
 *     if isinstance(value, float):
 *         return repr(value).encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, (int, long, decimal.Decimal)):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = PyObject_Repr(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1718, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1718, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_4) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_charset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1718, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1718, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_INCREF(__pyx_v_charset);
      __Pyx_GIVEREF(__pyx_v_charset);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_charset);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1718, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1717
 *         return '1' if value else '0'
 * 
 *     if isinstance(value, float):             # <<<<<<<<<<<<<<
 *         return repr(value).encode(charset)
 * 
 */
  }

  /* "_mssql.pyx":1720
 *         return repr(value).encode(charset)
 * 
 *     if isinstance(value, (int, long, decimal.Decimal)):             # <<<<<<<<<<<<<<
 *         return str(value).encode(charset)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_decimal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1720, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Decimal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1720, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = PyInt_Check(__pyx_v_value); 
  __pyx_t_7 = (__pyx_t_3 != 0);
  if (!__pyx_t_7) {
  } else {
    __pyx_t_2 = __pyx_t_7;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_7 = PyLong_Check(__pyx_v_value); 
  __pyx_t_3 = (__pyx_t_7 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_3 = PyObject_IsInstance(__pyx_v_value, __pyx_t_5); 
  __pyx_t_7 = (__pyx_t_3 != 0);
  __pyx_t_2 = __pyx_t_7;
  __pyx_L7_bool_binop_done:;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = (__pyx_t_2 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1721
 * 
 *     if isinstance(value, (int, long, decimal.Decimal)):
 *         return str(value).encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, uuid.UUID):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
    __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)(&PyString_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_charset); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_charset);
      __Pyx_GIVEREF(__pyx_v_charset);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_charset);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1720
 *         return repr(value).encode(charset)
 * 
 *     if isinstance(value, (int, long, decimal.Decimal)):             # <<<<<<<<<<<<<<
 *         return str(value).encode(charset)
 * 
 */
  }

  /* "_mssql.pyx":1723
 *         return str(value).encode(charset)
 * 
 *     if isinstance(value, uuid.UUID):             # <<<<<<<<<<<<<<
 *         return _quote_simple_value(str(value))
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_uuid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1723, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_UUID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1723, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = PyObject_IsInstance(__pyx_v_value, __pyx_t_1); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 1723, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_2 = (__pyx_t_7 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1724
 * 
 *     if isinstance(value, uuid.UUID):
 *         return _quote_simple_value(str(value))             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, unicode):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)(&PyString_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __pyx_f_6_mssql__quote_simple_value(__pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1723
 *         return str(value).encode(charset)
 * 
 *     if isinstance(value, uuid.UUID):             # <<<<<<<<<<<<<<
 *         return _quote_simple_value(str(value))
 * 
 */
  }

  /* "_mssql.pyx":1726
 *         return _quote_simple_value(str(value))
 * 
 *     if isinstance(value, unicode):             # <<<<<<<<<<<<<<
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)
 * 
 */
  __pyx_t_2 = PyUnicode_Check(__pyx_v_value); 
  __pyx_t_7 = (__pyx_t_2 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1727
 * 
 *     if isinstance(value, unicode):
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, bytearray):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_replace); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Add(__pyx_kp_s_N, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_kp_s__31); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_4) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_charset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1727, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1727, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_INCREF(__pyx_v_charset);
      __Pyx_GIVEREF(__pyx_v_charset);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_charset);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1727, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1726
 *         return _quote_simple_value(str(value))
 * 
 *     if isinstance(value, unicode):             # <<<<<<<<<<<<<<
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)
 * 
 */
  }

  /* "_mssql.pyx":1729
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)
 * 
 *     if isinstance(value, bytearray):             # <<<<<<<<<<<<<<
 *         return b'0x' + binascii.hexlify(bytes(value))
 * 
 */
  __pyx_t_7 = PyByteArray_Check(__pyx_v_value); 
  __pyx_t_2 = (__pyx_t_7 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1730
 * 
 *     if isinstance(value, bytearray):
 *         return b'0x' + binascii.hexlify(bytes(value))             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, (str, bytes)):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_binascii); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_hexlify); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_value);
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&PyBytes_Type)), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1730, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1730, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1730, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyNumber_Add(__pyx_kp_b_0x, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1729
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)
 * 
 *     if isinstance(value, bytearray):             # <<<<<<<<<<<<<<
 *         return b'0x' + binascii.hexlify(bytes(value))
 * 
 */
  }

  /* "_mssql.pyx":1732
 *         return b'0x' + binascii.hexlify(bytes(value))
 * 
 *     if isinstance(value, (str, bytes)):             # <<<<<<<<<<<<<<
 *         # see if it can be decoded as ascii if there are no null bytes
 *         if b'\0' not in value:
 */
  __pyx_t_7 = PyString_Check(__pyx_v_value); 
  __pyx_t_3 = (__pyx_t_7 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L14_bool_binop_done;
  }
  __pyx_t_3 = PyBytes_Check(__pyx_v_value); 
  __pyx_t_7 = (__pyx_t_3 != 0);
  __pyx_t_2 = __pyx_t_7;
  __pyx_L14_bool_binop_done:;
  __pyx_t_7 = (__pyx_t_2 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1734
 *     if isinstance(value, (str, bytes)):
 *         # see if it can be decoded as ascii if there are no null bytes
 *         if b'\0' not in value:             # <<<<<<<<<<<<<<
 *             try:
 *                 value.decode('ascii')
 */
    __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_kp_b__34, __pyx_v_value, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1734, __pyx_L1_error)
    __pyx_t_2 = (__pyx_t_7 != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1735
 *         # see if it can be decoded as ascii if there are no null bytes
 *         if b'\0' not in value:
 *             try:             # <<<<<<<<<<<<<<
 *                 value.decode('ascii')
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
        __Pyx_XGOTREF(__pyx_t_9);
        __Pyx_XGOTREF(__pyx_t_10);
        __Pyx_XGOTREF(__pyx_t_11);
        /*try:*/ {

          /* "_mssql.pyx":1736
 *         if b'\0' not in value:
 *             try:
 *                 value.decode('ascii')             # <<<<<<<<<<<<<<
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 *             except UnicodeDecodeError:
 */
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_decode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1736, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1736, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "_mssql.pyx":1737
 *             try:
 *                 value.decode('ascii')
 *                 return b"'" + value.replace(b"'", b"''") + b"'"             # <<<<<<<<<<<<<<
 *             except UnicodeDecodeError:
 *                 pass
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_replace); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1737, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1737, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = PyNumber_Add(__pyx_kp_b__31, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1737, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_kp_b__31); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1737, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_r = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L21_try_return;

          /* "_mssql.pyx":1735
 *         # see if it can be decoded as ascii if there are no null bytes
 *         if b'\0' not in value:
 *             try:             # <<<<<<<<<<<<<<
 *                 value.decode('ascii')
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 */
        }
        __pyx_L17_error:;
        __Pyx_PyThreadState_assign
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "_mssql.pyx":1738
 *                 value.decode('ascii')
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 *             except UnicodeDecodeError:             # <<<<<<<<<<<<<<
 *                 pass
 * 
 */
        __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError);
        if (__pyx_t_12) {
          __Pyx_ErrRestore(0,0,0);
          goto __pyx_L18_exception_handled;
        }
        goto __pyx_L19_except_error;
        __pyx_L19_except_error:;

        /* "_mssql.pyx":1735
 *         # see if it can be decoded as ascii if there are no null bytes
 *         if b'\0' not in value:
 *             try:             # <<<<<<<<<<<<<<
 *                 value.decode('ascii')
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 */
        __Pyx_PyThreadState_assign
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        goto __pyx_L1_error;
        __pyx_L21_try_return:;
        __Pyx_PyThreadState_assign
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        goto __pyx_L0;
        __pyx_L18_exception_handled:;
        __Pyx_PyThreadState_assign
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }

      /* "_mssql.pyx":1734
 *     if isinstance(value, (str, bytes)):
 *         # see if it can be decoded as ascii if there are no null bytes
 *         if b'\0' not in value:             # <<<<<<<<<<<<<<
 *             try:
 *                 value.decode('ascii')
 */
    }

    /* "_mssql.pyx":1743
 *         # Python 3: handle bytes
 *         # @todo - Marc - hack hack hack
 *         if isinstance(value, bytes):             # <<<<<<<<<<<<<<
 *             return b'0x' + binascii.hexlify(value)
 * 
 */
    __pyx_t_2 = PyBytes_Check(__pyx_v_value); 
    __pyx_t_7 = (__pyx_t_2 != 0);
    if (__pyx_t_7) {

      /* "_mssql.pyx":1744
 *         # @todo - Marc - hack hack hack
 *         if isinstance(value, bytes):
 *             return b'0x' + binascii.hexlify(value)             # <<<<<<<<<<<<<<
 * 
 *         # will still be string type if there was a null byte in it or if the
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_binascii); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1744, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_hexlify); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1744, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1744, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
      } else {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1744, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
        __Pyx_INCREF(__pyx_v_value);
        __Pyx_GIVEREF(__pyx_v_value);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_value);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1744, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyNumber_Add(__pyx_kp_b_0x, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1744, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_r = __pyx_t_8;
      __pyx_t_8 = 0;
      goto __pyx_L0;

      /* "_mssql.pyx":1743
 *         # Python 3: handle bytes
 *         # @todo - Marc - hack hack hack
 *         if isinstance(value, bytes):             # <<<<<<<<<<<<<<
 *             return b'0x' + binascii.hexlify(value)
 * 
 */
    }

    /* "_mssql.pyx":1748
 *         # will still be string type if there was a null byte in it or if the
 *         # decoding failed.  In this case, just send it as hex.
 *         if isinstance(value, str):             # <<<<<<<<<<<<<<
 *             return '0x' + value.encode('hex')
 * 
 */
    __pyx_t_7 = PyString_Check(__pyx_v_value); 
    __pyx_t_2 = (__pyx_t_7 != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1749
 *         # decoding failed.  In this case, just send it as hex.
 *         if isinstance(value, str):
 *             return '0x' + value.encode('hex')             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, datetime.datetime):
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1749, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1749, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyNumber_Add(__pyx_kp_s_0x, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1749, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_r = __pyx_t_8;
      __pyx_t_8 = 0;
      goto __pyx_L0;

      /* "_mssql.pyx":1748
 *         # will still be string type if there was a null byte in it or if the
 *         # decoding failed.  In this case, just send it as hex.
 *         if isinstance(value, str):             # <<<<<<<<<<<<<<
 *             return '0x' + value.encode('hex')
 * 
 */
    }

    /* "_mssql.pyx":1732
 *         return b'0x' + binascii.hexlify(bytes(value))
 * 
 *     if isinstance(value, (str, bytes)):             # <<<<<<<<<<<<<<
 *         # see if it can be decoded as ascii if there are no null bytes
 *         if b'\0' not in value:
 */
  }

  /* "_mssql.pyx":1751
 *             return '0x' + value.encode('hex')
 * 
 *     if isinstance(value, datetime.datetime):             # <<<<<<<<<<<<<<
 *         return "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}" % (
 *             value.year, value.month, value.day,
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_datetime); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_datetime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_value, __pyx_t_6); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 1751, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_7 = (__pyx_t_2 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1752
 * 
 *     if isinstance(value, datetime.datetime):
 *         return "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}" % (             # <<<<<<<<<<<<<<
 *             value.year, value.month, value.day,
 *             value.hour, value.minute, value.second,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "_mssql.pyx":1753
 *     if isinstance(value, datetime.datetime):
 *         return "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}" % (
 *             value.year, value.month, value.day,             # <<<<<<<<<<<<<<
 *             value.hour, value.minute, value.second,
 *             value.microsecond / 1000)
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_year); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1753, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_month); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1753, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_day); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1753, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "_mssql.pyx":1754
 *         return "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}" % (
 *             value.year, value.month, value.day,
 *             value.hour, value.minute, value.second,             # <<<<<<<<<<<<<<
 *             value.microsecond / 1000)
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_hour); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1754, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_minute); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1754, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_second); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1754, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);

    /* "_mssql.pyx":1755
 *             value.year, value.month, value.day,
 *             value.hour, value.minute, value.second,
 *             value.microsecond / 1000)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, datetime.date):
 */
    __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_microsecond); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_15 = __Pyx_PyNumber_Divide(__pyx_t_14, __pyx_int_1000); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

    /* "_mssql.pyx":1753
 *     if isinstance(value, datetime.datetime):
 *         return "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}" % (
 *             value.year, value.month, value.day,             # <<<<<<<<<<<<<<
 *             value.hour, value.minute, value.second,
 *             value.microsecond / 1000)
 */
    __pyx_t_14 = PyTuple_New(7); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1753, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_14, 5, __pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_14, 6, __pyx_t_15);
    __pyx_t_6 = 0;
    __pyx_t_8 = 0;
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_5 = 0;
    __pyx_t_13 = 0;
    __pyx_t_15 = 0;

    /* "_mssql.pyx":1752
 * 
 *     if isinstance(value, datetime.datetime):
 *         return "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}" % (             # <<<<<<<<<<<<<<
 *             value.year, value.month, value.day,
 *             value.hour, value.minute, value.second,
 */
    __pyx_t_15 = __Pyx_PyString_Format(__pyx_kp_s_ts_04d_02d_02d_02d_02d_02d_03d, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1752, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_r = __pyx_t_15;
    __pyx_t_15 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1751
 *             return '0x' + value.encode('hex')
 * 
 *     if isinstance(value, datetime.datetime):             # <<<<<<<<<<<<<<
 *         return "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}" % (
 *             value.year, value.month, value.day,
 */
  }

  /* "_mssql.pyx":1757
 *             value.microsecond / 1000)
 * 
 *     if isinstance(value, datetime.date):             # <<<<<<<<<<<<<<
 *         return "{d '%04d-%02d-%02d'} " % (
 *         value.year, value.month, value.day)
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_datetime); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_date); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_7 = PyObject_IsInstance(__pyx_v_value, __pyx_t_14); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 1757, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __pyx_t_2 = (__pyx_t_7 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1758
 * 
 *     if isinstance(value, datetime.date):
 *         return "{d '%04d-%02d-%02d'} " % (             # <<<<<<<<<<<<<<
 *         value.year, value.month, value.day)
 * 
 */
    __Pyx_XDECREF(__pyx_r);

    /* "_mssql.pyx":1759
 *     if isinstance(value, datetime.date):
 *         return "{d '%04d-%02d-%02d'} " % (
 *         value.year, value.month, value.day)             # <<<<<<<<<<<<<<
 * 
 *     return None
 */
    __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_year); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1759, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_month); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1759, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_day); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1759, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1759, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_14);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_13);
    __pyx_t_14 = 0;
    __pyx_t_15 = 0;
    __pyx_t_13 = 0;

    /* "_mssql.pyx":1758
 * 
 *     if isinstance(value, datetime.date):
 *         return "{d '%04d-%02d-%02d'} " % (             # <<<<<<<<<<<<<<
 *         value.year, value.month, value.day)
 * 
 */
    __pyx_t_13 = __Pyx_PyString_Format(__pyx_kp_s_d_04d_02d_02d, __pyx_t_5); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1758, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_13;
    __pyx_t_13 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1757
 *             value.microsecond / 1000)
 * 
 *     if isinstance(value, datetime.date):             # <<<<<<<<<<<<<<
 *         return "{d '%04d-%02d-%02d'} " % (
 *         value.year, value.month, value.day)
 */
  }

  /* "_mssql.pyx":1761
 *         value.year, value.month, value.day)
 * 
 *     return None             # <<<<<<<<<<<<<<
 * 
 * cdef _quote_or_flatten(data, charset='utf8'):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  /* "_mssql.pyx":1709
 * ## Quoting Functions ##
 * #######################
 * cdef _quote_simple_value(value, charset='utf8'):             # <<<<<<<<<<<<<<
 * 
 *     if value == None:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("_mssql._quote_simple_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1763
 *     return None
 * 
 * cdef _quote_or_flatten(data, charset='utf8'):             # <<<<<<<<<<<<<<
 *     result = _quote_simple_value(data, charset)
 * 
 */

static PyObject *__pyx_f_6_mssql__quote_or_flatten(PyObject *__pyx_v_data, struct __pyx_opt_args_6_mssql__quote_or_flatten *__pyx_optional_args) {
  PyObject *__pyx_v_charset = ((PyObject *)__pyx_n_s_utf8);
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_quoted = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_6_mssql__quote_simple_value __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("_quote_or_flatten", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_charset = __pyx_optional_args->charset;
    }
  }

  /* "_mssql.pyx":1764
 * 
 * cdef _quote_or_flatten(data, charset='utf8'):
 *     result = _quote_simple_value(data, charset)             # <<<<<<<<<<<<<<
 * 
 *     if result is not None:
 */
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.charset = __pyx_v_charset;
  __pyx_t_1 = __pyx_f_6_mssql__quote_simple_value(__pyx_v_data, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_mssql.pyx":1766
 *     result = _quote_simple_value(data, charset)
 * 
 *     if result is not None:             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  __pyx_t_3 = (__pyx_v_result != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "_mssql.pyx":1767
 * 
 *     if result is not None:
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     if not issubclass(type(data), (list, tuple)):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_result);
    __pyx_r = __pyx_v_result;
    goto __pyx_L0;

    /* "_mssql.pyx":1766
 *     result = _quote_simple_value(data, charset)
 * 
 *     if result is not None:             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  }

  /* "_mssql.pyx":1769
 *         return result
 * 
 *     if not issubclass(type(data), (list, tuple)):             # <<<<<<<<<<<<<<
 *         raise ValueError('expected a simple type, a tuple or a list')
 * 
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)(&PyList_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyList_Type)));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)(&PyList_Type)));
  __Pyx_INCREF(((PyObject *)(&PyTuple_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyTuple_Type)));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)(&PyTuple_Type)));
  __pyx_t_4 = PyObject_IsSubclass(((PyObject *)Py_TYPE(__pyx_v_data)), __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!(__pyx_t_4 != 0)) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1770
 * 
 *     if not issubclass(type(data), (list, tuple)):
 *         raise ValueError('expected a simple type, a tuple or a list')             # <<<<<<<<<<<<<<
 * 
 *     quoted = []
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1770, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1770, __pyx_L1_error)

    /* "_mssql.pyx":1769
 *         return result
 * 
 *     if not issubclass(type(data), (list, tuple)):             # <<<<<<<<<<<<<<
 *         raise ValueError('expected a simple type, a tuple or a list')
 * 
 */
  }

  /* "_mssql.pyx":1772
 *         raise ValueError('expected a simple type, a tuple or a list')
 * 
 *     quoted = []             # <<<<<<<<<<<<<<
 *     for value in data:
 *         value = _quote_simple_value(value, charset)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_quoted = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_mssql.pyx":1773
 * 
 *     quoted = []
 *     for value in data:             # <<<<<<<<<<<<<<
 *         value = _quote_simple_value(value, charset)
 * 
 */
  if (likely(PyList_CheckExact(__pyx_v_data)) || PyTuple_CheckExact(__pyx_v_data)) {
    __pyx_t_1 = __pyx_v_data; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1773, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1773, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1773, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1773, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1773, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1773, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "_mssql.pyx":1774
 *     quoted = []
 *     for value in data:
 *         value = _quote_simple_value(value, charset)             # <<<<<<<<<<<<<<
 * 
 *         if value is None:
 */
    __pyx_t_2.__pyx_n = 1;
    __pyx_t_2.charset = __pyx_v_charset;
    __pyx_t_7 = __pyx_f_6_mssql__quote_simple_value(__pyx_v_value, &__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1774, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "_mssql.pyx":1776
 *         value = _quote_simple_value(value, charset)
 * 
 *         if value is None:             # <<<<<<<<<<<<<<
 *             raise ValueError('found an unsupported type')
 * 
 */
    __pyx_t_3 = (__pyx_v_value == Py_None);
    __pyx_t_4 = (__pyx_t_3 != 0);
    if (__pyx_t_4) {

      /* "_mssql.pyx":1777
 * 
 *         if value is None:
 *             raise ValueError('found an unsupported type')             # <<<<<<<<<<<<<<
 * 
 *         quoted.append(value)
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1777, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 1777, __pyx_L1_error)

      /* "_mssql.pyx":1776
 *         value = _quote_simple_value(value, charset)
 * 
 *         if value is None:             # <<<<<<<<<<<<<<
 *             raise ValueError('found an unsupported type')
 * 
 */
    }

    /* "_mssql.pyx":1779
 *             raise ValueError('found an unsupported type')
 * 
 *         quoted.append(value)             # <<<<<<<<<<<<<<
 *     return b'(' + b','.join(quoted) + b')'
 * 
 */
    __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_quoted, __pyx_v_value); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 1779, __pyx_L1_error)

    /* "_mssql.pyx":1773
 * 
 *     quoted = []
 *     for value in data:             # <<<<<<<<<<<<<<
 *         value = _quote_simple_value(value, charset)
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1780
 * 
 *         quoted.append(value)
 *     return b'(' + b','.join(quoted) + b')'             # <<<<<<<<<<<<<<
 * 
 * # This function is supposed to take a simple value, tuple or dictionary,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_Join(__pyx_kp_b__41, __pyx_v_quoted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyNumber_Add(__pyx_kp_b__40, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Add(__pyx_t_7, __pyx_kp_b__42); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1763
 *     return None
 * 
 * cdef _quote_or_flatten(data, charset='utf8'):             # <<<<<<<<<<<<<<
 *     result = _quote_simple_value(data, charset)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("_mssql._quote_or_flatten", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_quoted);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1785
 * # normally passed in via the params argument in the execute_* methods. It
 * # then quotes and flattens the arguments and returns then.
 * cdef _quote_data(data, charset='utf8'):             # <<<<<<<<<<<<<<
 *     result = _quote_simple_value(data)
 * 
 */

static PyObject *__pyx_f_6_mssql__quote_data(PyObject *__pyx_v_data, struct __pyx_opt_args_6_mssql__quote_data *__pyx_optional_args) {
  PyObject *__pyx_v_charset = ((PyObject *)__pyx_n_s_utf8);
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_k = NULL;
  PyObject *__pyx_v_v = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  struct __pyx_opt_args_6_mssql__quote_or_flatten __pyx_t_10;
  PyObject *(*__pyx_t_11)(PyObject *);
  int __pyx_t_12;
  __Pyx_RefNannySetupContext("_quote_data", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_charset = __pyx_optional_args->charset;
    }
  }

  /* "_mssql.pyx":1786
 * # then quotes and flattens the arguments and returns then.
 * cdef _quote_data(data, charset='utf8'):
 *     result = _quote_simple_value(data)             # <<<<<<<<<<<<<<
 * 
 *     if result is not None:
 */
  __pyx_t_1 = __pyx_f_6_mssql__quote_simple_value(__pyx_v_data, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1786, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_mssql.pyx":1788
 *     result = _quote_simple_value(data)
 * 
 *     if result is not None:             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  __pyx_t_2 = (__pyx_v_result != Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1789
 * 
 *     if result is not None:
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     if issubclass(type(data), dict):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_result);
    __pyx_r = __pyx_v_result;
    goto __pyx_L0;

    /* "_mssql.pyx":1788
 *     result = _quote_simple_value(data)
 * 
 *     if result is not None:             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  }

  /* "_mssql.pyx":1791
 *         return result
 * 
 *     if issubclass(type(data), dict):             # <<<<<<<<<<<<<<
 *         result = {}
 *         for k, v in data.iteritems():
 */
  __pyx_t_3 = PyObject_IsSubclass(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)(&PyDict_Type))); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 1791, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1792
 * 
 *     if issubclass(type(data), dict):
 *         result = {}             # <<<<<<<<<<<<<<
 *         for k, v in data.iteritems():
 *             result[k] = _quote_or_flatten(v, charset)
 */
    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1792, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "_mssql.pyx":1793
 *     if issubclass(type(data), dict):
 *         result = {}
 *         for k, v in data.iteritems():             # <<<<<<<<<<<<<<
 *             result[k] = _quote_or_flatten(v, charset)
 *         return result
 */
    __pyx_t_4 = 0;
    if (unlikely(__pyx_v_data == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "iteritems");
      __PYX_ERR(0, 1793, __pyx_L1_error)
    }
    __pyx_t_7 = __Pyx_dict_iterator(__pyx_v_data, 0, __pyx_n_s_iteritems, (&__pyx_t_5), (&__pyx_t_6)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1793, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_7;
    __pyx_t_7 = 0;
    while (1) {
      __pyx_t_9 = __Pyx_dict_iter_next(__pyx_t_1, __pyx_t_5, &__pyx_t_4, &__pyx_t_7, &__pyx_t_8, NULL, __pyx_t_6);
      if (unlikely(__pyx_t_9 == 0)) break;
      if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 1793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "_mssql.pyx":1794
 *         result = {}
 *         for k, v in data.iteritems():
 *             result[k] = _quote_or_flatten(v, charset)             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
      __pyx_t_10.__pyx_n = 1;
      __pyx_t_10.charset = __pyx_v_charset;
      __pyx_t_8 = __pyx_f_6_mssql__quote_or_flatten(__pyx_v_v, &__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1794, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_v_k, __pyx_t_8) < 0)) __PYX_ERR(0, 1794, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1795
 *         for k, v in data.iteritems():
 *             result[k] = _quote_or_flatten(v, charset)
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     if issubclass(type(data), tuple):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_result);
    __pyx_r = __pyx_v_result;
    goto __pyx_L0;

    /* "_mssql.pyx":1791
 *         return result
 * 
 *     if issubclass(type(data), dict):             # <<<<<<<<<<<<<<
 *         result = {}
 *         for k, v in data.iteritems():
 */
  }

  /* "_mssql.pyx":1797
 *         return result
 * 
 *     if issubclass(type(data), tuple):             # <<<<<<<<<<<<<<
 *         result = []
 *         for v in data:
 */
  __pyx_t_2 = PyObject_IsSubclass(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)(&PyTuple_Type))); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 1797, __pyx_L1_error)
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1798
 * 
 *     if issubclass(type(data), tuple):
 *         result = []             # <<<<<<<<<<<<<<
 *         for v in data:
 *             result.append(_quote_or_flatten(v, charset))
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1798, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "_mssql.pyx":1799
 *     if issubclass(type(data), tuple):
 *         result = []
 *         for v in data:             # <<<<<<<<<<<<<<
 *             result.append(_quote_or_flatten(v, charset))
 *         return tuple(result)
 */
    if (likely(PyList_CheckExact(__pyx_v_data)) || PyTuple_CheckExact(__pyx_v_data)) {
      __pyx_t_1 = __pyx_v_data; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
      __pyx_t_11 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1799, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_11 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1799, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_11)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_8); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1799, __pyx_L1_error)
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1799, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_8); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1799, __pyx_L1_error)
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1799, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          #endif
        }
      } else {
        __pyx_t_8 = __pyx_t_11(__pyx_t_1);
        if (unlikely(!__pyx_t_8)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1799, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_8);
      }
      __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "_mssql.pyx":1800
 *         result = []
 *         for v in data:
 *             result.append(_quote_or_flatten(v, charset))             # <<<<<<<<<<<<<<
 *         return tuple(result)
 * 
 */
      __pyx_t_10.__pyx_n = 1;
      __pyx_t_10.charset = __pyx_v_charset;
      __pyx_t_8 = __pyx_f_6_mssql__quote_or_flatten(__pyx_v_v, &__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1800, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_12 = __Pyx_PyObject_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_12 == -1)) __PYX_ERR(0, 1800, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "_mssql.pyx":1799
 *     if issubclass(type(data), tuple):
 *         result = []
 *         for v in data:             # <<<<<<<<<<<<<<
 *             result.append(_quote_or_flatten(v, charset))
 *         return tuple(result)
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1801
 *         for v in data:
 *             result.append(_quote_or_flatten(v, charset))
 *         return tuple(result)             # <<<<<<<<<<<<<<
 * 
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PySequence_Tuple(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1801, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "_mssql.pyx":1797
 *         return result
 * 
 *     if issubclass(type(data), tuple):             # <<<<<<<<<<<<<<
 *         result = []
 *         for v in data:
 */
  }

  /* "_mssql.pyx":1803
 *         return tuple(result)
 * 
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')             # <<<<<<<<<<<<<<
 * 
 * _re_pos_param = re.compile(br'(%([sd]))')
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(0, 1803, __pyx_L1_error)

  /* "_mssql.pyx":1785
 * # normally passed in via the params argument in the execute_* methods. It
 * # then quotes and flattens the arguments and returns then.
 * cdef _quote_data(data, charset='utf8'):             # <<<<<<<<<<<<<<
 *     result = _quote_simple_value(data)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("_mssql._quote_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_k);
  __Pyx_XDECREF(__pyx_v_v);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1807
 * _re_pos_param = re.compile(br'(%([sd]))')
 * _re_name_param = re.compile(br'(%\(([^\)]+)\)(?:[sd]))')
 * cdef _substitute_params(toformat, params, charset):             # <<<<<<<<<<<<<<
 *     if params is None:
 *         return toformat
 */

static PyObject *__pyx_f_6_mssql__substitute_params(PyObject *__pyx_v_toformat, PyObject *__pyx_v_params, PyObject *__pyx_v_charset) {
  PyObject *__pyx_v_quoted = NULL;
  PyObject *__pyx_v_offset = NULL;
  PyObject *__pyx_v_match = NULL;
  PyObject *__pyx_v_param_key = NULL;
  PyObject *__pyx_v_param_val = NULL;
  PyObject *__pyx_v_param_val_len = NULL;
  PyObject *__pyx_v_placeholder_len = NULL;
  PyObject *__pyx_v_offset_adjust = NULL;
  PyObject *__pyx_v_match_start = NULL;
  PyObject *__pyx_v_match_end = NULL;
  PyObject *__pyx_v_count = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  struct __pyx_opt_args_6_mssql__quote_data __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  Py_ssize_t __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  int __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  __Pyx_RefNannySetupContext("_substitute_params", 0);
  __Pyx_INCREF(__pyx_v_toformat);

  /* "_mssql.pyx":1808
 * _re_name_param = re.compile(br'(%\(([^\)]+)\)(?:[sd]))')
 * cdef _substitute_params(toformat, params, charset):
 *     if params is None:             # <<<<<<<<<<<<<<
 *         return toformat
 * 
 */
  __pyx_t_1 = (__pyx_v_params == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1809
 * cdef _substitute_params(toformat, params, charset):
 *     if params is None:
 *         return toformat             # <<<<<<<<<<<<<<
 * 
 *     if not issubclass(type(params),
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_toformat);
    __pyx_r = __pyx_v_toformat;
    goto __pyx_L0;

    /* "_mssql.pyx":1808
 * _re_name_param = re.compile(br'(%\(([^\)]+)\)(?:[sd]))')
 * cdef _substitute_params(toformat, params, charset):
 *     if params is None:             # <<<<<<<<<<<<<<
 *         return toformat
 * 
 */
  }

  /* "_mssql.pyx":1813
 *     if not issubclass(type(params),
 *             (bool, int, long, float, unicode, str, bytes, bytearray, dict, tuple,
 *              datetime.datetime, datetime.date, dict, decimal.Decimal, uuid.UUID)):             # <<<<<<<<<<<<<<
 *         raise ValueError("'params' arg (%r) can be only a tuple or a dictionary." % type(params))
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_date); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_decimal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Decimal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_uuid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_UUID); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1812
 * 
 *     if not issubclass(type(params),
 *             (bool, int, long, float, unicode, str, bytes, bytearray, dict, tuple,             # <<<<<<<<<<<<<<
 *              datetime.datetime, datetime.date, dict, decimal.Decimal, uuid.UUID)):
 *         raise ValueError("'params' arg (%r) can be only a tuple or a dictionary." % type(params))
 */
  __pyx_t_3 = PyTuple_New(15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1812, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_ptype_7cpython_4bool_bool));
  __Pyx_GIVEREF(((PyObject *)__pyx_ptype_7cpython_4bool_bool));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_ptype_7cpython_4bool_bool));
  __Pyx_INCREF(((PyObject *)(&PyInt_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyInt_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)(&PyInt_Type)));
  __Pyx_INCREF(((PyObject *)(&PyLong_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyLong_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)(&PyLong_Type)));
  __Pyx_INCREF(((PyObject *)(&PyFloat_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyFloat_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)(&PyFloat_Type)));
  __Pyx_INCREF(((PyObject *)(&PyUnicode_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyUnicode_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)(&PyUnicode_Type)));
  __Pyx_INCREF(((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)(&PyString_Type)));
  __Pyx_INCREF(((PyObject *)(&PyBytes_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyBytes_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 6, ((PyObject *)(&PyBytes_Type)));
  __Pyx_INCREF(((PyObject *)(&PyByteArray_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyByteArray_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 7, ((PyObject *)(&PyByteArray_Type)));
  __Pyx_INCREF(((PyObject *)(&PyDict_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyDict_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 8, ((PyObject *)(&PyDict_Type)));
  __Pyx_INCREF(((PyObject *)(&PyTuple_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyTuple_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 9, ((PyObject *)(&PyTuple_Type)));
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 10, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 11, __pyx_t_5);
  __Pyx_INCREF(((PyObject *)(&PyDict_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyDict_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 12, ((PyObject *)(&PyDict_Type)));
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_3, 13, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_3, 14, __pyx_t_7);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;

  /* "_mssql.pyx":1811
 *         return toformat
 * 
 *     if not issubclass(type(params),             # <<<<<<<<<<<<<<
 *             (bool, int, long, float, unicode, str, bytes, bytearray, dict, tuple,
 *              datetime.datetime, datetime.date, dict, decimal.Decimal, uuid.UUID)):
 */
  __pyx_t_2 = PyObject_IsSubclass(((PyObject *)Py_TYPE(__pyx_v_params)), __pyx_t_3); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 1811, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1814
 *             (bool, int, long, float, unicode, str, bytes, bytearray, dict, tuple,
 *              datetime.datetime, datetime.date, dict, decimal.Decimal, uuid.UUID)):
 *         raise ValueError("'params' arg (%r) can be only a tuple or a dictionary." % type(params))             # <<<<<<<<<<<<<<
 * 
 *     if charset:
 */
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_params_arg_r_can_be_only_a_tupl, ((PyObject *)Py_TYPE(__pyx_v_params))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1814, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1814, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1814, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1814, __pyx_L1_error)

    /* "_mssql.pyx":1811
 *         return toformat
 * 
 *     if not issubclass(type(params),             # <<<<<<<<<<<<<<
 *             (bool, int, long, float, unicode, str, bytes, bytearray, dict, tuple,
 *              datetime.datetime, datetime.date, dict, decimal.Decimal, uuid.UUID)):
 */
  }

  /* "_mssql.pyx":1816
 *         raise ValueError("'params' arg (%r) can be only a tuple or a dictionary." % type(params))
 * 
 *     if charset:             # <<<<<<<<<<<<<<
 *         quoted = _quote_data(params, charset)
 *     else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_charset); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1816, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1817
 * 
 *     if charset:
 *         quoted = _quote_data(params, charset)             # <<<<<<<<<<<<<<
 *     else:
 *         quoted = _quote_data(params)
 */
    __pyx_t_8.__pyx_n = 1;
    __pyx_t_8.charset = __pyx_v_charset;
    __pyx_t_3 = __pyx_f_6_mssql__quote_data(__pyx_v_params, &__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1817, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_quoted = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "_mssql.pyx":1816
 *         raise ValueError("'params' arg (%r) can be only a tuple or a dictionary." % type(params))
 * 
 *     if charset:             # <<<<<<<<<<<<<<
 *         quoted = _quote_data(params, charset)
 *     else:
 */
    goto __pyx_L5;
  }

  /* "_mssql.pyx":1819
 *         quoted = _quote_data(params, charset)
 *     else:
 *         quoted = _quote_data(params)             # <<<<<<<<<<<<<<
 * 
 *     # positional string substitution now requires a tuple
 */
  /*else*/ {
    __pyx_t_3 = __pyx_f_6_mssql__quote_data(__pyx_v_params, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_quoted = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L5:;

  /* "_mssql.pyx":1822
 * 
 *     # positional string substitution now requires a tuple
 *     if hasattr(quoted, 'startswith'):             # <<<<<<<<<<<<<<
 *         quoted = (quoted,)
 * 
 */
  __pyx_t_1 = PyObject_HasAttr(__pyx_v_quoted, __pyx_n_s_startswith); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 1822, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1823
 *     # positional string substitution now requires a tuple
 *     if hasattr(quoted, 'startswith'):
 *         quoted = (quoted,)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(toformat, unicode):
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1823, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_quoted);
    __Pyx_GIVEREF(__pyx_v_quoted);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_quoted);
    __Pyx_DECREF_SET(__pyx_v_quoted, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "_mssql.pyx":1822
 * 
 *     # positional string substitution now requires a tuple
 *     if hasattr(quoted, 'startswith'):             # <<<<<<<<<<<<<<
 *         quoted = (quoted,)
 * 
 */
  }

  /* "_mssql.pyx":1825
 *         quoted = (quoted,)
 * 
 *     if isinstance(toformat, unicode):             # <<<<<<<<<<<<<<
 *         toformat = toformat.encode(charset)
 * 
 */
  __pyx_t_2 = PyUnicode_Check(__pyx_v_toformat); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1826
 * 
 *     if isinstance(toformat, unicode):
 *         toformat = toformat.encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(params, dict):
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_toformat, __pyx_n_s_encode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_charset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1826, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1826, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_charset);
      __Pyx_GIVEREF(__pyx_v_charset);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_charset);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1826, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_toformat, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "_mssql.pyx":1825
 *         quoted = (quoted,)
 * 
 *     if isinstance(toformat, unicode):             # <<<<<<<<<<<<<<
 *         toformat = toformat.encode(charset)
 * 
 */
  }

  /* "_mssql.pyx":1828
 *         toformat = toformat.encode(charset)
 * 
 *     if isinstance(params, dict):             # <<<<<<<<<<<<<<
 *         """ assume name based substitutions """
 *         offset = 0
 */
  __pyx_t_1 = PyDict_Check(__pyx_v_params); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1830
 *     if isinstance(params, dict):
 *         """ assume name based substitutions """
 *         offset = 0             # <<<<<<<<<<<<<<
 *         for match in _re_name_param.finditer(toformat):
 *             param_key = match.group(2).decode(charset)
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_offset = __pyx_int_0;

    /* "_mssql.pyx":1831
 *         """ assume name based substitutions """
 *         offset = 0
 *         for match in _re_name_param.finditer(toformat):             # <<<<<<<<<<<<<<
 *             param_key = match.group(2).decode(charset)
 * 
 */
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_re_name_param); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1831, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_finditer); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1831, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_7) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_toformat); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1831, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1831, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
      __Pyx_INCREF(__pyx_v_toformat);
      __Pyx_GIVEREF(__pyx_v_toformat);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_toformat);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1831, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_5 = __pyx_t_3; __Pyx_INCREF(__pyx_t_5); __pyx_t_9 = 0;
      __pyx_t_10 = NULL;
    } else {
      __pyx_t_9 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1831, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1831, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_10)) {
        if (likely(PyList_CheckExact(__pyx_t_5))) {
          if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1831, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1831, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1831, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1831, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_10(__pyx_t_5);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1831, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_v_match, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1832
 *         offset = 0
 *         for match in _re_name_param.finditer(toformat):
 *             param_key = match.group(2).decode(charset)             # <<<<<<<<<<<<<<
 * 
 *             if not param_key in params:
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_group); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1832, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1832, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_decode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1832, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (!__pyx_t_7) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_charset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1832, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1832, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL;
        __Pyx_INCREF(__pyx_v_charset);
        __Pyx_GIVEREF(__pyx_v_charset);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_charset);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1832, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_v_param_key, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1834
 *             param_key = match.group(2).decode(charset)
 * 
 *             if not param_key in params:             # <<<<<<<<<<<<<<
 *                 raise ValueError('params dictionary did not contain value for placeholder: %s' % param_key)
 * 
 */
      __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_param_key, __pyx_v_params, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1834, __pyx_L1_error)
      __pyx_t_1 = (__pyx_t_2 != 0);
      if (__pyx_t_1) {

        /* "_mssql.pyx":1835
 * 
 *             if not param_key in params:
 *                 raise ValueError('params dictionary did not contain value for placeholder: %s' % param_key)             # <<<<<<<<<<<<<<
 * 
 *             # calculate string positions so we can keep track of the offset to
 */
        __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_params_dictionary_did_not_contai, __pyx_v_param_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1835, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1835, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1835, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 1835, __pyx_L1_error)

        /* "_mssql.pyx":1834
 *             param_key = match.group(2).decode(charset)
 * 
 *             if not param_key in params:             # <<<<<<<<<<<<<<
 *                 raise ValueError('params dictionary did not contain value for placeholder: %s' % param_key)
 * 
 */
      }

      /* "_mssql.pyx":1844
 *             # the length of the placeholder and the length of the value being
 *             # substituted
 *             param_val = quoted[param_key]             # <<<<<<<<<<<<<<
 *             param_val_len = len(param_val)
 *             placeholder_len = len(match.group(1))
 */
      __pyx_t_3 = PyObject_GetItem(__pyx_v_quoted, __pyx_v_param_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1844, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_param_val, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1845
 *             # substituted
 *             param_val = quoted[param_key]
 *             param_val_len = len(param_val)             # <<<<<<<<<<<<<<
 *             placeholder_len = len(match.group(1))
 *             offset_adjust = param_val_len - placeholder_len
 */
      __pyx_t_11 = PyObject_Length(__pyx_v_param_val); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 1845, __pyx_L1_error)
      __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1845, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_param_val_len, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1846
 *             param_val = quoted[param_key]
 *             param_val_len = len(param_val)
 *             placeholder_len = len(match.group(1))             # <<<<<<<<<<<<<<
 *             offset_adjust = param_val_len - placeholder_len
 * 
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_group); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1846, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1846, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_11 = PyObject_Length(__pyx_t_6); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 1846, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1846, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_XDECREF_SET(__pyx_v_placeholder_len, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1847
 *             param_val_len = len(param_val)
 *             placeholder_len = len(match.group(1))
 *             offset_adjust = param_val_len - placeholder_len             # <<<<<<<<<<<<<<
 * 
 *             # do the string substitution
 */
      __pyx_t_6 = PyNumber_Subtract(__pyx_v_param_val_len, __pyx_v_placeholder_len); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1847, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_XDECREF_SET(__pyx_v_offset_adjust, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1850
 * 
 *             # do the string substitution
 *             match_start = match.start(1) + offset             # <<<<<<<<<<<<<<
 *             match_end = match.end(1) + offset
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_start); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1850, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1850, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_v_offset); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1850, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_match_start, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1851
 *             # do the string substitution
 *             match_start = match.start(1) + offset
 *             match_end = match.end(1) + offset             # <<<<<<<<<<<<<<
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]
 * 
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_end); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1851, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1851, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_v_offset); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1851, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_match_end, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1852
 *             match_start = match.start(1) + offset
 *             match_end = match.end(1) + offset
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]             # <<<<<<<<<<<<<<
 * 
 *             # adjust the offset for the next usage
 */
      __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_v_toformat, 0, 0, NULL, &__pyx_v_match_start, NULL, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __pyx_f_6_mssql_ensure_bytes(__pyx_v_param_val, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyNumber_Add(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_toformat, 0, 0, &__pyx_v_match_end, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF_SET(__pyx_v_toformat, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1855
 * 
 *             # adjust the offset for the next usage
 *             offset += offset_adjust             # <<<<<<<<<<<<<<
 *     else:
 *         """ assume position based substitutions """
 */
      __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_offset, __pyx_v_offset_adjust); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1855, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF_SET(__pyx_v_offset, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1831
 *         """ assume name based substitutions """
 *         offset = 0
 *         for match in _re_name_param.finditer(toformat):             # <<<<<<<<<<<<<<
 *             param_key = match.group(2).decode(charset)
 * 
 */
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "_mssql.pyx":1828
 *         toformat = toformat.encode(charset)
 * 
 *     if isinstance(params, dict):             # <<<<<<<<<<<<<<
 *         """ assume name based substitutions """
 *         offset = 0
 */
    goto __pyx_L8;
  }

  /* "_mssql.pyx":1857
 *             offset += offset_adjust
 *     else:
 *         """ assume position based substitutions """             # <<<<<<<<<<<<<<
 *         offset = 0
 *         for count, match in enumerate(_re_pos_param.finditer(toformat)):
 */
  /*else*/ {

    /* "_mssql.pyx":1858
 *     else:
 *         """ assume position based substitutions """
 *         offset = 0             # <<<<<<<<<<<<<<
 *         for count, match in enumerate(_re_pos_param.finditer(toformat)):
 *             # calculate string positions so we can keep track of the offset to
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_offset = __pyx_int_0;

    /* "_mssql.pyx":1859
 *         """ assume position based substitutions """
 *         offset = 0
 *         for count, match in enumerate(_re_pos_param.finditer(toformat)):             # <<<<<<<<<<<<<<
 *             # calculate string positions so we can keep track of the offset to
 *             # be used in future substitutions on this string. This is
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_5 = __pyx_int_0;
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_re_pos_param); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1859, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_finditer); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1859, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_toformat); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_toformat);
      __Pyx_GIVEREF(__pyx_v_toformat);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_toformat);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
      __pyx_t_4 = __pyx_t_6; __Pyx_INCREF(__pyx_t_4); __pyx_t_9 = 0;
      __pyx_t_10 = NULL;
    } else {
      __pyx_t_9 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1859, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    for (;;) {
      if (likely(!__pyx_t_10)) {
        if (likely(PyList_CheckExact(__pyx_t_4))) {
          if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1859, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1859, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1859, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1859, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_10(__pyx_t_4);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1859, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_match, __pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_v_count, __pyx_t_5);
      __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_t_5, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5);
      __pyx_t_5 = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1867
 *             # the length of the placeholder and the length of the value being
 *             # substituted
 *             try:             # <<<<<<<<<<<<<<
 *                 param_val = quoted[count]
 *             except IndexError:
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
        __Pyx_XGOTREF(__pyx_t_12);
        __Pyx_XGOTREF(__pyx_t_13);
        __Pyx_XGOTREF(__pyx_t_14);
        /*try:*/ {

          /* "_mssql.pyx":1868
 *             # substituted
 *             try:
 *                 param_val = quoted[count]             # <<<<<<<<<<<<<<
 *             except IndexError:
 *                 raise ValueError('more placeholders in sql than params available')
 */
          __pyx_t_6 = PyObject_GetItem(__pyx_v_quoted, __pyx_v_count); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1868, __pyx_L14_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_XDECREF_SET(__pyx_v_param_val, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "_mssql.pyx":1867
 *             # the length of the placeholder and the length of the value being
 *             # substituted
 *             try:             # <<<<<<<<<<<<<<
 *                 param_val = quoted[count]
 *             except IndexError:
 */
        }
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L21_try_end;
        __pyx_L14_error:;
        __Pyx_PyThreadState_assign
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "_mssql.pyx":1869
 *             try:
 *                 param_val = quoted[count]
 *             except IndexError:             # <<<<<<<<<<<<<<
 *                 raise ValueError('more placeholders in sql than params available')
 *             param_val_len = len(param_val)
 */
        __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_IndexError);
        if (__pyx_t_15) {
          __Pyx_AddTraceback("_mssql._substitute_params", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_3) < 0) __PYX_ERR(0, 1869, __pyx_L16_except_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GOTREF(__pyx_t_3);

          /* "_mssql.pyx":1870
 *                 param_val = quoted[count]
 *             except IndexError:
 *                 raise ValueError('more placeholders in sql than params available')             # <<<<<<<<<<<<<<
 *             param_val_len = len(param_val)
 *             placeholder_len = 2
 */
          __pyx_t_16 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1870, __pyx_L16_except_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_Raise(__pyx_t_16, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __PYX_ERR(0, 1870, __pyx_L16_except_error)
        }
        goto __pyx_L16_except_error;
        __pyx_L16_except_error:;

        /* "_mssql.pyx":1867
 *             # the length of the placeholder and the length of the value being
 *             # substituted
 *             try:             # <<<<<<<<<<<<<<
 *                 param_val = quoted[count]
 *             except IndexError:
 */
        __Pyx_PyThreadState_assign
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
        goto __pyx_L1_error;
        __pyx_L21_try_end:;
      }

      /* "_mssql.pyx":1871
 *             except IndexError:
 *                 raise ValueError('more placeholders in sql than params available')
 *             param_val_len = len(param_val)             # <<<<<<<<<<<<<<
 *             placeholder_len = 2
 *             offset_adjust = param_val_len - placeholder_len
 */
      __pyx_t_11 = PyObject_Length(__pyx_v_param_val); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 1871, __pyx_L1_error)
      __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1871, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_param_val_len, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1872
 *                 raise ValueError('more placeholders in sql than params available')
 *             param_val_len = len(param_val)
 *             placeholder_len = 2             # <<<<<<<<<<<<<<
 *             offset_adjust = param_val_len - placeholder_len
 * 
 */
      __Pyx_INCREF(__pyx_int_2);
      __Pyx_XDECREF_SET(__pyx_v_placeholder_len, __pyx_int_2);

      /* "_mssql.pyx":1873
 *             param_val_len = len(param_val)
 *             placeholder_len = 2
 *             offset_adjust = param_val_len - placeholder_len             # <<<<<<<<<<<<<<
 * 
 *             # do the string substitution
 */
      __pyx_t_3 = PyNumber_Subtract(__pyx_v_param_val_len, __pyx_v_placeholder_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1873, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_offset_adjust, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1876
 * 
 *             # do the string substitution
 *             match_start = match.start(1) + offset             # <<<<<<<<<<<<<<
 *             match_end = match.end(1) + offset
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1876, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1876, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyNumber_Add(__pyx_t_7, __pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1876, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_match_start, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1877
 *             # do the string substitution
 *             match_start = match.start(1) + offset
 *             match_end = match.end(1) + offset             # <<<<<<<<<<<<<<
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]
 *             #print(param_val, param_val_len, offset_adjust, match_start, match_end)
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_end); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1877, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1877, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyNumber_Add(__pyx_t_7, __pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1877, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_match_end, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1878
 *             match_start = match.start(1) + offset
 *             match_end = match.end(1) + offset
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]             # <<<<<<<<<<<<<<
 *             #print(param_val, param_val_len, offset_adjust, match_start, match_end)
 *             # adjust the offset for the next usage
 */
      __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_toformat, 0, 0, NULL, &__pyx_v_match_start, NULL, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1878, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = __pyx_f_6_mssql_ensure_bytes(__pyx_v_param_val, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1878, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1878, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_toformat, 0, 0, &__pyx_v_match_end, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1878, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_3 = PyNumber_Add(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1878, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF_SET(__pyx_v_toformat, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1881
 *             #print(param_val, param_val_len, offset_adjust, match_start, match_end)
 *             # adjust the offset for the next usage
 *             offset += offset_adjust             # <<<<<<<<<<<<<<
 *     return toformat
 * 
 */
      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_offset, __pyx_v_offset_adjust); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1881, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF_SET(__pyx_v_offset, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "_mssql.pyx":1859
 *         """ assume position based substitutions """
 *         offset = 0
 *         for count, match in enumerate(_re_pos_param.finditer(toformat)):             # <<<<<<<<<<<<<<
 *             # calculate string positions so we can keep track of the offset to
 *             # be used in future substitutions on this string. This is
 */
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_L8:;

  /* "_mssql.pyx":1882
 *             # adjust the offset for the next usage
 *             offset += offset_adjust
 *     return toformat             # <<<<<<<<<<<<<<
 * 
 * # We'll add these methods to the module to allow for unit testing of the
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_toformat);
  __pyx_r = __pyx_v_toformat;
  goto __pyx_L0;

  /* "_mssql.pyx":1807
 * _re_pos_param = re.compile(br'(%([sd]))')
 * _re_name_param = re.compile(br'(%\(([^\)]+)\)(?:[sd]))')
 * cdef _substitute_params(toformat, params, charset):             # <<<<<<<<<<<<<<
 *     if params is None:
 *         return toformat
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("_mssql._substitute_params", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_quoted);
  __Pyx_XDECREF(__pyx_v_offset);
  __Pyx_XDECREF(__pyx_v_match);
  __Pyx_XDECREF(__pyx_v_param_key);
  __Pyx_XDECREF(__pyx_v_param_val);
  __Pyx_XDECREF(__pyx_v_param_val_len);
  __Pyx_XDECREF(__pyx_v_placeholder_len);
  __Pyx_XDECREF(__pyx_v_offset_adjust);
  __Pyx_XDECREF(__pyx_v_match_start);
  __Pyx_XDECREF(__pyx_v_match_end);
  __Pyx_XDECREF(__pyx_v_count);
  __Pyx_XDECREF(__pyx_v_toformat);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1886
 * # We'll add these methods to the module to allow for unit testing of the
 * # underlying C methods.
 * def quote_simple_value(value):             # <<<<<<<<<<<<<<
 *     return _quote_simple_value(value)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_5quote_simple_value(PyObject *__pyx_self, PyObject *__pyx_v_value); /*proto*/
static PyMethodDef __pyx_mdef_6_mssql_5quote_simple_value = {"quote_simple_value", (PyCFunction)__pyx_pw_6_mssql_5quote_simple_value, METH_O, 0};
static PyObject *__pyx_pw_6_mssql_5quote_simple_value(PyObject *__pyx_self, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("quote_simple_value (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_4quote_simple_value(__pyx_self, ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_4quote_simple_value(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("quote_simple_value", 0);

  /* "_mssql.pyx":1887
 * # underlying C methods.
 * def quote_simple_value(value):
 *     return _quote_simple_value(value)             # <<<<<<<<<<<<<<
 * 
 * def quote_or_flatten(data):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6_mssql__quote_simple_value(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1886
 * # We'll add these methods to the module to allow for unit testing of the
 * # underlying C methods.
 * def quote_simple_value(value):             # <<<<<<<<<<<<<<
 *     return _quote_simple_value(value)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.quote_simple_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1889
 *     return _quote_simple_value(value)
 * 
 * def quote_or_flatten(data):             # <<<<<<<<<<<<<<
 *     return _quote_or_flatten(data)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_7quote_or_flatten(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
static PyMethodDef __pyx_mdef_6_mssql_7quote_or_flatten = {"quote_or_flatten", (PyCFunction)__pyx_pw_6_mssql_7quote_or_flatten, METH_O, 0};
static PyObject *__pyx_pw_6_mssql_7quote_or_flatten(PyObject *__pyx_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("quote_or_flatten (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_6quote_or_flatten(__pyx_self, ((PyObject *)__pyx_v_data));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_6quote_or_flatten(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("quote_or_flatten", 0);

  /* "_mssql.pyx":1890
 * 
 * def quote_or_flatten(data):
 *     return _quote_or_flatten(data)             # <<<<<<<<<<<<<<
 * 
 * def quote_data(data):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6_mssql__quote_or_flatten(__pyx_v_data, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1889
 *     return _quote_simple_value(value)
 * 
 * def quote_or_flatten(data):             # <<<<<<<<<<<<<<
 *     return _quote_or_flatten(data)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.quote_or_flatten", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1892
 *     return _quote_or_flatten(data)
 * 
 * def quote_data(data):             # <<<<<<<<<<<<<<
 *     return _quote_data(data)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_9quote_data(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
static PyMethodDef __pyx_mdef_6_mssql_9quote_data = {"quote_data", (PyCFunction)__pyx_pw_6_mssql_9quote_data, METH_O, 0};
static PyObject *__pyx_pw_6_mssql_9quote_data(PyObject *__pyx_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("quote_data (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_8quote_data(__pyx_self, ((PyObject *)__pyx_v_data));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_8quote_data(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("quote_data", 0);

  /* "_mssql.pyx":1893
 * 
 * def quote_data(data):
 *     return _quote_data(data)             # <<<<<<<<<<<<<<
 * 
 * def substitute_params(toformat, params, charset='utf8'):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6_mssql__quote_data(__pyx_v_data, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1893, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1892
 *     return _quote_or_flatten(data)
 * 
 * def quote_data(data):             # <<<<<<<<<<<<<<
 *     return _quote_data(data)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.quote_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1895
 *     return _quote_data(data)
 * 
 * def substitute_params(toformat, params, charset='utf8'):             # <<<<<<<<<<<<<<
 *     return _substitute_params(toformat, params, charset)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_11substitute_params(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_6_mssql_11substitute_params = {"substitute_params", (PyCFunction)__pyx_pw_6_mssql_11substitute_params, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_6_mssql_11substitute_params(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_toformat = 0;
  PyObject *__pyx_v_params = 0;
  PyObject *__pyx_v_charset = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("substitute_params (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_toformat,&__pyx_n_s_params,&__pyx_n_s_charset,0};
    PyObject* values[3] = {0,0,0};
    values[2] = ((PyObject *)__pyx_n_s_utf8);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_toformat)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("substitute_params", 0, 2, 3, 1); __PYX_ERR(0, 1895, __pyx_L3_error)
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_charset);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "substitute_params") < 0)) __PYX_ERR(0, 1895, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_toformat = values[0];
    __pyx_v_params = values[1];
    __pyx_v_charset = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("substitute_params", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1895, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.substitute_params", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_10substitute_params(__pyx_self, __pyx_v_toformat, __pyx_v_params, __pyx_v_charset);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_10substitute_params(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_toformat, PyObject *__pyx_v_params, PyObject *__pyx_v_charset) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("substitute_params", 0);

  /* "_mssql.pyx":1896
 * 
 * def substitute_params(toformat, params, charset='utf8'):
 *     return _substitute_params(toformat, params, charset)             # <<<<<<<<<<<<<<
 * 
 * ###########################
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6_mssql__substitute_params(__pyx_v_toformat, __pyx_v_params, __pyx_v_charset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1895
 *     return _quote_data(data)
 * 
 * def substitute_params(toformat, params, charset='utf8'):             # <<<<<<<<<<<<<<
 *     return _substitute_params(toformat, params, charset)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.substitute_params", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1901
 * ## Compatibility Aliases ##
 * ###########################
 * def connect(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return MSSQLConnection(*args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_13connect(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_6_mssql_13connect = {"connect", (PyCFunction)__pyx_pw_6_mssql_13connect, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_6_mssql_13connect(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("connect (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "connect", 1))) return NULL;
  if (unlikely(__pyx_kwds)) {
    __pyx_v_kwargs = PyDict_Copy(__pyx_kwds); if (unlikely(!__pyx_v_kwargs)) return NULL;
    __Pyx_GOTREF(__pyx_v_kwargs);
  } else {
    __pyx_v_kwargs = NULL;
  }
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_6_mssql_12connect(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_12connect(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("connect", 0);

  /* "_mssql.pyx":1902
 * ###########################
 * def connect(*args, **kwargs):
 *     return MSSQLConnection(*args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * MssqlDatabaseException = MSSQLDatabaseException
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLConnection), __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1902, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1901
 * ## Compatibility Aliases ##
 * ###########################
 * def connect(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return MSSQLConnection(*args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.connect", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1912
 * ###########################
 * 
 * def test_err_handler(connection, int severity, int dberr, int oserr, dberrstr, oserrstr):             # <<<<<<<<<<<<<<
 *     """
 *     Expose err_handler function and its side effects to facilitate testing.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15test_err_handler(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_14test_err_handler[] = "\n    Expose err_handler function and its side effects to facilitate testing.\n    ";
static PyMethodDef __pyx_mdef_6_mssql_15test_err_handler = {"test_err_handler", (PyCFunction)__pyx_pw_6_mssql_15test_err_handler, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6_mssql_14test_err_handler};
static PyObject *__pyx_pw_6_mssql_15test_err_handler(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_connection = 0;
  int __pyx_v_severity;
  int __pyx_v_dberr;
  int __pyx_v_oserr;
  PyObject *__pyx_v_dberrstr = 0;
  PyObject *__pyx_v_oserrstr = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("test_err_handler (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_connection,&__pyx_n_s_severity,&__pyx_n_s_dberr,&__pyx_n_s_oserr,&__pyx_n_s_dberrstr,&__pyx_n_s_oserrstr,0};
    PyObject* values[6] = {0,0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_connection)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_severity)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("test_err_handler", 1, 6, 6, 1); __PYX_ERR(0, 1912, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_dberr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("test_err_handler", 1, 6, 6, 2); __PYX_ERR(0, 1912, __pyx_L3_error)
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_oserr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("test_err_handler", 1, 6, 6, 3); __PYX_ERR(0, 1912, __pyx_L3_error)
        }
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_dberrstr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("test_err_handler", 1, 6, 6, 4); __PYX_ERR(0, 1912, __pyx_L3_error)
        }
        case  5:
        if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_oserrstr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("test_err_handler", 1, 6, 6, 5); __PYX_ERR(0, 1912, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "test_err_handler") < 0)) __PYX_ERR(0, 1912, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
    }
    __pyx_v_connection = values[0];
    __pyx_v_severity = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_severity == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1912, __pyx_L3_error)
    __pyx_v_dberr = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_dberr == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1912, __pyx_L3_error)
    __pyx_v_oserr = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_oserr == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1912, __pyx_L3_error)
    __pyx_v_dberrstr = values[4];
    __pyx_v_oserrstr = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("test_err_handler", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1912, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.test_err_handler", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_14test_err_handler(__pyx_self, __pyx_v_connection, __pyx_v_severity, __pyx_v_dberr, __pyx_v_oserr, __pyx_v_dberrstr, __pyx_v_oserrstr);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_14test_err_handler(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_connection, int __pyx_v_severity, int __pyx_v_dberr, int __pyx_v_oserr, PyObject *__pyx_v_dberrstr, PyObject *__pyx_v_oserrstr) {
  DBPROCESS *__pyx_v_dbproc;
  char *__pyx_v_dberrstrc;
  char *__pyx_v_oserrstrc;
  PyObject *__pyx_v_dberrstr_byte_string = NULL;
  PyObject *__pyx_v_oserrstr_byte_string = NULL;
  PyObject *__pyx_v_results = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  DBPROCESS *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_RefNannySetupContext("test_err_handler", 0);

  /* "_mssql.pyx":1916
 *     Expose err_handler function and its side effects to facilitate testing.
 *     """
 *     cdef DBPROCESS *dbproc = NULL             # <<<<<<<<<<<<<<
 *     cdef char *dberrstrc = NULL
 *     cdef char *oserrstrc = NULL
 */
  __pyx_v_dbproc = NULL;

  /* "_mssql.pyx":1917
 *     """
 *     cdef DBPROCESS *dbproc = NULL
 *     cdef char *dberrstrc = NULL             # <<<<<<<<<<<<<<
 *     cdef char *oserrstrc = NULL
 *     if dberrstr:
 */
  __pyx_v_dberrstrc = NULL;

  /* "_mssql.pyx":1918
 *     cdef DBPROCESS *dbproc = NULL
 *     cdef char *dberrstrc = NULL
 *     cdef char *oserrstrc = NULL             # <<<<<<<<<<<<<<
 *     if dberrstr:
 *         dberrstr_byte_string = dberrstr.encode('UTF-8')
 */
  __pyx_v_oserrstrc = NULL;

  /* "_mssql.pyx":1919
 *     cdef char *dberrstrc = NULL
 *     cdef char *oserrstrc = NULL
 *     if dberrstr:             # <<<<<<<<<<<<<<
 *         dberrstr_byte_string = dberrstr.encode('UTF-8')
 *         dberrstrc = dberrstr_byte_string
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dberrstr); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1919, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1920
 *     cdef char *oserrstrc = NULL
 *     if dberrstr:
 *         dberrstr_byte_string = dberrstr.encode('UTF-8')             # <<<<<<<<<<<<<<
 *         dberrstrc = dberrstr_byte_string
 *     if oserrstr:
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_dberrstr, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1920, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1920, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_dberrstr_byte_string = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "_mssql.pyx":1921
 *     if dberrstr:
 *         dberrstr_byte_string = dberrstr.encode('UTF-8')
 *         dberrstrc = dberrstr_byte_string             # <<<<<<<<<<<<<<
 *     if oserrstr:
 *         oserrstr_byte_string = oserrstr.encode('UTF-8')
 */
    __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_dberrstr_byte_string); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 1921, __pyx_L1_error)
    __pyx_v_dberrstrc = __pyx_t_4;

    /* "_mssql.pyx":1919
 *     cdef char *dberrstrc = NULL
 *     cdef char *oserrstrc = NULL
 *     if dberrstr:             # <<<<<<<<<<<<<<
 *         dberrstr_byte_string = dberrstr.encode('UTF-8')
 *         dberrstrc = dberrstr_byte_string
 */
  }

  /* "_mssql.pyx":1922
 *         dberrstr_byte_string = dberrstr.encode('UTF-8')
 *         dberrstrc = dberrstr_byte_string
 *     if oserrstr:             # <<<<<<<<<<<<<<
 *         oserrstr_byte_string = oserrstr.encode('UTF-8')
 *         oserrstrc = oserrstr_byte_string
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_oserrstr); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1922, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1923
 *         dberrstrc = dberrstr_byte_string
 *     if oserrstr:
 *         oserrstr_byte_string = oserrstr.encode('UTF-8')             # <<<<<<<<<<<<<<
 *         oserrstrc = oserrstr_byte_string
 *     if connection:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_oserrstr, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1923, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1923, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_oserrstr_byte_string = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "_mssql.pyx":1924
 *     if oserrstr:
 *         oserrstr_byte_string = oserrstr.encode('UTF-8')
 *         oserrstrc = oserrstr_byte_string             # <<<<<<<<<<<<<<
 *     if connection:
 *         dbproc = (<MSSQLConnection>connection).dbproc
 */
    __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_oserrstr_byte_string); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 1924, __pyx_L1_error)
    __pyx_v_oserrstrc = __pyx_t_4;

    /* "_mssql.pyx":1922
 *         dberrstr_byte_string = dberrstr.encode('UTF-8')
 *         dberrstrc = dberrstr_byte_string
 *     if oserrstr:             # <<<<<<<<<<<<<<
 *         oserrstr_byte_string = oserrstr.encode('UTF-8')
 *         oserrstrc = oserrstr_byte_string
 */
  }

  /* "_mssql.pyx":1925
 *         oserrstr_byte_string = oserrstr.encode('UTF-8')
 *         oserrstrc = oserrstr_byte_string
 *     if connection:             # <<<<<<<<<<<<<<
 *         dbproc = (<MSSQLConnection>connection).dbproc
 *     results = (
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_connection); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1925, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "_mssql.pyx":1926
 *         oserrstrc = oserrstr_byte_string
 *     if connection:
 *         dbproc = (<MSSQLConnection>connection).dbproc             # <<<<<<<<<<<<<<
 *     results = (
 *         err_handler(dbproc, severity, dberr, oserr, dberrstrc, oserrstrc),
 */
    __pyx_t_5 = ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_connection)->dbproc;
    __pyx_v_dbproc = __pyx_t_5;

    /* "_mssql.pyx":1925
 *         oserrstr_byte_string = oserrstr.encode('UTF-8')
 *         oserrstrc = oserrstr_byte_string
 *     if connection:             # <<<<<<<<<<<<<<
 *         dbproc = (<MSSQLConnection>connection).dbproc
 *     results = (
 */
  }

  /* "_mssql.pyx":1928
 *         dbproc = (<MSSQLConnection>connection).dbproc
 *     results = (
 *         err_handler(dbproc, severity, dberr, oserr, dberrstrc, oserrstrc),             # <<<<<<<<<<<<<<
 *         get_last_msg_str(connection),
 *         get_last_msg_no(connection),
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_f_6_mssql_err_handler(__pyx_v_dbproc, __pyx_v_severity, __pyx_v_dberr, __pyx_v_oserr, __pyx_v_dberrstrc, __pyx_v_oserrstrc)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1928, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "_mssql.pyx":1929
 *     results = (
 *         err_handler(dbproc, severity, dberr, oserr, dberrstrc, oserrstrc),
 *         get_last_msg_str(connection),             # <<<<<<<<<<<<<<
 *         get_last_msg_no(connection),
 *         get_last_msg_severity(connection),
 */
  if (!(likely(((__pyx_v_connection) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_connection, __pyx_ptype_6_mssql_MSSQLConnection))))) __PYX_ERR(0, 1929, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_f_6_mssql_get_last_msg_str(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_connection))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1929, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "_mssql.pyx":1930
 *         err_handler(dbproc, severity, dberr, oserr, dberrstrc, oserrstrc),
 *         get_last_msg_str(connection),
 *         get_last_msg_no(connection),             # <<<<<<<<<<<<<<
 *         get_last_msg_severity(connection),
 *         get_last_msg_state(connection)
 */
  if (!(likely(((__pyx_v_connection) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_connection, __pyx_ptype_6_mssql_MSSQLConnection))))) __PYX_ERR(0, 1930, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_f_6_mssql_get_last_msg_no(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_connection))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1930, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "_mssql.pyx":1931
 *         get_last_msg_str(connection),
 *         get_last_msg_no(connection),
 *         get_last_msg_severity(connection),             # <<<<<<<<<<<<<<
 *         get_last_msg_state(connection)
 *     )
 */
  if (!(likely(((__pyx_v_connection) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_connection, __pyx_ptype_6_mssql_MSSQLConnection))))) __PYX_ERR(0, 1931, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_f_6_mssql_get_last_msg_severity(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_connection))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1931, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);

  /* "_mssql.pyx":1932
 *         get_last_msg_no(connection),
 *         get_last_msg_severity(connection),
 *         get_last_msg_state(connection)             # <<<<<<<<<<<<<<
 *     )
 *     clr_err(connection)
 */
  if (!(likely(((__pyx_v_connection) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_connection, __pyx_ptype_6_mssql_MSSQLConnection))))) __PYX_ERR(0, 1932, __pyx_L1_error)
  __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_f_6_mssql_get_last_msg_state(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_connection))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1932, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "_mssql.pyx":1928
 *         dbproc = (<MSSQLConnection>connection).dbproc
 *     results = (
 *         err_handler(dbproc, severity, dberr, oserr, dberrstrc, oserrstrc),             # <<<<<<<<<<<<<<
 *         get_last_msg_str(connection),
 *         get_last_msg_no(connection),
 */
  __pyx_t_9 = PyTuple_New(5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1928, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_8);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_v_results = __pyx_t_9;
  __pyx_t_9 = 0;

  /* "_mssql.pyx":1934
 *         get_last_msg_state(connection)
 *     )
 *     clr_err(connection)             # <<<<<<<<<<<<<<
 *     return results
 * 
 */
  if (!(likely(((__pyx_v_connection) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_connection, __pyx_ptype_6_mssql_MSSQLConnection))))) __PYX_ERR(0, 1934, __pyx_L1_error)
  __pyx_f_6_mssql_clr_err(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_connection));

  /* "_mssql.pyx":1935
 *     )
 *     clr_err(connection)
 *     return results             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_results);
  __pyx_r = __pyx_v_results;
  goto __pyx_L0;

  /* "_mssql.pyx":1912
 * ###########################
 * 
 * def test_err_handler(connection, int severity, int dberr, int oserr, dberrstr, oserrstr):             # <<<<<<<<<<<<<<
 *     """
 *     Expose err_handler function and its side effects to facilitate testing.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("_mssql.test_err_handler", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_dberrstr_byte_string);
  __Pyx_XDECREF(__pyx_v_oserrstr_byte_string);
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1941
 * ## Max Connections ##
 * #####################
 * def get_max_connections():             # <<<<<<<<<<<<<<
 *     """
 *     Get maximum simultaneous connections db-lib will open to the server.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_17get_max_connections(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_16get_max_connections[] = "\n    Get maximum simultaneous connections db-lib will open to the server.\n    ";
static PyMethodDef __pyx_mdef_6_mssql_17get_max_connections = {"get_max_connections", (PyCFunction)__pyx_pw_6_mssql_17get_max_connections, METH_NOARGS, __pyx_doc_6_mssql_16get_max_connections};
static PyObject *__pyx_pw_6_mssql_17get_max_connections(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_max_connections (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_16get_max_connections(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_16get_max_connections(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("get_max_connections", 0);

  /* "_mssql.pyx":1945
 *     Get maximum simultaneous connections db-lib will open to the server.
 *     """
 *     return dbgetmaxprocs()             # <<<<<<<<<<<<<<
 * 
 * def set_max_connections(int limit):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(dbgetmaxprocs()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1945, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "_mssql.pyx":1941
 * ## Max Connections ##
 * #####################
 * def get_max_connections():             # <<<<<<<<<<<<<<
 *     """
 *     Get maximum simultaneous connections db-lib will open to the server.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.get_max_connections", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1947
 *     return dbgetmaxprocs()
 * 
 * def set_max_connections(int limit):             # <<<<<<<<<<<<<<
 *     """
 *     Set maximum simultaneous connections db-lib will open to the server.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_19set_max_connections(PyObject *__pyx_self, PyObject *__pyx_arg_limit); /*proto*/
static char __pyx_doc_6_mssql_18set_max_connections[] = "\n    Set maximum simultaneous connections db-lib will open to the server.\n\n    :param limit: the connection limit\n    :type limit: int\n    ";
static PyMethodDef __pyx_mdef_6_mssql_19set_max_connections = {"set_max_connections", (PyCFunction)__pyx_pw_6_mssql_19set_max_connections, METH_O, __pyx_doc_6_mssql_18set_max_connections};
static PyObject *__pyx_pw_6_mssql_19set_max_connections(PyObject *__pyx_self, PyObject *__pyx_arg_limit) {
  int __pyx_v_limit;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_max_connections (wrapper)", 0);
  assert(__pyx_arg_limit); {
    __pyx_v_limit = __Pyx_PyInt_As_int(__pyx_arg_limit); if (unlikely((__pyx_v_limit == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1947, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("_mssql.set_max_connections", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6_mssql_18set_max_connections(__pyx_self, ((int)__pyx_v_limit));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_18set_max_connections(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_limit) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_max_connections", 0);

  /* "_mssql.pyx":1954
 *     :type limit: int
 *     """
 *     dbsetmaxprocs(limit)             # <<<<<<<<<<<<<<
 * 
 * cdef void init_mssql():
 */
  dbsetmaxprocs(__pyx_v_limit);

  /* "_mssql.pyx":1947
 *     return dbgetmaxprocs()
 * 
 * def set_max_connections(int limit):             # <<<<<<<<<<<<<<
 *     """
 *     Set maximum simultaneous connections db-lib will open to the server.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1956
 *     dbsetmaxprocs(limit)
 * 
 * cdef void init_mssql():             # <<<<<<<<<<<<<<
 *     if dbinit() == FAIL:
 *         raise MSSQLDriverException("dbinit() failed")
 */

static void __pyx_f_6_mssql_init_mssql(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("init_mssql", 0);

  /* "_mssql.pyx":1957
 * 
 * cdef void init_mssql():
 *     if dbinit() == FAIL:             # <<<<<<<<<<<<<<
 *         raise MSSQLDriverException("dbinit() failed")
 * 
 */
  __pyx_t_1 = ((dbinit() == FAIL) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1958
 * cdef void init_mssql():
 *     if dbinit() == FAIL:
 *         raise MSSQLDriverException("dbinit() failed")             # <<<<<<<<<<<<<<
 * 
 *     dberrhandle(err_handler)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException), __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1958, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1958, __pyx_L1_error)

    /* "_mssql.pyx":1957
 * 
 * cdef void init_mssql():
 *     if dbinit() == FAIL:             # <<<<<<<<<<<<<<
 *         raise MSSQLDriverException("dbinit() failed")
 * 
 */
  }

  /* "_mssql.pyx":1960
 *         raise MSSQLDriverException("dbinit() failed")
 * 
 *     dberrhandle(err_handler)             # <<<<<<<<<<<<<<
 *     dbmsghandle(msg_handler)
 * 
 */
  dberrhandle(__pyx_f_6_mssql_err_handler);

  /* "_mssql.pyx":1961
 * 
 *     dberrhandle(err_handler)
 *     dbmsghandle(msg_handler)             # <<<<<<<<<<<<<<
 * 
 * init_mssql()
 */
  dbmsghandle(__pyx_f_6_mssql_msg_handler);

  /* "_mssql.pyx":1956
 *     dbsetmaxprocs(limit)
 * 
 * cdef void init_mssql():             # <<<<<<<<<<<<<<
 *     if dbinit() == FAIL:
 *         raise MSSQLDriverException("dbinit() failed")
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.init_mssql", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}
static struct __pyx_vtabstruct_6_mssql_MSSQLConnection __pyx_vtable_6_mssql_MSSQLConnection;

static PyObject *__pyx_tp_new_6_mssql_MSSQLConnection(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_6_mssql_MSSQLConnection *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_6_mssql_MSSQLConnection *)o);
  p->__pyx_vtab = __pyx_vtabptr_6_mssql_MSSQLConnection;
  p->column_names = ((PyObject*)Py_None); Py_INCREF(Py_None);
  p->column_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  p->msghandler = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_6_mssql_15MSSQLConnection_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_6_mssql_MSSQLConnection(PyObject *o) {
  struct __pyx_obj_6_mssql_MSSQLConnection *p = (struct __pyx_obj_6_mssql_MSSQLConnection *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_6_mssql_15MSSQLConnection_5__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->column_names);
  Py_CLEAR(p->column_types);
  Py_CLEAR(p->msghandler);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6_mssql_MSSQLConnection(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6_mssql_MSSQLConnection *p = (struct __pyx_obj_6_mssql_MSSQLConnection *)o;
  if (p->column_names) {
    e = (*v)(p->column_names, a); if (e) return e;
  }
  if (p->column_types) {
    e = (*v)(p->column_types, a); if (e) return e;
  }
  if (p->msghandler) {
    e = (*v)(p->msghandler, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6_mssql_MSSQLConnection(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_6_mssql_MSSQLConnection *p = (struct __pyx_obj_6_mssql_MSSQLConnection *)o;
  tmp = ((PyObject*)p->column_names);
  p->column_names = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->column_types);
  p->column_types = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->msghandler);
  p->msghandler = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6_mssql_15MSSQLConnection_charset(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_15MSSQLConnection_7charset_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_15MSSQLConnection_connected(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_15MSSQLConnection_9connected_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_15MSSQLConnection_identity(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_15MSSQLConnection_8identity_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_15MSSQLConnection_query_timeout(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_15MSSQLConnection_13query_timeout_1__get__(o);
}

static int __pyx_setprop_6_mssql_15MSSQLConnection_query_timeout(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6_mssql_15MSSQLConnection_13query_timeout_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_6_mssql_15MSSQLConnection_rows_affected(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_15MSSQLConnection_13rows_affected_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_15MSSQLConnection_tds_version(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_15MSSQLConnection_11tds_version_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_15MSSQLConnection_debug_queries(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_15MSSQLConnection_13debug_queries_1__get__(o);
}

static int __pyx_setprop_6_mssql_15MSSQLConnection_debug_queries(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6_mssql_15MSSQLConnection_13debug_queries_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_6_mssql_MSSQLConnection[] = {
  {"__enter__", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_7__enter__, METH_NOARGS, 0},
  {"__exit__", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_9__exit__, METH_VARARGS|METH_KEYWORDS, 0},
  {"set_msghandler", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_13set_msghandler, METH_O, __pyx_doc_6_mssql_15MSSQLConnection_12set_msghandler},
  {"cancel", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_15cancel, METH_NOARGS, __pyx_doc_6_mssql_15MSSQLConnection_14cancel},
  {"close", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_17close, METH_NOARGS, __pyx_doc_6_mssql_15MSSQLConnection_16close},
  {"mark_disconnected", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_19mark_disconnected, METH_NOARGS, 0},
  {"execute_non_query", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_21execute_non_query, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6_mssql_15MSSQLConnection_20execute_non_query},
  {"execute_query", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_23execute_query, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6_mssql_15MSSQLConnection_22execute_query},
  {"execute_row", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_25execute_row, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6_mssql_15MSSQLConnection_24execute_row},
  {"execute_scalar", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_27execute_scalar, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6_mssql_15MSSQLConnection_26execute_scalar},
  {"get_header", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_29get_header, METH_NOARGS, __pyx_doc_6_mssql_15MSSQLConnection_28get_header},
  {"get_iterator", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_31get_iterator, METH_O, __pyx_doc_6_mssql_15MSSQLConnection_30get_iterator},
  {"init_procedure", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_33init_procedure, METH_O, __pyx_doc_6_mssql_15MSSQLConnection_32init_procedure},
  {"nextresult", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_35nextresult, METH_NOARGS, __pyx_doc_6_mssql_15MSSQLConnection_34nextresult},
  {"select_db", (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_37select_db, METH_O, __pyx_doc_6_mssql_15MSSQLConnection_36select_db},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6_mssql_MSSQLConnection[] = {
  {(char *)"charset", __pyx_getprop_6_mssql_15MSSQLConnection_charset, 0, (char *)"\n        The current encoding in use.\n        ", 0},
  {(char *)"connected", __pyx_getprop_6_mssql_15MSSQLConnection_connected, 0, (char *)"\n        True if the connection to a database is open.\n        ", 0},
  {(char *)"identity", __pyx_getprop_6_mssql_15MSSQLConnection_identity, 0, (char *)"\n        Returns identity value of the last inserted row. If the previous\n        operation did not involve inserting a row into a table with an\n        identity column, None is returned.\n\n        ** Usage **\n        >>> conn.execute_non_query(\"INSERT INTO table (name) VALUES ('John')\")\n        >>> print 'Last inserted row has ID = %s' % conn.identity\n        Last inserted row has ID = 178\n        ", 0},
  {(char *)"query_timeout", __pyx_getprop_6_mssql_15MSSQLConnection_query_timeout, __pyx_setprop_6_mssql_15MSSQLConnection_query_timeout, (char *)"\n        A\n        ", 0},
  {(char *)"rows_affected", __pyx_getprop_6_mssql_15MSSQLConnection_rows_affected, 0, (char *)"\n        Number of rows affected by last query. For SELECT statements this\n        value is only meaningful after reading all rows.\n        ", 0},
  {(char *)"tds_version", __pyx_getprop_6_mssql_15MSSQLConnection_tds_version, 0, (char *)"\n        Returns what TDS version the connection is using.\n        ", 0},
  {(char *)"debug_queries", __pyx_getprop_6_mssql_15MSSQLConnection_debug_queries, __pyx_setprop_6_mssql_15MSSQLConnection_debug_queries, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLConnection = {
  PyVarObject_HEAD_INIT(0, 0)
  "_mssql.MSSQLConnection", /*tp_name*/
  sizeof(struct __pyx_obj_6_mssql_MSSQLConnection), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6_mssql_MSSQLConnection, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6_mssql_MSSQLConnection, /*tp_traverse*/
  __pyx_tp_clear_6_mssql_MSSQLConnection, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_6_mssql_15MSSQLConnection_11__iter__, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6_mssql_MSSQLConnection, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6_mssql_MSSQLConnection, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_6_mssql_15MSSQLConnection_3__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6_mssql_MSSQLConnection, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_6_mssql_MSSQLRowIterator(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_6_mssql_MSSQLRowIterator *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_6_mssql_MSSQLRowIterator *)o);
  p->conn = ((struct __pyx_obj_6_mssql_MSSQLConnection *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6_mssql_MSSQLRowIterator(PyObject *o) {
  struct __pyx_obj_6_mssql_MSSQLRowIterator *p = (struct __pyx_obj_6_mssql_MSSQLRowIterator *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->conn);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6_mssql_MSSQLRowIterator(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6_mssql_MSSQLRowIterator *p = (struct __pyx_obj_6_mssql_MSSQLRowIterator *)o;
  if (p->conn) {
    e = (*v)(((PyObject*)p->conn), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6_mssql_MSSQLRowIterator(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_6_mssql_MSSQLRowIterator *p = (struct __pyx_obj_6_mssql_MSSQLRowIterator *)o;
  tmp = ((PyObject*)p->conn);
  p->conn = ((struct __pyx_obj_6_mssql_MSSQLConnection *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_6_mssql_MSSQLRowIterator[] = {
  {"__next__", (PyCFunction)__pyx_pw_6_mssql_16MSSQLRowIterator_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLRowIterator = {
  PyVarObject_HEAD_INIT(0, 0)
  "_mssql.MSSQLRowIterator", /*tp_name*/
  sizeof(struct __pyx_obj_6_mssql_MSSQLRowIterator), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6_mssql_MSSQLRowIterator, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6_mssql_MSSQLRowIterator, /*tp_traverse*/
  __pyx_tp_clear_6_mssql_MSSQLRowIterator, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_6_mssql_16MSSQLRowIterator_3__iter__, /*tp_iter*/
  __pyx_pw_6_mssql_16MSSQLRowIterator_5__next__, /*tp_iternext*/
  __pyx_methods_6_mssql_MSSQLRowIterator, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_6_mssql_16MSSQLRowIterator_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6_mssql_MSSQLRowIterator, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_6_mssql_MSSQLStoredProcedure(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_6_mssql_MSSQLStoredProcedure *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)o);
  p->conn = ((struct __pyx_obj_6_mssql_MSSQLConnection *)Py_None); Py_INCREF(Py_None);
  p->had_positional = ((PyBoolObject *)Py_None); Py_INCREF(Py_None);
  p->output_indexes = ((PyObject*)Py_None); Py_INCREF(Py_None);
  p->params = ((PyObject*)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6_mssql_MSSQLStoredProcedure(PyObject *o) {
  struct __pyx_obj_6_mssql_MSSQLStoredProcedure *p = (struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_6_mssql_20MSSQLStoredProcedure_3__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->conn);
  Py_CLEAR(p->had_positional);
  Py_CLEAR(p->output_indexes);
  Py_CLEAR(p->params);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6_mssql_MSSQLStoredProcedure(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6_mssql_MSSQLStoredProcedure *p = (struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)o;
  if (p->conn) {
    e = (*v)(((PyObject*)p->conn), a); if (e) return e;
  }
  if (p->had_positional) {
    e = (*v)(((PyObject*)p->had_positional), a); if (e) return e;
  }
  if (p->output_indexes) {
    e = (*v)(p->output_indexes, a); if (e) return e;
  }
  if (p->params) {
    e = (*v)(p->params, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6_mssql_MSSQLStoredProcedure(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_6_mssql_MSSQLStoredProcedure *p = (struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)o;
  tmp = ((PyObject*)p->conn);
  p->conn = ((struct __pyx_obj_6_mssql_MSSQLConnection *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->had_positional);
  p->had_positional = ((PyBoolObject *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->output_indexes);
  p->output_indexes = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->params);
  p->params = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6_mssql_20MSSQLStoredProcedure_connection(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_20MSSQLStoredProcedure_10connection_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_20MSSQLStoredProcedure_name(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_20MSSQLStoredProcedure_4name_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_20MSSQLStoredProcedure_parameters(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_20MSSQLStoredProcedure_10parameters_1__get__(o);
}

static PyMethodDef __pyx_methods_6_mssql_MSSQLStoredProcedure[] = {
  {"bind", (PyCFunction)__pyx_pw_6_mssql_20MSSQLStoredProcedure_5bind, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6_mssql_20MSSQLStoredProcedure_4bind},
  {"execute", (PyCFunction)__pyx_pw_6_mssql_20MSSQLStoredProcedure_7execute, METH_NOARGS, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6_mssql_MSSQLStoredProcedure[] = {
  {(char *)"connection", __pyx_getprop_6_mssql_20MSSQLStoredProcedure_connection, 0, (char *)"The underlying MSSQLConnection object.", 0},
  {(char *)"name", __pyx_getprop_6_mssql_20MSSQLStoredProcedure_name, 0, (char *)"The name of the procedure that this object represents.", 0},
  {(char *)"parameters", __pyx_getprop_6_mssql_20MSSQLStoredProcedure_parameters, 0, (char *)"The parameters that have been bound to this procedure.", 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLStoredProcedure = {
  PyVarObject_HEAD_INIT(0, 0)
  "_mssql.MSSQLStoredProcedure", /*tp_name*/
  sizeof(struct __pyx_obj_6_mssql_MSSQLStoredProcedure), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6_mssql_MSSQLStoredProcedure, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6_mssql_MSSQLStoredProcedure, /*tp_traverse*/
  __pyx_tp_clear_6_mssql_MSSQLStoredProcedure, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6_mssql_MSSQLStoredProcedure, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6_mssql_MSSQLStoredProcedure, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_6_mssql_20MSSQLStoredProcedure_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6_mssql_MSSQLStoredProcedure, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_6_mssql_MSSQLException(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = __pyx_ptype_6_mssql_Exception->tp_new(t, a, k);
  if (unlikely(!o)) return 0;
  return o;
}

static void __pyx_tp_dealloc_6_mssql_MSSQLException(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  if (likely(__pyx_ptype_6_mssql_Exception)) __pyx_ptype_6_mssql_Exception->tp_dealloc(o); else __Pyx_call_next_tp_dealloc(o, __pyx_tp_dealloc_6_mssql_MSSQLException);
}

static PyTypeObject __pyx_type_6_mssql_MSSQLException = {
  PyVarObject_HEAD_INIT(0, 0)
  "_mssql.MSSQLException", /*tp_name*/
  sizeof(struct __pyx_obj_6_mssql_MSSQLException), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6_mssql_MSSQLException, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "\n    Base exception class for the MSSQL driver.\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6_mssql_MSSQLException, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_6_mssql_MSSQLDriverException(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = __pyx_tp_new_6_mssql_MSSQLException(t, a, k);
  if (unlikely(!o)) return 0;
  return o;
}

static PyTypeObject __pyx_type_6_mssql_MSSQLDriverException = {
  PyVarObject_HEAD_INIT(0, 0)
  "_mssql.MSSQLDriverException", /*tp_name*/
  sizeof(struct __pyx_obj_6_mssql_MSSQLDriverException), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6_mssql_MSSQLException, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "\n    Inherits from the base class and raised when an error is caused within\n    the driver itself.\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6_mssql_MSSQLDriverException, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_6_mssql_MSSQLDatabaseException(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = __pyx_tp_new_6_mssql_MSSQLException(t, a, k);
  if (unlikely(!o)) return 0;
  return o;
}

static PyObject *__pyx_getprop_6_mssql_22MSSQLDatabaseException_message(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_22MSSQLDatabaseException_7message_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_22MSSQLDatabaseException_number(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_22MSSQLDatabaseException_6number_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_22MSSQLDatabaseException_severity(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_22MSSQLDatabaseException_8severity_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_22MSSQLDatabaseException_state(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_22MSSQLDatabaseException_5state_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_22MSSQLDatabaseException_line(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_22MSSQLDatabaseException_4line_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_22MSSQLDatabaseException_text(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_22MSSQLDatabaseException_4text_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_22MSSQLDatabaseException_srvname(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_22MSSQLDatabaseException_7srvname_1__get__(o);
}

static PyObject *__pyx_getprop_6_mssql_22MSSQLDatabaseException_procname(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6_mssql_22MSSQLDatabaseException_8procname_1__get__(o);
}

static struct PyGetSetDef __pyx_getsets_6_mssql_MSSQLDatabaseException[] = {
  {(char *)"message", __pyx_getprop_6_mssql_22MSSQLDatabaseException_message, 0, (char *)0, 0},
  {(char *)"number", __pyx_getprop_6_mssql_22MSSQLDatabaseException_number, 0, (char *)0, 0},
  {(char *)"severity", __pyx_getprop_6_mssql_22MSSQLDatabaseException_severity, 0, (char *)0, 0},
  {(char *)"state", __pyx_getprop_6_mssql_22MSSQLDatabaseException_state, 0, (char *)0, 0},
  {(char *)"line", __pyx_getprop_6_mssql_22MSSQLDatabaseException_line, 0, (char *)0, 0},
  {(char *)"text", __pyx_getprop_6_mssql_22MSSQLDatabaseException_text, 0, (char *)0, 0},
  {(char *)"srvname", __pyx_getprop_6_mssql_22MSSQLDatabaseException_srvname, 0, (char *)0, 0},
  {(char *)"procname", __pyx_getprop_6_mssql_22MSSQLDatabaseException_procname, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLDatabaseException = {
  PyVarObject_HEAD_INIT(0, 0)
  "_mssql.MSSQLDatabaseException", /*tp_name*/
  sizeof(struct __pyx_obj_6_mssql_MSSQLDatabaseException), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6_mssql_MSSQLException, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "\n    Raised when an error occurs within the database.\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6_mssql_MSSQLDatabaseException, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6_mssql_MSSQLDatabaseException, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "_mssql",
    __pyx_k_This_is_an_effort_to_convert_th, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_0, __pyx_k_0, sizeof(__pyx_k_0), 0, 0, 1, 0},
  {&__pyx_kp_s_03d, __pyx_k_03d, sizeof(__pyx_k_03d), 0, 0, 1, 0},
  {&__pyx_kp_b_0x, __pyx_k_0x, sizeof(__pyx_k_0x), 0, 0, 0, 0},
  {&__pyx_kp_s_0x, __pyx_k_0x, sizeof(__pyx_k_0x), 0, 0, 1, 0},
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_1433, __pyx_k_1433, sizeof(__pyx_k_1433), 0, 0, 1, 0},
  {&__pyx_kp_u_4_2, __pyx_k_4_2, sizeof(__pyx_k_4_2), 0, 1, 0, 0},
  {&__pyx_kp_u_7_0, __pyx_k_7_0, sizeof(__pyx_k_7_0), 0, 1, 0, 0},
  {&__pyx_kp_s_7_1, __pyx_k_7_1, sizeof(__pyx_k_7_1), 0, 0, 1, 0},
  {&__pyx_kp_u_7_1, __pyx_k_7_1, sizeof(__pyx_k_7_1), 0, 1, 0, 0},
  {&__pyx_kp_u_7_2, __pyx_k_7_2, sizeof(__pyx_k_7_2), 0, 1, 0, 0},
  {&__pyx_kp_u_8_0, __pyx_k_8_0, sizeof(__pyx_k_8_0), 0, 1, 0, 0},
  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  {&__pyx_n_s_BINARY, __pyx_k_BINARY, sizeof(__pyx_k_BINARY), 0, 0, 1, 1},
  {&__pyx_kp_s_Cannot_bind_named_parameter_afte, __pyx_k_Cannot_bind_named_parameter_afte, sizeof(__pyx_k_Cannot_bind_named_parameter_afte), 0, 0, 1, 0},
  {&__pyx_kp_s_Connection_to_the_database_faile, __pyx_k_Connection_to_the_database_faile, sizeof(__pyx_k_Connection_to_the_database_faile), 0, 0, 1, 0},
  {&__pyx_kp_s_Could_not_set_connection_propert, __pyx_k_Could_not_set_connection_propert, sizeof(__pyx_k_Could_not_set_connection_propert), 0, 0, 1, 0},
  {&__pyx_n_s_DATETIME, __pyx_k_DATETIME, sizeof(__pyx_k_DATETIME), 0, 0, 1, 1},
  {&__pyx_n_s_DECIMAL, __pyx_k_DECIMAL, sizeof(__pyx_k_DECIMAL), 0, 0, 1, 1},
  {&__pyx_n_s_Decimal, __pyx_k_Decimal, sizeof(__pyx_k_Decimal), 0, 0, 1, 1},
  {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1},
  {&__pyx_n_s_Iterable, __pyx_k_Iterable, sizeof(__pyx_k_Iterable), 0, 0, 1, 1},
  {&__pyx_n_s_MssqlConnection, __pyx_k_MssqlConnection, sizeof(__pyx_k_MssqlConnection), 0, 0, 1, 1},
  {&__pyx_n_s_MssqlDatabaseException, __pyx_k_MssqlDatabaseException, sizeof(__pyx_k_MssqlDatabaseException), 0, 0, 1, 1},
  {&__pyx_n_s_MssqlDriverException, __pyx_k_MssqlDriverException, sizeof(__pyx_k_MssqlDriverException), 0, 0, 1, 1},
  {&__pyx_kp_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 0},
  {&__pyx_n_b_NULL, __pyx_k_NULL, sizeof(__pyx_k_NULL), 0, 0, 0, 1},
  {&__pyx_n_s_NUMBER, __pyx_k_NUMBER, sizeof(__pyx_k_NUMBER), 0, 0, 1, 1},
  {&__pyx_kp_s_Not_connected_to_any_MS_SQL_serv, __pyx_k_Not_connected_to_any_MS_SQL_serv, sizeof(__pyx_k_Not_connected_to_any_MS_SQL_serv), 0, 0, 1, 0},
  {&__pyx_kp_s_Out_of_memory, __pyx_k_Out_of_memory, sizeof(__pyx_k_Out_of_memory), 0, 0, 1, 0},
  {&__pyx_n_s_ROW_FORMAT_DICT, __pyx_k_ROW_FORMAT_DICT, sizeof(__pyx_k_ROW_FORMAT_DICT), 0, 0, 1, 1},
  {&__pyx_n_s_ROW_FORMAT_TUPLE, __pyx_k_ROW_FORMAT_TUPLE, sizeof(__pyx_k_ROW_FORMAT_TUPLE), 0, 0, 1, 1},
  {&__pyx_kp_s_SELECT_SCOPE_IDENTITY, __pyx_k_SELECT_SCOPE_IDENTITY, sizeof(__pyx_k_SELECT_SCOPE_IDENTITY), 0, 0, 1, 0},
  {&__pyx_kp_s_SET_ARITHABORT_ON_SET_CONCAT_NUL, __pyx_k_SET_ARITHABORT_ON_SET_CONCAT_NUL, sizeof(__pyx_k_SET_ARITHABORT_ON_SET_CONCAT_NUL), 0, 0, 1, 0},
  {&__pyx_n_s_SQLBINARY, __pyx_k_SQLBINARY, sizeof(__pyx_k_SQLBINARY), 0, 0, 1, 1},
  {&__pyx_n_s_SQLBIT, __pyx_k_SQLBIT, sizeof(__pyx_k_SQLBIT), 0, 0, 1, 1},
  {&__pyx_n_s_SQLBITN, __pyx_k_SQLBITN, sizeof(__pyx_k_SQLBITN), 0, 0, 1, 1},
  {&__pyx_n_s_SQLCHAR, __pyx_k_SQLCHAR, sizeof(__pyx_k_SQLCHAR), 0, 0, 1, 1},
  {&__pyx_n_s_SQLDATETIM4, __pyx_k_SQLDATETIM4, sizeof(__pyx_k_SQLDATETIM4), 0, 0, 1, 1},
  {&__pyx_n_s_SQLDATETIME, __pyx_k_SQLDATETIME, sizeof(__pyx_k_SQLDATETIME), 0, 0, 1, 1},
  {&__pyx_n_s_SQLDATETIMN, __pyx_k_SQLDATETIMN, sizeof(__pyx_k_SQLDATETIMN), 0, 0, 1, 1},
  {&__pyx_n_s_SQLDECIMAL, __pyx_k_SQLDECIMAL, sizeof(__pyx_k_SQLDECIMAL), 0, 0, 1, 1},
  {&__pyx_n_s_SQLFLT4, __pyx_k_SQLFLT4, sizeof(__pyx_k_SQLFLT4), 0, 0, 1, 1},
  {&__pyx_n_s_SQLFLT8, __pyx_k_SQLFLT8, sizeof(__pyx_k_SQLFLT8), 0, 0, 1, 1},
  {&__pyx_n_s_SQLFLTN, __pyx_k_SQLFLTN, sizeof(__pyx_k_SQLFLTN), 0, 0, 1, 1},
  {&__pyx_n_s_SQLIMAGE, __pyx_k_SQLIMAGE, sizeof(__pyx_k_SQLIMAGE), 0, 0, 1, 1},
  {&__pyx_n_s_SQLINT1, __pyx_k_SQLINT1, sizeof(__pyx_k_SQLINT1), 0, 0, 1, 1},
  {&__pyx_n_s_SQLINT2, __pyx_k_SQLINT2, sizeof(__pyx_k_SQLINT2), 0, 0, 1, 1},
  {&__pyx_n_s_SQLINT4, __pyx_k_SQLINT4, sizeof(__pyx_k_SQLINT4), 0, 0, 1, 1},
  {&__pyx_n_s_SQLINT8, __pyx_k_SQLINT8, sizeof(__pyx_k_SQLINT8), 0, 0, 1, 1},
  {&__pyx_n_s_SQLINTN, __pyx_k_SQLINTN, sizeof(__pyx_k_SQLINTN), 0, 0, 1, 1},
  {&__pyx_n_s_SQLMONEY, __pyx_k_SQLMONEY, sizeof(__pyx_k_SQLMONEY), 0, 0, 1, 1},
  {&__pyx_n_s_SQLMONEY4, __pyx_k_SQLMONEY4, sizeof(__pyx_k_SQLMONEY4), 0, 0, 1, 1},
  {&__pyx_n_s_SQLMONEYN, __pyx_k_SQLMONEYN, sizeof(__pyx_k_SQLMONEYN), 0, 0, 1, 1},
  {&__pyx_n_s_SQLNUMERIC, __pyx_k_SQLNUMERIC, sizeof(__pyx_k_SQLNUMERIC), 0, 0, 1, 1},
  {&__pyx_n_s_SQLREAL, __pyx_k_SQLREAL, sizeof(__pyx_k_SQLREAL), 0, 0, 1, 1},
  {&__pyx_n_s_SQLTEXT, __pyx_k_SQLTEXT, sizeof(__pyx_k_SQLTEXT), 0, 0, 1, 1},
  {&__pyx_n_s_SQLUUID, __pyx_k_SQLUUID, sizeof(__pyx_k_SQLUUID), 0, 0, 1, 1},
  {&__pyx_n_s_SQLVARBINARY, __pyx_k_SQLVARBINARY, sizeof(__pyx_k_SQLVARBINARY), 0, 0, 1, 1},
  {&__pyx_n_s_SQLVARCHAR, __pyx_k_SQLVARCHAR, sizeof(__pyx_k_SQLVARCHAR), 0, 0, 1, 1},
  {&__pyx_kp_s_SQL_Server_message_d_severity_d, __pyx_k_SQL_Server_message_d_severity_d, sizeof(__pyx_k_SQL_Server_message_d_severity_d), 0, 0, 1, 0},
  {&__pyx_kp_s_SQL_Server_message_d_severity_d_2, __pyx_k_SQL_Server_message_d_severity_d_2, sizeof(__pyx_k_SQL_Server_message_d_severity_d_2), 0, 0, 1, 0},
  {&__pyx_n_s_STRING, __pyx_k_STRING, sizeof(__pyx_k_STRING), 0, 0, 1, 1},
  {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1},
  {&__pyx_kp_s_Stored_Procedures_aren_t_support, __pyx_k_Stored_Procedures_aren_t_support, sizeof(__pyx_k_Stored_Procedures_aren_t_support), 0, 0, 1, 0},
  {&__pyx_kp_s_The_query_timeout_attribute_must, __pyx_k_The_query_timeout_attribute_must, sizeof(__pyx_k_The_query_timeout_attribute_must), 0, 0, 1, 0},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_kp_s_UTF_8, __pyx_k_UTF_8, sizeof(__pyx_k_UTF_8), 0, 0, 1, 0},
  {&__pyx_n_s_UUID, __pyx_k_UUID, sizeof(__pyx_k_UUID), 0, 0, 1, 1},
  {&__pyx_kp_s_Unable_to_convert_value, __pyx_k_Unable_to_convert_value, sizeof(__pyx_k_Unable_to_convert_value), 0, 0, 1, 0},
  {&__pyx_n_s_UnicodeDecodeError, __pyx_k_UnicodeDecodeError, sizeof(__pyx_k_UnicodeDecodeError), 0, 0, 1, 1},
  {&__pyx_kp_b_Unknown_error, __pyx_k_Unknown_error, sizeof(__pyx_k_Unknown_error), 0, 0, 0, 0},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s_Y_m_d_H_M_S, __pyx_k_Y_m_d_H_M_S, sizeof(__pyx_k_Y_m_d_H_M_S), 0, 0, 1, 0},
  {&__pyx_kp_s__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 0, 1, 0},
  {&__pyx_kp_s__15, __pyx_k__15, sizeof(__pyx_k__15), 0, 0, 1, 0},
  {&__pyx_kp_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 0},
  {&__pyx_kp_s__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 1, 0},
  {&__pyx_kp_b__31, __pyx_k__31, sizeof(__pyx_k__31), 0, 0, 0, 0},
  {&__pyx_kp_s__31, __pyx_k__31, sizeof(__pyx_k__31), 0, 0, 1, 0},
  {&__pyx_kp_b__32, __pyx_k__32, sizeof(__pyx_k__32), 0, 0, 0, 0},
  {&__pyx_kp_s__32, __pyx_k__32, sizeof(__pyx_k__32), 0, 0, 1, 0},
  {&__pyx_kp_b__34, __pyx_k__34, sizeof(__pyx_k__34), 0, 0, 0, 0},
  {&__pyx_kp_b__40, __pyx_k__40, sizeof(__pyx_k__40), 0, 0, 0, 0},
  {&__pyx_kp_b__41, __pyx_k__41, sizeof(__pyx_k__41), 0, 0, 0, 0},
  {&__pyx_kp_b__42, __pyx_k__42, sizeof(__pyx_k__42), 0, 0, 0, 0},
  {&__pyx_kp_s__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 1, 0},
  {&__pyx_n_s_a_callable, __pyx_k_a_callable, sizeof(__pyx_k_a_callable), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_appname, __pyx_k_appname, sizeof(__pyx_k_appname), 0, 0, 1, 1},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_n_s_as_tuple, __pyx_k_as_tuple, sizeof(__pyx_k_as_tuple), 0, 0, 1, 1},
  {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1},
  {&__pyx_n_s_binascii, __pyx_k_binascii, sizeof(__pyx_k_binascii), 0, 0, 1, 1},
  {&__pyx_n_s_bytes_le, __pyx_k_bytes_le, sizeof(__pyx_k_bytes_le), 0, 0, 1, 1},
  {&__pyx_n_s_cancel, __pyx_k_cancel, sizeof(__pyx_k_cancel), 0, 0, 1, 1},
  {&__pyx_n_s_charset, __pyx_k_charset, sizeof(__pyx_k_charset), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
  {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1},
  {&__pyx_n_s_conn_properties, __pyx_k_conn_properties, sizeof(__pyx_k_conn_properties), 0, 0, 1, 1},
  {&__pyx_n_s_connect, __pyx_k_connect, sizeof(__pyx_k_connect), 0, 0, 1, 1},
  {&__pyx_n_s_connected, __pyx_k_connected, sizeof(__pyx_k_connected), 0, 0, 1, 1},
  {&__pyx_n_s_connection, __pyx_k_connection, sizeof(__pyx_k_connection), 0, 0, 1, 1},
  {&__pyx_kp_s_d_04d_02d_02d, __pyx_k_d_04d_02d_02d, sizeof(__pyx_k_d_04d_02d_02d), 0, 0, 1, 0},
  {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1},
  {&__pyx_n_s_database, __pyx_k_database, sizeof(__pyx_k_database), 0, 0, 1, 1},
  {&__pyx_n_s_date, __pyx_k_date, sizeof(__pyx_k_date), 0, 0, 1, 1},
  {&__pyx_n_s_datetime, __pyx_k_datetime, sizeof(__pyx_k_datetime), 0, 0, 1, 1},
  {&__pyx_n_s_day, __pyx_k_day, sizeof(__pyx_k_day), 0, 0, 1, 1},
  {&__pyx_n_s_dberr, __pyx_k_dberr, sizeof(__pyx_k_dberr), 0, 0, 1, 1},
  {&__pyx_n_s_dberrstr, __pyx_k_dberrstr, sizeof(__pyx_k_dberrstr), 0, 0, 1, 1},
  {&__pyx_n_s_dberrstr_byte_string, __pyx_k_dberrstr_byte_string, sizeof(__pyx_k_dberrstr_byte_string), 0, 0, 1, 1},
  {&__pyx_n_s_dberrstrc, __pyx_k_dberrstrc, sizeof(__pyx_k_dberrstrc), 0, 0, 1, 1},
  {&__pyx_kp_s_dbinit_failed, __pyx_k_dbinit_failed, sizeof(__pyx_k_dbinit_failed), 0, 0, 1, 0},
  {&__pyx_kp_s_dblogin_failed, __pyx_k_dblogin_failed, sizeof(__pyx_k_dblogin_failed), 0, 0, 1, 0},
  {&__pyx_n_s_dbproc, __pyx_k_dbproc, sizeof(__pyx_k_dbproc), 0, 0, 1, 1},
  {&__pyx_n_s_dbtype, __pyx_k_dbtype, sizeof(__pyx_k_dbtype), 0, 0, 1, 1},
  {&__pyx_n_s_decimal, __pyx_k_decimal, sizeof(__pyx_k_decimal), 0, 0, 1, 1},
  {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1},
  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_s_exc_type, __pyx_k_exc_type, sizeof(__pyx_k_exc_type), 0, 0, 1, 1},
  {&__pyx_n_s_exc_value, __pyx_k_exc_value, sizeof(__pyx_k_exc_value), 0, 0, 1, 1},
  {&__pyx_n_s_execute_non_query, __pyx_k_execute_non_query, sizeof(__pyx_k_execute_non_query), 0, 0, 1, 1},
  {&__pyx_n_s_execute_query, __pyx_k_execute_query, sizeof(__pyx_k_execute_query), 0, 0, 1, 1},
  {&__pyx_n_s_execute_row, __pyx_k_execute_row, sizeof(__pyx_k_execute_row), 0, 0, 1, 1},
  {&__pyx_n_s_execute_scalar, __pyx_k_execute_scalar, sizeof(__pyx_k_execute_scalar), 0, 0, 1, 1},
  {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1},
  {&__pyx_kp_s_expected_a_simple_type_a_tuple_o, __pyx_k_expected_a_simple_type_a_tuple_o, sizeof(__pyx_k_expected_a_simple_type_a_tuple_o), 0, 0, 1, 0},
  {&__pyx_kp_s_expected_a_simple_type_a_tuple_o_2, __pyx_k_expected_a_simple_type_a_tuple_o_2, sizeof(__pyx_k_expected_a_simple_type_a_tuple_o_2), 0, 0, 1, 0},
  {&__pyx_n_s_exponent, __pyx_k_exponent, sizeof(__pyx_k_exponent), 0, 0, 1, 1},
  {&__pyx_n_s_finditer, __pyx_k_finditer, sizeof(__pyx_k_finditer), 0, 0, 1, 1},
  {&__pyx_kp_s_found_an_unsupported_type, __pyx_k_found_an_unsupported_type, sizeof(__pyx_k_found_an_unsupported_type), 0, 0, 1, 0},
  {&__pyx_n_s_full_version, __pyx_k_full_version, sizeof(__pyx_k_full_version), 0, 0, 1, 1},
  {&__pyx_n_s_get_max_connections, __pyx_k_get_max_connections, sizeof(__pyx_k_get_max_connections), 0, 0, 1, 1},
  {&__pyx_n_s_gethostname, __pyx_k_gethostname, sizeof(__pyx_k_gethostname), 0, 0, 1, 1},
  {&__pyx_n_s_group, __pyx_k_group, sizeof(__pyx_k_group), 0, 0, 1, 1},
  {&__pyx_n_s_hex, __pyx_k_hex, sizeof(__pyx_k_hex), 0, 0, 1, 1},
  {&__pyx_n_s_hexlify, __pyx_k_hexlify, sizeof(__pyx_k_hexlify), 0, 0, 1, 1},
  {&__pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_k_home_travis_build_pymssql_pymss, sizeof(__pyx_k_home_travis_build_pymssql_pymss), 0, 0, 1, 0},
  {&__pyx_n_s_hour, __pyx_k_hour, sizeof(__pyx_k_hour), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_iteritems, __pyx_k_iteritems, sizeof(__pyx_k_iteritems), 0, 0, 1, 1},
  {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1},
  {&__pyx_n_s_kwargs, __pyx_k_kwargs, sizeof(__pyx_k_kwargs), 0, 0, 1, 1},
  {&__pyx_n_s_l, __pyx_k_l, sizeof(__pyx_k_l), 0, 0, 1, 1},
  {&__pyx_n_s_limit, __pyx_k_limit, sizeof(__pyx_k_limit), 0, 0, 1, 1},
  {&__pyx_kp_s_local, __pyx_k_local, sizeof(__pyx_k_local), 0, 0, 1, 0},
  {&__pyx_n_s_localcontext, __pyx_k_localcontext, sizeof(__pyx_k_localcontext), 0, 0, 1, 1},
  {&__pyx_n_s_localhost, __pyx_k_localhost, sizeof(__pyx_k_localhost), 0, 0, 1, 1},
  {&__pyx_n_s_login_timeout, __pyx_k_login_timeout, sizeof(__pyx_k_login_timeout), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_mark_disconnected, __pyx_k_mark_disconnected, sizeof(__pyx_k_mark_disconnected), 0, 0, 1, 1},
  {&__pyx_n_s_max_length, __pyx_k_max_length, sizeof(__pyx_k_max_length), 0, 0, 1, 1},
  {&__pyx_n_s_microsecond, __pyx_k_microsecond, sizeof(__pyx_k_microsecond), 0, 0, 1, 1},
  {&__pyx_n_s_min_error_severity, __pyx_k_min_error_severity, sizeof(__pyx_k_min_error_severity), 0, 0, 1, 1},
  {&__pyx_n_s_minute, __pyx_k_minute, sizeof(__pyx_k_minute), 0, 0, 1, 1},
  {&__pyx_n_s_month, __pyx_k_month, sizeof(__pyx_k_month), 0, 0, 1, 1},
  {&__pyx_kp_s_more_placeholders_in_sql_than_pa, __pyx_k_more_placeholders_in_sql_than_pa, sizeof(__pyx_k_more_placeholders_in_sql_than_pa), 0, 0, 1, 0},
  {&__pyx_n_s_mssql, __pyx_k_mssql, sizeof(__pyx_k_mssql), 0, 0, 1, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_null, __pyx_k_null, sizeof(__pyx_k_null), 0, 0, 1, 1},
  {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
  {&__pyx_n_s_oserr, __pyx_k_oserr, sizeof(__pyx_k_oserr), 0, 0, 1, 1},
  {&__pyx_n_s_oserrstr, __pyx_k_oserrstr, sizeof(__pyx_k_oserrstr), 0, 0, 1, 1},
  {&__pyx_n_s_oserrstr_byte_string, __pyx_k_oserrstr_byte_string, sizeof(__pyx_k_oserrstr_byte_string), 0, 0, 1, 1},
  {&__pyx_n_s_oserrstrc, __pyx_k_oserrstrc, sizeof(__pyx_k_oserrstrc), 0, 0, 1, 1},
  {&__pyx_n_s_output, __pyx_k_output, sizeof(__pyx_k_output), 0, 0, 1, 1},
  {&__pyx_n_s_param_name, __pyx_k_param_name, sizeof(__pyx_k_param_name), 0, 0, 1, 1},
  {&__pyx_n_s_params, __pyx_k_params, sizeof(__pyx_k_params), 0, 0, 1, 1},
  {&__pyx_kp_s_params_arg_r_can_be_only_a_tupl, __pyx_k_params_arg_r_can_be_only_a_tupl, sizeof(__pyx_k_params_arg_r_can_be_only_a_tupl), 0, 0, 1, 0},
  {&__pyx_kp_s_params_dictionary_did_not_contai, __pyx_k_params_dictionary_did_not_contai, sizeof(__pyx_k_params_dictionary_did_not_contai), 0, 0, 1, 0},
  {&__pyx_n_s_password, __pyx_k_password, sizeof(__pyx_k_password), 0, 0, 1, 1},
  {&__pyx_n_s_port, __pyx_k_port, sizeof(__pyx_k_port), 0, 0, 1, 1},
  {&__pyx_n_s_prec, __pyx_k_prec, sizeof(__pyx_k_prec), 0, 0, 1, 1},
  {&__pyx_kp_s_pymssql_s, __pyx_k_pymssql_s, sizeof(__pyx_k_pymssql_s), 0, 0, 1, 0},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_query_string, __pyx_k_query_string, sizeof(__pyx_k_query_string), 0, 0, 1, 1},
  {&__pyx_n_s_quote_data, __pyx_k_quote_data, sizeof(__pyx_k_quote_data), 0, 0, 1, 1},
  {&__pyx_n_s_quote_or_flatten, __pyx_k_quote_or_flatten, sizeof(__pyx_k_quote_or_flatten), 0, 0, 1, 1},
  {&__pyx_n_s_quote_simple_value, __pyx_k_quote_simple_value, sizeof(__pyx_k_quote_simple_value), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1},
  {&__pyx_n_s_re_name_param, __pyx_k_re_name_param, sizeof(__pyx_k_re_name_param), 0, 0, 1, 1},
  {&__pyx_n_s_re_pos_param, __pyx_k_re_pos_param, sizeof(__pyx_k_re_pos_param), 0, 0, 1, 1},
  {&__pyx_n_s_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1},
  {&__pyx_n_s_remove_locale, __pyx_k_remove_locale, sizeof(__pyx_k_remove_locale), 0, 0, 1, 1},
  {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1},
  {&__pyx_n_s_results, __pyx_k_results, sizeof(__pyx_k_results), 0, 0, 1, 1},
  {&__pyx_n_s_row_format, __pyx_k_row_format, sizeof(__pyx_k_row_format), 0, 0, 1, 1},
  {&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0},
  {&__pyx_n_s_s_2, __pyx_k_s_2, sizeof(__pyx_k_s_2), 0, 0, 1, 1},
  {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0},
  {&__pyx_n_s_sa, __pyx_k_sa, sizeof(__pyx_k_sa), 0, 0, 1, 1},
  {&__pyx_kp_b_sd, __pyx_k_sd, sizeof(__pyx_k_sd), 0, 0, 0, 0},
  {&__pyx_kp_b_sd_2, __pyx_k_sd_2, sizeof(__pyx_k_sd_2), 0, 0, 0, 0},
  {&__pyx_n_s_second, __pyx_k_second, sizeof(__pyx_k_second), 0, 0, 1, 1},
  {&__pyx_n_s_select_db, __pyx_k_select_db, sizeof(__pyx_k_select_db), 0, 0, 1, 1},
  {&__pyx_n_s_server, __pyx_k_server, sizeof(__pyx_k_server), 0, 0, 1, 1},
  {&__pyx_n_s_set_max_connections, __pyx_k_set_max_connections, sizeof(__pyx_k_set_max_connections), 0, 0, 1, 1},
  {&__pyx_n_s_set_msghandler, __pyx_k_set_msghandler, sizeof(__pyx_k_set_msghandler), 0, 0, 1, 1},
  {&__pyx_n_s_set_wait_callback, __pyx_k_set_wait_callback, sizeof(__pyx_k_set_wait_callback), 0, 0, 1, 1},
  {&__pyx_n_s_severity, __pyx_k_severity, sizeof(__pyx_k_severity), 0, 0, 1, 1},
  {&__pyx_n_s_socket, __pyx_k_socket, sizeof(__pyx_k_socket), 0, 0, 1, 1},
  {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
  {&__pyx_n_s_stderr, __pyx_k_stderr, sizeof(__pyx_k_stderr), 0, 0, 1, 1},
  {&__pyx_n_s_strftime, __pyx_k_strftime, sizeof(__pyx_k_strftime), 0, 0, 1, 1},
  {&__pyx_n_s_string_types, __pyx_k_string_types, sizeof(__pyx_k_string_types), 0, 0, 1, 1},
  {&__pyx_n_s_substitute_params, __pyx_k_substitute_params, sizeof(__pyx_k_substitute_params), 0, 0, 1, 1},
  {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
  {&__pyx_n_s_tds_version, __pyx_k_tds_version, sizeof(__pyx_k_tds_version), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_test_err_handler, __pyx_k_test_err_handler, sizeof(__pyx_k_test_err_handler), 0, 0, 1, 1},
  {&__pyx_n_s_toformat, __pyx_k_toformat, sizeof(__pyx_k_toformat), 0, 0, 1, 1},
  {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1},
  {&__pyx_kp_s_ts_04d_02d_02d_02d_02d_02d_03d, __pyx_k_ts_04d_02d_02d_02d_02d_02d_03d, sizeof(__pyx_k_ts_04d_02d_02d_02d_02d_02d_03d), 0, 0, 1, 0},
  {&__pyx_kp_s_unrecognized_tds_version_s, __pyx_k_unrecognized_tds_version_s, sizeof(__pyx_k_unrecognized_tds_version_s), 0, 0, 1, 0},
  {&__pyx_n_s_user, __pyx_k_user, sizeof(__pyx_k_user), 0, 0, 1, 1},
  {&__pyx_n_s_utf8, __pyx_k_utf8, sizeof(__pyx_k_utf8), 0, 0, 1, 1},
  {&__pyx_kp_s_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 0, 1, 0},
  {&__pyx_n_s_uuid, __pyx_k_uuid, sizeof(__pyx_k_uuid), 0, 0, 1, 1},
  {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  {&__pyx_kp_s_value_can_only_be_a_Decimal, __pyx_k_value_can_only_be_a_Decimal, sizeof(__pyx_k_value_can_only_be_a_Decimal), 0, 0, 1, 0},
  {&__pyx_kp_s_value_can_only_be_a_date_or_date, __pyx_k_value_can_only_be_a_date_or_date, sizeof(__pyx_k_value_can_only_be_a_date_or_date), 0, 0, 1, 0},
  {&__pyx_kp_s_value_can_only_be_str, __pyx_k_value_can_only_be_str, sizeof(__pyx_k_value_can_only_be_str), 0, 0, 1, 0},
  {&__pyx_kp_s_value_cannot_be_larger_than_d, __pyx_k_value_cannot_be_larger_than_d, sizeof(__pyx_k_value_cannot_be_larger_than_d), 0, 0, 1, 0},
  {&__pyx_kp_s_value_cannot_be_smaller_than_d, __pyx_k_value_cannot_be_smaller_than_d, sizeof(__pyx_k_value_cannot_be_smaller_than_d), 0, 0, 1, 0},
  {&__pyx_kp_s_value_must_be_a_string_type, __pyx_k_value_must_be_a_string_type, sizeof(__pyx_k_value_must_be_a_string_type), 0, 0, 1, 0},
  {&__pyx_n_s_version, __pyx_k_version, sizeof(__pyx_k_version), 0, 0, 1, 1},
  {&__pyx_n_s_wait_callback, __pyx_k_wait_callback, sizeof(__pyx_k_wait_callback), 0, 0, 1, 1},
  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
  {&__pyx_n_s_xrange, __pyx_k_xrange, sizeof(__pyx_k_xrange), 0, 0, 1, 1},
  {&__pyx_n_s_year, __pyx_k_year, sizeof(__pyx_k_year), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 202, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 491, __pyx_L1_error)
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 896, __pyx_L1_error)
  __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 1120, __pyx_L1_error)
  #if PY_MAJOR_VERSION >= 3
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) __PYX_ERR(0, 1202, __pyx_L1_error)
  #else
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) __PYX_ERR(0, 1202, __pyx_L1_error)
  #endif
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 1671, __pyx_L1_error)
  __pyx_builtin_UnicodeDecodeError = __Pyx_GetBuiltinName(__pyx_n_s_UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) __PYX_ERR(0, 1738, __pyx_L1_error)
  __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 1869, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "_mssql.pyx":491
 *             cdef RETCODE rtc
 *             if val < 0:
 *                 raise ValueError("The 'query_timeout' attribute must be >= 0.")             # <<<<<<<<<<<<<<
 * 
 *             # XXX: Currently this will set it application wide :-(
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_The_query_timeout_attribute_must); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "_mssql.pyx":553
 *         instance = ""
 *         if "\\" in server:
 *             server, instance = server.split("\\")             # <<<<<<<<<<<<<<
 * 
 *         if server in (".", "(local)"):
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s__3); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "_mssql.pyx":562
 *         login = dblogin()
 *         if login == NULL:
 *             raise MSSQLDriverException("dblogin() failed")             # <<<<<<<<<<<<<<
 * 
 *         appname = appname or "pymssql=%s" % __full_version__
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_dblogin_failed); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "_mssql.pyx":567
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 *         cdef bytes user_bytes = user.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *user_cstr = user_bytes
 *         cdef bytes password_bytes = password.encode('utf-8')
 */
  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_utf_8); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);

  /* "_mssql.pyx":569
 *         cdef bytes user_bytes = user.encode('utf-8')
 *         cdef char *user_cstr = user_bytes
 *         cdef bytes password_bytes = password.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *password_cstr = password_bytes
 *         cdef bytes appname_bytes = appname.encode('utf-8')
 */
  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_utf_8); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "_mssql.pyx":571
 *         cdef bytes password_bytes = password.encode('utf-8')
 *         cdef char *password_cstr = password_bytes
 *         cdef bytes appname_bytes = appname.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *appname_cstr = appname_bytes
 * 
 */
  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_utf_8); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "_mssql.pyx":603
 *         # Set the character set name
 *         if charset:
 *             charset_bytes = charset.encode('utf-8')             # <<<<<<<<<<<<<<
 *             _charset = charset_bytes
 *             strncpy(self._charset, _charset, PYMSSQL_CHARSETBUFSIZE)
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_utf_8); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 603, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "_mssql.pyx":614
 *         if database:
 *             if FREETDS_SUPPORTS_DBSETLDBNAME:
 *                 dbname_bytes = database.encode('ascii')             # <<<<<<<<<<<<<<
 *                 dbname_cstr = dbname_bytes
 *                 DBSETLDBNAME(login, dbname_cstr)
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "_mssql.pyx":624
 *         dbsetlogintime(login_timeout)
 * 
 *         cdef bytes server_bytes = server.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *server_cstr = server_bytes
 * 
 */
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_utf_8); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);

  /* "_mssql.pyx":638
 *             connection_object_list.remove(self)
 *             maybe_raise_MSSQLDatabaseException(None)
 *             raise MSSQLDriverException("Connection to the database failed for an unknown reason.")             # <<<<<<<<<<<<<<
 * 
 *         self._connected = 1
 */
  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_Connection_to_the_database_faile); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "_mssql.pyx":668
 *             rtc = db_sqlexec(self.dbproc)
 *             if (rtc == FAIL):
 *                 raise MSSQLDriverException("Could not set connection properties")             # <<<<<<<<<<<<<<
 * 
 *         db_cancel(self)
 */
  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_Could_not_set_connection_propert); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "_mssql.pyx":802
 *                 <BYTE *>buf, NUMERIC_BUF_SZ)
 * 
 *             with decimal.localcontext() as ctx:             # <<<<<<<<<<<<<<
 *                 # Python 3 doesn't like decimal.localcontext() with prec == 0
 *                 ctx.prec = precision if precision > 0 else 1
 */
  __pyx_tuple__17 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);
  __pyx_tuple__18 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "_mssql.pyx":896
 *         if dbtype[0] in (SQLDATETIM4, SQLDATETIME):
 *             if type(value) not in (datetime.date, datetime.datetime):
 *                 raise TypeError('value can only be a date or datetime')             # <<<<<<<<<<<<<<
 * 
 *             value = value.strftime('%Y-%m-%d %H:%M:%S.') + \
 */
  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_value_can_only_be_a_date_or_date); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "_mssql.pyx":898
 *                 raise TypeError('value can only be a date or datetime')
 * 
 *             value = value.strftime('%Y-%m-%d %H:%M:%S.') + \             # <<<<<<<<<<<<<<
 *                 "%03d" % (value.microsecond // 1000)
 *             value = value.encode(self.charset)
 */
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_Y_m_d_H_M_S); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 898, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "_mssql.pyx":941
 * 
 *             if type(value) not in (decimal.Decimal, float):
 *                 raise TypeError('value can only be a Decimal')             # <<<<<<<<<<<<<<
 * 
 *             value = str(value)
 */
  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_value_can_only_be_a_Decimal); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 941, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "_mssql.pyx":948
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *             if not hasattr(value, 'startswith'):
 *                 raise TypeError('value must be a string type')             # <<<<<<<<<<<<<<
 * 
 *             if strlen(self._charset) > 0 and type(value) is unicode:
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_value_must_be_a_string_type); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 948, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "_mssql.pyx":962
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):
 *             if type(value) is not str:
 *                 raise TypeError('value can only be str')             # <<<<<<<<<<<<<<
 * 
 *             binValue = <BYTE *>PyMem_Malloc(len(value))
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_value_can_only_be_str); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 962, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "_mssql.pyx":978
 * 
 *         # No conversion was possible so raise an error
 *         raise MSSQLDriverException('Unable to convert value')             # <<<<<<<<<<<<<<
 * 
 *     cpdef execute_non_query(self, query_string, params=None):
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_convert_value); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 978, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "_mssql.pyx":1375
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 *         cdef bytes dbname_bytes = dbname.encode('ascii')             # <<<<<<<<<<<<<<
 *         cdef char *dbname_cstr = dbname_bytes
 * 
 */
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 1375, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "_mssql.pyx":1407
 *         # doesn't support remote procedure calls.
 *         if connection.tds_version < 7:
 *             raise MSSQLDriverException("Stored Procedures aren't "             # <<<<<<<<<<<<<<
 *                 "supported with a TDS version less than 7.")
 * 
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_Stored_Procedures_aren_t_support); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 1407, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "_mssql.pyx":1469
 *             pn = <_mssql_parameter_node *>PyMem_Malloc(sizeof(_mssql_parameter_node))
 *             if pn == NULL:
 *                 raise MSSQLDriverException('Out of memory')             # <<<<<<<<<<<<<<
 *             pn.next = self.params_list
 *             pn.value = data
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_Out_of_memory); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 1469, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "_mssql.pyx":1503
 * 
 *         if param_name:
 *             param_name_bytes = param_name.encode('ascii')             # <<<<<<<<<<<<<<
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:
 */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 1503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "_mssql.pyx":1506
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')             # <<<<<<<<<<<<<<
 *         else:
 *             param_name_cstr = ''
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_Cannot_bind_named_parameter_afte); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 1506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "_mssql.pyx":1635
 *     log("_mssql.assert_connected()")
 *     if not conn.connected:
 *         raise MSSQLDriverException("Not connected to any MS SQL server")             # <<<<<<<<<<<<<<
 * 
 * cdef inline BYTE *get_data(DBPROCESS *dbproc, int row_info, int col) nogil:
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_Not_connected_to_any_MS_SQL_serv); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 1635, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "_mssql.pyx":1727
 * 
 *     if isinstance(value, unicode):
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, bytearray):
 */
  __pyx_tuple__33 = PyTuple_Pack(2, __pyx_kp_s__31, __pyx_kp_s__32); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 1727, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "_mssql.pyx":1736
 *         if b'\0' not in value:
 *             try:
 *                 value.decode('ascii')             # <<<<<<<<<<<<<<
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 *             except UnicodeDecodeError:
 */
  __pyx_tuple__35 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 1736, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "_mssql.pyx":1737
 *             try:
 *                 value.decode('ascii')
 *                 return b"'" + value.replace(b"'", b"''") + b"'"             # <<<<<<<<<<<<<<
 *             except UnicodeDecodeError:
 *                 pass
 */
  __pyx_tuple__36 = PyTuple_Pack(2, __pyx_kp_b__31, __pyx_kp_b__32); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 1737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "_mssql.pyx":1749
 *         # decoding failed.  In this case, just send it as hex.
 *         if isinstance(value, str):
 *             return '0x' + value.encode('hex')             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, datetime.datetime):
 */
  __pyx_tuple__37 = PyTuple_Pack(1, __pyx_n_s_hex); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 1749, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "_mssql.pyx":1770
 * 
 *     if not issubclass(type(data), (list, tuple)):
 *         raise ValueError('expected a simple type, a tuple or a list')             # <<<<<<<<<<<<<<
 * 
 *     quoted = []
 */
  __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_expected_a_simple_type_a_tuple_o); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 1770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "_mssql.pyx":1777
 * 
 *         if value is None:
 *             raise ValueError('found an unsupported type')             # <<<<<<<<<<<<<<
 * 
 *         quoted.append(value)
 */
  __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_found_an_unsupported_type); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 1777, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "_mssql.pyx":1803
 *         return tuple(result)
 * 
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')             # <<<<<<<<<<<<<<
 * 
 * _re_pos_param = re.compile(br'(%([sd]))')
 */
  __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_expected_a_simple_type_a_tuple_o_2); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 1803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);

  /* "_mssql.pyx":1832
 *         offset = 0
 *         for match in _re_name_param.finditer(toformat):
 *             param_key = match.group(2).decode(charset)             # <<<<<<<<<<<<<<
 * 
 *             if not param_key in params:
 */
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_int_2); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 1832, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "_mssql.pyx":1846
 *             param_val = quoted[param_key]
 *             param_val_len = len(param_val)
 *             placeholder_len = len(match.group(1))             # <<<<<<<<<<<<<<
 *             offset_adjust = param_val_len - placeholder_len
 * 
 */
  __pyx_tuple__45 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 1846, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);

  /* "_mssql.pyx":1850
 * 
 *             # do the string substitution
 *             match_start = match.start(1) + offset             # <<<<<<<<<<<<<<
 *             match_end = match.end(1) + offset
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]
 */
  __pyx_tuple__46 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 1850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);

  /* "_mssql.pyx":1851
 *             # do the string substitution
 *             match_start = match.start(1) + offset
 *             match_end = match.end(1) + offset             # <<<<<<<<<<<<<<
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]
 * 
 */
  __pyx_tuple__47 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 1851, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);

  /* "_mssql.pyx":1870
 *                 param_val = quoted[count]
 *             except IndexError:
 *                 raise ValueError('more placeholders in sql than params available')             # <<<<<<<<<<<<<<
 *             param_val_len = len(param_val)
 *             placeholder_len = 2
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_more_placeholders_in_sql_than_pa); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 1870, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "_mssql.pyx":1876
 * 
 *             # do the string substitution
 *             match_start = match.start(1) + offset             # <<<<<<<<<<<<<<
 *             match_end = match.end(1) + offset
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]
 */
  __pyx_tuple__49 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 1876, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);

  /* "_mssql.pyx":1877
 *             # do the string substitution
 *             match_start = match.start(1) + offset
 *             match_end = match.end(1) + offset             # <<<<<<<<<<<<<<
 *             toformat = toformat[:match_start] + ensure_bytes(param_val) + toformat[match_end:]
 *             #print(param_val, param_val_len, offset_adjust, match_start, match_end)
 */
  __pyx_tuple__50 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 1877, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "_mssql.pyx":1920
 *     cdef char *oserrstrc = NULL
 *     if dberrstr:
 *         dberrstr_byte_string = dberrstr.encode('UTF-8')             # <<<<<<<<<<<<<<
 *         dberrstrc = dberrstr_byte_string
 *     if oserrstr:
 */
  __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_s_UTF_8); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 1920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);

  /* "_mssql.pyx":1923
 *         dberrstrc = dberrstr_byte_string
 *     if oserrstr:
 *         oserrstr_byte_string = oserrstr.encode('UTF-8')             # <<<<<<<<<<<<<<
 *         oserrstrc = oserrstr_byte_string
 *     if connection:
 */
  __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_UTF_8); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 1923, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "_mssql.pyx":1958
 * cdef void init_mssql():
 *     if dbinit() == FAIL:
 *         raise MSSQLDriverException("dbinit() failed")             # <<<<<<<<<<<<<<
 * 
 *     dberrhandle(err_handler)
 */
  __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_dbinit_failed); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 1958, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);

  /* "_mssql.pyx":87
 *     cdef int _row_count = 0
 * 
 * cdef bytes HOSTNAME = socket.gethostname().encode('utf-8')             # <<<<<<<<<<<<<<
 * 
 * # List to store the connection objects in
 */
  __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_utf_8); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "_mssql.pyx":98
 * # Store the module version
 * __full_version__ = PYMSSQL_VERSION.decode('ascii')
 * __version__ = '.'.join(__full_version__.split('.')[:3]) # drop '.dev' from 'X.Y.Z.dev'             # <<<<<<<<<<<<<<
 * 
 * #############################
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s__5); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);
  __pyx_slice__56 = PySlice_New(Py_None, __pyx_int_3, Py_None); if (unlikely(!__pyx_slice__56)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__56);
  __Pyx_GIVEREF(__pyx_slice__56);

  /* "_mssql.pyx":190
 * wait_callback = None
 * 
 * def set_wait_callback(a_callable):             # <<<<<<<<<<<<<<
 *     global wait_callback
 * 
 */
  __pyx_tuple__57 = PyTuple_Pack(1, __pyx_n_s_a_callable); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);
  __pyx_codeobj__58 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_set_wait_callback, 190, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__58)) __PYX_ERR(0, 190, __pyx_L1_error)

  /* "_mssql.pyx":1685
 *     return stripped
 * 
 * def remove_locale(bytes value):             # <<<<<<<<<<<<<<
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)
 */
  __pyx_tuple__59 = PyTuple_Pack(3, __pyx_n_s_value, __pyx_n_s_s_2, __pyx_n_s_l); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 1685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);
  __pyx_codeobj__60 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_remove_locale, 1685, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__60)) __PYX_ERR(0, 1685, __pyx_L1_error)

  /* "_mssql.pyx":1805
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')
 * 
 * _re_pos_param = re.compile(br'(%([sd]))')             # <<<<<<<<<<<<<<
 * _re_name_param = re.compile(br'(%\(([^\)]+)\)(?:[sd]))')
 * cdef _substitute_params(toformat, params, charset):
 */
  __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_b_sd); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 1805, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);

  /* "_mssql.pyx":1806
 * 
 * _re_pos_param = re.compile(br'(%([sd]))')
 * _re_name_param = re.compile(br'(%\(([^\)]+)\)(?:[sd]))')             # <<<<<<<<<<<<<<
 * cdef _substitute_params(toformat, params, charset):
 *     if params is None:
 */
  __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_b_sd_2); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(0, 1806, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);

  /* "_mssql.pyx":1886
 * # We'll add these methods to the module to allow for unit testing of the
 * # underlying C methods.
 * def quote_simple_value(value):             # <<<<<<<<<<<<<<
 *     return _quote_simple_value(value)
 * 
 */
  __pyx_tuple__63 = PyTuple_Pack(1, __pyx_n_s_value); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 1886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);
  __pyx_codeobj__64 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_quote_simple_value, 1886, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__64)) __PYX_ERR(0, 1886, __pyx_L1_error)

  /* "_mssql.pyx":1889
 *     return _quote_simple_value(value)
 * 
 * def quote_or_flatten(data):             # <<<<<<<<<<<<<<
 *     return _quote_or_flatten(data)
 * 
 */
  __pyx_tuple__65 = PyTuple_Pack(1, __pyx_n_s_data); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(0, 1889, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);
  __pyx_codeobj__66 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__65, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_quote_or_flatten, 1889, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__66)) __PYX_ERR(0, 1889, __pyx_L1_error)

  /* "_mssql.pyx":1892
 *     return _quote_or_flatten(data)
 * 
 * def quote_data(data):             # <<<<<<<<<<<<<<
 *     return _quote_data(data)
 * 
 */
  __pyx_tuple__67 = PyTuple_Pack(1, __pyx_n_s_data); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 1892, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);
  __pyx_codeobj__68 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_quote_data, 1892, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__68)) __PYX_ERR(0, 1892, __pyx_L1_error)

  /* "_mssql.pyx":1895
 *     return _quote_data(data)
 * 
 * def substitute_params(toformat, params, charset='utf8'):             # <<<<<<<<<<<<<<
 *     return _substitute_params(toformat, params, charset)
 * 
 */
  __pyx_tuple__69 = PyTuple_Pack(3, __pyx_n_s_toformat, __pyx_n_s_params, __pyx_n_s_charset); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 1895, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);
  __pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_substitute_params, 1895, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) __PYX_ERR(0, 1895, __pyx_L1_error)

  /* "_mssql.pyx":1901
 * ## Compatibility Aliases ##
 * ###########################
 * def connect(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return MSSQLConnection(*args, **kwargs)
 * 
 */
  __pyx_tuple__71 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(0, 1901, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);
  __pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__71, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_connect, 1901, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) __PYX_ERR(0, 1901, __pyx_L1_error)

  /* "_mssql.pyx":1912
 * ###########################
 * 
 * def test_err_handler(connection, int severity, int dberr, int oserr, dberrstr, oserrstr):             # <<<<<<<<<<<<<<
 *     """
 *     Expose err_handler function and its side effects to facilitate testing.
 */
  __pyx_tuple__73 = PyTuple_Pack(12, __pyx_n_s_connection, __pyx_n_s_severity, __pyx_n_s_dberr, __pyx_n_s_oserr, __pyx_n_s_dberrstr, __pyx_n_s_oserrstr, __pyx_n_s_dbproc, __pyx_n_s_dberrstrc, __pyx_n_s_oserrstrc, __pyx_n_s_dberrstr_byte_string, __pyx_n_s_oserrstr_byte_string, __pyx_n_s_results); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 1912, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);
  __pyx_codeobj__74 = (PyObject*)__Pyx_PyCode_New(6, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__73, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_test_err_handler, 1912, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__74)) __PYX_ERR(0, 1912, __pyx_L1_error)

  /* "_mssql.pyx":1941
 * ## Max Connections ##
 * #####################
 * def get_max_connections():             # <<<<<<<<<<<<<<
 *     """
 *     Get maximum simultaneous connections db-lib will open to the server.
 */
  __pyx_codeobj__75 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_get_max_connections, 1941, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__75)) __PYX_ERR(0, 1941, __pyx_L1_error)

  /* "_mssql.pyx":1947
 *     return dbgetmaxprocs()
 * 
 * def set_max_connections(int limit):             # <<<<<<<<<<<<<<
 *     """
 *     Set maximum simultaneous connections db-lib will open to the server.
 */
  __pyx_tuple__76 = PyTuple_Pack(2, __pyx_n_s_limit, __pyx_n_s_limit); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(0, 1947, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__76);
  __Pyx_GIVEREF(__pyx_tuple__76);
  __pyx_codeobj__77 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__76, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_pymssql_pymss, __pyx_n_s_set_max_connections, 1947, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__77)) __PYX_ERR(0, 1947, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_float_4_2 = PyFloat_FromDouble(4.2); if (unlikely(!__pyx_float_4_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_5_0 = PyFloat_FromDouble(5.0); if (unlikely(!__pyx_float_5_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_7_0 = PyFloat_FromDouble(7.0); if (unlikely(!__pyx_float_7_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_7_2 = PyFloat_FromDouble(7.2); if (unlikely(!__pyx_float_7_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_7_3 = PyFloat_FromDouble(7.3); if (unlikely(!__pyx_float_7_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_8_0 = PyFloat_FromDouble(8.0); if (unlikely(!__pyx_float_8_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_36 = PyInt_FromLong(36); if (unlikely(!__pyx_int_36)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_60 = PyInt_FromLong(60); if (unlikely(!__pyx_int_60)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_104 = PyInt_FromLong(104); if (unlikely(!__pyx_int_104)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_mssql(void); /*proto*/
PyMODINIT_FUNC init_mssql(void)
#else
PyMODINIT_FUNC PyInit__mssql(void); /*proto*/
PyMODINIT_FUNC PyInit__mssql(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__mssql(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("_mssql", __pyx_methods, __pyx_k_This_is_an_effort_to_convert_th, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main__mssql) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "_mssql")) {
      if (unlikely(PyDict_SetItemString(modules, "_mssql", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global init code ---*/
  __pyx_v_6_mssql_HOSTNAME = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_6_mssql_connection_object_list = ((PyObject*)Py_None); Py_INCREF(Py_None);
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  if (__Pyx_ExportFunction("log", (void (*)(void))__pyx_f_6_mssql_log, "void (char *, ...)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Type init code ---*/
  __pyx_vtabptr_6_mssql_MSSQLConnection = &__pyx_vtable_6_mssql_MSSQLConnection;
  __pyx_vtable_6_mssql_MSSQLConnection.cancel = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, int __pyx_skip_dispatch))__pyx_f_6_mssql_15MSSQLConnection_cancel;
  __pyx_vtable_6_mssql_MSSQLConnection.clear_metadata = (void (*)(struct __pyx_obj_6_mssql_MSSQLConnection *))__pyx_f_6_mssql_15MSSQLConnection_clear_metadata;
  __pyx_vtable_6_mssql_MSSQLConnection.convert_db_value = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, BYTE *, int, int))__pyx_f_6_mssql_15MSSQLConnection_convert_db_value;
  __pyx_vtable_6_mssql_MSSQLConnection.convert_python_value = (int (*)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, BYTE **, int *, int *))__pyx_f_6_mssql_15MSSQLConnection_convert_python_value;
  __pyx_vtable_6_mssql_MSSQLConnection.execute_query = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_query *__pyx_optional_args))__pyx_f_6_mssql_15MSSQLConnection_execute_query;
  __pyx_vtable_6_mssql_MSSQLConnection.execute_non_query = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_non_query *__pyx_optional_args))__pyx_f_6_mssql_15MSSQLConnection_execute_non_query;
  __pyx_vtable_6_mssql_MSSQLConnection.execute_row = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_row *__pyx_optional_args))__pyx_f_6_mssql_15MSSQLConnection_execute_row;
  __pyx_vtable_6_mssql_MSSQLConnection.execute_scalar = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_scalar *__pyx_optional_args))__pyx_f_6_mssql_15MSSQLConnection_execute_scalar;
  __pyx_vtable_6_mssql_MSSQLConnection.fetch_next_row = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, int, int))__pyx_f_6_mssql_15MSSQLConnection_fetch_next_row;
  __pyx_vtable_6_mssql_MSSQLConnection.format_and_run_query = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query *__pyx_optional_args))__pyx_f_6_mssql_15MSSQLConnection_format_and_run_query;
  __pyx_vtable_6_mssql_MSSQLConnection.format_sql_command = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_sql_command *__pyx_optional_args))__pyx_f_6_mssql_15MSSQLConnection_format_sql_command;
  __pyx_vtable_6_mssql_MSSQLConnection.get_result = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *))__pyx_f_6_mssql_15MSSQLConnection_get_result;
  __pyx_vtable_6_mssql_MSSQLConnection.get_row = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, int, int))__pyx_f_6_mssql_15MSSQLConnection_get_row;
  __pyx_vtable_6_mssql_MSSQLConnection.set_msghandler = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, PyObject *, int __pyx_skip_dispatch))__pyx_f_6_mssql_15MSSQLConnection_set_msghandler;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLConnection) < 0) __PYX_ERR(0, 445, __pyx_L1_error)
  __pyx_type_6_mssql_MSSQLConnection.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_6_mssql_MSSQLConnection.tp_dict, __pyx_vtabptr_6_mssql_MSSQLConnection) < 0) __PYX_ERR(0, 445, __pyx_L1_error)
  if (PyObject_SetAttrString(__pyx_m, "MSSQLConnection", (PyObject *)&__pyx_type_6_mssql_MSSQLConnection) < 0) __PYX_ERR(0, 445, __pyx_L1_error)
  __pyx_ptype_6_mssql_MSSQLConnection = &__pyx_type_6_mssql_MSSQLConnection;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLRowIterator) < 0) __PYX_ERR(0, 428, __pyx_L1_error)
  __pyx_type_6_mssql_MSSQLRowIterator.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "MSSQLRowIterator", (PyObject *)&__pyx_type_6_mssql_MSSQLRowIterator) < 0) __PYX_ERR(0, 428, __pyx_L1_error)
  __pyx_ptype_6_mssql_MSSQLRowIterator = &__pyx_type_6_mssql_MSSQLRowIterator;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLStoredProcedure) < 0) __PYX_ERR(0, 1383, __pyx_L1_error)
  __pyx_type_6_mssql_MSSQLStoredProcedure.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "MSSQLStoredProcedure", (PyObject *)&__pyx_type_6_mssql_MSSQLStoredProcedure) < 0) __PYX_ERR(0, 1383, __pyx_L1_error)
  __pyx_ptype_6_mssql_MSSQLStoredProcedure = &__pyx_type_6_mssql_MSSQLStoredProcedure;
  __pyx_ptype_6_mssql_Exception = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "Exception", sizeof(PyBaseExceptionObject), 0); if (unlikely(!__pyx_ptype_6_mssql_Exception)) __PYX_ERR(0, 143, __pyx_L1_error)
  __pyx_type_6_mssql_MSSQLException.tp_base = __pyx_ptype_6_mssql_Exception;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLException) < 0) __PYX_ERR(0, 146, __pyx_L1_error)
  __pyx_type_6_mssql_MSSQLException.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "MSSQLException", (PyObject *)&__pyx_type_6_mssql_MSSQLException) < 0) __PYX_ERR(0, 146, __pyx_L1_error)
  __pyx_ptype_6_mssql_MSSQLException = &__pyx_type_6_mssql_MSSQLException;
  __pyx_type_6_mssql_MSSQLDriverException.tp_base = __pyx_ptype_6_mssql_MSSQLException;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLDriverException) < 0) __PYX_ERR(0, 151, __pyx_L1_error)
  __pyx_type_6_mssql_MSSQLDriverException.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "MSSQLDriverException", (PyObject *)&__pyx_type_6_mssql_MSSQLDriverException) < 0) __PYX_ERR(0, 151, __pyx_L1_error)
  __pyx_ptype_6_mssql_MSSQLDriverException = &__pyx_type_6_mssql_MSSQLDriverException;
  __pyx_type_6_mssql_MSSQLDatabaseException.tp_base = __pyx_ptype_6_mssql_MSSQLException;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLDatabaseException) < 0) __PYX_ERR(0, 157, __pyx_L1_error)
  __pyx_type_6_mssql_MSSQLDatabaseException.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "MSSQLDatabaseException", (PyObject *)&__pyx_type_6_mssql_MSSQLDatabaseException) < 0) __PYX_ERR(0, 157, __pyx_L1_error)
  __pyx_ptype_6_mssql_MSSQLDatabaseException = &__pyx_type_6_mssql_MSSQLDatabaseException;
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(2, 9, __pyx_L1_error)
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) __PYX_ERR(3, 8, __pyx_L1_error)
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) __PYX_ERR(4, 15, __pyx_L1_error)
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "_mssql.pyx":38
 * DEF DBVERSION_72 = 6
 * 
 * ROW_FORMAT_TUPLE = 1             # <<<<<<<<<<<<<<
 * ROW_FORMAT_DICT = 2
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ROW_FORMAT_TUPLE, __pyx_int_1) < 0) __PYX_ERR(0, 38, __pyx_L1_error)

  /* "_mssql.pyx":39
 * 
 * ROW_FORMAT_TUPLE = 1
 * ROW_FORMAT_DICT = 2             # <<<<<<<<<<<<<<
 * 
 * cdef int _ROW_FORMAT_TUPLE = ROW_FORMAT_TUPLE
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ROW_FORMAT_DICT, __pyx_int_2) < 0) __PYX_ERR(0, 39, __pyx_L1_error)

  /* "_mssql.pyx":41
 * ROW_FORMAT_DICT = 2
 * 
 * cdef int _ROW_FORMAT_TUPLE = ROW_FORMAT_TUPLE             # <<<<<<<<<<<<<<
 * cdef int _ROW_FORMAT_DICT = ROW_FORMAT_DICT
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ROW_FORMAT_TUPLE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_6_mssql__ROW_FORMAT_TUPLE = __pyx_t_2;

  /* "_mssql.pyx":42
 * 
 * cdef int _ROW_FORMAT_TUPLE = ROW_FORMAT_TUPLE
 * cdef int _ROW_FORMAT_DICT = ROW_FORMAT_DICT             # <<<<<<<<<<<<<<
 * 
 * from cpython cimport PY_MAJOR_VERSION, PY_MINOR_VERSION
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ROW_FORMAT_DICT); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_6_mssql__ROW_FORMAT_DICT = __pyx_t_2;

  /* "_mssql.pyx":46
 * from cpython cimport PY_MAJOR_VERSION, PY_MINOR_VERSION
 * 
 * from collections import Iterable             # <<<<<<<<<<<<<<
 * import os
 * import sys
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_Iterable);
  __Pyx_GIVEREF(__pyx_n_s_Iterable);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Iterable);
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_1, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Iterable); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Iterable, __pyx_t_1) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":47
 * 
 * from collections import Iterable
 * import os             # <<<<<<<<<<<<<<
 * import sys
 * import socket
 */
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 47, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_3) < 0) __PYX_ERR(0, 47, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":48
 * from collections import Iterable
 * import os
 * import sys             # <<<<<<<<<<<<<<
 * import socket
 * import decimal
 */
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_3) < 0) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":49
 * import os
 * import sys
 * import socket             # <<<<<<<<<<<<<<
 * import decimal
 * import binascii
 */
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_socket, 0, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_socket, __pyx_t_3) < 0) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":50
 * import sys
 * import socket
 * import decimal             # <<<<<<<<<<<<<<
 * import binascii
 * import datetime
 */
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_decimal, 0, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_decimal, __pyx_t_3) < 0) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":51
 * import socket
 * import decimal
 * import binascii             # <<<<<<<<<<<<<<
 * import datetime
 * import re
 */
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_binascii, 0, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_binascii, __pyx_t_3) < 0) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":52
 * import decimal
 * import binascii
 * import datetime             # <<<<<<<<<<<<<<
 * import re
 * import uuid
 */
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_datetime, 0, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 52, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_datetime, __pyx_t_3) < 0) __PYX_ERR(0, 52, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":53
 * import binascii
 * import datetime
 * import re             # <<<<<<<<<<<<<<
 * import uuid
 * 
 */
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 53, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_3) < 0) __PYX_ERR(0, 53, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":54
 * import datetime
 * import re
 * import uuid             # <<<<<<<<<<<<<<
 * 
 * from sqlfront cimport *
 */
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_uuid, 0, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_uuid, __pyx_t_3) < 0) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":74
 * 
 * # Vars to store messages from the server in
 * cdef int _mssql_last_msg_no = 0             # <<<<<<<<<<<<<<
 * cdef int _mssql_last_msg_severity = 0
 * cdef int _mssql_last_msg_state = 0
 */
  __pyx_v_6_mssql__mssql_last_msg_no = 0;

  /* "_mssql.pyx":75
 * # Vars to store messages from the server in
 * cdef int _mssql_last_msg_no = 0
 * cdef int _mssql_last_msg_severity = 0             # <<<<<<<<<<<<<<
 * cdef int _mssql_last_msg_state = 0
 * cdef int _mssql_last_msg_line = 0
 */
  __pyx_v_6_mssql__mssql_last_msg_severity = 0;

  /* "_mssql.pyx":76
 * cdef int _mssql_last_msg_no = 0
 * cdef int _mssql_last_msg_severity = 0
 * cdef int _mssql_last_msg_state = 0             # <<<<<<<<<<<<<<
 * cdef int _mssql_last_msg_line = 0
 * cdef char *_mssql_last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 */
  __pyx_v_6_mssql__mssql_last_msg_state = 0;

  /* "_mssql.pyx":77
 * cdef int _mssql_last_msg_severity = 0
 * cdef int _mssql_last_msg_state = 0
 * cdef int _mssql_last_msg_line = 0             # <<<<<<<<<<<<<<
 * cdef char *_mssql_last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * _mssql_last_msg_str[0] = <char>0
 */
  __pyx_v_6_mssql__mssql_last_msg_line = 0;

  /* "_mssql.pyx":78
 * cdef int _mssql_last_msg_state = 0
 * cdef int _mssql_last_msg_line = 0
 * cdef char *_mssql_last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 * _mssql_last_msg_str[0] = <char>0
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 */
  __pyx_v_6_mssql__mssql_last_msg_str = ((char *)PyMem_Malloc(0x2000));

  /* "_mssql.pyx":79
 * cdef int _mssql_last_msg_line = 0
 * cdef char *_mssql_last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * _mssql_last_msg_str[0] = <char>0             # <<<<<<<<<<<<<<
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * _mssql_last_msg_srv[0] = <char>0
 */
  (__pyx_v_6_mssql__mssql_last_msg_str[0]) = ((char)0);

  /* "_mssql.pyx":80
 * cdef char *_mssql_last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * _mssql_last_msg_str[0] = <char>0
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 * _mssql_last_msg_srv[0] = <char>0
 * cdef char *_mssql_last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 */
  __pyx_v_6_mssql__mssql_last_msg_srv = ((char *)PyMem_Malloc(0x2000));

  /* "_mssql.pyx":81
 * _mssql_last_msg_str[0] = <char>0
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * _mssql_last_msg_srv[0] = <char>0             # <<<<<<<<<<<<<<
 * cdef char *_mssql_last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * _mssql_last_msg_proc[0] = <char>0
 */
  (__pyx_v_6_mssql__mssql_last_msg_srv[0]) = ((char)0);

  /* "_mssql.pyx":82
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * _mssql_last_msg_srv[0] = <char>0
 * cdef char *_mssql_last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 * _mssql_last_msg_proc[0] = <char>0
 * IF PYMSSQL_DEBUG == 1:
 */
  __pyx_v_6_mssql__mssql_last_msg_proc = ((char *)PyMem_Malloc(0x2000));

  /* "_mssql.pyx":83
 * _mssql_last_msg_srv[0] = <char>0
 * cdef char *_mssql_last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * _mssql_last_msg_proc[0] = <char>0             # <<<<<<<<<<<<<<
 * IF PYMSSQL_DEBUG == 1:
 *     cdef int _row_count = 0
 */
  (__pyx_v_6_mssql__mssql_last_msg_proc[0]) = ((char)0);

  /* "_mssql.pyx":87
 *     cdef int _row_count = 0
 * 
 * cdef bytes HOSTNAME = socket.gethostname().encode('utf-8')             # <<<<<<<<<<<<<<
 * 
 * # List to store the connection objects in
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_socket); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_gethostname); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (__pyx_t_1) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_XGOTREF(__pyx_v_6_mssql_HOSTNAME);
  __Pyx_DECREF_SET(__pyx_v_6_mssql_HOSTNAME, ((PyObject*)__pyx_t_3));
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;

  /* "_mssql.pyx":90
 * 
 * # List to store the connection objects in
 * cdef list connection_object_list = list()             # <<<<<<<<<<<<<<
 * 
 * # Store the 32bit int limit values
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 90, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_XGOTREF(__pyx_v_6_mssql_connection_object_list);
  __Pyx_DECREF_SET(__pyx_v_6_mssql_connection_object_list, ((PyObject*)__pyx_t_3));
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;

  /* "_mssql.pyx":93
 * 
 * # Store the 32bit int limit values
 * cdef int MAX_INT = 2147483647             # <<<<<<<<<<<<<<
 * cdef int MIN_INT = -2147483648
 * 
 */
  __pyx_v_6_mssql_MAX_INT = 0x7FFFFFFF;

  /* "_mssql.pyx":94
 * # Store the 32bit int limit values
 * cdef int MAX_INT = 2147483647
 * cdef int MIN_INT = -2147483648             # <<<<<<<<<<<<<<
 * 
 * # Store the module version
 */
  __pyx_v_6_mssql_MIN_INT = -2147483648;

  /* "_mssql.pyx":97
 * 
 * # Store the module version
 * __full_version__ = PYMSSQL_VERSION.decode('ascii')             # <<<<<<<<<<<<<<
 * __version__ = '.'.join(__full_version__.split('.')[:3]) # drop '.dev' from 'X.Y.Z.dev'
 * 
 */
  __pyx_t_3 = __Pyx_decode_c_string(PYMSSQL_VERSION, 0, strlen(PYMSSQL_VERSION), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 97, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_full_version, __pyx_t_3) < 0) __PYX_ERR(0, 97, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":98
 * # Store the module version
 * __full_version__ = PYMSSQL_VERSION.decode('ascii')
 * __version__ = '.'.join(__full_version__.split('.')[:3]) # drop '.dev' from 'X.Y.Z.dev'             # <<<<<<<<<<<<<<
 * 
 * #############################
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_full_version); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_split); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_t_3, 0, 3, NULL, NULL, &__pyx_slice__56, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_t_3) < 0) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":103
 * ## DB-API type definitions ##
 * #############################
 * STRING = 1             # <<<<<<<<<<<<<<
 * BINARY = 2
 * NUMBER = 3
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_STRING, __pyx_int_1) < 0) __PYX_ERR(0, 103, __pyx_L1_error)

  /* "_mssql.pyx":104
 * #############################
 * STRING = 1
 * BINARY = 2             # <<<<<<<<<<<<<<
 * NUMBER = 3
 * DATETIME = 4
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_BINARY, __pyx_int_2) < 0) __PYX_ERR(0, 104, __pyx_L1_error)

  /* "_mssql.pyx":105
 * STRING = 1
 * BINARY = 2
 * NUMBER = 3             # <<<<<<<<<<<<<<
 * DATETIME = 4
 * DECIMAL = 5
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_NUMBER, __pyx_int_3) < 0) __PYX_ERR(0, 105, __pyx_L1_error)

  /* "_mssql.pyx":106
 * BINARY = 2
 * NUMBER = 3
 * DATETIME = 4             # <<<<<<<<<<<<<<
 * DECIMAL = 5
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_DATETIME, __pyx_int_4) < 0) __PYX_ERR(0, 106, __pyx_L1_error)

  /* "_mssql.pyx":107
 * NUMBER = 3
 * DATETIME = 4
 * DECIMAL = 5             # <<<<<<<<<<<<<<
 * 
 * ##################
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_DECIMAL, __pyx_int_5) < 0) __PYX_ERR(0, 107, __pyx_L1_error)

  /* "_mssql.pyx":112
 * ## DB-LIB types ##
 * ##################
 * SQLBINARY = SYBBINARY             # <<<<<<<<<<<<<<
 * SQLBIT = SYBBIT
 * SQLBITN = 104
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBBINARY); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLBINARY, __pyx_t_3) < 0) __PYX_ERR(0, 112, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":113
 * ##################
 * SQLBINARY = SYBBINARY
 * SQLBIT = SYBBIT             # <<<<<<<<<<<<<<
 * SQLBITN = 104
 * SQLCHAR = SYBCHAR
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBBIT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 113, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLBIT, __pyx_t_3) < 0) __PYX_ERR(0, 113, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":114
 * SQLBINARY = SYBBINARY
 * SQLBIT = SYBBIT
 * SQLBITN = 104             # <<<<<<<<<<<<<<
 * SQLCHAR = SYBCHAR
 * SQLDATETIME = SYBDATETIME
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLBITN, __pyx_int_104) < 0) __PYX_ERR(0, 114, __pyx_L1_error)

  /* "_mssql.pyx":115
 * SQLBIT = SYBBIT
 * SQLBITN = 104
 * SQLCHAR = SYBCHAR             # <<<<<<<<<<<<<<
 * SQLDATETIME = SYBDATETIME
 * SQLDATETIM4 = SYBDATETIME4
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBCHAR); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLCHAR, __pyx_t_3) < 0) __PYX_ERR(0, 115, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":116
 * SQLBITN = 104
 * SQLCHAR = SYBCHAR
 * SQLDATETIME = SYBDATETIME             # <<<<<<<<<<<<<<
 * SQLDATETIM4 = SYBDATETIME4
 * SQLDATETIMN = SYBDATETIMN
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBDATETIME); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLDATETIME, __pyx_t_3) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":117
 * SQLCHAR = SYBCHAR
 * SQLDATETIME = SYBDATETIME
 * SQLDATETIM4 = SYBDATETIME4             # <<<<<<<<<<<<<<
 * SQLDATETIMN = SYBDATETIMN
 * SQLDECIMAL = SYBDECIMAL
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBDATETIME4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLDATETIM4, __pyx_t_3) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":118
 * SQLDATETIME = SYBDATETIME
 * SQLDATETIM4 = SYBDATETIME4
 * SQLDATETIMN = SYBDATETIMN             # <<<<<<<<<<<<<<
 * SQLDECIMAL = SYBDECIMAL
 * SQLFLT4 = SYBREAL
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBDATETIMN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLDATETIMN, __pyx_t_3) < 0) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":119
 * SQLDATETIM4 = SYBDATETIME4
 * SQLDATETIMN = SYBDATETIMN
 * SQLDECIMAL = SYBDECIMAL             # <<<<<<<<<<<<<<
 * SQLFLT4 = SYBREAL
 * SQLFLT8 = SYBFLT8
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBDECIMAL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLDECIMAL, __pyx_t_3) < 0) __PYX_ERR(0, 119, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":120
 * SQLDATETIMN = SYBDATETIMN
 * SQLDECIMAL = SYBDECIMAL
 * SQLFLT4 = SYBREAL             # <<<<<<<<<<<<<<
 * SQLFLT8 = SYBFLT8
 * SQLFLTN = SYBFLTN
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBREAL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLFLT4, __pyx_t_3) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":121
 * SQLDECIMAL = SYBDECIMAL
 * SQLFLT4 = SYBREAL
 * SQLFLT8 = SYBFLT8             # <<<<<<<<<<<<<<
 * SQLFLTN = SYBFLTN
 * SQLIMAGE = SYBIMAGE
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBFLT8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 121, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLFLT8, __pyx_t_3) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":122
 * SQLFLT4 = SYBREAL
 * SQLFLT8 = SYBFLT8
 * SQLFLTN = SYBFLTN             # <<<<<<<<<<<<<<
 * SQLIMAGE = SYBIMAGE
 * SQLINT1 = SYBINT1
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBFLTN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLFLTN, __pyx_t_3) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":123
 * SQLFLT8 = SYBFLT8
 * SQLFLTN = SYBFLTN
 * SQLIMAGE = SYBIMAGE             # <<<<<<<<<<<<<<
 * SQLINT1 = SYBINT1
 * SQLINT2 = SYBINT2
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBIMAGE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLIMAGE, __pyx_t_3) < 0) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":124
 * SQLFLTN = SYBFLTN
 * SQLIMAGE = SYBIMAGE
 * SQLINT1 = SYBINT1             # <<<<<<<<<<<<<<
 * SQLINT2 = SYBINT2
 * SQLINT4 = SYBINT4
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBINT1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLINT1, __pyx_t_3) < 0) __PYX_ERR(0, 124, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":125
 * SQLIMAGE = SYBIMAGE
 * SQLINT1 = SYBINT1
 * SQLINT2 = SYBINT2             # <<<<<<<<<<<<<<
 * SQLINT4 = SYBINT4
 * SQLINT8 = SYBINT8
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBINT2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLINT2, __pyx_t_3) < 0) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":126
 * SQLINT1 = SYBINT1
 * SQLINT2 = SYBINT2
 * SQLINT4 = SYBINT4             # <<<<<<<<<<<<<<
 * SQLINT8 = SYBINT8
 * SQLINTN = SYBINTN
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBINT4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLINT4, __pyx_t_3) < 0) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":127
 * SQLINT2 = SYBINT2
 * SQLINT4 = SYBINT4
 * SQLINT8 = SYBINT8             # <<<<<<<<<<<<<<
 * SQLINTN = SYBINTN
 * SQLMONEY = SYBMONEY
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBINT8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLINT8, __pyx_t_3) < 0) __PYX_ERR(0, 127, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":128
 * SQLINT4 = SYBINT4
 * SQLINT8 = SYBINT8
 * SQLINTN = SYBINTN             # <<<<<<<<<<<<<<
 * SQLMONEY = SYBMONEY
 * SQLMONEY4 = SYBMONEY4
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBINTN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLINTN, __pyx_t_3) < 0) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":129
 * SQLINT8 = SYBINT8
 * SQLINTN = SYBINTN
 * SQLMONEY = SYBMONEY             # <<<<<<<<<<<<<<
 * SQLMONEY4 = SYBMONEY4
 * SQLMONEYN = SYBMONEYN
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBMONEY); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLMONEY, __pyx_t_3) < 0) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":130
 * SQLINTN = SYBINTN
 * SQLMONEY = SYBMONEY
 * SQLMONEY4 = SYBMONEY4             # <<<<<<<<<<<<<<
 * SQLMONEYN = SYBMONEYN
 * SQLNUMERIC = SYBNUMERIC
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBMONEY4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 130, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLMONEY4, __pyx_t_3) < 0) __PYX_ERR(0, 130, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":131
 * SQLMONEY = SYBMONEY
 * SQLMONEY4 = SYBMONEY4
 * SQLMONEYN = SYBMONEYN             # <<<<<<<<<<<<<<
 * SQLNUMERIC = SYBNUMERIC
 * SQLREAL = SYBREAL
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBMONEYN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLMONEYN, __pyx_t_3) < 0) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":132
 * SQLMONEY4 = SYBMONEY4
 * SQLMONEYN = SYBMONEYN
 * SQLNUMERIC = SYBNUMERIC             # <<<<<<<<<<<<<<
 * SQLREAL = SYBREAL
 * SQLTEXT = SYBTEXT
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBNUMERIC); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLNUMERIC, __pyx_t_3) < 0) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":133
 * SQLMONEYN = SYBMONEYN
 * SQLNUMERIC = SYBNUMERIC
 * SQLREAL = SYBREAL             # <<<<<<<<<<<<<<
 * SQLTEXT = SYBTEXT
 * SQLVARBINARY = SYBVARBINARY
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBREAL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLREAL, __pyx_t_3) < 0) __PYX_ERR(0, 133, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":134
 * SQLNUMERIC = SYBNUMERIC
 * SQLREAL = SYBREAL
 * SQLTEXT = SYBTEXT             # <<<<<<<<<<<<<<
 * SQLVARBINARY = SYBVARBINARY
 * SQLVARCHAR = SYBVARCHAR
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBTEXT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLTEXT, __pyx_t_3) < 0) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":135
 * SQLREAL = SYBREAL
 * SQLTEXT = SYBTEXT
 * SQLVARBINARY = SYBVARBINARY             # <<<<<<<<<<<<<<
 * SQLVARCHAR = SYBVARCHAR
 * SQLUUID = 36
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBVARBINARY); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLVARBINARY, __pyx_t_3) < 0) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":136
 * SQLTEXT = SYBTEXT
 * SQLVARBINARY = SYBVARBINARY
 * SQLVARCHAR = SYBVARCHAR             # <<<<<<<<<<<<<<
 * SQLUUID = 36
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(SYBVARCHAR); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLVARCHAR, __pyx_t_3) < 0) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":137
 * SQLVARBINARY = SYBVARBINARY
 * SQLVARCHAR = SYBVARCHAR
 * SQLUUID = 36             # <<<<<<<<<<<<<<
 * 
 * #######################
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SQLUUID, __pyx_int_36) < 0) __PYX_ERR(0, 137, __pyx_L1_error)

  /* "_mssql.pyx":184
 * 
 * # Module attributes for configuring _mssql
 * login_timeout = 60             # <<<<<<<<<<<<<<
 * 
 * min_error_severity = 6
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_login_timeout, __pyx_int_60) < 0) __PYX_ERR(0, 184, __pyx_L1_error)

  /* "_mssql.pyx":186
 * login_timeout = 60
 * 
 * min_error_severity = 6             # <<<<<<<<<<<<<<
 * 
 * wait_callback = None
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_min_error_severity, __pyx_int_6) < 0) __PYX_ERR(0, 186, __pyx_L1_error)

  /* "_mssql.pyx":188
 * min_error_severity = 6
 * 
 * wait_callback = None             # <<<<<<<<<<<<<<
 * 
 * def set_wait_callback(a_callable):
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_wait_callback, Py_None) < 0) __PYX_ERR(0, 188, __pyx_L1_error)

  /* "_mssql.pyx":190
 * wait_callback = None
 * 
 * def set_wait_callback(a_callable):             # <<<<<<<<<<<<<<
 *     global wait_callback
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_1set_wait_callback, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_wait_callback, __pyx_t_3) < 0) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":209
 *         fprintf(stderr, "+++ %s\n", message)
 * 
 * if PY_MAJOR_VERSION == '3':             # <<<<<<<<<<<<<<
 *     string_types = str,
 * else:
 */
  __pyx_t_5 = ((PY_MAJOR_VERSION == '3') != 0);
  if (__pyx_t_5) {

    /* "_mssql.pyx":210
 * 
 * if PY_MAJOR_VERSION == '3':
 *     string_types = str,             # <<<<<<<<<<<<<<
 * else:
 *     string_types = basestring,
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 210, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)(&PyString_Type)));
    __Pyx_GIVEREF(((PyObject *)(&PyString_Type)));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)(&PyString_Type)));
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_string_types, __pyx_t_3) < 0) __PYX_ERR(0, 210, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "_mssql.pyx":209
 *         fprintf(stderr, "+++ %s\n", message)
 * 
 * if PY_MAJOR_VERSION == '3':             # <<<<<<<<<<<<<<
 *     string_types = str,
 * else:
 */
    goto __pyx_L2;
  }

  /* "_mssql.pyx":212
 *     string_types = str,
 * else:
 *     string_types = basestring,             # <<<<<<<<<<<<<<
 * 
 * ###################
 */
  /*else*/ {
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)(&PyBaseString_Type)));
    __Pyx_GIVEREF(((PyObject *)(&PyBaseString_Type)));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)(&PyBaseString_Type)));
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_string_types, __pyx_t_3) < 0) __PYX_ERR(0, 212, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_L2:;

  /* "_mssql.pyx":1685
 *     return stripped
 * 
 * def remove_locale(bytes value):             # <<<<<<<<<<<<<<
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_3remove_locale, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_remove_locale, __pyx_t_3) < 0) __PYX_ERR(0, 1685, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1805
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')
 * 
 * _re_pos_param = re.compile(br'(%([sd]))')             # <<<<<<<<<<<<<<
 * _re_name_param = re.compile(br'(%\(([^\)]+)\)(?:[sd]))')
 * cdef _substitute_params(toformat, params, charset):
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1805, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_compile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1805, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1805, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re_pos_param, __pyx_t_3) < 0) __PYX_ERR(0, 1805, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1806
 * 
 * _re_pos_param = re.compile(br'(%([sd]))')
 * _re_name_param = re.compile(br'(%\(([^\)]+)\)(?:[sd]))')             # <<<<<<<<<<<<<<
 * cdef _substitute_params(toformat, params, charset):
 *     if params is None:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1806, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_compile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1806, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1806, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re_name_param, __pyx_t_3) < 0) __PYX_ERR(0, 1806, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1886
 * # We'll add these methods to the module to allow for unit testing of the
 * # underlying C methods.
 * def quote_simple_value(value):             # <<<<<<<<<<<<<<
 *     return _quote_simple_value(value)
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_5quote_simple_value, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_quote_simple_value, __pyx_t_3) < 0) __PYX_ERR(0, 1886, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1889
 *     return _quote_simple_value(value)
 * 
 * def quote_or_flatten(data):             # <<<<<<<<<<<<<<
 *     return _quote_or_flatten(data)
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_7quote_or_flatten, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1889, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_quote_or_flatten, __pyx_t_3) < 0) __PYX_ERR(0, 1889, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1892
 *     return _quote_or_flatten(data)
 * 
 * def quote_data(data):             # <<<<<<<<<<<<<<
 *     return _quote_data(data)
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_9quote_data, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1892, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_quote_data, __pyx_t_3) < 0) __PYX_ERR(0, 1892, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1895
 *     return _quote_data(data)
 * 
 * def substitute_params(toformat, params, charset='utf8'):             # <<<<<<<<<<<<<<
 *     return _substitute_params(toformat, params, charset)
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_11substitute_params, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1895, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_substitute_params, __pyx_t_3) < 0) __PYX_ERR(0, 1895, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1901
 * ## Compatibility Aliases ##
 * ###########################
 * def connect(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return MSSQLConnection(*args, **kwargs)
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_13connect, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1901, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_connect, __pyx_t_3) < 0) __PYX_ERR(0, 1901, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1904
 *     return MSSQLConnection(*args, **kwargs)
 * 
 * MssqlDatabaseException = MSSQLDatabaseException             # <<<<<<<<<<<<<<
 * MssqlDriverException = MSSQLDriverException
 * MssqlConnection = MSSQLConnection
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MssqlDatabaseException, ((PyObject *)__pyx_ptype_6_mssql_MSSQLDatabaseException)) < 0) __PYX_ERR(0, 1904, __pyx_L1_error)

  /* "_mssql.pyx":1905
 * 
 * MssqlDatabaseException = MSSQLDatabaseException
 * MssqlDriverException = MSSQLDriverException             # <<<<<<<<<<<<<<
 * MssqlConnection = MSSQLConnection
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MssqlDriverException, ((PyObject *)__pyx_ptype_6_mssql_MSSQLDriverException)) < 0) __PYX_ERR(0, 1905, __pyx_L1_error)

  /* "_mssql.pyx":1906
 * MssqlDatabaseException = MSSQLDatabaseException
 * MssqlDriverException = MSSQLDriverException
 * MssqlConnection = MSSQLConnection             # <<<<<<<<<<<<<<
 * 
 * ###########################
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MssqlConnection, ((PyObject *)__pyx_ptype_6_mssql_MSSQLConnection)) < 0) __PYX_ERR(0, 1906, __pyx_L1_error)

  /* "_mssql.pyx":1912
 * ###########################
 * 
 * def test_err_handler(connection, int severity, int dberr, int oserr, dberrstr, oserrstr):             # <<<<<<<<<<<<<<
 *     """
 *     Expose err_handler function and its side effects to facilitate testing.
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_15test_err_handler, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1912, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test_err_handler, __pyx_t_3) < 0) __PYX_ERR(0, 1912, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1941
 * ## Max Connections ##
 * #####################
 * def get_max_connections():             # <<<<<<<<<<<<<<
 *     """
 *     Get maximum simultaneous connections db-lib will open to the server.
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_17get_max_connections, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1941, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_max_connections, __pyx_t_3) < 0) __PYX_ERR(0, 1941, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1947
 *     return dbgetmaxprocs()
 * 
 * def set_max_connections(int limit):             # <<<<<<<<<<<<<<
 *     """
 *     Set maximum simultaneous connections db-lib will open to the server.
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_19set_max_connections, NULL, __pyx_n_s_mssql); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1947, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_max_connections, __pyx_t_3) < 0) __PYX_ERR(0, 1947, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1963
 *     dbmsghandle(msg_handler)
 * 
 * init_mssql()             # <<<<<<<<<<<<<<
 */
  __pyx_f_6_mssql_init_mssql();

  /* "_mssql.pyx":1
 * """             # <<<<<<<<<<<<<<
 * This is an effort to convert the pymssql low-level C module to Cython.
 * """
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init _mssql", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init _mssql");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* SaveResetException */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* PyErrExceptionMatches */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    return PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* GetException */
  #if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
#endif
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_COMPILING_IN_CPYTHON
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* GetModuleGlobalName */
    static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

/* PyObjectCallNoArg */
      #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* PyErrFetchRestore */
        #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* WriteUnraisableException */
        static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* RaiseArgTupleInvalid */
        static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
        static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
        static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* ExtTypeTest */
        static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

/* decode_c_string */
        static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
    Py_ssize_t length;
    if (unlikely((start < 0) | (stop < 0))) {
        size_t slen = strlen(cstring);
        if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) {
            PyErr_SetString(PyExc_OverflowError,
                            "c-string too long to convert to Python");
            return NULL;
        }
        length = (Py_ssize_t) slen;
        if (start < 0) {
            start += length;
            if (start < 0)
                start = 0;
        }
        if (stop < 0)
            stop += length;
    }
    length = stop - start;
    if (unlikely(length <= 0))
        return PyUnicode_FromUnicode(NULL, 0);
    cstring += start;
    if (decode_func) {
        return decode_func(cstring, length, errors);
    } else {
        return PyUnicode_Decode(cstring, length, encoding, errors);
    }
}

/* RaiseException */
        #if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* KeywordStringCheck */
          static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CYTHON_COMPILING_IN_PYPY
    if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

/* RaiseTooManyValuesToUnpack */
          static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
          static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
          static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

/* UnpackItemEndCheck */
          static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

/* BytesEquals */
          static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* UnicodeEquals */
          static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* StringJoin */
          #if !CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) {
    return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL);
}
#endif

/* PyIntBinop */
          #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            if (unlikely(b == -1 && ((unsigned long)a) == 0-(unsigned long)a))
                return PyInt_Type.tp_as_number->nb_floor_divide(op1, op2);
            else {
                long q, r;
                q = a / b;
                r = a - q*b;
                q -= ((r != 0) & ((r ^ b) < 0));
                x = q;
            }
            return PyInt_FromLong(x);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                default: return PyLong_Type.tp_as_number->nb_floor_divide(op1, op2);
            }
        }
                {
                    long q, r;
                    q = a / b;
                    r = a - q*b;
                    q -= ((r != 0) & ((r ^ b) < 0));
                    x = q;
                }
            return PyLong_FromLong(x);
        long_long:
                {
                    PY_LONG_LONG q, r;
                    q = lla / llb;
                    r = lla - q*llb;
                    q -= ((r != 0) & ((r ^ llb) < 0));
                    llx = q;
                }
            return PyLong_FromLongLong(llx);
    }
    #endif
    return (inplace ? PyNumber_InPlaceFloorDivide : PyNumber_FloorDivide)(op1, op2);
}
#endif

/* GetItemInt */
          static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* SwapException */
          #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = *type;
    tstate->exc_value = *value;
    tstate->exc_traceback = *tb;
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#endif

/* None */
          static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* ArgTypeTest */
          static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
}
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (likely(Py_TYPE(obj) == type)) return 1;
        #if PY_MAJOR_VERSION == 2
        else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(PyObject_TypeCheck(obj, type))) return 1;
    }
    __Pyx_RaiseArgumentTypeInvalid(name, obj, type);
    return 0;
}

/* PyObjectCallMethod0 */
          static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *function = PyMethod_GET_FUNCTION(method);
            result = __Pyx_PyObject_CallOneArg(function, self);
            Py_DECREF(method);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallNoArg(method);
    Py_DECREF(method);
bad:
    return result;
}

/* RaiseNoneIterError */
          static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* UnpackTupleError */
          static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
    if (t == Py_None) {
      __Pyx_RaiseNoneNotIterableError();
    } else if (PyTuple_GET_SIZE(t) < index) {
      __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
    } else {
      __Pyx_RaiseTooManyValuesError(index);
    }
}

/* UnpackTuple2 */
          static CYTHON_INLINE int __Pyx_unpack_tuple2(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
                                             int is_tuple, int has_known_size, int decref_tuple) {
    Py_ssize_t index;
    PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
    if (!is_tuple && unlikely(!PyTuple_Check(tuple))) {
        iternextfunc iternext;
        iter = PyObject_GetIter(tuple);
        if (unlikely(!iter)) goto bad;
        if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
        iternext = Py_TYPE(iter)->tp_iternext;
        value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
        value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
        if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
        Py_DECREF(iter);
    } else {
        if (!has_known_size && unlikely(PyTuple_GET_SIZE(tuple) != 2)) {
            __Pyx_UnpackTupleError(tuple, 2);
            goto bad;
        }
#if CYTHON_COMPILING_IN_PYPY
        value1 = PySequence_ITEM(tuple, 0);
        if (unlikely(!value1)) goto bad;
        value2 = PySequence_ITEM(tuple, 1);
        if (unlikely(!value2)) goto bad;
#else
        value1 = PyTuple_GET_ITEM(tuple, 0);
        value2 = PyTuple_GET_ITEM(tuple, 1);
        Py_INCREF(value1);
        Py_INCREF(value2);
#endif
        if (decref_tuple) { Py_DECREF(tuple); }
    }
    *pvalue1 = value1;
    *pvalue2 = value2;
    return 0;
unpacking_failed:
    if (!has_known_size && __Pyx_IterFinish() == 0)
        __Pyx_RaiseNeedMoreValuesError(index);
bad:
    Py_XDECREF(iter);
    Py_XDECREF(value1);
    Py_XDECREF(value2);
    if (decref_tuple) { Py_XDECREF(tuple); }
    return -1;
}

/* dict_iter */
          static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_source_is_dict) {
    is_dict = is_dict || likely(PyDict_CheckExact(iterable));
    *p_source_is_dict = is_dict;
#if !CYTHON_COMPILING_IN_PYPY
    if (is_dict) {
        *p_orig_length = PyDict_Size(iterable);
        Py_INCREF(iterable);
        return iterable;
    }
#endif
    *p_orig_length = 0;
    if (method_name) {
        PyObject* iter;
        iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
        if (!iterable)
            return NULL;
#if !CYTHON_COMPILING_IN_PYPY
        if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
            return iterable;
#endif
        iter = PyObject_GetIter(iterable);
        Py_DECREF(iterable);
        return iter;
    }
    return PyObject_GetIter(iterable);
}
static CYTHON_INLINE int __Pyx_dict_iter_next(
        PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
        PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
    PyObject* next_item;
#if !CYTHON_COMPILING_IN_PYPY
    if (source_is_dict) {
        PyObject *key, *value;
        if (unlikely(orig_length != PyDict_Size(iter_obj))) {
            PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
            return -1;
        }
        if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
            return 0;
        }
        if (pitem) {
            PyObject* tuple = PyTuple_New(2);
            if (unlikely(!tuple)) {
                return -1;
            }
            Py_INCREF(key);
            Py_INCREF(value);
            PyTuple_SET_ITEM(tuple, 0, key);
            PyTuple_SET_ITEM(tuple, 1, value);
            *pitem = tuple;
        } else {
            if (pkey) {
                Py_INCREF(key);
                *pkey = key;
            }
            if (pvalue) {
                Py_INCREF(value);
                *pvalue = value;
            }
        }
        return 1;
    } else if (PyTuple_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyTuple_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else if (PyList_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyList_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else
#endif
    {
        next_item = PyIter_Next(iter_obj);
        if (unlikely(!next_item)) {
            return __Pyx_IterFinish();
        }
    }
    if (pitem) {
        *pitem = next_item;
    } else if (pkey && pvalue) {
        if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
            return -1;
    } else if (pkey) {
        *pkey = next_item;
    } else {
        *pvalue = next_item;
    }
    return 1;
}

/* PyObjectCallMethod1 */
          static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            args = PyTuple_New(2);
            if (unlikely(!args)) goto bad;
            Py_INCREF(self);
            PyTuple_SET_ITEM(args, 0, self);
            Py_INCREF(arg);
            PyTuple_SET_ITEM(args, 1, arg);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
bad:
    Py_XDECREF(method);
    return result;
}

/* append */
          static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

/* SliceObject */
          static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_COMPILING_IN_CPYTHON
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

/* PyIntBinop */
          #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* CallNextTpDealloc */
          static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc) {
    PyTypeObject* type = Py_TYPE(obj);
    while (type && type->tp_dealloc != current_tp_dealloc)
        type = type->tp_base;
    while (type && type->tp_dealloc == current_tp_dealloc)
        type = type->tp_base;
    if (type)
        type->tp_dealloc(obj);
}

/* SetVTable */
          static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

/* Import */
          static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* ImportFrom */
          static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* CodeObjectCache */
          static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

/* AddTraceback */
          #include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

/* CIntFromPyVerify */
          #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(PY_LONG_LONG) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(PY_LONG_LONG) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(PY_LONG_LONG),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_BYTE(BYTE value) {
    const BYTE neg_one = (BYTE) -1, const_zero = (BYTE) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(BYTE) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(BYTE) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(BYTE) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(BYTE) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(BYTE) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(BYTE),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_DBINT(DBINT value) {
    const DBINT neg_one = (DBINT) -1, const_zero = (DBINT) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(DBINT) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(DBINT) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(DBINT) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(DBINT) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(DBINT) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(DBINT),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
          static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntFromPy */
          static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(PY_LONG_LONG) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (PY_LONG_LONG) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (PY_LONG_LONG) 0;
                case  1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, digits[0])
                case 2:
                    if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) >= 2 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) (((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) >= 3 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) (((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) >= 4 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) (((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (PY_LONG_LONG) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (PY_LONG_LONG) 0;
                case -1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) ((((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) ((((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                            return (PY_LONG_LONG) ((((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(PY_LONG_LONG) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, long, PyLong_AsLong(x))
            } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            PY_LONG_LONG val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (PY_LONG_LONG) -1;
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (PY_LONG_LONG) -1;
        val = __Pyx_PyInt_As_PY_LONG_LONG(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to PY_LONG_LONG");
    return (PY_LONG_LONG) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to PY_LONG_LONG");
    return (PY_LONG_LONG) -1;
}

/* CIntFromPy */
          static CYTHON_INLINE DBINT __Pyx_PyInt_As_DBINT(PyObject *x) {
    const DBINT neg_one = (DBINT) -1, const_zero = (DBINT) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(DBINT) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(DBINT, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (DBINT) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (DBINT) 0;
                case  1: __PYX_VERIFY_RETURN_INT(DBINT, digit, digits[0])
                case 2:
                    if (8 * sizeof(DBINT) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) >= 2 * PyLong_SHIFT) {
                            return (DBINT) (((((DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(DBINT) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) >= 3 * PyLong_SHIFT) {
                            return (DBINT) (((((((DBINT)digits[2]) << PyLong_SHIFT) | (DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(DBINT) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) >= 4 * PyLong_SHIFT) {
                            return (DBINT) (((((((((DBINT)digits[3]) << PyLong_SHIFT) | (DBINT)digits[2]) << PyLong_SHIFT) | (DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (DBINT) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(DBINT) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(DBINT, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(DBINT) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(DBINT, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (DBINT) 0;
                case -1: __PYX_VERIFY_RETURN_INT(DBINT, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(DBINT,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(DBINT) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) - 1 > 2 * PyLong_SHIFT) {
                            return (DBINT) (((DBINT)-1)*(((((DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(DBINT) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) - 1 > 2 * PyLong_SHIFT) {
                            return (DBINT) ((((((DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(DBINT) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) - 1 > 3 * PyLong_SHIFT) {
                            return (DBINT) (((DBINT)-1)*(((((((DBINT)digits[2]) << PyLong_SHIFT) | (DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(DBINT) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) - 1 > 3 * PyLong_SHIFT) {
                            return (DBINT) ((((((((DBINT)digits[2]) << PyLong_SHIFT) | (DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(DBINT) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) - 1 > 4 * PyLong_SHIFT) {
                            return (DBINT) (((DBINT)-1)*(((((((((DBINT)digits[3]) << PyLong_SHIFT) | (DBINT)digits[2]) << PyLong_SHIFT) | (DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(DBINT) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(DBINT, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(DBINT) - 1 > 4 * PyLong_SHIFT) {
                            return (DBINT) ((((((((((DBINT)digits[3]) << PyLong_SHIFT) | (DBINT)digits[2]) << PyLong_SHIFT) | (DBINT)digits[1]) << PyLong_SHIFT) | (DBINT)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(DBINT) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(DBINT, long, PyLong_AsLong(x))
            } else if (sizeof(DBINT) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(DBINT, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            DBINT val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (DBINT) -1;
        }
    } else {
        DBINT val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (DBINT) -1;
        val = __Pyx_PyInt_As_DBINT(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to DBINT");
    return (DBINT) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to DBINT");
    return (DBINT) -1;
}

/* CIntFromPy */
          static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CIntFromPy */
          static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) {
    const char neg_one = (char) -1, const_zero = (char) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(char) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (char) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case  1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0])
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) {
                            return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) {
                            return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 4 * PyLong_SHIFT) {
                            return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (char) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(char) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(char,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(char) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x))
            } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            char val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (char) -1;
        }
    } else {
        char val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (char) -1;
        val = __Pyx_PyInt_As_char(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to char");
    return (char) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to char");
    return (char) -1;
}

/* CheckBinaryVersion */
          static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* FunctionExport */
          static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
    if (!d) {
        PyErr_Clear();
        d = PyDict_New();
        if (!d)
            goto bad;
        Py_INCREF(d);
        if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
            goto bad;
    }
    tmp.fp = f;
#if PY_VERSION_HEX >= 0x02070000
    cobj = PyCapsule_New(tmp.p, sig, 0);
#else
    cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
#endif
    if (!cobj)
        goto bad;
    if (PyDict_SetItemString(d, name, cobj) < 0)
        goto bad;
    Py_DECREF(cobj);
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(cobj);
    Py_XDECREF(d);
    return -1;
}

/* ModuleImport */
          #ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

/* TypeImport */
          #ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

/* InitStrings */
          static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_LENGTH(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else
        return PyUnicode_AsUTF8AndSize(o, length);
#endif
#endif
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return __Pyx_NewRef(x);
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(x);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
