/* Generated by Cython 0.19.1 on Wed Oct 23 00:37:34 2013 */

#define PY_SSIZE_T_CLEAN
#ifndef CYTHON_USE_PYLONG_INTERNALS
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 0
#else
#include "pyconfig.h"
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 1
#else
#define CYTHON_USE_PYLONG_INTERNALS 0
#endif
#endif
#endif
#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 < 0x02040000
    #error Cython requires Python 2.4+.
#else
#include <stddef.h> /* For offsetof */
#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 PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define CYTHON_FORMAT_SSIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   __Pyx_PyInt_AsInt(o)
  #define PyNumber_Index(o)    ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
                                (PyErr_Format(PyExc_TypeError, \
                                              "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
                                 (PyObject*)0))
  #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
                                  !PyComplex_Check(o))
  #define PyIndex_Check __Pyx_PyIndex_Check
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
  #define __PYX_BUILD_PY_SSIZE_T "i"
#else
  #define __PYX_BUILD_PY_SSIZE_T "n"
  #define CYTHON_FORMAT_SSIZE_T "z"
  #define __Pyx_PyIndex_Check PyIndex_Check
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)
  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;
  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
  #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
  #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
  typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
#endif
#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, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#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)
#endif
#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
  #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_TPFLAGS_HAVE_VERSION_TAG 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_READ(k, d, i)   PyUnicode_READ(k, d, i)
#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_READ(k, d, i)   ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#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_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
#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_CheckExact(obj) || PyUnicode_CheckExact(obj) || \
                                         PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (Py_TYPE(obj) == &PyBaseString_Type)
#endif
#if PY_VERSION_HEX < 0x02060000
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#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
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_VERSION_HEX < 0x03020000
  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) || (PY_VERSION_HEX >= 0x03010300)
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif
#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
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER)
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
   a quiet NaN. */
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif


#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

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE___mssql
#define __PYX_HAVE_API___mssql
#include "string.h"
#include "stdio.h"
#include "pythread.h"
#include "sqlfront.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
typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/

#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
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(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_AsUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromUString(s)  __Pyx_PyObject_FromString((char*)s)
#define __Pyx_PyBytes_FromUString(s)   __Pyx_PyBytes_FromString((char*)s)
#define __Pyx_PyStr_FromUString(s)     __Pyx_PyStr_FromString((char*)s)
#define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((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 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_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
#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 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params() {
    PyObject* sys = NULL;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    sys = PyImport_ImportModule("sys");
    if (sys == NULL) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    if (default_encoding == NULL) goto bad;
    if (strcmp(PyBytes_AsString(default_encoding), "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        const char* default_encoding_c = PyBytes_AS_STRING(default_encoding);
        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 == NULL) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (ascii_chars_b == NULL || strncmp(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 '%s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
    }
    Py_XDECREF(sys);
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return 0;
bad:
    Py_XDECREF(sys);
    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() {
    PyObject* sys = NULL;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (sys == NULL) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    if (default_encoding == NULL) goto bad;
    default_encoding_c = PyBytes_AS_STRING(default_encoding);
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(sys);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(sys);
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


#ifdef __GNUC__
  /* Test for GCC > 2.95 */
  #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
    #define likely(x)   __builtin_expect(!!(x), 1)
    #define unlikely(x) __builtin_expect(!!(x), 0)
  #else /* __GNUC__ > 2 ... */
    #define likely(x)   (x)
    #define unlikely(x) (x)
  #endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
  #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 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":655
 *     RETCODE DBSETLVERSION(LOGINREC *login, BYTE version)
 * 
 * ctypedef int LINE_T             # <<<<<<<<<<<<<<
 */
typedef int __pyx_t_8sqlfront_LINE_T;

/*--- Type declarations ---*/
struct __pyx_obj_6_mssql_MSSQLRowIterator;
struct __pyx_obj_6_mssql_MSSQLConnection;
struct __pyx_obj_6_mssql_MSSQLException;
struct __pyx_obj_6_mssql_MSSQLStoredProcedure;
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":37
 *     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":38
 *     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":39
 *     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)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_row {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pxd":40
 *     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)
 *     cdef fetch_next_row_dict(self, int)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_execute_scalar {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pxd":43
 *     cdef fetch_next_row(self, int)
 *     cdef fetch_next_row_dict(self, 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":44
 *     cdef fetch_next_row_dict(self, 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)
 */
struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_sql_command {
  int __pyx_n;
  PyObject *params;
};

/* "_mssql.pyx":179
 * 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":1548
 * ## 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":1597
 *     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":1619
 * # 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":48
 *     cdef get_row(self, int)
 * 
 * cdef class MSSQLRowIterator:             # <<<<<<<<<<<<<<
 *     cdef MSSQLConnection conn
 * 
 */
struct __pyx_obj_6_mssql_MSSQLRowIterator {
  PyObject_HEAD
  struct __pyx_obj_6_mssql_MSSQLConnection *conn;
};


/* "_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;
};


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


/* "_mssql.pxd":51
 *     cdef MSSQLConnection conn
 * 
 * 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":132
 *     """
 * 
 * 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":138
 *     """
 * 
 * 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":359
 * ## 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);
  PyObject *(*fetch_next_row_dict)(struct __pyx_obj_6_mssql_MSSQLConnection *, 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);
};
static struct __pyx_vtabstruct_6_mssql_MSSQLConnection *__pyx_vtabptr_6_mssql_MSSQLConnection;
#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); /*proto*/
  #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 /* CYTHON_REFNANNY */
#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)

#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

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

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif

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

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

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

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

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
    const char* function_name); /*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); /*proto*/

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*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));

#include <string.h>

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

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

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

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

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

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*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

#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

#define __Pyx_GetItemInt(o, i, size, to_py_func, is_list, wraparound, boundscheck) \
    (((size) <= sizeof(Py_ssize_t)) ? \
    __Pyx_GetItemInt_Fast(o, i, is_list, wraparound, boundscheck) : \
    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
#define __Pyx_GetItemInt_List(o, i, size, to_py_func, is_list, wraparound, boundscheck) \
    (((size) <= sizeof(Py_ssize_t)) ? \
    __Pyx_GetItemInt_List_Fast(o, i, wraparound, boundscheck) : \
    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func, is_list, wraparound, boundscheck) \
    (((size) <= sizeof(Py_ssize_t)) ? \
    __Pyx_GetItemInt_Tuple_Fast(o, i, wraparound, boundscheck) : \
    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
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);

#define __Pyx_SetItemInt(o, i, v, size, to_py_func, is_list, wraparound, boundscheck) \
    (((size) <= sizeof(Py_ssize_t)) ? \
    __Pyx_SetItemInt_Fast(o, i, v, is_list, wraparound, boundscheck) : \
    __Pyx_SetItemInt_Generic(o, to_py_func(i), v))
static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
                                               int is_list, int wraparound, int boundscheck);

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

static PyObject* __Pyx_PyObject_CallMethodTuple(PyObject* obj, PyObject* method_name, PyObject* args) {
    PyObject *method, *result = NULL;
    if (unlikely(!args)) return NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
    result = PyObject_Call(method, args, NULL);
    Py_DECREF(method);
bad:
    Py_DECREF(args);
    return result;
}
#define __Pyx_PyObject_CallMethod3(obj, name, arg1, arg2, arg3) \
    __Pyx_PyObject_CallMethodTuple(obj, name, PyTuple_Pack(3, arg1, arg2, arg3))
#define __Pyx_PyObject_CallMethod2(obj, name, arg1, arg2) \
    __Pyx_PyObject_CallMethodTuple(obj, name, PyTuple_Pack(2, arg1, arg2))
#define __Pyx_PyObject_CallMethod1(obj, name, arg1) \
    __Pyx_PyObject_CallMethodTuple(obj, name, PyTuple_Pack(1, arg1))
#define __Pyx_PyObject_CallMethod0(obj, name) \
    __Pyx_PyObject_CallMethodTuple(obj, name, (Py_INCREF(__pyx_empty_tuple), __pyx_empty_tuple))

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

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

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

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);

static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x); /*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);

static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc);

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

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

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

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_PY_LONG_LONG(PY_LONG_LONG);

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_DBINT(DBINT);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_from_py_PY_LONG_LONG(PyObject *);

static CYTHON_INLINE DBINT __Pyx_PyInt_from_py_DBINT(PyObject *);

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static int __Pyx_check_binary_version(void);

static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig); /*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

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

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

typedef struct {
    int code_line;
    PyCodeObject* code_object;
} __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);

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

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


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

/* 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 'libc.string' */

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

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

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

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

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

/* Module declarations from '__builtin__' */

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

/* 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_MSSQLRowIterator = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLConnection = 0;
static PyTypeObject *__pyx_ptype_6_mssql_Exception = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLException = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLStoredProcedure = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLDriverException = 0;
static PyTypeObject *__pyx_ptype_6_mssql_MSSQLDatabaseException = 0;
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 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 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 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); /* 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); /* 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__iter__(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_8cancel(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_10close(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_12execute_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_14execute_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_16execute_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_18execute_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_20get_header(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_22init_procedure(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, PyObject *__pyx_v_procname); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_24nextresult(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_26select_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_14get_max_connections(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6_mssql_16set_max_connections(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_limit); /* proto */
static PyObject *__pyx_tp_new_6_mssql_MSSQLRowIterator(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6_mssql_MSSQLConnection(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_MSSQLStoredProcedure(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 char __pyx_k_1[] = "SQL Server message %d, severity %d, state %d, procedure %s, line %d:\n%s";
static char __pyx_k_2[] = "SQL Server message %d, severity %d, state %d, line %d:\n%s";
static char __pyx_k_3[] = "utf-8";
static char __pyx_k_4[] = "%s DB-Lib error message %d, severity %d:\n%s\n";
static char __pyx_k_5[] = "Net-Lib";
static char __pyx_k_6[] = "Operating System";
static char __pyx_k_7[] = "%s error during %s";
static char __pyx_k_8[] = "SELECT SCOPE_IDENTITY()";
static char __pyx_k_9[] = "The 'query_timeout' attribute must be >= 0.";
static char __pyx_k_11[] = "_mssql.MSSQLConnection.__cinit__()";
static char __pyx_k_12[] = "";
static char __pyx_k_13[] = "UTF-8";
static char __pyx_k_14[] = "7.1";
static char __pyx_k_15[] = "_mssql.MSSQLConnection.__init__()";
static char __pyx_k_16[] = "\\";
static char __pyx_k_18[] = ".";
static char __pyx_k_19[] = "(local)";
static char __pyx_k_20[] = "Out of memory";
static char __pyx_k_25[] = ":";
static char __pyx_k_26[] = "%s:%s";
static char __pyx_k_29[] = "_mssql.MSSQLConnection.__init__() -> dbopen() returned NULL";
static char __pyx_k_30[] = "Connection to the database failed for an unknown reason.";
static char __pyx_k_32[] = "_mssql.MSSQLConnection.__init__() -> dbcmd() setting connection values";
static char __pyx_k_33[] = "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 char __pyx_k_34[] = "Could not set connection properties";
static char __pyx_k_36[] = "_mssql.MSSQLConnection.__dealloc__()";
static char __pyx_k_37[] = "_mssql.MSSQLConnection.cancel()";
static char __pyx_k_38[] = "_mssql.MSSQLConnection.clear_metadata()";
static char __pyx_k_39[] = "_mssql.MSSQLConnection.close()";
static char __pyx_k_40[] = "_mssql.MSSQLConnection.convert_db_value()";
static char __pyx_k_42[] = "_mssql.MSSQLConnection.convert_python_value()";
static char __pyx_k_43[] = "value cannot be larger than %d";
static char __pyx_k_44[] = "value can only be a date or datetime";
static char __pyx_k_46[] = "%Y-%m-%d %H:%M:%S.";
static char __pyx_k_48[] = "%03d";
static char __pyx_k_49[] = "value can only be a Decimal";
static char __pyx_k_51[] = "value must be a string type";
static char __pyx_k_53[] = "value can only be str";
static char __pyx_k_55[] = "Unable to convert value";
static char __pyx_k_57[] = "_mssql.MSSQLConnection.execute_non_query() BEGIN";
static char __pyx_k_58[] = "_mssql.MSSQLConnection.execute_non_query() END";
static char __pyx_k_59[] = "_mssql.MSSQLConnection.execute_query() BEGIN";
static char __pyx_k_60[] = "_mssql.MSSQLConnection.execute_query() END";
static char __pyx_k_61[] = "_mssql.MSSQLConnection.execute_row()";
static char __pyx_k_62[] = "_mssql.MSSQLConnection.execute_scalar()";
static char __pyx_k_63[] = "_mssql.MSSQLConnection.fetch_next_row() BEGIN";
static char __pyx_k_64[] = "_mssql.MSSQLConnection.fetch_next_row(): NO MORE RESULTS";
static char __pyx_k_65[] = "_mssql.MSSQLConnection.fetch_next_row(): NO MORE ROWS";
static char __pyx_k_66[] = "_mssql.MSSQLConnection.fetch_next_row() END";
static char __pyx_k_67[] = "_mssql.MSSQLConnection.fetch_next_row_dict()";
static char __pyx_k_68[] = "_mssql.MSSQLConnection.format_and_run_query() BEGIN";
static char __pyx_k_69[] = "#%s#\n";
static char __pyx_k_70[] = "_mssql.MSSQLConnection.format_and_run_query() END";
static char __pyx_k_71[] = "_mssql.MSSQLConnection.format_sql_command()";
static char __pyx_k_72[] = "_mssql.MSSQLConnection.get_header() BEGIN";
static char __pyx_k_73[] = "_mssql.MSSQLConnection.get_header(): num_columns == 0";
static char __pyx_k_74[] = "_mssql.MSSQLConnection.get_header() END";
static char __pyx_k_75[] = "_mssql.MSSQLConnection.get_result() BEGIN";
static char __pyx_k_76[] = "_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None";
static char __pyx_k_77[] = "_mssql.MSSQLConnection.get_result(): NO_MORE_RESULTS, return None";
static char __pyx_k_78[] = "_mssql.MSSQLConnection.get_result(): num_columns = %d";
static char __pyx_k_79[] = "_mssql.MSSQLConnection.get_result() END";
static char __pyx_k_80[] = "_mssql.MSSQLConnection.get_row()";
static char __pyx_k_82[] = "_mssql.MSSQLConnection.init_procedure()";
static char __pyx_k_83[] = "_mssql.MSSQLConnection.nextresult()";
static char __pyx_k_84[] = "_mssql.MSSQLConnection.select_db()";
static char __pyx_k_86[] = "_mssql.MSSQLStoredProcedure.__init__()";
static char __pyx_k_87[] = "Stored Procedures aren't supported with a TDS version less than 7.";
static char __pyx_k_89[] = "_mssql.MSSQLStoredProcedure.__dealloc__()";
static char __pyx_k_90[] = "_mssql.MSSQLStoredProcedure.bind()";
static char __pyx_k_93[] = "Cannot bind named parameter after positional";
static char __pyx_k_95[] = "_mssql.MSSQLStoredProcedure.execute()";
static char __pyx_k_96[] = "Unknown error";
static char __pyx_k_97[] = "_mssql.assert_connected()";
static char __pyx_k_98[] = "Not connected to any MS SQL server";
static char __pyx_k__0[] = "0";
static char __pyx_k__1[] = "1";
static char __pyx_k__l[] = "l";
static char __pyx_k__s[] = "s";
static char __pyx_k_100[] = "4.2";
static char __pyx_k_101[] = "7.0";
static char __pyx_k_102[] = "7.2";
static char __pyx_k_103[] = "8.0";
static char __pyx_k_104[] = "unrecognized tds version: %s";
static char __pyx_k_105[] = "N'";
static char __pyx_k_106[] = "'";
static char __pyx_k_107[] = "''";
static char __pyx_k_109[] = "\000";
static char __pyx_k_113[] = "{ts '%04d-%02d-%02d %02d:%02d:%02d.%03d'}";
static char __pyx_k_114[] = "{d '%04d-%02d-%02d'} ";
static char __pyx_k_115[] = "expected a simple type, a tuple or a list";
static char __pyx_k_117[] = "found an unsupported type";
static char __pyx_k_119[] = "(";
static char __pyx_k_120[] = ",";
static char __pyx_k_121[] = ")";
static char __pyx_k_122[] = "expected a simple type, a tuple or a dictionary.";
static char __pyx_k_124[] = "'params' arg (%r) can be only a tuple or a dictionary.";
static char __pyx_k_126[] = "params dictionary did not contain value for placeholder: %s";
static char __pyx_k_130[] = "more placeholders in sql than params available";
static char __pyx_k_134[] = "Could not initialize communication layer";
static char __pyx_k_136[] = "\n        The current encoding in use.\n        ";
static char __pyx_k_137[] = "\n        True if the connection to a database is open.\n        ";
static char __pyx_k_138[] = "\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        ";
static char __pyx_k_139[] = "\n        A\n        ";
static char __pyx_k_140[] = "\n        Number of rows affected by last query. For SELECT statements this\n        value is only meaningful after reading all rows.\n        ";
static char __pyx_k_141[] = "\n        Returns what TDS version the connection is using.\n        ";
static char __pyx_k_142[] = "The underlying MSSQLConnection object.";
static char __pyx_k_143[] = "The name of the procedure that this object represents.";
static char __pyx_k_144[] = "The parameters that have been bound to this procedure.";
static char __pyx_k_145[] = "\nThis is an effort to convert the pymssql low-level C module to Cython.\n";
static char __pyx_k_147[] = "1.9.909";
static char __pyx_k_150[] = "/Users/marca/dev/git-repos/pymssql/_mssql.pyx";
static char __pyx_k_153[] = "(%(s|d))";
static char __pyx_k_155[] = "(%\\(([^\\)]+)\\)s)";
static char __pyx_k_167[] = "MssqlDatabaseException";
static char __pyx_k_168[] = "MssqlDriverException";
static char __pyx_k__0x[] = "0x";
static char __pyx_k__os[] = "os";
static char __pyx_k__re[] = "re";
static char __pyx_k__sa[] = "sa";
static char __pyx_k__day[] = "day";
static char __pyx_k__end[] = "end";
static char __pyx_k__hex[] = "hex";
static char __pyx_k__sys[] = "sys";
static char __pyx_k__1433[] = "1433";
static char __pyx_k__NULL[] = "NULL";
static char __pyx_k__UUID[] = "UUID";
static char __pyx_k__args[] = "args";
static char __pyx_k__data[] = "data";
static char __pyx_k__date[] = "date";
static char __pyx_k__hour[] = "hour";
static char __pyx_k__join[] = "join";
static char __pyx_k__name[] = "name";
static char __pyx_k__null[] = "null";
static char __pyx_k__port[] = "port";
static char __pyx_k__prec[] = "prec";
static char __pyx_k__user[] = "user";
static char __pyx_k__utf8[] = "utf8";
static char __pyx_k__uuid[] = "uuid";
static char __pyx_k__year[] = "year";
static char __pyx_k__ascii[] = "ascii";
static char __pyx_k__close[] = "close";
static char __pyx_k__group[] = "group";
static char __pyx_k__limit[] = "limit";
static char __pyx_k__month[] = "month";
static char __pyx_k__range[] = "range";
static char __pyx_k__split[] = "split";
static char __pyx_k__start[] = "start";
static char __pyx_k__value[] = "value";
static char __pyx_k__write[] = "write";
static char __pyx_k__BINARY[] = "BINARY";
static char __pyx_k__NUMBER[] = "NUMBER";
static char __pyx_k__SQLBIT[] = "SQLBIT";
static char __pyx_k__STRING[] = "STRING";
static char __pyx_k___mssql[] = "_mssql";
static char __pyx_k__append[] = "append";
static char __pyx_k__cancel[] = "cancel";
static char __pyx_k__dbtype[] = "dbtype";
static char __pyx_k__decode[] = "decode";
static char __pyx_k__encode[] = "encode";
static char __pyx_k__kwargs[] = "kwargs";
static char __pyx_k__minute[] = "minute";
static char __pyx_k__output[] = "output";
static char __pyx_k__params[] = "params";
static char __pyx_k__remove[] = "remove";
static char __pyx_k__second[] = "second";
static char __pyx_k__server[] = "server";
static char __pyx_k__socket[] = "socket";
static char __pyx_k__stderr[] = "stderr";
static char __pyx_k__xrange[] = "xrange";
static char __pyx_k__DECIMAL[] = "DECIMAL";
static char __pyx_k__Decimal[] = "Decimal";
static char __pyx_k__SQLBITN[] = "SQLBITN";
static char __pyx_k__SQLCHAR[] = "SQLCHAR";
static char __pyx_k__SQLFLT4[] = "SQLFLT4";
static char __pyx_k__SQLFLT8[] = "SQLFLT8";
static char __pyx_k__SQLFLTN[] = "SQLFLTN";
static char __pyx_k__SQLINT1[] = "SQLINT1";
static char __pyx_k__SQLINT2[] = "SQLINT2";
static char __pyx_k__SQLINT4[] = "SQLINT4";
static char __pyx_k__SQLINT8[] = "SQLINT8";
static char __pyx_k__SQLINTN[] = "SQLINTN";
static char __pyx_k__SQLREAL[] = "SQLREAL";
static char __pyx_k__SQLTEXT[] = "SQLTEXT";
static char __pyx_k__SQLUUID[] = "SQLUUID";
static char __pyx_k__appname[] = "appname";
static char __pyx_k__charset[] = "charset";
static char __pyx_k__compile[] = "compile";
static char __pyx_k__connect[] = "connect";
static char __pyx_k__decimal[] = "decimal";
static char __pyx_k__hexlify[] = "hexlify";
static char __pyx_k__pymssql[] = "pymssql";
static char __pyx_k__replace[] = "replace";
static char __pyx_k__DATETIME[] = "DATETIME";
static char __pyx_k__SQLIMAGE[] = "SQLIMAGE";
static char __pyx_k__SQLMONEY[] = "SQLMONEY";
static char __pyx_k____exit__[] = "__exit__";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__as_tuple[] = "as_tuple";
static char __pyx_k__binascii[] = "binascii";
static char __pyx_k__bytes_le[] = "bytes_le";
static char __pyx_k__database[] = "database";
static char __pyx_k__datetime[] = "datetime";
static char __pyx_k__exponent[] = "exponent";
static char __pyx_k__finditer[] = "finditer";
static char __pyx_k__password[] = "password";
static char __pyx_k__strftime[] = "strftime";
static char __pyx_k__toformat[] = "toformat";
static char __pyx_k__SQLBINARY[] = "SQLBINARY";
static char __pyx_k__SQLMONEY4[] = "SQLMONEY4";
static char __pyx_k__SQLMONEYN[] = "SQLMONEYN";
static char __pyx_k__TypeError[] = "TypeError";
static char __pyx_k____enter__[] = "__enter__";
static char __pyx_k__connected[] = "connected";
static char __pyx_k__enumerate[] = "enumerate";
static char __pyx_k__iteritems[] = "iteritems";
static char __pyx_k__localhost[] = "localhost";
static char __pyx_k__select_db[] = "select_db";
static char __pyx_k__IndexError[] = "IndexError";
static char __pyx_k__SQLDECIMAL[] = "SQLDECIMAL";
static char __pyx_k__SQLNUMERIC[] = "SQLNUMERIC";
static char __pyx_k__SQLVARCHAR[] = "SQLVARCHAR";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k____import__[] = "__import__";
static char __pyx_k__a_callable[] = "a_callable";
static char __pyx_k__connection[] = "connection";
static char __pyx_k__max_length[] = "max_length";
static char __pyx_k__param_name[] = "param_name";
static char __pyx_k__quote_data[] = "quote_data";
static char __pyx_k__startswith[] = "startswith";
static char __pyx_k__SQLDATETIM4[] = "SQLDATETIM4";
static char __pyx_k__SQLDATETIME[] = "SQLDATETIME";
static char __pyx_k__SQLDATETIMN[] = "SQLDATETIMN";
static char __pyx_k____version__[] = "__version__";
static char __pyx_k__execute_row[] = "execute_row";
static char __pyx_k__gethostname[] = "gethostname";
static char __pyx_k__microsecond[] = "microsecond";
static char __pyx_k__tds_version[] = "tds_version";
static char __pyx_k__SQLVARBINARY[] = "SQLVARBINARY";
static char __pyx_k__localcontext[] = "localcontext";
static char __pyx_k__query_string[] = "query_string";
static char __pyx_k__StopIteration[] = "StopIteration";
static char __pyx_k___re_pos_param[] = "_re_pos_param";
static char __pyx_k__execute_query[] = "execute_query";
static char __pyx_k__login_timeout[] = "login_timeout";
static char __pyx_k__remove_locale[] = "remove_locale";
static char __pyx_k__wait_callback[] = "wait_callback";
static char __pyx_k__AttributeError[] = "AttributeError";
static char __pyx_k____pyx_vtable__[] = "__pyx_vtable__";
static char __pyx_k___re_name_param[] = "_re_name_param";
static char __pyx_k__execute_scalar[] = "execute_scalar";
static char __pyx_k__MssqlConnection[] = "MssqlConnection";
static char __pyx_k__quote_or_flatten[] = "quote_or_flatten";
static char __pyx_k__execute_non_query[] = "execute_non_query";
static char __pyx_k__set_wait_callback[] = "set_wait_callback";
static char __pyx_k__substitute_params[] = "substitute_params";
static char __pyx_k__UnicodeDecodeError[] = "UnicodeDecodeError";
static char __pyx_k__min_error_severity[] = "min_error_severity";
static char __pyx_k__quote_simple_value[] = "quote_simple_value";
static char __pyx_k__get_max_connections[] = "get_max_connections";
static char __pyx_k__set_max_connections[] = "set_max_connections";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_u_100;
static PyObject *__pyx_kp_u_101;
static PyObject *__pyx_kp_u_102;
static PyObject *__pyx_kp_u_103;
static PyObject *__pyx_kp_s_104;
static PyObject *__pyx_kp_s_105;
static PyObject *__pyx_kp_b_106;
static PyObject *__pyx_kp_s_106;
static PyObject *__pyx_kp_b_107;
static PyObject *__pyx_kp_s_107;
static PyObject *__pyx_kp_b_109;
static PyObject *__pyx_kp_s_113;
static PyObject *__pyx_kp_s_114;
static PyObject *__pyx_kp_s_115;
static PyObject *__pyx_kp_s_117;
static PyObject *__pyx_kp_b_119;
static PyObject *__pyx_kp_s_12;
static PyObject *__pyx_kp_b_120;
static PyObject *__pyx_kp_b_121;
static PyObject *__pyx_kp_s_122;
static PyObject *__pyx_kp_s_124;
static PyObject *__pyx_kp_s_126;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_130;
static PyObject *__pyx_kp_s_134;
static PyObject *__pyx_kp_s_14;
static PyObject *__pyx_kp_u_14;
static PyObject *__pyx_kp_s_147;
static PyObject *__pyx_kp_s_150;
static PyObject *__pyx_kp_s_153;
static PyObject *__pyx_kp_s_155;
static PyObject *__pyx_kp_s_16;
static PyObject *__pyx_n_s_167;
static PyObject *__pyx_n_s_168;
static PyObject *__pyx_kp_s_18;
static PyObject *__pyx_kp_s_19;
static PyObject *__pyx_kp_s_2;
static PyObject *__pyx_kp_s_20;
static PyObject *__pyx_kp_s_25;
static PyObject *__pyx_kp_s_26;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_s_30;
static PyObject *__pyx_kp_s_34;
static PyObject *__pyx_kp_s_43;
static PyObject *__pyx_kp_s_44;
static PyObject *__pyx_kp_s_46;
static PyObject *__pyx_kp_s_48;
static PyObject *__pyx_kp_s_49;
static PyObject *__pyx_kp_s_51;
static PyObject *__pyx_kp_s_53;
static PyObject *__pyx_kp_s_55;
static PyObject *__pyx_kp_s_69;
static PyObject *__pyx_kp_s_8;
static PyObject *__pyx_kp_s_87;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_kp_s_93;
static PyObject *__pyx_kp_s_96;
static PyObject *__pyx_kp_s_98;
static PyObject *__pyx_kp_s__0;
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_n_s__AttributeError;
static PyObject *__pyx_n_s__BINARY;
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__MssqlConnection;
static PyObject *__pyx_n_b__NULL;
static PyObject *__pyx_n_s__NUMBER;
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_n_s__STRING;
static PyObject *__pyx_n_s__StopIteration;
static PyObject *__pyx_n_s__TypeError;
static PyObject *__pyx_n_s__UUID;
static PyObject *__pyx_n_s__UnicodeDecodeError;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____enter__;
static PyObject *__pyx_n_s____exit__;
static PyObject *__pyx_n_s____import__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____pyx_vtable__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s____version__;
static PyObject *__pyx_n_s___mssql;
static PyObject *__pyx_n_s___re_name_param;
static PyObject *__pyx_n_s___re_pos_param;
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__compile;
static PyObject *__pyx_n_s__connect;
static PyObject *__pyx_n_s__connected;
static PyObject *__pyx_n_s__connection;
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__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__enumerate;
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__exponent;
static PyObject *__pyx_n_s__finditer;
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_n_s__hour;
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_n_s__localcontext;
static PyObject *__pyx_n_s__localhost;
static PyObject *__pyx_n_s__login_timeout;
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_n_s__name;
static PyObject *__pyx_n_s__null;
static PyObject *__pyx_n_s__os;
static PyObject *__pyx_n_s__output;
static PyObject *__pyx_n_s__param_name;
static PyObject *__pyx_n_s__params;
static PyObject *__pyx_n_s__password;
static PyObject *__pyx_n_s__port;
static PyObject *__pyx_n_s__prec;
static PyObject *__pyx_n_s__pymssql;
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__remove;
static PyObject *__pyx_n_s__remove_locale;
static PyObject *__pyx_n_s__replace;
static PyObject *__pyx_n_s__s;
static PyObject *__pyx_n_s__sa;
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_wait_callback;
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__substitute_params;
static PyObject *__pyx_n_s__sys;
static PyObject *__pyx_n_s__tds_version;
static PyObject *__pyx_n_s__toformat;
static PyObject *__pyx_n_s__user;
static PyObject *__pyx_n_s__utf8;
static PyObject *__pyx_n_s__uuid;
static PyObject *__pyx_n_s__value;
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_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_k_tuple_10;
static PyObject *__pyx_k_tuple_17;
static PyObject *__pyx_k_tuple_21;
static PyObject *__pyx_k_tuple_22;
static PyObject *__pyx_k_tuple_23;
static PyObject *__pyx_k_tuple_24;
static PyObject *__pyx_k_tuple_27;
static PyObject *__pyx_k_tuple_28;
static PyObject *__pyx_k_tuple_31;
static PyObject *__pyx_k_tuple_35;
static PyObject *__pyx_k_tuple_41;
static PyObject *__pyx_k_tuple_45;
static PyObject *__pyx_k_tuple_47;
static PyObject *__pyx_k_tuple_50;
static PyObject *__pyx_k_tuple_52;
static PyObject *__pyx_k_tuple_54;
static PyObject *__pyx_k_tuple_56;
static PyObject *__pyx_k_tuple_81;
static PyObject *__pyx_k_tuple_85;
static PyObject *__pyx_k_tuple_88;
static PyObject *__pyx_k_tuple_91;
static PyObject *__pyx_k_tuple_92;
static PyObject *__pyx_k_tuple_94;
static PyObject *__pyx_k_tuple_99;
static PyObject *__pyx_k_tuple_108;
static PyObject *__pyx_k_tuple_110;
static PyObject *__pyx_k_tuple_111;
static PyObject *__pyx_k_tuple_112;
static PyObject *__pyx_k_tuple_116;
static PyObject *__pyx_k_tuple_118;
static PyObject *__pyx_k_tuple_123;
static PyObject *__pyx_k_tuple_125;
static PyObject *__pyx_k_tuple_127;
static PyObject *__pyx_k_tuple_128;
static PyObject *__pyx_k_tuple_129;
static PyObject *__pyx_k_tuple_131;
static PyObject *__pyx_k_tuple_132;
static PyObject *__pyx_k_tuple_133;
static PyObject *__pyx_k_tuple_135;
static PyObject *__pyx_k_tuple_146;
static PyObject *__pyx_k_tuple_148;
static PyObject *__pyx_k_tuple_151;
static PyObject *__pyx_k_tuple_154;
static PyObject *__pyx_k_tuple_156;
static PyObject *__pyx_k_tuple_157;
static PyObject *__pyx_k_tuple_159;
static PyObject *__pyx_k_tuple_161;
static PyObject *__pyx_k_tuple_163;
static PyObject *__pyx_k_tuple_165;
static PyObject *__pyx_k_tuple_170;
static PyObject *__pyx_k_codeobj_149;
static PyObject *__pyx_k_codeobj_152;
static PyObject *__pyx_k_codeobj_158;
static PyObject *__pyx_k_codeobj_160;
static PyObject *__pyx_k_codeobj_162;
static PyObject *__pyx_k_codeobj_164;
static PyObject *__pyx_k_codeobj_166;
static PyObject *__pyx_k_codeobj_169;
static PyObject *__pyx_k_codeobj_171;

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":154
 * 
 *         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":155
 *         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":156
 *             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 = PyInt_FromLong(__pyx_v_self->number); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);

    /* "_mssql.pyx":157
 *                 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 = PyInt_FromLong(__pyx_v_self->severity); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyInt_FromLong(__pyx_v_self->state); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_self->procname); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));

    /* "_mssql.pyx":158
 *                     '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 = PyInt_FromLong(__pyx_v_self->line); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyBytes_FromString(__pyx_v_self->text); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_8, 3, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_8, 5, ((PyObject *)__pyx_t_7));
    __Pyx_GIVEREF(((PyObject *)__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 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __pyx_r = ((PyObject *)__pyx_t_7);
    __pyx_t_7 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "_mssql.pyx":160
 *                     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)
 */
    __Pyx_XDECREF(__pyx_r);

    /* "_mssql.pyx":161
 *             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 = PyInt_FromLong(__pyx_v_self->number); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyInt_FromLong(__pyx_v_self->severity); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);

    /* "_mssql.pyx":162
 *                 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 = PyInt_FromLong(__pyx_v_self->state); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = PyInt_FromLong(__pyx_v_self->line); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__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 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_r = ((PyObject *)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }
  __pyx_L3:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->number); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->severity); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->srvname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->procname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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 = {__Pyx_NAMESTR("set_wait_callback"), (PyCFunction)__pyx_pw_6_mssql_1set_wait_callback, METH_O, __Pyx_DOCSTR(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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_wait_callback", 0);

  /* "_mssql.pyx":174
 *     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_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __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":179
 * 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_3);
  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;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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":180
 * 
 * cdef bytes ensure_bytes(s, encoding='utf-8'):
 *     try:             # <<<<<<<<<<<<<<
 *         decoded = s.decode(encoding)
 *         return decoded.encode(encoding)
 */
  {
    __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":181
 * cdef bytes ensure_bytes(s, encoding='utf-8'):
 *     try:
 *         decoded = s.decode(encoding)             # <<<<<<<<<<<<<<
 *         return decoded.encode(encoding)
 *     except AttributeError:
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_encoding);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_encoding);
      __Pyx_GIVEREF(__pyx_v_encoding);
      __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_v_decoded = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "_mssql.pyx":182
 *     try:
 *         decoded = s.decode(encoding)
 *         return decoded.encode(encoding)             # <<<<<<<<<<<<<<
 *     except AttributeError:
 *         return s.encode(encoding)
 */
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_decoded, __pyx_n_s__encode); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_encoding);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_encoding);
      __Pyx_GIVEREF(__pyx_v_encoding);
      __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_r = ((PyObject*)__pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L7_try_return;
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L10_try_end;
    __pyx_L7_try_return:;
    __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_L3_error:;
    __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":183
 *         decoded = s.decode(encoding)
 *         return decoded.encode(encoding)
 *     except AttributeError:             # <<<<<<<<<<<<<<
 *         return s.encode(encoding)
 * 
 */
    __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_7) {
      __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_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);

      /* "_mssql.pyx":184
 *         return decoded.encode(encoding)
 *     except AttributeError:
 *         return s.encode(encoding)             # <<<<<<<<<<<<<<
 * 
 * cdef void log(char * message, ...):
 */
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s__encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_v_encoding);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_encoding);
      __Pyx_GIVEREF(__pyx_v_encoding);
      __pyx_t_10 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
      if (!(likely(PyBytes_CheckExact(__pyx_t_10))||((__pyx_t_10) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_10)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __pyx_r = ((PyObject*)__pyx_t_10);
      __pyx_t_10 = 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;
      __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_L4_exception_handled;
    }
    __pyx_L5_except_error:;
    __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_L6_except_return:;
    __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_L4_exception_handled:;
    __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);
    __pyx_L10_try_end:;
  }

  __pyx_r = ((PyObject*)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_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __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":186
 *         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":187
 * 
 * cdef void log(char * message, ...):
 *     if PYMSSQL_DEBUG == 1:             # <<<<<<<<<<<<<<
 *         fprintf(stderr, "+++ %s\n", message)
 * 
 */

  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":193
 * ## 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[8192];
  char __pyx_v_error_type[16];
  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;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("err_handler", 0);

  /* "_mssql.pyx":199
 *     cdef int *mssql_lastmsgseverity
 *     cdef int *mssql_lastmsgstate
 *     cdef int _min_error_severity = min_error_severity             # <<<<<<<<<<<<<<
 *     cdef char mssql_message[PYMSSQL_MSGSIZE]
 *     cdef char error_type[16]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__min_error_severity); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v__min_error_severity = __pyx_t_2;

  /* "_mssql.pyx":203
 *     cdef char error_type[16]
 * 
 *     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":204
 * 
 *     if severity < _min_error_severity:
 *         return INT_CANCEL             # <<<<<<<<<<<<<<
 * 
 *     IF PYMSSQL_DEBUG == 1 or PYMSSQL_DEBUG_ERRORS == 1:
 */
    __pyx_r = INT_CANCEL;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":214
 *             _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":215
 * 
 *     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":216
 *     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":217
 *     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":219
 *     mssql_lastmsgstate = &_mssql_last_msg_state
 * 
 *     for conn in connection_object_list:             # <<<<<<<<<<<<<<
 *         if dbproc != (<MSSQLConnection>conn).dbproc:
 *             continue
 */
  if (unlikely(((PyObject *)__pyx_v_6_mssql_connection_object_list) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_1 = ((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_XDECREF(__pyx_v_conn);
    __pyx_v_conn = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "_mssql.pyx":220
 * 
 *     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":221
 *     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_L4_continue;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "_mssql.pyx":222
 *         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":223
 *             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":224
 *         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
 *         break
 */
    __pyx_v_mssql_lastmsgseverity = (&((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_severity);

    /* "_mssql.pyx":225
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state             # <<<<<<<<<<<<<<
 *         break
 * 
 */
    __pyx_v_mssql_lastmsgstate = (&((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_state);

    /* "_mssql.pyx":226
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 *         break             # <<<<<<<<<<<<<<
 * 
 *     if severity > mssql_lastmsgseverity[0]:
 */
    goto __pyx_L5_break;
    __pyx_L4_continue:;
  }
  __pyx_L5_break:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":228
 *         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":229
 * 
 *     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":230
 *     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":231
 *         mssql_lastmsgseverity[0] = severity
 *         mssql_lastmsgno[0] = dberr
 *         mssql_lastmsgstate[0] = oserr             # <<<<<<<<<<<<<<
 * 
 *     sprintf(mssql_message, '%s DB-Lib error message %d, severity %d:\n%s\n',
 */
    (__pyx_v_mssql_lastmsgstate[0]) = __pyx_v_oserr;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "_mssql.pyx":234
 * 
 *     sprintf(mssql_message, '%s DB-Lib error message %d, severity %d:\n%s\n',
 *         mssql_lastmsgstr, dberr, severity, dberrstr)             # <<<<<<<<<<<<<<
 * 
 *     if oserr != DBNOERR and oserr != 0:
 */
  sprintf(__pyx_v_mssql_message, __pyx_k_4, __pyx_v_mssql_lastmsgstr, __pyx_v_dberr, __pyx_v_severity, __pyx_v_dberrstr);

  /* "_mssql.pyx":236
 *         mssql_lastmsgstr, dberr, severity, dberrstr)
 * 
 *     if oserr != DBNOERR and oserr != 0:             # <<<<<<<<<<<<<<
 *         if severity == EXCOMM:
 *             strcpy(error_type, 'Net-Lib')
 */
  __pyx_t_3 = ((__pyx_v_oserr != DBNOERR) != 0);
  if (__pyx_t_3) {
    __pyx_t_7 = ((__pyx_v_oserr != 0) != 0);
    __pyx_t_8 = __pyx_t_7;
  } else {
    __pyx_t_8 = __pyx_t_3;
  }
  if (__pyx_t_8) {

    /* "_mssql.pyx":237
 * 
 *     if oserr != DBNOERR and oserr != 0:
 *         if severity == EXCOMM:             # <<<<<<<<<<<<<<
 *             strcpy(error_type, 'Net-Lib')
 *         else:
 */
    __pyx_t_8 = ((__pyx_v_severity == 9) != 0);
    if (__pyx_t_8) {

      /* "_mssql.pyx":238
 *     if oserr != DBNOERR and oserr != 0:
 *         if severity == EXCOMM:
 *             strcpy(error_type, 'Net-Lib')             # <<<<<<<<<<<<<<
 *         else:
 *             strcpy(error_type, 'Operating System')
 */
      strcpy(__pyx_v_error_type, __pyx_k_5);
      goto __pyx_L9;
    }
    /*else*/ {

      /* "_mssql.pyx":240
 *             strcpy(error_type, 'Net-Lib')
 *         else:
 *             strcpy(error_type, 'Operating System')             # <<<<<<<<<<<<<<
 *         sprintf(mssql_message, '%s error during %s', error_type, oserrstr)
 * 
 */
      strcpy(__pyx_v_error_type, __pyx_k_6);
    }
    __pyx_L9:;

    /* "_mssql.pyx":241
 *         else:
 *             strcpy(error_type, 'Operating System')
 *         sprintf(mssql_message, '%s error during %s', error_type, oserrstr)             # <<<<<<<<<<<<<<
 * 
 *     strncpy(mssql_lastmsgstr, mssql_message, PYMSSQL_MSGSIZE)
 */
    sprintf(__pyx_v_mssql_message, __pyx_k_7, __pyx_v_error_type, __pyx_v_oserrstr);
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "_mssql.pyx":243
 *         sprintf(mssql_message, '%s error during %s', error_type, oserrstr)
 * 
 *     strncpy(mssql_lastmsgstr, mssql_message, PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 * 
 *     return INT_CANCEL
 */
  strncpy(__pyx_v_mssql_lastmsgstr, __pyx_v_mssql_message, 8192);

  /* "_mssql.pyx":245
 *     strncpy(mssql_lastmsgstr, mssql_message, PYMSSQL_MSGSIZE)
 * 
 *     return INT_CANCEL             # <<<<<<<<<<<<<<
 * 
 * #####################
 */
  __pyx_r = INT_CANCEL;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_WriteUnraisable("_mssql.err_handler", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __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":250
 * ## 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;
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("msg_handler", 0);

  /* "_mssql.pyx":261
 *     cdef char *mssql_lastmsgsrv
 *     cdef char *mssql_lastmsgproc
 *     cdef int _min_error_severity = min_error_severity             # <<<<<<<<<<<<<<
 * 
 *     IF PYMSSQL_DEBUG == 1:
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__min_error_severity); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v__min_error_severity = __pyx_t_2;

  /* "_mssql.pyx":272
 *             _mssql_last_msg_severity);
 * 
 *     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":273
 * 
 *     if severity < _min_error_severity:
 *         return INT_CANCEL             # <<<<<<<<<<<<<<
 * 
 *     mssql_lastmsgstr = _mssql_last_msg_str
 */
    __pyx_r = INT_CANCEL;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":275
 *         return INT_CANCEL
 * 
 *     mssql_lastmsgstr = _mssql_last_msg_str             # <<<<<<<<<<<<<<
 *     mssql_lastmsgsrv = _mssql_last_msg_srv
 *     mssql_lastmsgproc = _mssql_last_msg_proc
 */
  __pyx_v_mssql_lastmsgstr = __pyx_v_6_mssql__mssql_last_msg_str;

  /* "_mssql.pyx":276
 * 
 *     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":277
 *     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":278
 *     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":279
 *     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":280
 *     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":281
 *     mssql_lastmsgseverity = &_mssql_last_msg_severity
 *     mssql_lastmsgstate = &_mssql_last_msg_state
 *     mssql_lastmsgline = &_mssql_last_msg_line             # <<<<<<<<<<<<<<
 * 
 *     for conn in connection_object_list:
 */
  __pyx_v_mssql_lastmsgline = (&__pyx_v_6_mssql__mssql_last_msg_line);

  /* "_mssql.pyx":283
 *     mssql_lastmsgline = &_mssql_last_msg_line
 * 
 *     for conn in connection_object_list:             # <<<<<<<<<<<<<<
 *         if dbproc != (<MSSQLConnection>conn).dbproc:
 *             continue
 */
  if (unlikely(((PyObject *)__pyx_v_6_mssql_connection_object_list) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_1 = ((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_XDECREF(__pyx_v_conn);
    __pyx_v_conn = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "_mssql.pyx":284
 * 
 *     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":285
 *     for conn in connection_object_list:
 *         if dbproc != (<MSSQLConnection>conn).dbproc:
 *             continue             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str
 *         mssql_lastmsgsrv = (<MSSQLConnection>conn).last_msg_srv
 */
      goto __pyx_L4_continue;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "_mssql.pyx":286
 *         if dbproc != (<MSSQLConnection>conn).dbproc:
 *             continue
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str             # <<<<<<<<<<<<<<
 *         mssql_lastmsgsrv = (<MSSQLConnection>conn).last_msg_srv
 *         mssql_lastmsgproc = (<MSSQLConnection>conn).last_msg_proc
 */
    __pyx_t_6 = ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_str;
    __pyx_v_mssql_lastmsgstr = __pyx_t_6;

    /* "_mssql.pyx":287
 *             continue
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str
 *         mssql_lastmsgsrv = (<MSSQLConnection>conn).last_msg_srv             # <<<<<<<<<<<<<<
 *         mssql_lastmsgproc = (<MSSQLConnection>conn).last_msg_proc
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no
 */
    __pyx_t_6 = ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_srv;
    __pyx_v_mssql_lastmsgsrv = __pyx_t_6;

    /* "_mssql.pyx":288
 *         mssql_lastmsgstr = (<MSSQLConnection>conn).last_msg_str
 *         mssql_lastmsgsrv = (<MSSQLConnection>conn).last_msg_srv
 *         mssql_lastmsgproc = (<MSSQLConnection>conn).last_msg_proc             # <<<<<<<<<<<<<<
 *         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_proc;
    __pyx_v_mssql_lastmsgproc = __pyx_t_6;

    /* "_mssql.pyx":289
 *         mssql_lastmsgsrv = (<MSSQLConnection>conn).last_msg_srv
 *         mssql_lastmsgproc = (<MSSQLConnection>conn).last_msg_proc
 *         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":290
 *         mssql_lastmsgproc = (<MSSQLConnection>conn).last_msg_proc
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity             # <<<<<<<<<<<<<<
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 *         mssql_lastmsgline = &(<MSSQLConnection>conn).last_msg_line
 */
    __pyx_v_mssql_lastmsgseverity = (&((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_severity);

    /* "_mssql.pyx":291
 *         mssql_lastmsgno = &(<MSSQLConnection>conn).last_msg_no
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state             # <<<<<<<<<<<<<<
 *         mssql_lastmsgline = &(<MSSQLConnection>conn).last_msg_line
 *         break
 */
    __pyx_v_mssql_lastmsgstate = (&((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_state);

    /* "_mssql.pyx":292
 *         mssql_lastmsgseverity = &(<MSSQLConnection>conn).last_msg_severity
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 *         mssql_lastmsgline = &(<MSSQLConnection>conn).last_msg_line             # <<<<<<<<<<<<<<
 *         break
 * 
 */
    __pyx_v_mssql_lastmsgline = (&((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_conn)->last_msg_line);

    /* "_mssql.pyx":293
 *         mssql_lastmsgstate = &(<MSSQLConnection>conn).last_msg_state
 *         mssql_lastmsgline = &(<MSSQLConnection>conn).last_msg_line
 *         break             # <<<<<<<<<<<<<<
 * 
 *     # Calculate the maximum severity of all messages in a row
 */
    goto __pyx_L5_break;
    __pyx_L4_continue:;
  }
  __pyx_L5_break:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":297
 *     # 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_3 = ((__pyx_v_severity > (__pyx_v_mssql_lastmsgseverity[0])) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":298
 *     # 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":299
 *     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":300
 *         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":301
 *         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":302
 *         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, 8192);

    /* "_mssql.pyx":303
 *         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, 8192);

    /* "_mssql.pyx":304
 *         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, 8192);
    goto __pyx_L7;
  }
  __pyx_L7:;

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

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_WriteUnraisable("_mssql.msg_handler", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __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":309
 *     return 0
 * 
 * cdef int db_sqlexec(DBPROCESS *dbproc):             # <<<<<<<<<<<<<<
 *     cdef RETCODE rtc
 *     with nogil:
 */

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

  /* "_mssql.pyx":311
 * cdef int db_sqlexec(DBPROCESS *dbproc):
 *     cdef RETCODE rtc
 *     with nogil:             # <<<<<<<<<<<<<<
 *         rtc = dbsqlexec(dbproc)
 *     return rtc
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":312
 *     cdef RETCODE rtc
 *     with nogil:
 *         rtc = dbsqlexec(dbproc)             # <<<<<<<<<<<<<<
 *     return rtc
 * 
 */
        __pyx_v_rtc = dbsqlexec(__pyx_v_dbproc);
      }

      /* "_mssql.pyx":311
 * cdef int db_sqlexec(DBPROCESS *dbproc):
 *     cdef RETCODE rtc
 *     with nogil:             # <<<<<<<<<<<<<<
 *         rtc = dbsqlexec(dbproc)
 *     return rtc
 */
      /*finally:*/ {
        #ifdef WITH_THREAD
        Py_BLOCK_THREADS
        #endif
      }
  }

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

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":315
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("clr_err", 0);

  /* "_mssql.pyx":316
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":317
 * 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":318
 *     if conn != None:
 *         conn.last_msg_no = 0
 *         conn.last_msg_severity = 0             # <<<<<<<<<<<<<<
 *         conn.last_msg_state = 0
 *     else:
 */
    __pyx_v_conn->last_msg_severity = 0;

    /* "_mssql.pyx":319
 *         conn.last_msg_no = 0
 *         conn.last_msg_severity = 0
 *         conn.last_msg_state = 0             # <<<<<<<<<<<<<<
 *     else:
 *         _mssql_last_msg_no = 0
 */
    __pyx_v_conn->last_msg_state = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "_mssql.pyx":321
 *         conn.last_msg_state = 0
 *     else:
 *         _mssql_last_msg_no = 0             # <<<<<<<<<<<<<<
 *         _mssql_last_msg_severity = 0
 *         _mssql_last_msg_state = 0
 */
    __pyx_v__mssql_last_msg_no = 0;

    /* "_mssql.pyx":322
 *     else:
 *         _mssql_last_msg_no = 0
 *         _mssql_last_msg_severity = 0             # <<<<<<<<<<<<<<
 *         _mssql_last_msg_state = 0
 * 
 */
    __pyx_v__mssql_last_msg_severity = 0;

    /* "_mssql.pyx":323
 *         _mssql_last_msg_no = 0
 *         _mssql_last_msg_severity = 0
 *         _mssql_last_msg_state = 0             # <<<<<<<<<<<<<<
 * 
 * cdef RETCODE db_cancel(MSSQLConnection conn):
 */
    __pyx_v__mssql_last_msg_state = 0;
  }
  __pyx_L3:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("_mssql.clr_err", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":325
 *         _mssql_last_msg_state = 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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("db_cancel", 0);

  /* "_mssql.pyx":328
 *     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_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

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

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

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

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

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

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

  /* "_mssql.pyx":337
 *         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":338
 * 
 *     conn.clear_metadata()
 *     return rtc             # <<<<<<<<<<<<<<
 * 
 * ##############################
 */
  __pyx_r = __pyx_v_rtc;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("_mssql.db_cancel", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__connection,0};
    PyObject* values[1] = {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  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;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_connection = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __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_RefNannyFinishContext();
  return __pyx_r;
}

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

static int __pyx_pf_6_mssql_16MSSQLRowIterator___init__(struct __pyx_obj_6_mssql_MSSQLRowIterator *__pyx_v_self, PyObject *__pyx_v_connection) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "_mssql.pyx":346
 * 
 *     def __init__(self, connection):
 *         self.conn = connection             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  if (!(likely(((__pyx_v_connection) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_connection, __pyx_ptype_6_mssql_MSSQLConnection))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_v_connection);
  __Pyx_GIVEREF(__pyx_v_connection);
  __Pyx_GOTREF(__pyx_v_self->conn);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->conn));
  __pyx_v_self->conn = ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_connection);

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("_mssql.MSSQLRowIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":348
 *         self.conn = connection
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

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":349
 * 
 *     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;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 0);

  /* "_mssql.pyx":352
 * 
 *     def __next__(self):
 *         assert_connected(self.conn)             # <<<<<<<<<<<<<<
 *         clr_err(self.conn)
 *         return self.conn.fetch_next_row_dict(1)
 */
  __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));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":353
 *     def __next__(self):
 *         assert_connected(self.conn)
 *         clr_err(self.conn)             # <<<<<<<<<<<<<<
 *         return self.conn.fetch_next_row_dict(1)
 * 
 */
  __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":354
 *         assert_connected(self.conn)
 *         clr_err(self.conn)
 *         return self.conn.fetch_next_row_dict(1)             # <<<<<<<<<<<<<<
 * 
 * ############################
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->conn->__pyx_vtab)->fetch_next_row_dict(__pyx_v_self->conn, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":367
 * 
 *         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":368
 *         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 = ((PyObject *)__Pyx_decode_c_string(__pyx_t_3, 0, strlen(__pyx_t_3), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __Pyx_INCREF(((PyObject *)__pyx_t_4));
      __pyx_t_2 = ((PyObject *)__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    } else {
      __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->_charset); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __pyx_t_2 = ((PyObject *)__pyx_t_4);
      __pyx_t_4 = 0;
    }
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":369
 *             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;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":377
 * 
 *         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_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":392
 * 
 *         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, ((PyObject *)__pyx_kp_s_8), 0, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":399
 *         """
 *         def __get__(self):
 *             return self._query_timeout             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, value):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_query_timeout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);

  /* "_mssql.pyx":402
 * 
 *         def __set__(self, value):
 *             cdef int val = int(value)             # <<<<<<<<<<<<<<
 *             cdef RETCODE rtc
 *             if val < 0:
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_value);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_val = __pyx_t_3;

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

    /* "_mssql.pyx":405
 *             cdef RETCODE rtc
 *             if val < 0:
 *                 raise ValueError("The 'query_timeout' attribute must be >= 0.")             # <<<<<<<<<<<<<<
 * 
 *             # currently this will set it application wide :-(
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

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

  /* "_mssql.pyx":409
 *             # 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_3 = __pyx_f_6_mssql_check_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

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

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":421
 * 
 *         def __get__(self):
 *             return self._rows_affected             # <<<<<<<<<<<<<<
 * 
 *     property tds_version:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_rows_affected); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

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

  /* "_mssql.pyx":433
 *             elif version == 8:
 *                 return 7.0
 *             elif version == 4:             # <<<<<<<<<<<<<<
 *                 return 4.2
 * 
 */
  switch (__pyx_v_version) {

    /* "_mssql.pyx":429
 *         def __get__(self):
 *             cdef int version = dbtds(self.dbproc)
 *             if version == 9:             # <<<<<<<<<<<<<<
 *                 return 8.0
 *             elif version == 8:
 */
    case 9:

    /* "_mssql.pyx":430
 *             cdef int version = dbtds(self.dbproc)
 *             if version == 9:
 *                 return 8.0             # <<<<<<<<<<<<<<
 *             elif version == 8:
 *                 return 7.0
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyFloat_FromDouble(8.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    break;

    /* "_mssql.pyx":431
 *             if version == 9:
 *                 return 8.0
 *             elif version == 8:             # <<<<<<<<<<<<<<
 *                 return 7.0
 *             elif version == 4:
 */
    case 8:

    /* "_mssql.pyx":432
 *                 return 8.0
 *             elif version == 8:
 *                 return 7.0             # <<<<<<<<<<<<<<
 *             elif version == 4:
 *                 return 4.2
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyFloat_FromDouble(7.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    break;

    /* "_mssql.pyx":433
 *             elif version == 8:
 *                 return 7.0
 *             elif version == 4:             # <<<<<<<<<<<<<<
 *                 return 4.2
 * 
 */
    case 4:

    /* "_mssql.pyx":434
 *                 return 7.0
 *             elif version == 4:
 *                 return 4.2             # <<<<<<<<<<<<<<
 * 
 *     def __cinit__(self):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyFloat_FromDouble(4.2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    break;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.tds_version.__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_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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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":437
 * 
 *     def __cinit__(self):
 *         log("_mssql.MSSQLConnection.__cinit__()")             # <<<<<<<<<<<<<<
 *         self._connected = 0
 *         self._charset = <char *>PyMem_Malloc(PYMSSQL_CHARSETBUFSIZE)
 */
  __pyx_f_6_mssql_log(__pyx_k_11);

  /* "_mssql.pyx":438
 *     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":439
 *         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(100));

  /* "_mssql.pyx":440
 *         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":441
 *         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(8192));

  /* "_mssql.pyx":442
 *         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":443
 *         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(8192));

  /* "_mssql.pyx":444
 *         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":445
 *         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(8192));

  /* "_mssql.pyx":446
 *         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":447
 *         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(((PyObject *)__pyx_v_self->column_names));
  __pyx_v_self->column_names = ((PyObject*)Py_None);

  /* "_mssql.pyx":448
 *         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(((PyObject *)__pyx_v_self->column_types));
  __pyx_v_self->column_types = ((PyObject*)Py_None);

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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,0};
    PyObject* values[8] = {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_12);
    values[3] = ((PyObject *)__pyx_kp_s_13);
    values[4] = ((PyObject *)__pyx_kp_s_12);

    /* "_mssql.pyx":451
 * 
 *     def __init__(self, server="localhost", user="sa", password="",
 *             charset='UTF-8', database='', appname=None, port='1433', tds_version='7.1'):             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.__init__()")
 * 
 */
    values[5] = ((PyObject *)Py_None);
    values[6] = ((PyObject *)__pyx_kp_s__1433);
    values[7] = ((PyObject *)__pyx_kp_s_14);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        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--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        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];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __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_RefNannyFinishContext();
  return __pyx_r;
}

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

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) {
  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_server_bytes = 0;
  char *__pyx_v_server_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 *);
  int __pyx_t_8;
  char *__pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_INCREF(__pyx_v_server);
  __Pyx_INCREF(__pyx_v_appname);

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

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

  /* "_mssql.pyx":460
 *         # support MS methods of connecting locally
 *         instance = ""
 *         if "\\" in server:             # <<<<<<<<<<<<<<
 *             server, instance = server.split("\\")
 * 
 */
  __pyx_t_1 = (__Pyx_PySequence_Contains(((PyObject *)__pyx_kp_s_16), __pyx_v_server, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":461
 *         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_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L5_unpacking_done:;
    }
    __Pyx_DECREF(__pyx_v_server);
    __pyx_v_server = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_instance);
    __pyx_v_instance = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":463
 *             server, instance = server.split("\\")
 * 
 *         if server in (".", "(local)"):             # <<<<<<<<<<<<<<
 *             server = "localhost"
 * 
 */
  __Pyx_INCREF(__pyx_v_server);
  __pyx_t_4 = __pyx_v_server;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, ((PyObject *)__pyx_kp_s_18), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!((int)__pyx_t_2)) {
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, ((PyObject *)__pyx_kp_s_19), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_8 = ((int)__pyx_t_1);
  } else {
    __pyx_t_8 = ((int)__pyx_t_2);
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = (__pyx_t_8 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":464
 * 
 *         if server in (".", "(local)"):
 *             server = "localhost"             # <<<<<<<<<<<<<<
 * 
 *         server = server + "\\" + instance if instance else server
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__localhost));
    __Pyx_DECREF(__pyx_v_server);
    __pyx_v_server = ((PyObject *)__pyx_n_s__localhost);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "_mssql.pyx":466
 *             server = "localhost"
 * 
 *         server = server + "\\" + instance if instance else server             # <<<<<<<<<<<<<<
 * 
 *         login = dblogin()
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_instance); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {
    __pyx_t_5 = PyNumber_Add(__pyx_v_server, ((PyObject *)__pyx_kp_s_16)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __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(__pyx_v_server);
  __pyx_v_server = __pyx_t_4;
  __pyx_t_4 = 0;

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

  /* "_mssql.pyx":469
 * 
 *         login = dblogin()
 *         if login == NULL:             # <<<<<<<<<<<<<<
 *             raise MSSQLDriverException("Out of memory")
 * 
 */
  __pyx_t_2 = ((__pyx_v_login == NULL) != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":470
 *         login = dblogin()
 *         if login == NULL:
 *             raise MSSQLDriverException("Out of memory")             # <<<<<<<<<<<<<<
 * 
 *         appname = appname or "pymssql"
 */
    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "_mssql.pyx":472
 *             raise MSSQLDriverException("Out of memory")
 * 
 *         appname = appname or "pymssql"             # <<<<<<<<<<<<<<
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_appname); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_2) {
    __Pyx_INCREF(((PyObject *)__pyx_n_s__pymssql));
    __pyx_t_4 = __pyx_n_s__pymssql;
  } else {
    __Pyx_INCREF(__pyx_v_appname);
    __pyx_t_4 = __pyx_v_appname;
  }
  __Pyx_DECREF(__pyx_v_appname);
  __pyx_v_appname = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "_mssql.pyx":475
 * 
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __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 bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_user_bytes = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "_mssql.pyx":476
 *         # 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_9 = __Pyx_PyObject_AsString(((PyObject *)__pyx_v_user_bytes)); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_user_cstr = __pyx_t_9;

  /* "_mssql.pyx":477
 *         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_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_password, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_password_bytes = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "_mssql.pyx":478
 *         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_9 = __Pyx_PyObject_AsString(((PyObject *)__pyx_v_password_bytes)); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_password_cstr = __pyx_t_9;

  /* "_mssql.pyx":479
 *         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_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __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 bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_appname_bytes = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "_mssql.pyx":480
 *         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_9 = __Pyx_PyObject_AsString(((PyObject *)__pyx_v_appname_bytes)); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_appname_cstr = __pyx_t_9;

  /* "_mssql.pyx":482
 *         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":483
 * 
 *         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":484
 *         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":485
 *         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_10 = __pyx_f_6_mssql__tds_ver_str_to_constant(__pyx_v_tds_version); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  DBSETLVERSION(__pyx_v_login, __pyx_t_10);

  /* "_mssql.pyx":489
 *         # 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_Contains(((PyObject *)__pyx_kp_s_25), __pyx_v_server, Py_NE)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if ((__pyx_t_2 != 0)) {
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_instance); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = ((!__pyx_t_8) != 0);
    __pyx_t_8 = __pyx_t_1;
  } else {
    __pyx_t_8 = (__pyx_t_2 != 0);
  }
  if (__pyx_t_8) {

    /* "_mssql.pyx":490
 *         # 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_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_server);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_server);
    __Pyx_GIVEREF(__pyx_v_server);
    __Pyx_INCREF(__pyx_v_port);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_port);
    __Pyx_GIVEREF(__pyx_v_port);
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_26), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_server);
    __pyx_v_server = ((PyObject *)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "_mssql.pyx":505
 * 
 *         # Add ourselves to the global connection list
 *         connection_object_list.append(self)             # <<<<<<<<<<<<<<
 * 
 *         cdef bytes charset_bytes
 */
  if (unlikely(((PyObject *)__pyx_v_6_mssql_connection_object_list) == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":510
 * 
 *         # Set the character set name
 *         if charset:             # <<<<<<<<<<<<<<
 *             charset_bytes = charset.encode('utf-8')
 *             _charset = charset_bytes
 */
  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_charset); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_8) {

    /* "_mssql.pyx":511
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __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 bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_charset_bytes = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "_mssql.pyx":512
 *         if charset:
 *             charset_bytes = charset.encode('utf-8')
 *             _charset = charset_bytes             # <<<<<<<<<<<<<<
 *             strncpy(self._charset, _charset, PYMSSQL_CHARSETBUFSIZE)
 *             DBSETLCHARSET(login, self._charset)
 */
    __pyx_t_9 = __Pyx_PyObject_AsString(((PyObject *)__pyx_v_charset_bytes)); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v__charset = __pyx_t_9;

    /* "_mssql.pyx":513
 *             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, 100);

    /* "_mssql.pyx":514
 *             _charset = charset_bytes
 *             strncpy(self._charset, _charset, PYMSSQL_CHARSETBUFSIZE)
 *             DBSETLCHARSET(login, self._charset)             # <<<<<<<<<<<<<<
 * 
 *         # Set the login timeout
 */
    DBSETLCHARSET(__pyx_v_login, __pyx_v_self->_charset);
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "_mssql.pyx":517
 * 
 *         # Set the login timeout
 *         dbsetlogintime(login_timeout)             # <<<<<<<<<<<<<<
 * 
 *         cdef bytes server_bytes = server.encode('utf-8')
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__login_timeout); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  dbsetlogintime(__pyx_t_10);

  /* "_mssql.pyx":519
 *         dbsetlogintime(login_timeout)
 * 
 *         cdef bytes server_bytes = server.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *server_cstr = server_bytes
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_server, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_28), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_server_bytes = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "_mssql.pyx":520
 * 
 *         cdef bytes server_bytes = server.encode('utf-8')
 *         cdef char *server_cstr = server_bytes             # <<<<<<<<<<<<<<
 * 
 *         # Connect to the server
 */
  __pyx_t_9 = __Pyx_PyObject_AsString(((PyObject *)__pyx_v_server_bytes)); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_server_cstr = __pyx_t_9;

  /* "_mssql.pyx":523
 * 
 *         # Connect to the server
 *         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":526
 * 
 *         # Frees the login record, can be called immediately after dbopen.
 *         dbloginfree(login)             # <<<<<<<<<<<<<<
 * 
 *         if self.dbproc == NULL:
 */
  dbloginfree(__pyx_v_login);

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

    /* "_mssql.pyx":529
 * 
 *         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(__pyx_k_29);

    /* "_mssql.pyx":530
 *         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(((PyObject *)__pyx_v_6_mssql_connection_object_list), __pyx_n_s__remove); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "_mssql.pyx":531
 *             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_10 = __pyx_f_6_mssql_maybe_raise_MSSQLDatabaseException(((struct __pyx_obj_6_mssql_MSSQLConnection *)Py_None)); if (unlikely(__pyx_t_10 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "_mssql.pyx":532
 *             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 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_31), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "_mssql.pyx":534
 *             raise MSSQLDriverException("Connection to the database failed for an unknown reason.")
 * 
 *         self._connected = 1             # <<<<<<<<<<<<<<
 * 
 *         log("_mssql.MSSQLConnection.__init__() -> dbcmd() setting connection values")
 */
  __pyx_v_self->_connected = 1;

  /* "_mssql.pyx":536
 *         self._connected = 1
 * 
 *         log("_mssql.MSSQLConnection.__init__() -> dbcmd() setting connection values")             # <<<<<<<<<<<<<<
 *         # Set some connection properties to some reasonable values
 *         dbcmd(self.dbproc,
 */
  __pyx_f_6_mssql_log(__pyx_k_32);

  /* "_mssql.pyx":538
 *         log("_mssql.MSSQLConnection.__init__() -> dbcmd() setting connection values")
 *         # Set some connection properties to some reasonable values
 *         dbcmd(self.dbproc,             # <<<<<<<<<<<<<<
 *             "SET ARITHABORT ON;"                \
 *             "SET CONCAT_NULL_YIELDS_NULL ON;"   \
 */
  dbcmd(__pyx_v_self->dbproc, __pyx_k_33);

  /* "_mssql.pyx":552
 *         )
 * 
 *         rtc = dbsqlexec(self.dbproc)             # <<<<<<<<<<<<<<
 *         if (rtc == FAIL):
 *             raise MSSQLDriverException("Could not set connection properties")
 */
  __pyx_v_rtc = dbsqlexec(__pyx_v_self->dbproc);

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

    /* "_mssql.pyx":554
 *         rtc = dbsqlexec(self.dbproc)
 *         if (rtc == FAIL):
 *             raise MSSQLDriverException("Could not set connection properties")             # <<<<<<<<<<<<<<
 * 
 *         db_cancel(self)
 */
    __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L11;
  }
  __pyx_L11:;

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

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

  /* "_mssql.pyx":559
 *         clr_err(self)
 * 
 *         if database:             # <<<<<<<<<<<<<<
 *             self.select_db(database)
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_database); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_8) {

    /* "_mssql.pyx":560
 * 
 *         if database:
 *             self.select_db(database)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s__select_db); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_database);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_database);
    __Pyx_GIVEREF(__pyx_v_database);
    __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L12;
  }
  __pyx_L12:;

  __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_server_bytes);
  __Pyx_XDECREF(__pyx_v_server);
  __Pyx_XDECREF(__pyx_v_appname);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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));
  __Pyx_RefNannyFinishContext();
}

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

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

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

  /* "_mssql.pyx":564
 *     def __dealloc__(self):
 *         log("_mssql.MSSQLConnection.__dealloc__()")
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_7__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_7__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6_mssql_15MSSQLConnection_6__iter__(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_6__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);

  /* "_mssql.pyx":567
 * 
 *     def __iter__(self):
 *         assert_connected(self)             # <<<<<<<<<<<<<<
 *         clr_err(self)
 *         return MSSQLRowIterator(self)
 */
  __pyx_f_6_mssql_assert_connected(__pyx_v_self);

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

  /* "_mssql.pyx":569
 *         assert_connected(self)
 *         clr_err(self)
 *         return MSSQLRowIterator(self)             # <<<<<<<<<<<<<<
 * 
 *     cpdef cancel(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLRowIterator)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __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.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":571
 *         return MSSQLRowIterator(self)
 * 
 *     cpdef cancel(self):             # <<<<<<<<<<<<<<
 *         """
 *         cancel() -- cancel all pending results.
 */

static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_9cancel(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;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 571; __pyx_clineno = __LINE__; goto __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_9cancel)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __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":579
 *         this case.
 *         """
 *         log("_mssql.MSSQLConnection.cancel()")             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 * 
 */
  __pyx_f_6_mssql_log(__pyx_k_37);

  /* "_mssql.pyx":582
 *         cdef RETCODE rtc
 * 
 *         assert_connected(self)             # <<<<<<<<<<<<<<
 *         clr_err(self)
 * 
 */
  __pyx_f_6_mssql_assert_connected(__pyx_v_self);

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

  /* "_mssql.pyx":585
 *         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":586
 * 
 *         rtc = db_cancel(self)
 *         check_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 * 
 *     cdef void clear_metadata(self):
 */
  __pyx_t_3 = __pyx_f_6_mssql_check_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __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.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_9cancel(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_8cancel[] = "\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_9cancel(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_8cancel(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":571
 *         return MSSQLRowIterator(self)
 * 
 *     cpdef cancel(self):             # <<<<<<<<<<<<<<
 *         """
 *         cancel() -- cancel all pending results.
 */

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_8cancel(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cancel", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->cancel(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":588
 *         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":589
 * 
 *     cdef void clear_metadata(self):
 *         log("_mssql.MSSQLConnection.clear_metadata()")             # <<<<<<<<<<<<<<
 *         self.column_names = None
 *         self.column_types = None
 */
  __pyx_f_6_mssql_log(__pyx_k_38);

  /* "_mssql.pyx":590
 *     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(((PyObject *)__pyx_v_self->column_names));
  __pyx_v_self->column_names = ((PyObject*)Py_None);

  /* "_mssql.pyx":591
 *         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(((PyObject *)__pyx_v_self->column_types));
  __pyx_v_self->column_types = ((PyObject*)Py_None);

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

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

  __Pyx_RefNannyFinishContext();
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_11close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_10close[] = "\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_11close(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_10close(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_10close(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("close", 0);

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

  /* "_mssql.pyx":604
 *         """
 *         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_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":605
 *         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;
    goto __pyx_L3;
  }
  __pyx_L3:;

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

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

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

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

        /* "_mssql.pyx":613
 * 
 *         with nogil:
 *             dbclose(self.dbproc)             # <<<<<<<<<<<<<<
 *             self.dbproc = NULL
 * 
 */
        dbclose(__pyx_v_self->dbproc);

        /* "_mssql.pyx":614
 *         with nogil:
 *             dbclose(self.dbproc)
 *             self.dbproc = NULL             # <<<<<<<<<<<<<<
 * 
 *         self._connected = 0
 */
        __pyx_v_self->dbproc = NULL;
      }

      /* "_mssql.pyx":612
 *         clr_err(self)
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             dbclose(self.dbproc)
 *             self.dbproc = NULL
 */
      /*finally:*/ {
        #ifdef WITH_THREAD
        Py_BLOCK_THREADS
        #endif
      }
  }

  /* "_mssql.pyx":616
 *             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":617
 * 
 *         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":618
 *         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":619
 *         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":620
 *         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":621
 *         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_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_6_mssql_connection_object_list), __pyx_n_s__remove); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  __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":623
 *         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;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  long __pyx_t_12;
  char *__pyx_t_13;
  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;
  PyObject *__pyx_t_20 = NULL;
  int __pyx_t_21;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("convert_db_value", 0);

  /* "_mssql.pyx":624
 * 
 *     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(__pyx_k_40);

  /* "_mssql.pyx":636
 *             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 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLBIT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":637
 * 
 *         if dbtype == SQLBIT:
 *             return bool(<int>(<DBBIT *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLINT1:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyInt_FromLong(((int)(((DBBIT *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7cpython_4bool_bool)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":639
 *             return bool(<int>(<DBBIT *>data)[0])
 * 
 *         elif dbtype == SQLINT1:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBTINYINT *>data)[0])
 * 
 */
  __pyx_t_3 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":640
 * 
 *         elif dbtype == SQLINT1:
 *             return int(<int>(<DBTINYINT *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLINT2:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyInt_FromLong(((int)(((DBTINYINT *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":642
 *             return int(<int>(<DBTINYINT *>data)[0])
 * 
 *         elif dbtype == SQLINT2:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBSMALLINT *>data)[0])
 * 
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":643
 * 
 *         elif dbtype == SQLINT2:
 *             return int(<int>(<DBSMALLINT *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLINT4:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyInt_FromLong(((int)(((DBSMALLINT *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":645
 *             return int(<int>(<DBSMALLINT *>data)[0])
 * 
 *         elif dbtype == SQLINT4:             # <<<<<<<<<<<<<<
 *             return int(<int>(<DBINT *>data)[0])
 * 
 */
  __pyx_t_3 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":646
 * 
 *         elif dbtype == SQLINT4:
 *             return int(<int>(<DBINT *>data)[0])             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLINT8:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyInt_FromLong(((int)(((DBINT *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":648
 *             return int(<int>(<DBINT *>data)[0])
 * 
 *         elif dbtype == SQLINT8:             # <<<<<<<<<<<<<<
 *             return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])
 * 
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":649
 * 
 *         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_to_py_PY_LONG_LONG(((PY_LONG_LONG)(((PY_LONG_LONG *)__pyx_v_data)[0]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyLong_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":651
 *             return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])
 * 
 *         elif dbtype == SQLFLT4:             # <<<<<<<<<<<<<<
 *             return float(<float>(<DBREAL *>data)[0])
 * 
 */
  __pyx_t_3 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLT4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 651; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 651; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":652
 * 
 *         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_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":654
 *             return float(<float>(<DBREAL *>data)[0])
 * 
 *         elif dbtype == SQLFLT8:             # <<<<<<<<<<<<<<
 *             return float(<double>(<DBFLT8 *>data)[0])
 * 
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLT8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":655
 * 
 *         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_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":657
 *             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 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!((int)__pyx_t_4)) {
    __pyx_t_1 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEY4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = ((int)__pyx_t_6);
  } else {
    __pyx_t_7 = ((int)__pyx_t_4);
  }
  if (!__pyx_t_7) {
    __pyx_t_3 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLNUMERIC); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = ((int)__pyx_t_4);
  } else {
    __pyx_t_6 = __pyx_t_7;
  }
  if (!__pyx_t_6) {
    __pyx_t_1 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDECIMAL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = ((int)__pyx_t_7);
  } else {
    __pyx_t_4 = __pyx_t_6;
  }
  __pyx_t_6 = (__pyx_t_4 != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":658
 * 
 *         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":660
 *             dbcol.SizeOfStruct = sizeof(dbcol)
 * 
 *             if dbtype in (SQLMONEY, SQLMONEY4):             # <<<<<<<<<<<<<<
 *                 precision = 4
 *             else:
 */
    __pyx_t_5 = __pyx_v_dbtype;
    __pyx_t_3 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!((int)__pyx_t_6)) {
      __pyx_t_1 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEY4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = ((int)__pyx_t_4);
    } else {
      __pyx_t_7 = ((int)__pyx_t_6);
    }
    __pyx_t_6 = (__pyx_t_7 != 0);
    if (__pyx_t_6) {

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

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

    /* "_mssql.pyx":665
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "_mssql.pyx":666
 * 
 *             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":668
 *                 <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_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__decimal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__localcontext); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s____exit__); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      /*try:*/ {
        {
          __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_INCREF(__pyx_t_1);
            __pyx_v_ctx = __pyx_t_1;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

            /* "_mssql.pyx":670
 *             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_12 = __pyx_v_precision;
            } else {
              __pyx_t_12 = 1;
            }
            __pyx_t_1 = PyInt_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
            __Pyx_GOTREF(__pyx_t_1);
            if (__Pyx_PyObject_SetAttrStr(__pyx_v_ctx, __pyx_n_s__prec, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

            /* "_mssql.pyx":671
 *                 # 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_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__decimal); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__Decimal); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_13 = __pyx_f_6_mssql__remove_locale(__pyx_v_buf, __pyx_v_converted_length);
            __pyx_t_1 = ((PyObject *)__Pyx_decode_c_string(__pyx_t_13, 0, strlen(__pyx_t_13), __pyx_v_self->_charset, NULL, NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
            __Pyx_GOTREF(((PyObject *)__pyx_t_1));
            __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_INCREF(((PyObject *)__pyx_t_1));
            PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
            __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
            __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
            __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
            __pyx_r = __pyx_t_1;
            __pyx_t_1 = 0;
            goto __pyx_L13_try_return;
          }
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          goto __pyx_L16_try_end;
          __pyx_L13_try_return:;
          __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_L6;
          __pyx_L9_error:;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "_mssql.pyx":668
 *                 <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
 */
          /*except:*/ {
            __Pyx_AddTraceback("_mssql.MSSQLConnection.convert_db_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
            if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
            __Pyx_GOTREF(__pyx_t_14);
            __Pyx_INCREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_1);
            __Pyx_GIVEREF(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_2);
            PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_2);
            __Pyx_GIVEREF(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_3);
            __pyx_t_15 = PyObject_Call(__pyx_t_8, __pyx_t_14, NULL);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
            __Pyx_GOTREF(__pyx_t_15);
            __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_15);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            if (__pyx_t_6 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
            __pyx_t_7 = ((!(__pyx_t_6 != 0)) != 0);
            if (__pyx_t_7) {
              __Pyx_GIVEREF(__pyx_t_1);
              __Pyx_GIVEREF(__pyx_t_2);
              __Pyx_GIVEREF(__pyx_t_3);
              __Pyx_ErrRestore(__pyx_t_1, __pyx_t_2, __pyx_t_3);
              __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; 
              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
              goto __pyx_L20;
            }
            __pyx_L20:;
            __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            goto __pyx_L10_exception_handled;
          }
          __pyx_L11_except_error:;
          __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_L10_exception_handled:;
          __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_L16_try_end:;
        }
      }
      /*finally:*/ {
        int __pyx_why;
        __pyx_why = 0; goto __pyx_L8;
        __pyx_L6: __pyx_why = 3; goto __pyx_L8;
        __pyx_L8:;
        if (__pyx_t_8) {
          __pyx_t_11 = PyObject_Call(__pyx_t_8, __pyx_k_tuple_41, NULL);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (__pyx_t_7 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        switch (__pyx_why) {
          case 3: goto __pyx_L0;
        }
      }
      goto __pyx_L21;
      __pyx_L5_error:;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L1_error;
      __pyx_L21:;
    }
    goto __pyx_L3;
  }

  /* "_mssql.pyx":673
 *                 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_3 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDATETIM4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_7) {

    /* "_mssql.pyx":674
 * 
 *         elif dbtype == SQLDATETIM4:
 *             dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,             # <<<<<<<<<<<<<<
 *                 <BYTE *>&dt, -1)
 *             dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDATETIME); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":675
 *         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":676
 *             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":677
 *                 <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_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__datetime); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.year); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.month); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_14 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.day); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_14);

    /* "_mssql.pyx":678
 *             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_16 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.hour); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_17 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.minute); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_17);
    __pyx_t_18 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.second); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_19 = PyInt_FromLong((__pyx_v_di.millisecond * 1000)); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_20 = PyTuple_New(7); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_20);
    PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_20, 2, __pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_14);
    PyTuple_SET_ITEM(__pyx_t_20, 3, __pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_20, 4, __pyx_t_17);
    __Pyx_GIVEREF(__pyx_t_17);
    PyTuple_SET_ITEM(__pyx_t_20, 5, __pyx_t_18);
    __Pyx_GIVEREF(__pyx_t_18);
    PyTuple_SET_ITEM(__pyx_t_20, 6, __pyx_t_19);
    __Pyx_GIVEREF(__pyx_t_19);
    __pyx_t_1 = 0;
    __pyx_t_3 = 0;
    __pyx_t_14 = 0;
    __pyx_t_16 = 0;
    __pyx_t_17 = 0;
    __pyx_t_18 = 0;
    __pyx_t_19 = 0;
    __pyx_t_19 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_20), NULL); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_20)); __pyx_t_20 = 0;
    __pyx_r = __pyx_t_19;
    __pyx_t_19 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":680
 *                 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_19 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_19);
  __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDATETIME); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_20);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_19, __pyx_t_20, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {

    /* "_mssql.pyx":681
 * 
 *         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":682
 *         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_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__datetime); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__datetime); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.year); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_19 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.month); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_19);
    __pyx_t_18 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.day); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);

    /* "_mssql.pyx":683
 *             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_17 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.hour); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_17);
    __pyx_t_16 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.minute); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_14 = __Pyx_PyInt_to_py_DBINT(__pyx_v_di.second); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_3 = PyInt_FromLong((__pyx_v_di.millisecond * 1000)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_19);
    __Pyx_GIVEREF(__pyx_t_19);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_18);
    __Pyx_GIVEREF(__pyx_t_18);
    PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_17);
    __Pyx_GIVEREF(__pyx_t_17);
    PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_14);
    PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_19 = 0;
    __pyx_t_18 = 0;
    __pyx_t_17 = 0;
    __pyx_t_16 = 0;
    __pyx_t_14 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_20, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":685
 *                 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_3 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLVARCHAR); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_20 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_20); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_20); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  if (!((int)__pyx_t_7)) {
    __pyx_t_20 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_20);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLCHAR); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_20, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = ((int)__pyx_t_6);
  } else {
    __pyx_t_4 = ((int)__pyx_t_7);
  }
  if (!__pyx_t_4) {
    __pyx_t_3 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLTEXT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_20 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_20); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_20); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_6 = ((int)__pyx_t_7);
  } else {
    __pyx_t_6 = __pyx_t_4;
  }
  __pyx_t_4 = (__pyx_t_6 != 0);
  if (__pyx_t_4) {

    /* "_mssql.pyx":686
 * 
 *         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":687
 *         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_20 = ((PyObject *)__Pyx_decode_c_string(((char *)__pyx_v_data), 0, __pyx_v_length, __pyx_v_self->_charset, NULL, NULL)); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_20));
      __pyx_r = ((PyObject *)__pyx_t_20);
      __pyx_t_20 = 0;
      goto __pyx_L0;
      goto __pyx_L22;
    }
    /*else*/ {

      /* "_mssql.pyx":689
 *                 return (<char *>data)[:length].decode(self._charset)
 *             else:
 *                 return (<char *>data)[:length]             # <<<<<<<<<<<<<<
 * 
 *         elif dbtype == SQLUUID and (PY_MAJOR_VERSION >= 2 and PY_MINOR_VERSION >= 5):
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_20 = __Pyx_PyBytes_FromStringAndSize(((char *)__pyx_v_data) + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_20));
      __pyx_r = ((PyObject *)__pyx_t_20);
      __pyx_t_20 = 0;
      goto __pyx_L0;
    }
    __pyx_L22:;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":691
 *                 return (<char *>data)[:length]
 * 
 *         elif dbtype == SQLUUID and (PY_MAJOR_VERSION >= 2 and PY_MINOR_VERSION >= 5):             # <<<<<<<<<<<<<<
 *             return uuid.UUID(bytes_le=(<char *>data)[:length])
 * 
 */
  __pyx_t_20 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_20);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLUUID); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_20, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {
    __pyx_t_6 = (PY_MAJOR_VERSION >= 2);
    if (__pyx_t_6) {
      __pyx_t_7 = (PY_MINOR_VERSION >= 5);
      __pyx_t_21 = __pyx_t_7;
    } else {
      __pyx_t_21 = __pyx_t_6;
    }
    __pyx_t_6 = __pyx_t_21;
  } else {
    __pyx_t_6 = __pyx_t_4;
  }
  if (__pyx_t_6) {

    /* "_mssql.pyx":692
 * 
 *         elif dbtype == SQLUUID and (PY_MAJOR_VERSION >= 2 and PY_MINOR_VERSION >= 5):
 *             return uuid.UUID(bytes_le=(<char *>data)[:length])             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__uuid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__UUID); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_20 = __Pyx_PyBytes_FromStringAndSize(((char *)__pyx_v_data) + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_20));
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__bytes_le), ((PyObject *)__pyx_t_20)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_t_20)); __pyx_t_20 = 0;
    __pyx_t_20 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_20;
    __pyx_t_20 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

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

  __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_14);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __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":697
 *             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;
  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;
  int __pyx_t_7;
  PY_LONG_LONG __pyx_t_8;
  double __pyx_t_9;
  DBINT __pyx_t_10;
  BYTE *__pyx_t_11;
  Py_ssize_t __pyx_t_12;
  char *__pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("convert_python_value", 0);
  __Pyx_INCREF(__pyx_v_value);

  /* "_mssql.pyx":699
 *     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(__pyx_k_42);

  /* "_mssql.pyx":710
 *             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":711
 * 
 *         if value is None:
 *             dbValue[0] = <BYTE *>NULL             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)NULL);

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

  /* "_mssql.pyx":714
 *             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 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLBIT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!((int)__pyx_t_2)) {
    __pyx_t_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLBITN); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_1);
  } else {
    __pyx_t_7 = ((int)__pyx_t_2);
  }
  __pyx_t_2 = (__pyx_t_7 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":715
 * 
 *         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":716
 *         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_AsInt(__pyx_v_value); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_intValue[0]) = ((int)__pyx_t_3);

    /* "_mssql.pyx":717
 *             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":718
 *             intValue[0] = <int>value
 *             dbValue[0] = <BYTE *><DBBIT *>intValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] == SQLINTN:
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "_mssql.pyx":720
 *             return 0
 * 
 *         if dbtype[0] == SQLINTN:             # <<<<<<<<<<<<<<
 *             dbtype[0] = SQLINT4
 * 
 */
  __pyx_t_4 = PyInt_FromLong((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINTN); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":721
 * 
 *         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_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    (__pyx_v_dbtype[0]) = __pyx_t_3;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "_mssql.pyx":723
 *             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 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!((int)__pyx_t_2)) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_1 = ((int)__pyx_t_7);
  } else {
    __pyx_t_1 = ((int)__pyx_t_2);
  }
  if (!__pyx_t_1) {
    __pyx_t_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_2);
  } else {
    __pyx_t_7 = __pyx_t_1;
  }
  __pyx_t_1 = (__pyx_t_7 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":724
 * 
 *         if dbtype[0] in (SQLINT1, SQLINT2, SQLINT4):
 *             if value > MAX_INT:             # <<<<<<<<<<<<<<
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 */
    __pyx_t_4 = PyInt_FromLong(__pyx_v_6_mssql_MAX_INT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_1) {

      /* "_mssql.pyx":725
 *         if dbtype[0] in (SQLINT1, SQLINT2, SQLINT4):
 *             if value > MAX_INT:
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_INT)             # <<<<<<<<<<<<<<
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value
 */
      __pyx_t_5 = PyInt_FromLong(__pyx_v_6_mssql_MAX_INT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_43), __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
      __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "_mssql.pyx":726
 *             if value > MAX_INT:
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_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":727
 *                 raise MSSQLDriverException('value cannot be larger than %d' % MAX_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_AsInt(__pyx_v_value); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_intValue[0]) = ((int)__pyx_t_3);

    /* "_mssql.pyx":728
 *             intValue = <int *>PyMem_Malloc(sizeof(int))
 *             intValue[0] = <int>value
 *             if dbtype[0] == SQLINT1:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue
 *                 return 0
 */
    __pyx_t_4 = PyInt_FromLong((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_1) {

      /* "_mssql.pyx":729
 *             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":730
 *             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;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "_mssql.pyx":731
 *                 dbValue[0] = <BYTE *><DBTINYINT *>intValue
 *                 return 0
 *             if dbtype[0] == SQLINT2:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue
 *                 return 0
 */
    __pyx_t_6 = PyInt_FromLong((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_1) {

      /* "_mssql.pyx":732
 *                 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":733
 *             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;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "_mssql.pyx":734
 *                 dbValue[0] = <BYTE *><DBSMALLINT *>intValue
 *                 return 0
 *             if dbtype[0] == SQLINT4:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBINT *>intValue
 *                 return 0
 */
    __pyx_t_4 = PyInt_FromLong((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_1) {

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

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

  /* "_mssql.pyx":738
 *                 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 = PyInt_FromLong((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT8); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "_mssql.pyx":739
 * 
 *         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":740
 *         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_8 = __Pyx_PyInt_from_py_PY_LONG_LONG(__pyx_v_value); if (unlikely((__pyx_t_8 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_longValue[0]) = ((PY_LONG_LONG)__pyx_t_8);

    /* "_mssql.pyx":741
 *             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":742
 *             longValue[0] = <PY_LONG_LONG>value
 *             dbValue[0] = <BYTE *>longValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLFLT4, SQLFLT8):
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "_mssql.pyx":744
 *             return 0
 * 
 *         if dbtype[0] in (SQLFLT4, SQLFLT8):             # <<<<<<<<<<<<<<
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))
 *             dblValue[0] = <double>value
 */
  __pyx_t_3 = (__pyx_v_dbtype[0]);
  __pyx_t_4 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLT4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!((int)__pyx_t_1)) {
    __pyx_t_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLT8); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = ((int)__pyx_t_7);
  } else {
    __pyx_t_2 = ((int)__pyx_t_1);
  }
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":745
 * 
 *         if dbtype[0] in (SQLFLT4, SQLFLT8):
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))             # <<<<<<<<<<<<<<
 *             dblValue[0] = <double>value
 *             if dbtype[0] == SQLFLT4:
 */
    __pyx_v_dblValue = ((double *)PyMem_Malloc((sizeof(double))));

    /* "_mssql.pyx":746
 *         if dbtype[0] in (SQLFLT4, SQLFLT8):
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))
 *             dblValue[0] = <double>value             # <<<<<<<<<<<<<<
 *             if dbtype[0] == SQLFLT4:
 *                 dbValue[0] = <BYTE *><DBREAL *>dblValue
 */
    __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_dblValue[0]) = ((double)__pyx_t_9);

    /* "_mssql.pyx":747
 *             dblValue = <double *>PyMem_Malloc(sizeof(double))
 *             dblValue[0] = <double>value
 *             if dbtype[0] == SQLFLT4:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBREAL *>dblValue
 *                 return 0
 */
    __pyx_t_4 = PyInt_FromLong((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLT4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_1) {

      /* "_mssql.pyx":748
 *             dblValue[0] = <double>value
 *             if dbtype[0] == SQLFLT4:
 *                 dbValue[0] = <BYTE *><DBREAL *>dblValue             # <<<<<<<<<<<<<<
 *                 return 0
 *             if dbtype[0] == SQLFLT8:
 */
      (__pyx_v_dbValue[0]) = ((BYTE *)((DBREAL *)__pyx_v_dblValue));

      /* "_mssql.pyx":749
 *             if dbtype[0] == SQLFLT4:
 *                 dbValue[0] = <BYTE *><DBREAL *>dblValue
 *                 return 0             # <<<<<<<<<<<<<<
 *             if dbtype[0] == SQLFLT8:
 *                 dbValue[0] = <BYTE *><DBFLT8 *>dblValue
 */
      __pyx_r = 0;
      goto __pyx_L0;
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "_mssql.pyx":750
 *                 dbValue[0] = <BYTE *><DBREAL *>dblValue
 *                 return 0
 *             if dbtype[0] == SQLFLT8:             # <<<<<<<<<<<<<<
 *                 dbValue[0] = <BYTE *><DBFLT8 *>dblValue
 *                 return 0
 */
    __pyx_t_6 = PyInt_FromLong((__pyx_v_dbtype[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLT8); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_1) {

      /* "_mssql.pyx":751
 *                 return 0
 *             if dbtype[0] == SQLFLT8:
 *                 dbValue[0] = <BYTE *><DBFLT8 *>dblValue             # <<<<<<<<<<<<<<
 *                 return 0
 * 
 */
      (__pyx_v_dbValue[0]) = ((BYTE *)((DBFLT8 *)__pyx_v_dblValue));

      /* "_mssql.pyx":752
 *             if dbtype[0] == SQLFLT8:
 *                 dbValue[0] = <BYTE *><DBFLT8 *>dblValue
 *                 return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLDATETIM4, SQLDATETIME):
 */
      __pyx_r = 0;
      goto __pyx_L0;
      goto __pyx_L14;
    }
    __pyx_L14:;
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "_mssql.pyx":754
 *                 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_4 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDATETIM4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!((int)__pyx_t_1)) {
    __pyx_t_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDATETIME); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_2);
  } else {
    __pyx_t_7 = ((int)__pyx_t_1);
  }
  __pyx_t_1 = (__pyx_t_7 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":755
 * 
 *         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_4 = ((PyObject *)Py_TYPE(__pyx_v_value));
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__datetime); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__date); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_RichCompare(((PyObject *)__pyx_t_4), __pyx_t_6, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (((int)__pyx_t_1)) {
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__datetime); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__datetime); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_RichCompare(((PyObject *)__pyx_t_4), __pyx_t_6, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_2 = ((int)__pyx_t_7);
    } else {
      __pyx_t_2 = ((int)__pyx_t_1);
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "_mssql.pyx":756
 *         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_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L16;
    }
    __pyx_L16:;

    /* "_mssql.pyx":758
 *                 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 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__strftime); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "_mssql.pyx":759
 * 
 *             value = value.strftime('%Y-%m-%d %H:%M:%S.') + \
 *                 "%03d" % (value.microsecond // 1000)             # <<<<<<<<<<<<<<
 *             value = value.encode(self.charset)
 *             dbtype[0] = SQLCHAR
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__microsecond); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = PyNumber_FloorDivide(__pyx_t_4, __pyx_int_1000); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_48), __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_v_value);
    __pyx_v_value = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "_mssql.pyx":760
 *             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_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s__charset); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_v_value);
    __pyx_v_value = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "_mssql.pyx":761
 *                 "%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_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    (__pyx_v_dbtype[0]) = __pyx_t_3;
    goto __pyx_L15;
  }
  __pyx_L15:;

  /* "_mssql.pyx":763
 *             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 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLNUMERIC); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!((int)__pyx_t_1)) {
    __pyx_t_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDECIMAL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_2);
  } else {
    __pyx_t_7 = ((int)__pyx_t_1);
  }
  __pyx_t_1 = (__pyx_t_7 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":766
 *             # 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":769
 * 
 *             # 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__as_tuple); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__exponent); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Absolute(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_10 = __Pyx_PyInt_from_py_DBINT(__pyx_t_5); if (unlikely((__pyx_t_10 == (DBINT)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_decimal_type_info.scale = __pyx_t_10;

    /* "_mssql.pyx":774
 *             # "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_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = ((PyObject *)PyUnicode_AsASCIIString(((PyObject*)__pyx_t_4))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_bytes_value = ((PyObject *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":776
 *             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":779
 *             length[0] = dbconvert_ps(
 *                 self.dbproc,
 *                 SQLCHAR,             # <<<<<<<<<<<<<<
 *                 bytes_value,
 *                 -1,
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLCHAR); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "_mssql.pyx":780
 *                 self.dbproc,
 *                 SQLCHAR,
 *                 bytes_value,             # <<<<<<<<<<<<<<
 *                 -1,
 *                 dbtype[0],
 */
    __pyx_t_11 = __Pyx_PyObject_AsUString(__pyx_v_bytes_value); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "_mssql.pyx":777
 * 
 *             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_11, -1, (__pyx_v_dbtype[0]), ((BYTE *)__pyx_v_decValue), (sizeof(DBDECIMAL)), (&__pyx_v_decimal_type_info));

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

    /* "_mssql.pyx":794
 *                     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;
    goto __pyx_L17;
  }
  __pyx_L17:;

  /* "_mssql.pyx":796
 *             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_5 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEY); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!((int)__pyx_t_1)) {
    __pyx_t_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEY4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = ((int)__pyx_t_7);
  } else {
    __pyx_t_2 = ((int)__pyx_t_1);
  }
  if (!__pyx_t_2) {
    __pyx_t_5 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLNUMERIC); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = ((int)__pyx_t_1);
  } else {
    __pyx_t_7 = __pyx_t_2;
  }
  if (!__pyx_t_7) {
    __pyx_t_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDECIMAL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_1 = ((int)__pyx_t_2);
  } else {
    __pyx_t_1 = __pyx_t_7;
  }
  __pyx_t_7 = (__pyx_t_1 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":797
 * 
 *         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_5 = ((PyObject *)Py_TYPE(__pyx_v_value));
    __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_t_5), ((PyObject *)((PyObject*)(&PyInt_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!((int)__pyx_t_7)) {
      __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_t_5), ((PyObject *)((PyObject*)(&PyLong_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_2 = ((int)__pyx_t_1);
    } else {
      __pyx_t_2 = ((int)__pyx_t_7);
    }
    if (!__pyx_t_2) {
      __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_t_5), ((PyObject *)((PyObject*)(&PyBytes_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_1 = ((int)__pyx_t_7);
    } else {
      __pyx_t_1 = __pyx_t_2;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":798
 *         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_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__decimal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__Decimal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L19;
    }
    __pyx_L19:;

    /* "_mssql.pyx":800
 *                 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_6 = ((PyObject *)Py_TYPE(__pyx_v_value));
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__decimal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__Decimal); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (((int)__pyx_t_2)) {
      __pyx_t_5 = PyObject_RichCompare(((PyObject *)__pyx_t_6), ((PyObject *)((PyObject*)(&PyFloat_Type))), Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = ((int)__pyx_t_1);
    } else {
      __pyx_t_7 = ((int)__pyx_t_2);
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_2 = (__pyx_t_7 != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":801
 * 
 *             if type(value) not in (decimal.Decimal, float):
 *                 raise TypeError('value can only be a Decimal')             # <<<<<<<<<<<<<<
 * 
 *             value = str(value)
 */
      __pyx_t_6 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L20;
    }
    __pyx_L20:;

    /* "_mssql.pyx":803
 *                 raise TypeError('value can only be a Decimal')
 * 
 *             value = str(value)             # <<<<<<<<<<<<<<
 *             dbtype[0] = SQLCHAR
 * 
 */
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_v_value);
    __pyx_v_value = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "_mssql.pyx":804
 * 
 *             value = str(value)
 *             dbtype[0] = SQLCHAR             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLCHAR); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    (__pyx_v_dbtype[0]) = __pyx_t_3;
    goto __pyx_L18;
  }
  __pyx_L18:;

  /* "_mssql.pyx":806
 *             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_5 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLVARCHAR); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!((int)__pyx_t_2)) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLCHAR); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_1 = ((int)__pyx_t_7);
  } else {
    __pyx_t_1 = ((int)__pyx_t_2);
  }
  if (!__pyx_t_1) {
    __pyx_t_5 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLTEXT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_2);
  } else {
    __pyx_t_7 = __pyx_t_1;
  }
  __pyx_t_1 = (__pyx_t_7 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":807
 * 
 *         if dbtype[0] in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *             if not hasattr(value, 'startswith'):             # <<<<<<<<<<<<<<
 *                 raise TypeError('value must be a string type')
 * 
 */
    __pyx_t_1 = PyObject_HasAttr(__pyx_v_value, ((PyObject *)__pyx_n_s__startswith)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = ((!(__pyx_t_1 != 0)) != 0);
    if (__pyx_t_7) {

      /* "_mssql.pyx":808
 *         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_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_52), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L22;
    }
    __pyx_L22:;

    /* "_mssql.pyx":810
 *                 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_7 = ((strlen(__pyx_v_self->_charset) > 0) != 0);
    if (__pyx_t_7) {
      __pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_value)) == ((PyObject *)((PyObject*)(&PyUnicode_Type))));
      __pyx_t_2 = (__pyx_t_1 != 0);
    } else {
      __pyx_t_2 = __pyx_t_7;
    }
    if (__pyx_t_2) {

      /* "_mssql.pyx":811
 * 
 *             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_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s__charset); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L23;
    }
    __pyx_L23:;

    /* "_mssql.pyx":813
 *                 value = value.encode(self.charset)
 * 
 *             strValue = <char *>PyMem_Malloc(len(value) + 1)             # <<<<<<<<<<<<<<
 *             tmp = value
 *             strcpy(strValue, tmp)
 */
    __pyx_t_12 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_strValue = ((char *)PyMem_Malloc((__pyx_t_12 + 1)));

    /* "_mssql.pyx":814
 * 
 *             strValue = <char *>PyMem_Malloc(len(value) + 1)
 *             tmp = value             # <<<<<<<<<<<<<<
 *             strcpy(strValue, tmp)
 *             dbValue[0] = <BYTE *>strValue
 */
    __pyx_t_13 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_tmp = __pyx_t_13;

    /* "_mssql.pyx":815
 *             strValue = <char *>PyMem_Malloc(len(value) + 1)
 *             tmp = value
 *             strcpy(strValue, tmp)             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *>strValue
 *             return 0
 */
    strcpy(__pyx_v_strValue, __pyx_v_tmp);

    /* "_mssql.pyx":816
 *             tmp = value
 *             strcpy(strValue, tmp)
 *             dbValue[0] = <BYTE *>strValue             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
    (__pyx_v_dbValue[0]) = ((BYTE *)__pyx_v_strValue);

    /* "_mssql.pyx":817
 *             strcpy(strValue, tmp)
 *             dbValue[0] = <BYTE *>strValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L21;
  }
  __pyx_L21:;

  /* "_mssql.pyx":819
 *             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_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLBINARY); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!((int)__pyx_t_2)) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLVARBINARY); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_1 = ((int)__pyx_t_7);
  } else {
    __pyx_t_1 = ((int)__pyx_t_2);
  }
  if (!__pyx_t_1) {
    __pyx_t_6 = PyInt_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLIMAGE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __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 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_2);
  } else {
    __pyx_t_7 = __pyx_t_1;
  }
  __pyx_t_1 = (__pyx_t_7 != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":820
 * 
 *         if dbtype[0] in (SQLBINARY, SQLVARBINARY, SQLIMAGE):
 *             if type(value) is not str:             # <<<<<<<<<<<<<<
 *                 raise TypeError('value can only be str')
 * 
 */
    __pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_value)) != ((PyObject *)((PyObject*)(&PyString_Type))));
    __pyx_t_7 = (__pyx_t_1 != 0);
    if (__pyx_t_7) {

      /* "_mssql.pyx":821
 *         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_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_54), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L25;
    }
    __pyx_L25:;

    /* "_mssql.pyx":823
 *                 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_12 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_binValue = ((BYTE *)PyMem_Malloc(__pyx_t_12));

    /* "_mssql.pyx":824
 * 
 *             binValue = <BYTE *>PyMem_Malloc(len(value))
 *             memcpy(binValue, <char *>value, len(value))             # <<<<<<<<<<<<<<
 *             length[0] = len(value)
 *             dbValue[0] = <BYTE *>binValue
 */
    __pyx_t_13 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    memcpy(__pyx_v_binValue, ((char *)__pyx_t_13), __pyx_t_12);

    /* "_mssql.pyx":825
 *             binValue = <BYTE *>PyMem_Malloc(len(value))
 *             memcpy(binValue, <char *>value, len(value))
 *             length[0] = len(value)             # <<<<<<<<<<<<<<
 *             dbValue[0] = <BYTE *>binValue
 *             return 0
 */
    __pyx_t_12 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_length[0]) = __pyx_t_12;

    /* "_mssql.pyx":826
 *             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":827
 *             length[0] = len(value)
 *             dbValue[0] = <BYTE *>binValue
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         # No conversion was possible so raise an error
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L24;
  }
  __pyx_L24:;

  /* "_mssql.pyx":830
 * 
 *         # 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_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_56), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __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":832
 *         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_13execute_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;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __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_13execute_non_query)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_query_string);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_query_string);
      __Pyx_GIVEREF(__pyx_v_query_string);
      __Pyx_INCREF(__pyx_v_params);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_params);
      __Pyx_GIVEREF(__pyx_v_params);
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":850
 *         rows affected by the last SQL command.
 *         """
 *         log("_mssql.MSSQLConnection.execute_non_query() BEGIN")             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 * 
 */
  __pyx_f_6_mssql_log(__pyx_k_57);

  /* "_mssql.pyx":853
 *         cdef RETCODE rtc
 * 
 *         self.format_and_run_query(query_string, params)             # <<<<<<<<<<<<<<
 * 
 *         with nogil:
 */
  __pyx_t_4.__pyx_n = 1;
  __pyx_t_4.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_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":855
 *         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":856
 * 
 *         with nogil:
 *             dbresults(self.dbproc)             # <<<<<<<<<<<<<<
 *             self._rows_affected = dbcount(self.dbproc)
 * 
 */
        dbresults(__pyx_v_self->dbproc);

        /* "_mssql.pyx":857
 *         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":855
 *         self.format_and_run_query(query_string, params)
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             dbresults(self.dbproc)
 *             self._rows_affected = dbcount(self.dbproc)
 */
      /*finally:*/ {
        #ifdef WITH_THREAD
        Py_BLOCK_THREADS
        #endif
      }
  }

  /* "_mssql.pyx":859
 *             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":860
 * 
 *         rtc = db_cancel(self)
 *         check_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 *         log("_mssql.MSSQLConnection.execute_non_query() END")
 * 
 */
  __pyx_t_5 = __pyx_f_6_mssql_check_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_5 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":861
 *         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(__pyx_k_58);

  __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.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_13execute_non_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_12execute_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_13execute_non_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query_string = 0;
  PyObject *__pyx_v_params = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};

    /* "_mssql.pyx":832
 *         raise MSSQLDriverException('Unable to convert value')
 * 
 *     cpdef execute_non_query(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_non_query(query_string, params=None)
 */
    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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __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_12execute_non_query(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_query_string, __pyx_v_params);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_12execute_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->execute_non_query(__pyx_v_self, __pyx_v_query_string, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":863
 *         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_15execute_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;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __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_15execute_query)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_query_string);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_query_string);
      __Pyx_GIVEREF(__pyx_v_query_string);
      __Pyx_INCREF(__pyx_v_params);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_params);
      __Pyx_GIVEREF(__pyx_v_params);
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":893
 *         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(__pyx_k_59);

  /* "_mssql.pyx":894
 *         """
 *         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_4.__pyx_n = 1;
  __pyx_t_4.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_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":895
 *         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_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":896
 *         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(__pyx_k_60);

  __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.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_15execute_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_14execute_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_15execute_query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query_string = 0;
  PyObject *__pyx_v_params = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};

    /* "_mssql.pyx":863
 *         log("_mssql.MSSQLConnection.execute_non_query() END")
 * 
 *     cpdef execute_query(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_query(query_string, params=None)
 */
    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_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __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_14execute_query(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_query_string, __pyx_v_params);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_14execute_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->execute_query(__pyx_v_self, __pyx_v_query_string, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":898
 *         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_17execute_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;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __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_17execute_row)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_query_string);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_query_string);
      __Pyx_GIVEREF(__pyx_v_query_string);
      __Pyx_INCREF(__pyx_v_params);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_params);
      __Pyx_GIVEREF(__pyx_v_params);
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":919
 *         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_dict(0)
 */
  __pyx_f_6_mssql_log(__pyx_k_61);

  /* "_mssql.pyx":920
 *         """
 *         log("_mssql.MSSQLConnection.execute_row()")
 *         self.format_and_run_query(query_string, params)             # <<<<<<<<<<<<<<
 *         return self.fetch_next_row_dict(0)
 * 
 */
  __pyx_t_4.__pyx_n = 1;
  __pyx_t_4.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_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 920; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":921
 *         log("_mssql.MSSQLConnection.execute_row()")
 *         self.format_and_run_query(query_string, params)
 *         return self.fetch_next_row_dict(0)             # <<<<<<<<<<<<<<
 * 
 *     cpdef execute_scalar(self, query_string, params=None):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->fetch_next_row_dict(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __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.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_17execute_row(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_16execute_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_17execute_row(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query_string = 0;
  PyObject *__pyx_v_params = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};

    /* "_mssql.pyx":898
 *         log("_mssql.MSSQLConnection.execute_query() END")
 * 
 *     cpdef execute_row(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_row(query_string, params=None)
 */
    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_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __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_16execute_row(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_query_string, __pyx_v_params);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_16execute_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->execute_row(__pyx_v_self, __pyx_v_query_string, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":923
 *         return self.fetch_next_row_dict(0)
 * 
 *     cpdef execute_scalar(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_scalar(query_string, params=None)
 */

static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_19execute_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;
  struct __pyx_opt_args_6_mssql_15MSSQLConnection_format_and_run_query __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __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_19execute_scalar)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_query_string);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_query_string);
      __Pyx_GIVEREF(__pyx_v_query_string);
      __Pyx_INCREF(__pyx_v_params);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_params);
      __Pyx_GIVEREF(__pyx_v_params);
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "_mssql.pyx":945
 *         """
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.execute_scalar()")             # <<<<<<<<<<<<<<
 * 
 *         self.format_and_run_query(query_string, params)
 */
  __pyx_f_6_mssql_log(__pyx_k_62);

  /* "_mssql.pyx":947
 *         log("_mssql.MSSQLConnection.execute_scalar()")
 * 
 *         self.format_and_run_query(query_string, params)             # <<<<<<<<<<<<<<
 *         self.get_result()
 * 
 */
  __pyx_t_4.__pyx_n = 1;
  __pyx_t_4.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_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":948
 * 
 *         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_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":950
 *         self.get_result()
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbnextrow(self.dbproc)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":951
 * 
 *         with nogil:
 *             rtc = dbnextrow(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *         self._rows_affected = dbcount(self.dbproc)
 */
        __pyx_v_rtc = dbnextrow(__pyx_v_self->dbproc);
      }

      /* "_mssql.pyx":950
 *         self.get_result()
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbnextrow(self.dbproc)
 * 
 */
      /*finally:*/ {
        #ifdef WITH_THREAD
        Py_BLOCK_THREADS
        #endif
      }
  }

  /* "_mssql.pyx":953
 *             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":955
 *         self._rows_affected = dbcount(self.dbproc)
 * 
 *         if rtc == NO_MORE_ROWS:             # <<<<<<<<<<<<<<
 *             self.clear_metadata()
 *             self.last_dbresults = 0
 */
  __pyx_t_5 = ((__pyx_v_rtc == NO_MORE_ROWS) != 0);
  if (__pyx_t_5) {

    /* "_mssql.pyx":956
 * 
 *         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":957
 *         if rtc == NO_MORE_ROWS:
 *             self.clear_metadata()
 *             self.last_dbresults = 0             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
    __pyx_v_self->last_dbresults = 0;

    /* "_mssql.pyx":958
 *             self.clear_metadata()
 *             self.last_dbresults = 0
 *             return None             # <<<<<<<<<<<<<<
 * 
 *         return self.get_row(rtc)[0]
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "_mssql.pyx":960
 *             return None
 * 
 *         return self.get_row(rtc)[0]             # <<<<<<<<<<<<<<
 * 
 *     cdef fetch_next_row(self, int throw):
 */
  __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); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __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.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_19execute_scalar(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_18execute_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_19execute_scalar(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query_string = 0;
  PyObject *__pyx_v_params = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};

    /* "_mssql.pyx":923
 *         return self.fetch_next_row_dict(0)
 * 
 *     cpdef execute_scalar(self, query_string, params=None):             # <<<<<<<<<<<<<<
 *         """
 *         execute_scalar(query_string, params=None)
 */
    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_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __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_18execute_scalar(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), __pyx_v_query_string, __pyx_v_params);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_18execute_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->execute_scalar(__pyx_v_self, __pyx_v_query_string, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":962
 *         return self.get_row(rtc)[0]
 * 
 *     cdef fetch_next_row(self, int throw):             # <<<<<<<<<<<<<<
 *         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) {
  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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("fetch_next_row", 0);

  /* "_mssql.pyx":964
 *     cdef fetch_next_row(self, int throw):
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.fetch_next_row() BEGIN")             # <<<<<<<<<<<<<<
 *         try:
 *             self.get_result()
 */
  __pyx_f_6_mssql_log(__pyx_k_63);

  /* "_mssql.pyx":965
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.fetch_next_row() BEGIN")
 *         try:             # <<<<<<<<<<<<<<
 *             self.get_result()
 * 
 */
  /*try:*/ {

    /* "_mssql.pyx":966
 *         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_filename = __pyx_f[0]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":968
 *             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":969
 * 
 *             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(__pyx_k_64);

      /* "_mssql.pyx":970
 *             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":971
 *                 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":972
 *                 self.clear_metadata()
 *                 if throw:
 *                     raise StopIteration             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
        __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L4;}
        goto __pyx_L7;
      }
      __pyx_L7:;

      /* "_mssql.pyx":973
 *                 if throw:
 *                     raise StopIteration
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             with nogil:
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L3;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "_mssql.pyx":975
 *                 return None
 * 
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 rtc = dbnextrow(self.dbproc)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        #endif
        /*try:*/ {

          /* "_mssql.pyx":976
 * 
 *             with nogil:
 *                 rtc = dbnextrow(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *             check_cancel_and_raise(rtc, self)
 */
          __pyx_v_rtc = dbnextrow(__pyx_v_self->dbproc);
        }

        /* "_mssql.pyx":975
 *                 return None
 * 
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 rtc = dbnextrow(self.dbproc)
 * 
 */
        /*finally:*/ {
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
        }
    }

    /* "_mssql.pyx":978
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L4;}

    /* "_mssql.pyx":980
 *             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":981
 * 
 *             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(__pyx_k_65);

      /* "_mssql.pyx":982
 *             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":984
 *                 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":985
 *                 # '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":986
 *                 self._rows_affected = dbcount(self.dbproc)
 *                 if throw:
 *                     raise StopIteration             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
        __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L4;}
        goto __pyx_L12;
      }
      __pyx_L12:;

      /* "_mssql.pyx":987
 *                 if throw:
 *                     raise StopIteration
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             return self.get_row(rtc)
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L3;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "_mssql.pyx":989
 *                 return None
 * 
 *             return self.get_row(rtc)             # <<<<<<<<<<<<<<
 *         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); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":991
 *             return self.get_row(rtc)
 *         finally:
 *             log("_mssql.MSSQLConnection.fetch_next_row() END")             # <<<<<<<<<<<<<<
 * 
 *     cdef fetch_next_row_dict(self, int throw):
 */
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L5;
    __pyx_L3: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 3; goto __pyx_L5;
    __pyx_L4: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L5;
    }
    __pyx_L5:;
    __pyx_f_6_mssql_log(__pyx_k_66);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":993
 *             log("_mssql.MSSQLConnection.fetch_next_row() END")
 * 
 *     cdef fetch_next_row_dict(self, int throw):             # <<<<<<<<<<<<<<
 *         cdef int col
 *         log("_mssql.MSSQLConnection.fetch_next_row_dict()")
 */

static PyObject *__pyx_f_6_mssql_15MSSQLConnection_fetch_next_row_dict(struct __pyx_obj_6_mssql_MSSQLConnection *__pyx_v_self, int __pyx_v_throw) {
  int __pyx_v_col;
  PyObject *__pyx_v_row_dict = NULL;
  PyObject *__pyx_v_row = NULL;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  long __pyx_t_2;
  int __pyx_t_3;
  long __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("fetch_next_row_dict", 0);

  /* "_mssql.pyx":995
 *     cdef fetch_next_row_dict(self, int throw):
 *         cdef int col
 *         log("_mssql.MSSQLConnection.fetch_next_row_dict()")             # <<<<<<<<<<<<<<
 * 
 *         row_dict = {}
 */
  __pyx_f_6_mssql_log(__pyx_k_67);

  /* "_mssql.pyx":997
 *         log("_mssql.MSSQLConnection.fetch_next_row_dict()")
 * 
 *         row_dict = {}             # <<<<<<<<<<<<<<
 *         row = self.fetch_next_row(throw)
 * 
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_v_row_dict = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_mssql.pyx":998
 * 
 *         row_dict = {}
 *         row = self.fetch_next_row(throw)             # <<<<<<<<<<<<<<
 * 
 *         for col in xrange(1, self.num_columns + 1):
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6_mssql_MSSQLConnection *)__pyx_v_self->__pyx_vtab)->fetch_next_row(__pyx_v_self, __pyx_v_throw); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 998; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_row = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_mssql.pyx":1000
 *         row = self.fetch_next_row(throw)
 * 
 *         for col in xrange(1, self.num_columns + 1):             # <<<<<<<<<<<<<<
 *             name = self.column_names[col - 1]
 *             value = row[col - 1]
 */
  __pyx_t_2 = (__pyx_v_self->num_columns + 1);
  for (__pyx_t_3 = 1; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_col = __pyx_t_3;

    /* "_mssql.pyx":1001
 * 
 *         for col in xrange(1, self.num_columns + 1):
 *             name = self.column_names[col - 1]             # <<<<<<<<<<<<<<
 *             value = row[col - 1]
 * 
 */
    if (unlikely(((PyObject *)__pyx_v_self->column_names) == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = (__pyx_v_col - 1);
    __pyx_t_1 = __Pyx_GetItemInt_Tuple(((PyObject *)__pyx_v_self->column_names), __pyx_t_4, sizeof(long), PyInt_FromLong, 0, 1, 1); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF(__pyx_v_name);
    __pyx_v_name = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "_mssql.pyx":1002
 *         for col in xrange(1, self.num_columns + 1):
 *             name = self.column_names[col - 1]
 *             value = row[col - 1]             # <<<<<<<<<<<<<<
 * 
 *             # Add key by column name, only if the column has a name
 */
    __pyx_t_4 = (__pyx_v_col - 1);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_row, __pyx_t_4, sizeof(long), PyInt_FromLong, 0, 1, 1); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF(__pyx_v_value);
    __pyx_v_value = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "_mssql.pyx":1005
 * 
 *             # Add key by column name, only if the column has a name
 *             if name:             # <<<<<<<<<<<<<<
 *                 row_dict[name] = value
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_name); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_5) {

      /* "_mssql.pyx":1006
 *             # Add key by column name, only if the column has a name
 *             if name:
 *                 row_dict[name] = value             # <<<<<<<<<<<<<<
 * 
 *             row_dict[col - 1] = value
 */
      if (PyDict_SetItem(((PyObject *)__pyx_v_row_dict), __pyx_v_name, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "_mssql.pyx":1008
 *                 row_dict[name] = value
 * 
 *             row_dict[col - 1] = value             # <<<<<<<<<<<<<<
 * 
 *         return row_dict
 */
    __pyx_t_4 = (__pyx_v_col - 1);
    if (__Pyx_SetItemInt(((PyObject *)__pyx_v_row_dict), __pyx_t_4, __pyx_v_value, sizeof(long), PyInt_FromLong, 0, 1, 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "_mssql.pyx":1010
 *             row_dict[col - 1] = value
 * 
 *         return row_dict             # <<<<<<<<<<<<<<
 * 
 *     cdef format_and_run_query(self, query_string, params=None):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_row_dict));
  __pyx_r = ((PyObject *)__pyx_v_row_dict);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.fetch_next_row_dict", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_row_dict);
  __Pyx_XDECREF(__pyx_v_row);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1012
 *         return row_dict
 * 
 *     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;
  int __pyx_v_read_fileno;
  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;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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":1023
 *         cdef char *query_string_cstr
 * 
 *         log("_mssql.MSSQLConnection.format_and_run_query() BEGIN")             # <<<<<<<<<<<<<<
 * 
 *         try:
 */
  __pyx_f_6_mssql_log(__pyx_k_68);

  /* "_mssql.pyx":1025
 *         log("_mssql.MSSQLConnection.format_and_run_query() BEGIN")
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             # Cancel any pending results
 *             self.cancel()
 */
  /*try:*/ {

    /* "_mssql.pyx":1027
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1029
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L4;}
    if (__pyx_t_2) {

      /* "_mssql.pyx":1030
 * 
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_v_query_string);
      __pyx_v_query_string = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "_mssql.pyx":1033
 * 
 *             # 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_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5.__pyx_n = 1;
    __pyx_t_5.encoding = __pyx_t_1;
    __pyx_t_4 = ((PyObject *)__pyx_f_6_mssql_ensure_bytes(__pyx_v_query_string, &__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __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":1034
 *             # 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(((PyObject *)__pyx_v_query_string_bytes)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __pyx_v_query_string_cstr = __pyx_t_6;

    /* "_mssql.pyx":1036
 *             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":1037
 * 
 *             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":1038
 *             log(query_string_cstr)
 *             if self.debug_queries:
 *                 sys.stderr.write("#%s#\n" % query_string)             # <<<<<<<<<<<<<<
 * 
 *             # Prepare the query buffer
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__sys); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__stderr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_69), __pyx_v_query_string); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "_mssql.pyx":1041
 * 
 *             # 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":1044
 * 
 *             # Execute the query
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 rtc = dbsqlsend(self.dbproc)
 *             if wait_callback:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        #endif
        /*try:*/ {

          /* "_mssql.pyx":1045
 *             # Execute the query
 *             with nogil:
 *                 rtc = dbsqlsend(self.dbproc)             # <<<<<<<<<<<<<<
 *             if wait_callback:
 *                 read_fileno = dbiordesc(self.dbproc)
 */
          __pyx_v_rtc = dbsqlsend(__pyx_v_self->dbproc);
        }

        /* "_mssql.pyx":1044
 * 
 *             # Execute the query
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 rtc = dbsqlsend(self.dbproc)
 *             if wait_callback:
 */
        /*finally:*/ {
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
        }
    }

    /* "_mssql.pyx":1046
 *             with nogil:
 *                 rtc = dbsqlsend(self.dbproc)
 *             if wait_callback:             # <<<<<<<<<<<<<<
 *                 read_fileno = dbiordesc(self.dbproc)
 *                 wait_callback(read_fileno)
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__wait_callback); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "_mssql.pyx":1047
 *                 rtc = dbsqlsend(self.dbproc)
 *             if wait_callback:
 *                 read_fileno = dbiordesc(self.dbproc)             # <<<<<<<<<<<<<<
 *                 wait_callback(read_fileno)
 *             with nogil:
 */
      __pyx_v_read_fileno = dbiordesc(__pyx_v_self->dbproc);

      /* "_mssql.pyx":1048
 *             if wait_callback:
 *                 read_fileno = dbiordesc(self.dbproc)
 *                 wait_callback(read_fileno)             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 rtc = dbsqlok(self.dbproc)
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__wait_callback); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyInt_FromLong(__pyx_v_read_fileno); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "_mssql.pyx":1049
 *                 read_fileno = dbiordesc(self.dbproc)
 *                 wait_callback(read_fileno)
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 rtc = dbsqlok(self.dbproc)
 *             check_cancel_and_raise(rtc, self)
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        #endif
        /*try:*/ {

          /* "_mssql.pyx":1050
 *                 wait_callback(read_fileno)
 *             with nogil:
 *                 rtc = dbsqlok(self.dbproc)             # <<<<<<<<<<<<<<
 *             check_cancel_and_raise(rtc, self)
 *         finally:
 */
          __pyx_v_rtc = dbsqlok(__pyx_v_self->dbproc);
        }

        /* "_mssql.pyx":1049
 *                 read_fileno = dbiordesc(self.dbproc)
 *                 wait_callback(read_fileno)
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 rtc = dbsqlok(self.dbproc)
 *             check_cancel_and_raise(rtc, self)
 */
        /*finally:*/ {
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
        }
    }

    /* "_mssql.pyx":1051
 *             with nogil:
 *                 rtc = dbsqlok(self.dbproc)
 *             check_cancel_and_raise(rtc, self)             # <<<<<<<<<<<<<<
 *         finally:
 *             log("_mssql.MSSQLConnection.format_and_run_query() END")
 */
    __pyx_t_8 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, __pyx_v_self); if (unlikely(__pyx_t_8 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L4;}
  }

  /* "_mssql.pyx":1053
 *             check_cancel_and_raise(rtc, self)
 *         finally:
 *             log("_mssql.MSSQLConnection.format_and_run_query() END")             # <<<<<<<<<<<<<<
 * 
 *     cdef format_sql_command(self, format, params=None):
 */
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L5;
    __pyx_L4: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L5;
    }
    __pyx_L5:;
    __pyx_f_6_mssql_log(__pyx_k_70);
    switch (__pyx_why) {
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  __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_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":1055
 *             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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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":1056
 * 
 *     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(__pyx_k_71);

  /* "_mssql.pyx":1057
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __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;

  __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.format_sql_command", __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_21get_header(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_20get_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_21get_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_20get_header(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1059
 *         return _substitute_params(format, params, self.charset)
 * 
 *     def get_header(self):             # <<<<<<<<<<<<<<
 *         """
 *         get_header() -- get the Python DB-API compliant header information.
 */

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_20get_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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_header", 0);

  /* "_mssql.pyx":1069
 *         """
 *         cdef int col
 *         log("_mssql.MSSQLConnection.get_header() BEGIN")             # <<<<<<<<<<<<<<
 *         try:
 *             self.get_result()
 */
  __pyx_f_6_mssql_log(__pyx_k_72);

  /* "_mssql.pyx":1070
 *         cdef int col
 *         log("_mssql.MSSQLConnection.get_header() BEGIN")
 *         try:             # <<<<<<<<<<<<<<
 *             self.get_result()
 * 
 */
  /*try:*/ {

    /* "_mssql.pyx":1071
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1073
 *             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":1074
 * 
 *             if self.num_columns == 0:
 *                 log("_mssql.MSSQLConnection.get_header(): num_columns == 0")             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
      __pyx_f_6_mssql_log(__pyx_k_73);

      /* "_mssql.pyx":1075
 *             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;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "_mssql.pyx":1077
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_header_tuple = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "_mssql.pyx":1078
 * 
 *             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":1079
 *             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(((PyObject *)__pyx_v_self->column_names) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L4;}
      }
      __pyx_t_5 = (__pyx_v_col - 1);
      __pyx_t_1 = __Pyx_GetItemInt_Tuple(((PyObject *)__pyx_v_self->column_names), __pyx_t_5, sizeof(long), PyInt_FromLong, 0, 1, 1); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_v_col_name);
      __pyx_v_col_name = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "_mssql.pyx":1080
 *             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(((PyObject *)__pyx_v_self->column_types) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L4;}
      }
      __pyx_t_5 = (__pyx_v_col - 1);
      __pyx_t_1 = __Pyx_GetItemInt_Tuple(((PyObject *)__pyx_v_self->column_types), __pyx_t_5, sizeof(long), PyInt_FromLong, 0, 1, 1); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_v_col_type);
      __pyx_v_col_type = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "_mssql.pyx":1081
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_col_name);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_col_name);
      __Pyx_GIVEREF(__pyx_v_col_name);
      __Pyx_INCREF(__pyx_v_col_type);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_col_type);
      __Pyx_GIVEREF(__pyx_v_col_type);
      __Pyx_INCREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_INCREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 3, Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_INCREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 4, Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_INCREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 5, Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_INCREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_1, 6, Py_None);
      __Pyx_GIVEREF(Py_None);
      __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_header_tuple, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    }

    /* "_mssql.pyx":1082
 *                 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 = ((PyObject *)PyList_AsTuple(__pyx_v_header_tuple)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __pyx_r = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":1084
 *             return tuple(header_tuple)
 *         finally:
 *             log("_mssql.MSSQLConnection.get_header() END")             # <<<<<<<<<<<<<<
 * 
 *     cdef get_result(self):
 */
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L5;
    __pyx_L3: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 3; goto __pyx_L5;
    __pyx_L4: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L5;
    }
    __pyx_L5:;
    __pyx_f_6_mssql_log(__pyx_k_74);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":1086
 *             log("_mssql.MSSQLConnection.get_header() END")
 * 
 *     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[200];
  PyObject *__pyx_v_column_names = NULL;
  PyObject *__pyx_v_column_types = NULL;
  long __pyx_v_col;
  PyObject *__pyx_v_column_name = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  long __pyx_t_7;
  char *__pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_result", 0);

  /* "_mssql.pyx":1090
 *         cdef char log_message[200]
 * 
 *         log("_mssql.MSSQLConnection.get_result() BEGIN")             # <<<<<<<<<<<<<<
 * 
 *         try:
 */
  __pyx_f_6_mssql_log(__pyx_k_75);

  /* "_mssql.pyx":1092
 *         log("_mssql.MSSQLConnection.get_result() BEGIN")
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             if self.last_dbresults:
 *                 log("_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None")
 */
  /*try:*/ {

    /* "_mssql.pyx":1093
 * 
 *         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":1094
 *         try:
 *             if self.last_dbresults:
 *                 log("_mssql.MSSQLConnection.get_result(): last_dbresults == True, return None")             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
      __pyx_f_6_mssql_log(__pyx_k_76);

      /* "_mssql.pyx":1095
 *             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;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "_mssql.pyx":1097
 *                 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":1100
 * 
 *             # 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) {
      if (!1) break;

      /* "_mssql.pyx":1101
 *             # 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":1102
 *             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":1101
 *             # 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:*/ {
            #ifdef WITH_THREAD
            Py_BLOCK_THREADS
            #endif
          }
      }

      /* "_mssql.pyx":1103
 *                 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":1104
 *                     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_1 = ((__pyx_v_self->last_dbresults != SUCCEED) != 0);
      if (!__pyx_t_1) {
        __pyx_t_2 = ((__pyx_v_self->num_columns > 0) != 0);
        __pyx_t_3 = __pyx_t_2;
      } else {
        __pyx_t_3 = __pyx_t_1;
      }
      if (__pyx_t_3) {

        /* "_mssql.pyx":1105
 *                 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;
        goto __pyx_L14;
      }
      __pyx_L14:;
    }
    __pyx_L8_break:;

    /* "_mssql.pyx":1106
 *                 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_4 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_self->last_dbresults, __pyx_v_self); if (unlikely(__pyx_t_4 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1106; __pyx_clineno = __LINE__; goto __pyx_L4;}

    /* "_mssql.pyx":1108
 *             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":1110
 *             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_3 = ((__pyx_v_self->last_dbresults == NO_MORE_RESULTS) != 0);
    if (__pyx_t_3) {

      /* "_mssql.pyx":1111
 * 
 *             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":1112
 *             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(__pyx_k_77);

      /* "_mssql.pyx":1113
 *                 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;
      goto __pyx_L15;
    }
    __pyx_L15:;

    /* "_mssql.pyx":1115
 *                 return None
 * 
 *             self.num_columns = dbnumcols(self.dbproc)             # <<<<<<<<<<<<<<
 * 
 *             sprintf(log_message, "_mssql.MSSQLConnection.get_result(): num_columns = %d", self.num_columns)
 */
    __pyx_v_self->num_columns = dbnumcols(__pyx_v_self->dbproc);

    /* "_mssql.pyx":1117
 *             self.num_columns = dbnumcols(self.dbproc)
 * 
 *             sprintf(log_message, "_mssql.MSSQLConnection.get_result(): num_columns = %d", self.num_columns)             # <<<<<<<<<<<<<<
 *             log(log_message)
 * 
 */
    sprintf(__pyx_v_log_message, __pyx_k_78, __pyx_v_self->num_columns);

    /* "_mssql.pyx":1118
 * 
 *             sprintf(log_message, "_mssql.MSSQLConnection.get_result(): num_columns = %d", self.num_columns)
 *             log(log_message)             # <<<<<<<<<<<<<<
 * 
 *             column_names = list()
 */
    __pyx_f_6_mssql_log(__pyx_v_log_message);

    /* "_mssql.pyx":1120
 *             log(log_message)
 * 
 *             column_names = list()             # <<<<<<<<<<<<<<
 *             column_types = list()
 * 
 */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_v_column_names = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":1121
 * 
 *             column_names = list()
 *             column_types = list()             # <<<<<<<<<<<<<<
 * 
 *             for col in xrange(1, self.num_columns + 1):
 */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_v_column_types = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":1123
 *             column_types = list()
 * 
 *             for col in xrange(1, self.num_columns + 1):             # <<<<<<<<<<<<<<
 *                 column_name = dbcolname(self.dbproc, col).decode(self._charset)
 *                 column_names.append(column_name)
 */
    __pyx_t_6 = (__pyx_v_self->num_columns + 1);
    for (__pyx_t_7 = 1; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
      __pyx_v_col = __pyx_t_7;

      /* "_mssql.pyx":1124
 * 
 *             for col in xrange(1, self.num_columns + 1):
 *                 column_name = dbcolname(self.dbproc, col).decode(self._charset)             # <<<<<<<<<<<<<<
 *                 column_names.append(column_name)
 *                 coltype = dbcoltype(self.dbproc, col)
 */
      __pyx_t_8 = dbcolname(__pyx_v_self->dbproc, __pyx_v_col);
      __pyx_t_5 = ((PyObject *)__Pyx_decode_c_string(__pyx_t_8, 0, strlen(__pyx_t_8), __pyx_v_self->_charset, NULL, NULL)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __Pyx_INCREF(((PyObject *)__pyx_t_5));
      __Pyx_XDECREF(__pyx_v_column_name);
      __pyx_v_column_name = ((PyObject *)__pyx_t_5);
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;

      /* "_mssql.pyx":1125
 *             for col in xrange(1, self.num_columns + 1):
 *                 column_name = dbcolname(self.dbproc, col).decode(self._charset)
 *                 column_names.append(column_name)             # <<<<<<<<<<<<<<
 *                 coltype = dbcoltype(self.dbproc, col)
 *                 column_types.append(get_api_coltype(coltype))
 */
      __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_column_names, __pyx_v_column_name); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L4;}

      /* "_mssql.pyx":1126
 *                 column_name = dbcolname(self.dbproc, col).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":1127
 *                 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_5 = PyInt_FromLong(__pyx_f_6_mssql_get_api_coltype(__pyx_v_coltype)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_column_types, __pyx_t_5); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }

    /* "_mssql.pyx":1129
 *                 column_types.append(get_api_coltype(coltype))
 * 
 *             self.column_names = tuple(column_names)             # <<<<<<<<<<<<<<
 *             self.column_types = tuple(column_types)
 *         finally:
 */
    __pyx_t_5 = ((PyObject *)PyList_AsTuple(__pyx_v_column_names)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __Pyx_GOTREF(__pyx_v_self->column_names);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->column_names));
    __pyx_v_self->column_names = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "_mssql.pyx":1130
 * 
 *             self.column_names = tuple(column_names)
 *             self.column_types = tuple(column_types)             # <<<<<<<<<<<<<<
 *         finally:
 *             log("_mssql.MSSQLConnection.get_result() END")
 */
    __pyx_t_5 = ((PyObject *)PyList_AsTuple(__pyx_v_column_types)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L4;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __Pyx_GOTREF(__pyx_v_self->column_types);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->column_types));
    __pyx_v_self->column_types = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;
  }

  /* "_mssql.pyx":1132
 *             self.column_types = tuple(column_types)
 *         finally:
 *             log("_mssql.MSSQLConnection.get_result() END")             # <<<<<<<<<<<<<<
 * 
 *     cdef get_row(self, int row_info):
 */
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L5;
    __pyx_L3: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 3; goto __pyx_L5;
    __pyx_L4: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L5;
    }
    __pyx_L5:;
    __pyx_f_6_mssql_log(__pyx_k_79);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __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":1134
 *             log("_mssql.MSSQLConnection.get_result() END")
 * 
 *     cdef get_row(self, int row_info):             # <<<<<<<<<<<<<<
 *         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) {
  DBPROCESS *__pyx_v_dbproc;
  int __pyx_v_col;
  int __pyx_v_col_type;
  int __pyx_v_len;
  BYTE *__pyx_v_data;
  PyObject *__pyx_v_record = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  DBPROCESS *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  long __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_row", 0);

  /* "_mssql.pyx":1135
 * 
 *     cdef get_row(self, int row_info):
 *         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":1140
 *         cdef int len
 *         cdef BYTE *data
 *         log("_mssql.MSSQLConnection.get_row()")             # <<<<<<<<<<<<<<
 * 
 *         if PYMSSQL_DEBUG == 1:
 */
  __pyx_f_6_mssql_log(__pyx_k_80);

  /* "_mssql.pyx":1146
 *             _row_count += 1
 * 
 *         record = tuple()             # <<<<<<<<<<<<<<
 * 
 *         for col in xrange(1, self.num_columns + 1):
 */
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_record = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1148
 *         record = tuple()
 * 
 *         for col in xrange(1, self.num_columns + 1):             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 data = get_data(dbproc, row_info, col)
 */
  __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":1149
 * 
 *         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":1150
 *         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":1151
 *             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":1152
 *                 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":1149
 * 
 *         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:*/ {
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
        }
    }

    /* "_mssql.pyx":1154
 *                 len = get_length(dbproc, row_info, col)
 * 
 *             if data == NULL:             # <<<<<<<<<<<<<<
 *                 record += (None,)
 *                 continue
 */
    __pyx_t_5 = ((__pyx_v_data == NULL) != 0);
    if (__pyx_t_5) {

      /* "_mssql.pyx":1155
 * 
 *             if data == NULL:
 *                 record += (None,)             # <<<<<<<<<<<<<<
 *                 continue
 * 
 */
      __pyx_t_2 = PyNumber_InPlaceAdd(((PyObject *)__pyx_v_record), ((PyObject *)__pyx_k_tuple_81)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_DECREF(((PyObject *)__pyx_v_record));
      __pyx_v_record = ((PyObject*)__pyx_t_2);
      __pyx_t_2 = 0;

      /* "_mssql.pyx":1156
 *             if data == NULL:
 *                 record += (None,)
 *                 continue             # <<<<<<<<<<<<<<
 * 
 *             IF PYMSSQL_DEBUG == 1:
 */
      goto __pyx_L3_continue;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "_mssql.pyx":1164
 *                     data, col_type, len)
 * 
 *             record += (self.convert_db_value(data, col_type, len),)             # <<<<<<<<<<<<<<
 *         return record
 * 
 */
    __pyx_t_2 = ((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_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_InPlaceAdd(((PyObject *)__pyx_v_record), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_record));
    __pyx_v_record = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_L3_continue:;
  }

  /* "_mssql.pyx":1165
 * 
 *             record += (self.convert_db_value(data, col_type, len),)
 *         return record             # <<<<<<<<<<<<<<
 * 
 *     def init_procedure(self, procname):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_record));
  __pyx_r = ((PyObject *)__pyx_v_record);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_mssql.MSSQLConnection.get_row", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_record);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_23init_procedure(PyObject *__pyx_v_self, PyObject *__pyx_v_procname); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_22init_procedure[] = "\n        init_procedure(procname) -- creates and returns a MSSQLStoredProcedure\n        object.\n\n        This methods initilizes 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_23init_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_22init_procedure(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), ((PyObject *)__pyx_v_procname));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1167
 *         return record
 * 
 *     def init_procedure(self, procname):             # <<<<<<<<<<<<<<
 *         """
 *         init_procedure(procname) -- creates and returns a MSSQLStoredProcedure
 */

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_22init_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("init_procedure", 0);

  /* "_mssql.pyx":1176
 *         be bound.
 *         """
 *         log("_mssql.MSSQLConnection.init_procedure()")             # <<<<<<<<<<<<<<
 *         return MSSQLStoredProcedure(procname.encode(self.charset), self)
 * 
 */
  __pyx_f_6_mssql_log(__pyx_k_82);

  /* "_mssql.pyx":1177
 *         """
 *         log("_mssql.MSSQLConnection.init_procedure()")
 *         return MSSQLStoredProcedure(procname.encode(self.charset), self)             # <<<<<<<<<<<<<<
 * 
 *     def nextresult(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_procname, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s__charset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLStoredProcedure)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __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.init_procedure", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_25nextresult(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_24nextresult[] = "\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_25nextresult(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_24nextresult(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1179
 *         return MSSQLStoredProcedure(procname.encode(self.charset), self)
 * 
 *     def nextresult(self):             # <<<<<<<<<<<<<<
 *         """
 *         nextresult() -- move to the next result, skipping all pending rows.
 */

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_24nextresult(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("nextresult", 0);

  /* "_mssql.pyx":1189
 * 
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.nextresult()")             # <<<<<<<<<<<<<<
 * 
 *         assert_connected(self)
 */
  __pyx_f_6_mssql_log(__pyx_k_83);

  /* "_mssql.pyx":1191
 *         log("_mssql.MSSQLConnection.nextresult()")
 * 
 *         assert_connected(self)             # <<<<<<<<<<<<<<
 *         clr_err(self)
 * 
 */
  __pyx_f_6_mssql_assert_connected(__pyx_v_self);

  /* "_mssql.pyx":1192
 * 
 *         assert_connected(self)
 *         clr_err(self)             # <<<<<<<<<<<<<<
 * 
 *         rtc = dbnextrow(self.dbproc)
 */
  __pyx_f_6_mssql_clr_err(__pyx_v_self);

  /* "_mssql.pyx":1194
 *         clr_err(self)
 * 
 *         rtc = dbnextrow(self.dbproc)             # <<<<<<<<<<<<<<
 *         check_cancel_and_raise(rtc, self)
 * 
 */
  __pyx_v_rtc = dbnextrow(__pyx_v_self->dbproc);

  /* "_mssql.pyx":1195
 * 
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1197
 *         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":1198
 * 
 *         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":1199
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "_mssql.pyx":1201
 *             check_cancel_and_raise(rtc, self)
 * 
 *         self.last_dbresults = 0             # <<<<<<<<<<<<<<
 *         self.get_result()
 * 
 */
  __pyx_v_self->last_dbresults = 0;

  /* "_mssql.pyx":1202
 * 
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1204
 *         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":1205
 * 
 *         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;
    goto __pyx_L5;
  }
  __pyx_L5:;

  __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15MSSQLConnection_27select_db(PyObject *__pyx_v_self, PyObject *__pyx_v_dbname); /*proto*/
static char __pyx_doc_6_mssql_15MSSQLConnection_26select_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_27select_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_26select_db(((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_v_self), ((PyObject *)__pyx_v_dbname));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1207
 *             return 1
 * 
 *     def select_db(self, dbname):             # <<<<<<<<<<<<<<
 *         """
 *         select_db(dbname) -- Select the current database.
 */

static PyObject *__pyx_pf_6_mssql_15MSSQLConnection_26select_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("select_db", 0);

  /* "_mssql.pyx":1215
 *         """
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLConnection.select_db()")             # <<<<<<<<<<<<<<
 * 
 *         # For Python 3, we need to convert unicode to byte strings
 */
  __pyx_f_6_mssql_log(__pyx_k_84);

  /* "_mssql.pyx":1218
 * 
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_85), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __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 bytes, got %.200s", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dbname_bytes = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1219
 *         # 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(((PyObject *)__pyx_v_dbname_bytes)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dbname_cstr = __pyx_t_3;

  /* "_mssql.pyx":1221
 *         cdef char *dbname_cstr = dbname_bytes
 * 
 *         dbuse(self.dbproc, dbname_cstr)             # <<<<<<<<<<<<<<
 * 
 * ##################################
 */
  dbuse(__pyx_v_self->dbproc, __pyx_v_dbname_cstr);

  __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;
}

/* 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));
  __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
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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_filename = __pyx_f[1]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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));
  __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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->debug_queries = __pyx_t_1;

  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1230
 *     property connection:
 *         """The underlying MSSQLConnection object."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.conn
 * 
 */

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":1231
 *         """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;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1235
 *     property name:
 *         """The name of the procedure that this object represents."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.procname
 * 
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "_mssql.pyx":1236
 *         """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_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1240
 *     property parameters:
 *         """The parameters that have been bound to this procedure."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.params
 * 
 */

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":1241
 *         """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(((PyObject *)__pyx_v_self->params));
  __pyx_r = ((PyObject *)__pyx_v_self->params);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_connection), __pyx_ptype_6_mssql_MSSQLConnection, 1, "connection", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1243
 *             return self.params
 * 
 *     def __init__(self, bytes name, MSSQLConnection connection):             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         log("_mssql.MSSQLStoredProcedure.__init__()")
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "_mssql.pyx":1245
 *     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(__pyx_k_86);

  /* "_mssql.pyx":1249
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "_mssql.pyx":1250
 *         # 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 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_88), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1253
 *                 "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":1254
 * 
 *         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":1255
 *         self.conn = connection
 *         self.dbproc = connection.dbproc
 *         self.procname = name             # <<<<<<<<<<<<<<
 *         self.params = dict()
 *         self.output_indexes = list()
 */
  __pyx_t_5 = __Pyx_PyObject_AsString(((PyObject *)__pyx_v_name)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->procname = __pyx_t_5;

  /* "_mssql.pyx":1256
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __Pyx_GOTREF(__pyx_v_self->params);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->params));
  __pyx_v_self->params = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1257
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __Pyx_GOTREF(__pyx_v_self->output_indexes);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->output_indexes));
  __pyx_v_self->output_indexes = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1258
 *         self.params = dict()
 *         self.output_indexes = list()
 *         self.param_count = 0             # <<<<<<<<<<<<<<
 *         self.had_positional = False
 * 
 */
  __pyx_v_self->param_count = 0;

  /* "_mssql.pyx":1259
 *         self.output_indexes = list()
 *         self.param_count = 0
 *         self.had_positional = False             # <<<<<<<<<<<<<<
 * 
 *         with nogil:
 */
  __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_4bool_bool)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->had_positional);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->had_positional));
  __pyx_v_self->had_positional = ((PyBoolObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_mssql.pyx":1261
 *         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":1262
 * 
 *         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":1261
 *         self.had_positional = False
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcinit(self.dbproc, self.procname, 0)
 * 
 */
      /*finally:*/ {
        #ifdef WITH_THREAD
        Py_BLOCK_THREADS
        #endif
      }
  }

  /* "_mssql.pyx":1264
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":1266
 *         check_cancel_and_raise(rtc, self.conn)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef _mssql_parameter_node *n, *p
 *         log("_mssql.MSSQLStoredProcedure.__dealloc__()")
 */

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":1268
 *     def __dealloc__(self):
 *         cdef _mssql_parameter_node *n, *p
 *         log("_mssql.MSSQLStoredProcedure.__dealloc__()")             # <<<<<<<<<<<<<<
 * 
 *         n = self.params_list
 */
  __pyx_f_6_mssql_log(__pyx_k_89);

  /* "_mssql.pyx":1270
 *         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":1271
 * 
 *         n = self.params_list
 *         p = NULL             # <<<<<<<<<<<<<<
 * 
 *         while n != NULL:
 */
  __pyx_v_p = NULL;

  /* "_mssql.pyx":1273
 *         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":1274
 * 
 *         while n != NULL:
 *             PyMem_Free(n.value)             # <<<<<<<<<<<<<<
 *             p = n
 *             n = n.next
 */
    PyMem_Free(__pyx_v_n->value);

    /* "_mssql.pyx":1275
 *         while n != NULL:
 *             PyMem_Free(n.value)
 *             p = n             # <<<<<<<<<<<<<<
 *             n = n.next
 *             PyMem_Free(p)
 */
    __pyx_v_p = __pyx_v_n;

    /* "_mssql.pyx":1276
 *             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":1277
 *             p = n
 *             n = n.next
 *             PyMem_Free(p)             # <<<<<<<<<<<<<<
 * 
 *     def bind(self, object value, int dbtype, str param_name=None,
 */
    PyMem_Free(__pyx_v_p);
  }

  __Pyx_RefNannyFinishContext();
}

/* 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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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};

    /* "_mssql.pyx":1279
 *             PyMem_Free(p)
 * 
 *     def bind(self, object value, int dbtype, str param_name=None,             # <<<<<<<<<<<<<<
 *             int output=False, int null=False, int max_length=-1):
 *         """
 */
    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_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __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_AsInt(values[1]); if (unlikely((__pyx_v_dbtype == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_param_name = ((PyObject*)values[2]);
    if (values[3]) {
      __pyx_v_output = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_output == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "_mssql.pyx":1280
 * 
 *     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_AsInt(values[4]); if (unlikely((__pyx_v_null == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_null = ((int)0);
    }
    if (values[5]) {
      __pyx_v_max_length = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_max_length == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1279
 *             PyMem_Free(p)
 * 
 *     def bind(self, object value, int dbtype, str param_name=None,             # <<<<<<<<<<<<<<
 *             int output=False, int null=False, int max_length=-1):
 *         """
 */

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;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  struct __pyx_t_6_mssql__mssql_parameter_node *__pyx_t_8;
  char *__pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("bind", 0);

  /* "_mssql.pyx":1287
 *         This method binds a parameter to the stored procedure.
 *         """
 *         cdef int length = -1             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         cdef BYTE status, *data
 */
  __pyx_v_length = -1;

  /* "_mssql.pyx":1293
 *         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(__pyx_k_90);

  /* "_mssql.pyx":1296
 * 
 *         # 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":1299
 * 
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1302
 * 
 *         # 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_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINTN); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!((int)__pyx_t_5)) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLBITN); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = ((int)__pyx_t_6);
  } else {
    __pyx_t_7 = ((int)__pyx_t_5);
  }
  __pyx_t_5 = (__pyx_t_7 != 0);
  if (__pyx_t_5) {
    __pyx_t_7 = ((__pyx_v_data == NULL) != 0);
    __pyx_t_6 = __pyx_t_7;
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  if (__pyx_t_6) {

    /* "_mssql.pyx":1303
 *         # 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;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1307
 *         # 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_6 = ((__pyx_v_data != NULL) != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":1308
 *         # 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":1309
 *         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_6 = ((__pyx_v_pn == NULL) != 0);
    if (__pyx_t_6) {

      /* "_mssql.pyx":1310
 *             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_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_91), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1310; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "_mssql.pyx":1311
 *             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":1312
 *                 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":1313
 *             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;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "_mssql.pyx":1317
 *         # 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_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLVARCHAR); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!((int)__pyx_t_6)) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLCHAR); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = ((int)__pyx_t_5);
  } else {
    __pyx_t_7 = ((int)__pyx_t_6);
  }
  if (!__pyx_t_7) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLTEXT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = ((int)__pyx_t_6);
  } else {
    __pyx_t_5 = __pyx_t_7;
  }
  if (!__pyx_t_5) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLBINARY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = ((int)__pyx_t_7);
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  if (!__pyx_t_6) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);

    /* "_mssql.pyx":1318
 *         # passed to the server here.
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,
 *             SQLVARBINARY, SQLIMAGE):             # <<<<<<<<<<<<<<
 *             if null or data == NULL:
 *                 length = 0
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLVARBINARY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_5);
  } else {
    __pyx_t_7 = __pyx_t_6;
  }
  if (!__pyx_t_7) {

    /* "_mssql.pyx":1317
 *         # 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_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "_mssql.pyx":1318
 *         # passed to the server here.
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,
 *             SQLVARBINARY, SQLIMAGE):             # <<<<<<<<<<<<<<
 *             if null or data == NULL:
 *                 length = 0
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLIMAGE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = ((int)__pyx_t_6);
  } else {
    __pyx_t_5 = __pyx_t_7;
  }
  __pyx_t_7 = (__pyx_t_5 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1319
 *         if dbtype in (SQLVARCHAR, SQLCHAR, SQLTEXT, SQLBINARY,
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:             # <<<<<<<<<<<<<<
 *                 length = 0
 *                 if not output:
 */
    if (!(__pyx_v_null != 0)) {
      __pyx_t_7 = (__pyx_v_data == NULL);
      __pyx_t_5 = __pyx_t_7;
    } else {
      __pyx_t_5 = (__pyx_v_null != 0);
    }
    if (__pyx_t_5) {

      /* "_mssql.pyx":1320
 *             SQLVARBINARY, SQLIMAGE):
 *             if null or data == NULL:
 *                 length = 0             # <<<<<<<<<<<<<<
 *                 if not output:
 *                     max_length = -1
 */
      __pyx_v_length = 0;

      /* "_mssql.pyx":1321
 *             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_5 = ((!(__pyx_v_output != 0)) != 0);
      if (__pyx_t_5) {

        /* "_mssql.pyx":1322
 *                 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;
        goto __pyx_L8;
      }
      __pyx_L8:;
      goto __pyx_L7;
    }

    /* "_mssql.pyx":1324
 *                     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_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLVARCHAR); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!((int)__pyx_t_5)) {
      __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLCHAR); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_6 = ((int)__pyx_t_7);
    } else {
      __pyx_t_6 = ((int)__pyx_t_5);
    }
    if (!__pyx_t_6) {
      __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLTEXT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_7 = ((int)__pyx_t_5);
    } else {
      __pyx_t_7 = __pyx_t_6;
    }
    __pyx_t_6 = (__pyx_t_7 != 0);
    if (__pyx_t_6) {

      /* "_mssql.pyx":1325
 *             # 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));
      goto __pyx_L7;
    }
    __pyx_L7:;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "_mssql.pyx":1328
 *         else:
 *             # Fixed length data type
 *             if null or (output and dbtype not in (SQLDECIMAL, SQLNUMERIC)):             # <<<<<<<<<<<<<<
 *                 length = 0
 *             max_length = -1
 */
    if (!(__pyx_v_null != 0)) {
      if ((__pyx_v_output != 0)) {
        __pyx_t_1 = __pyx_v_dbtype;
        __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDECIMAL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (((int)__pyx_t_6)) {
          __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLNUMERIC); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_5 = ((int)__pyx_t_7);
        } else {
          __pyx_t_5 = ((int)__pyx_t_6);
        }
        __pyx_t_6 = __pyx_t_5;
        __pyx_t_5 = __pyx_t_6;
      } else {
        __pyx_t_5 = (__pyx_v_output != 0);
      }
      __pyx_t_6 = __pyx_t_5;
    } else {
      __pyx_t_6 = (__pyx_v_null != 0);
    }
    if (__pyx_t_6) {

      /* "_mssql.pyx":1329
 *             # Fixed length data type
 *             if null or (output and dbtype not in (SQLDECIMAL, SQLNUMERIC)):
 *                 length = 0             # <<<<<<<<<<<<<<
 *             max_length = -1
 * 
 */
      __pyx_v_length = 0;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "_mssql.pyx":1330
 *             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_L6:;

  /* "_mssql.pyx":1333
 * 
 *         # Add some monkey fixing for nullable bit types
 *         if dbtype == SQLBITN:             # <<<<<<<<<<<<<<
 *             if output:
 *                 max_length = 1
 */
  __pyx_t_4 = PyInt_FromLong(__pyx_v_dbtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLBITN); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_6) {

    /* "_mssql.pyx":1334
 *         # Add some monkey fixing for nullable bit types
 *         if dbtype == SQLBITN:
 *             if output:             # <<<<<<<<<<<<<<
 *                 max_length = 1
 *                 length = 0
 */
    __pyx_t_6 = (__pyx_v_output != 0);
    if (__pyx_t_6) {

      /* "_mssql.pyx":1335
 *         if dbtype == SQLBITN:
 *             if output:
 *                 max_length = 1             # <<<<<<<<<<<<<<
 *                 length = 0
 *             else:
 */
      __pyx_v_max_length = 1;

      /* "_mssql.pyx":1336
 *             if output:
 *                 max_length = 1
 *                 length = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 length = 1
 */
      __pyx_v_length = 0;
      goto __pyx_L11;
    }
    /*else*/ {

      /* "_mssql.pyx":1338
 *                 length = 0
 *             else:
 *                 length = 1             # <<<<<<<<<<<<<<
 * 
 *         if status != DBRPCRETURN:
 */
      __pyx_v_length = 1;
    }
    __pyx_L11:;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "_mssql.pyx":1340
 *                 length = 1
 * 
 *         if status != DBRPCRETURN:             # <<<<<<<<<<<<<<
 *             max_length = -1
 * 
 */
  __pyx_t_6 = ((__pyx_v_status != DBRPCRETURN) != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":1341
 * 
 *         if status != DBRPCRETURN:
 *             max_length = -1             # <<<<<<<<<<<<<<
 * 
 *         if param_name:
 */
    __pyx_v_max_length = -1;
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "_mssql.pyx":1343
 *             max_length = -1
 * 
 *         if param_name:             # <<<<<<<<<<<<<<
 *             param_name_bytes = param_name.encode('ascii')
 *             param_name_cstr = param_name_bytes
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_param_name)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_6) {

    /* "_mssql.pyx":1344
 * 
 *         if param_name:
 *             param_name_bytes = param_name.encode('ascii')             # <<<<<<<<<<<<<<
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_param_name), __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_92), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_param_name_bytes = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "_mssql.pyx":1345
 *         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(((PyObject *)__pyx_v_param_name_bytes)); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_param_name_cstr = __pyx_t_9;

    /* "_mssql.pyx":1346
 *             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_6 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->had_positional)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_6) {

      /* "_mssql.pyx":1347
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')             # <<<<<<<<<<<<<<
 *         else:
 *             param_name_cstr = ''
 */
      __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L14;
    }
    __pyx_L14:;
    goto __pyx_L13;
  }
  /*else*/ {

    /* "_mssql.pyx":1349
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')
 *         else:
 *             param_name_cstr = ''             # <<<<<<<<<<<<<<
 *             self.had_positional = True
 * 
 */
    __pyx_v_param_name_cstr = __pyx_k_12;

    /* "_mssql.pyx":1350
 *         else:
 *             param_name_cstr = ''
 *             self.had_positional = True             # <<<<<<<<<<<<<<
 * 
 *         IF PYMSSQL_DEBUG == 1:
 */
    __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7cpython_4bool_bool)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(__pyx_v_self->had_positional);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->had_positional));
    __pyx_v_self->had_positional = ((PyBoolObject *)__pyx_t_3);
    __pyx_t_3 = 0;
  }
  __pyx_L13:;

  /* "_mssql.pyx":1359
 *             )
 * 
 *         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":1361
 *         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":1359
 *             )
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcparam(self.dbproc, param_name_cstr, status, dbtype,
 *                 max_length, length, data)
 */
      /*finally:*/ {
        #ifdef WITH_THREAD
        Py_BLOCK_THREADS
        #endif
      }
  }

  /* "_mssql.pyx":1362
 *             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_3 = ((PyObject *)__pyx_v_self->conn);
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_1 = __pyx_f_6_mssql_check_cancel_and_raise(__pyx_v_rtc, ((struct __pyx_obj_6_mssql_MSSQLConnection *)__pyx_t_3)); if (unlikely(__pyx_t_1 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "_mssql.pyx":1366
 *         # 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_6 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_param_name)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_6) {

    /* "_mssql.pyx":1367
 *         # 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(((PyObject *)__pyx_v_self->params) == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(((PyObject *)__pyx_v_self->params), ((PyObject *)__pyx_v_param_name), __pyx_v_value) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L18;
  }
  __pyx_L18:;

  /* "_mssql.pyx":1368
 *         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(((PyObject *)__pyx_v_self->params) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (__Pyx_SetItemInt(((PyObject *)__pyx_v_self->params), __pyx_v_self->param_count, __pyx_v_value, sizeof(int), PyInt_FromLong, 0, 1, 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1369
 *             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_6 = (__pyx_v_output != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":1370
 *         self.params[self.param_count] = value
 *         if output:
 *             self.output_indexes.append(self.param_count)             # <<<<<<<<<<<<<<
 *         self.param_count += 1
 * 
 */
    if (unlikely(((PyObject *)__pyx_v_self->output_indexes) == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_3 = PyInt_FromLong(__pyx_v_self->param_count); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_self->output_indexes, __pyx_t_3); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L19;
  }
  __pyx_L19:;

  /* "_mssql.pyx":1371
 *         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);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __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;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1373
 *         self.param_count += 1
 * 
 *     def execute(self):             # <<<<<<<<<<<<<<
 *         cdef RETCODE rtc
 *         cdef int output_count, i, type, length
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("execute", 0);

  /* "_mssql.pyx":1378
 *         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(__pyx_k_95);

  /* "_mssql.pyx":1382
 *         # 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":1385
 * 
 *         # 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":1386
 *         # 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":1385
 * 
 *         # Send the RPC request
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbrpcsend(self.dbproc)
 *         check_cancel_and_raise(rtc, self.conn)
 */
      /*finally:*/ {
        #ifdef WITH_THREAD
        Py_BLOCK_THREADS
        #endif
      }
  }

  /* "_mssql.pyx":1387
 *         with nogil:
 *             rtc = dbrpcsend(self.dbproc)
 *         check_cancel_and_raise(rtc, self.conn)             # <<<<<<<<<<<<<<
 * 
 *         # Wait for the server to return
 */
  __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_filename = __pyx_f[0]; __pyx_lineno = 1387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1390
 * 
 *         # Wait for the server to return
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbsqlok(self.dbproc)
 *         check_cancel_and_raise(rtc, self.conn)
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "_mssql.pyx":1391
 *         # Wait for the server to return
 *         with nogil:
 *             rtc = dbsqlok(self.dbproc)             # <<<<<<<<<<<<<<
 *         check_cancel_and_raise(rtc, self.conn)
 * 
 */
        __pyx_v_rtc = dbsqlok(__pyx_v_self->dbproc);
      }

      /* "_mssql.pyx":1390
 * 
 *         # Wait for the server to return
 *         with nogil:             # <<<<<<<<<<<<<<
 *             rtc = dbsqlok(self.dbproc)
 *         check_cancel_and_raise(rtc, self.conn)
 */
      /*finally:*/ {
        #ifdef WITH_THREAD
        Py_BLOCK_THREADS
        #endif
      }
  }

  /* "_mssql.pyx":1392
 *         with nogil:
 *             rtc = dbsqlok(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_filename = __pyx_f[0]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1396
 *         # 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":1400
 *         # 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":1401
 *         # 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":1402
 *         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":1403
 *             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":1404
 *                 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":1405
 *                     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":1406
 *                     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":1402
 *         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:*/ {
            #ifdef WITH_THREAD
            Py_BLOCK_THREADS
            #endif
          }
      }

      /* "_mssql.pyx":1408
 *                     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_filename = __pyx_f[0]; __pyx_lineno = 1408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_v_value);
      __pyx_v_value = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "_mssql.pyx":1409
 * 
 *                 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":1410
 *                 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 = ((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_1));
        __Pyx_XDECREF(__pyx_v_param_name);
        __pyx_v_param_name = ((PyObject *)__pyx_t_1);
        __pyx_t_1 = 0;

        /* "_mssql.pyx":1411
 *                 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(((PyObject *)__pyx_v_self->params) == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        if (PyDict_SetItem(((PyObject *)__pyx_v_self->params), __pyx_v_param_name, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L17;
      }
      __pyx_L17:;

      /* "_mssql.pyx":1412
 *                     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(((PyObject *)__pyx_v_self->params) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (unlikely(((PyObject *)__pyx_v_self->output_indexes) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_5 = (__pyx_v_i - 1);
      __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_self->output_indexes), __pyx_t_5, sizeof(long), PyInt_FromLong, 1, 1, 1); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(((PyObject *)__pyx_v_self->params), __pyx_t_1, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "_mssql.pyx":1415
 * 
 *         # 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_to_py_DBINT(dbretstatus(__pyx_v_self->dbproc)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":1417
 *         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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("check_and_raise", 0);

  /* "_mssql.pyx":1418
 * 
 * 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":1419
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_r = __pyx_t_2;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":1420
 *     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":1421
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_r = __pyx_t_2;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  __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":1423
 *         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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("check_cancel_and_raise", 0);

  /* "_mssql.pyx":1424
 * 
 * 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":1425
 * 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":1426
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_r = __pyx_t_2;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":1427
 *         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":1428
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_r = __pyx_t_2;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  __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":1430
 *         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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_last_msg_str", 0);

  /* "_mssql.pyx":1431
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __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;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1433
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_last_msg_srv", 0);

  /* "_mssql.pyx":1434
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1434; __pyx_clineno = __LINE__; goto __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;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_srv", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1436
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_last_msg_proc", 0);

  /* "_mssql.pyx":1437
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1437; __pyx_clineno = __LINE__; goto __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;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_proc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1439
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_last_msg_no", 0);

  /* "_mssql.pyx":1440
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __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;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_no", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1442
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_last_msg_severity", 0);

  /* "_mssql.pyx":1443
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1443; __pyx_clineno = __LINE__; goto __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;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_severity", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1445
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_last_msg_state", 0);

  /* "_mssql.pyx":1446
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1446; __pyx_clineno = __LINE__; goto __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;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1448
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_last_msg_line", 0);

  /* "_mssql.pyx":1449
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1449; __pyx_clineno = __LINE__; goto __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;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.get_last_msg_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1451
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("maybe_raise_MSSQLDatabaseException", 0);

  /* "_mssql.pyx":1453
 * cdef int maybe_raise_MSSQLDatabaseException(MSSQLConnection conn) except 1:
 * 
 *     if get_last_msg_severity(conn) < min_error_severity:             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_f_6_mssql_get_last_msg_severity(__pyx_v_conn)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "_mssql.pyx":1454
 * 
 *     if get_last_msg_severity(conn) < min_error_severity:
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     error_msg = get_last_msg_str(conn)
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1456
 *         return 0
 * 
 *     error_msg = get_last_msg_str(conn)             # <<<<<<<<<<<<<<
 *     if len(error_msg) == 0:
 *         error_msg = "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_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_v_error_msg = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "_mssql.pyx":1457
 * 
 *     error_msg = get_last_msg_str(conn)
 *     if len(error_msg) == 0:             # <<<<<<<<<<<<<<
 *         error_msg = "Unknown error"
 * 
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_error_msg); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((__pyx_t_5 == 0) != 0);
  if (__pyx_t_4) {

    /* "_mssql.pyx":1458
 *     error_msg = get_last_msg_str(conn)
 *     if len(error_msg) == 0:
 *         error_msg = "Unknown error"             # <<<<<<<<<<<<<<
 * 
 *     ex = MSSQLDatabaseException((get_last_msg_no(conn), error_msg))
 */
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_96));
    __Pyx_DECREF(__pyx_v_error_msg);
    __pyx_v_error_msg = ((PyObject *)__pyx_kp_s_96);
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "_mssql.pyx":1460
 *         error_msg = "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 = PyInt_FromLong(__pyx_f_6_mssql_get_last_msg_no(__pyx_v_conn)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_error_msg);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_error_msg);
  __Pyx_GIVEREF(__pyx_v_error_msg);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDatabaseException)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__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":1461
 * 
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_ex->text = __pyx_t_6;

  /* "_mssql.pyx":1462
 *     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":1463
 *     (<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":1464
 *     (<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":1465
 *     (<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":1466
 *     (<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":1467
 *     (<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":1468
 *     (<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":1469
 *     (<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":1470
 *     db_cancel(conn)
 *     clr_err(conn)
 *     raise ex             # <<<<<<<<<<<<<<
 * 
 * cdef void assert_connected(MSSQLConnection conn):
 */
  __Pyx_Raise(((PyObject *)__pyx_v_ex), 0, 0, 0);
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = 0;
  goto __pyx_L0;
  __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":1472
 *     raise ex
 * 
 * cdef void assert_connected(MSSQLConnection conn):             # <<<<<<<<<<<<<<
 *     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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("assert_connected", 0);

  /* "_mssql.pyx":1473
 * 
 * cdef void assert_connected(MSSQLConnection conn):
 *     log("_mssql.assert_connected()")             # <<<<<<<<<<<<<<
 *     if not conn.connected:
 *         raise MSSQLDriverException("Not connected to any MS SQL server")
 */
  __pyx_f_6_mssql_log(__pyx_k_97);

  /* "_mssql.pyx":1474
 * cdef void assert_connected(MSSQLConnection conn):
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __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":1475
 *     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 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_99), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1475; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("_mssql.assert_connected", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "_mssql.pyx":1477
 *         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":1478
 * 
 * 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":1479
 * 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;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "_mssql.pyx":1481
 *         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":1482
 * 
 * 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":1483
 * 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;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "_mssql.pyx":1485
 *         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":1486
 * 
 * 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":1487
 * 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;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "_mssql.pyx":1492
 * ## 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;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_api_coltype", 0);

  /* "_mssql.pyx":1493
 * ######################
 * 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_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLBIT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!((int)__pyx_t_5)) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = ((int)__pyx_t_6);
  } else {
    __pyx_t_7 = ((int)__pyx_t_5);
  }
  if (!__pyx_t_7) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = ((int)__pyx_t_5);
  } else {
    __pyx_t_6 = __pyx_t_7;
  }
  if (!__pyx_t_6) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = ((int)__pyx_t_7);
  } else {
    __pyx_t_5 = __pyx_t_6;
  }
  if (!__pyx_t_5) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINT8); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_6);
  } else {
    __pyx_t_7 = __pyx_t_5;
  }
  if (!__pyx_t_7) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLINTN); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = ((int)__pyx_t_5);
  } else {
    __pyx_t_6 = __pyx_t_7;
  }
  if (!__pyx_t_6) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);

    /* "_mssql.pyx":1494
 * 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_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLT4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = ((int)__pyx_t_7);
  } else {
    __pyx_t_5 = __pyx_t_6;
  }
  if (!__pyx_t_5) {

    /* "_mssql.pyx":1493
 * ######################
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,             # <<<<<<<<<<<<<<
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 */
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "_mssql.pyx":1494
 * 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_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLT8); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = ((int)__pyx_t_6);
  } else {
    __pyx_t_7 = __pyx_t_5;
  }
  if (!__pyx_t_7) {

    /* "_mssql.pyx":1493
 * ######################
 * cdef int get_api_coltype(int coltype):
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,             # <<<<<<<<<<<<<<
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 */
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);

    /* "_mssql.pyx":1494
 * 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_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLFLTN); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = ((int)__pyx_t_5);
  } else {
    __pyx_t_6 = __pyx_t_7;
  }
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1495
 *     if coltype in (SQLBIT, SQLINT1, SQLINT2, SQLINT4, SQLINT8, SQLINTN,
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER             # <<<<<<<<<<<<<<
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 *             SQLDECIMAL):
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__NUMBER); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":1496
 *             SQLFLT4, SQLFLT8, SQLFLTN):
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,             # <<<<<<<<<<<<<<
 *             SQLDECIMAL):
 *         return DECIMAL
 */
  __pyx_t_1 = __pyx_v_coltype;
  __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!((int)__pyx_t_7)) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEY4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = ((int)__pyx_t_6);
  } else {
    __pyx_t_5 = ((int)__pyx_t_7);
  }
  if (!__pyx_t_5) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLMONEYN); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = ((int)__pyx_t_7);
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  if (!__pyx_t_6) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLNUMERIC); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_5);
  } else {
    __pyx_t_7 = __pyx_t_6;
  }
  if (!__pyx_t_7) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "_mssql.pyx":1497
 *         return NUMBER
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 *             SQLDECIMAL):             # <<<<<<<<<<<<<<
 *         return DECIMAL
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDECIMAL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = ((int)__pyx_t_6);
  } else {
    __pyx_t_5 = __pyx_t_7;
  }
  __pyx_t_7 = (__pyx_t_5 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1498
 *     elif coltype in (SQLMONEY, SQLMONEY4, SQLMONEYN, SQLNUMERIC,
 *             SQLDECIMAL):
 *         return DECIMAL             # <<<<<<<<<<<<<<
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):
 *         return DATETIME
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__DECIMAL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":1499
 *             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_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDATETIME); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!((int)__pyx_t_7)) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDATETIM4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = ((int)__pyx_t_5);
  } else {
    __pyx_t_6 = ((int)__pyx_t_7);
  }
  if (!__pyx_t_6) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLDATETIMN); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = ((int)__pyx_t_7);
  } else {
    __pyx_t_5 = __pyx_t_6;
  }
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":1500
 *         return DECIMAL
 *     elif coltype in (SQLDATETIME, SQLDATETIM4, SQLDATETIMN):
 *         return DATETIME             # <<<<<<<<<<<<<<
 *     elif coltype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *         return STRING
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__DATETIME); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "_mssql.pyx":1501
 *     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_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLVARCHAR); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!((int)__pyx_t_6)) {
    __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLCHAR); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = ((int)__pyx_t_5);
  } else {
    __pyx_t_7 = ((int)__pyx_t_6);
  }
  if (!__pyx_t_7) {
    __pyx_t_4 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__SQLTEXT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = ((int)__pyx_t_6);
  } else {
    __pyx_t_5 = __pyx_t_7;
  }
  __pyx_t_7 = (__pyx_t_5 != 0);
  if (__pyx_t_7) {

    /* "_mssql.pyx":1502
 *         return DATETIME
 *     elif coltype in (SQLVARCHAR, SQLCHAR, SQLTEXT):
 *         return STRING             # <<<<<<<<<<<<<<
 *     else:
 *         return BINARY
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__STRING); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "_mssql.pyx":1504
 *         return STRING
 *     else:
 *         return BINARY             # <<<<<<<<<<<<<<
 * 
 * cdef char *_remove_locale(char *s, size_t buflen):
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__BINARY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;
  }
  __pyx_L3:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("_mssql.get_api_coltype", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1506
 *         return BINARY
 * 
 * cdef char *_remove_locale(char *s, size_t buflen):             # <<<<<<<<<<<<<<
 *     cdef char c, *stripped = s
 *     cdef int i, x = 0, last_sep = -1
 */

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;
  char __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_remove_locale", 0);

  /* "_mssql.pyx":1507
 * 
 * cdef char *_remove_locale(char *s, size_t buflen):
 *     cdef char c, *stripped = s             # <<<<<<<<<<<<<<
 *     cdef int i, x = 0, last_sep = -1
 * 
 */
  __pyx_v_stripped = __pyx_v_s;

  /* "_mssql.pyx":1508
 * cdef char *_remove_locale(char *s, size_t buflen):
 *     cdef char c, *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":1510
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (unlikely(((PyObject *)__pyx_t_2) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __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":1511
 * 
 *     for i, c in enumerate(s[0:buflen]):
 *         if c in (',', '.'):             # <<<<<<<<<<<<<<
 *             last_sep = i
 * 
 */
    __pyx_v_i = __pyx_t_1;

    /* "_mssql.pyx":1510
 *     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":1511
 * 
 *     for i, c in enumerate(s[0:buflen]):
 *         if c in (',', '.'):             # <<<<<<<<<<<<<<
 *             last_sep = i
 * 
 */
    __pyx_t_7 = __pyx_v_c;
    __pyx_t_8 = ((int)(__pyx_t_7 == ','));
    if (!__pyx_t_8) {
      __pyx_t_9 = ((int)(__pyx_t_7 == '.'));
      __pyx_t_10 = __pyx_t_9;
    } else {
      __pyx_t_10 = __pyx_t_8;
    }
    __pyx_t_8 = (__pyx_t_10 != 0);
    if (__pyx_t_8) {

      /* "_mssql.pyx":1512
 *     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;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "_mssql.pyx":1514
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (unlikely(((PyObject *)__pyx_t_2) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __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":1515
 * 
 *     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":1514
 *             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":1515
 * 
 *     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) {
      __pyx_t_10 = ((__pyx_v_c <= '9') != 0);
      __pyx_t_9 = __pyx_t_10;
    } else {
      __pyx_t_9 = __pyx_t_8;
    }
    if (!__pyx_t_9) {
      __pyx_t_7 = __pyx_v_c;
      __pyx_t_8 = ((int)(__pyx_t_7 == '+'));
      if (!__pyx_t_8) {
        __pyx_t_10 = ((int)(__pyx_t_7 == '-'));
        __pyx_t_11 = __pyx_t_10;
      } else {
        __pyx_t_11 = __pyx_t_8;
      }
      __pyx_t_8 = (__pyx_t_11 != 0);
      __pyx_t_11 = __pyx_t_8;
    } else {
      __pyx_t_11 = __pyx_t_9;
    }
    if (__pyx_t_11) {

      /* "_mssql.pyx":1516
 *     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":1517
 *         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);
      goto __pyx_L8;
    }

    /* "_mssql.pyx":1518
 *             stripped[x] = c
 *             x += 1
 *         elif i == last_sep:             # <<<<<<<<<<<<<<
 *             stripped[x] = c
 *             x += 1
 */
    __pyx_t_11 = ((__pyx_v_i == __pyx_v_last_sep) != 0);
    if (__pyx_t_11) {

      /* "_mssql.pyx":1519
 *             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":1520
 *         elif i == last_sep:
 *             stripped[x] = c
 *             x += 1             # <<<<<<<<<<<<<<
 *     stripped[x] = 0
 *     return stripped
 */
      __pyx_v_x = (__pyx_v_x + 1);
      goto __pyx_L8;
    }
    __pyx_L8:;
  }
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "_mssql.pyx":1521
 *             stripped[x] = c
 *             x += 1
 *     stripped[x] = 0             # <<<<<<<<<<<<<<
 *     return stripped
 * 
 */
  (__pyx_v_stripped[__pyx_v_x]) = 0;

  /* "_mssql.pyx":1522
 *             x += 1
 *     stripped[x] = 0
 *     return stripped             # <<<<<<<<<<<<<<
 * 
 * def remove_locale(bytes value):
 */
  __pyx_r = __pyx_v_stripped;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql._remove_locale", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("remove_locale"), (PyCFunction)__pyx_pw_6_mssql_3remove_locale, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_6_mssql_3remove_locale(PyObject *__pyx_self, PyObject *__pyx_v_value) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  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_filename = __pyx_f[0]; __pyx_lineno = 1524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_6_mssql_2remove_locale(__pyx_self, ((PyObject*)__pyx_v_value));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1524
 *     return stripped
 * 
 * def remove_locale(bytes value):             # <<<<<<<<<<<<<<
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("remove_locale", 0);

  /* "_mssql.pyx":1525
 * 
 * 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(((PyObject *)__pyx_v_value)); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_s = ((char *)__pyx_t_1);

  /* "_mssql.pyx":1526
 * 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":1527
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_r = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":1529
 *     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
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_tds_ver_str_to_constant", 0);

  /* "_mssql.pyx":1533
 *         http://www.freetds.org/userguide/choosingtdsprotocol.htm
 *     """
 *     if verstr == u'4.2':             # <<<<<<<<<<<<<<
 *         return DBVERSION_42
 *     if verstr == u'7.0':
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_verstr, ((PyObject *)__pyx_kp_u_100), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1534
 *     """
 *     if verstr == u'4.2':
 *         return DBVERSION_42             # <<<<<<<<<<<<<<
 *     if verstr == u'7.0':
 *         return DBVERSION_70
 */
    __pyx_r = DBVERSION_42;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1535
 *     if verstr == u'4.2':
 *         return DBVERSION_42
 *     if verstr == u'7.0':             # <<<<<<<<<<<<<<
 *         return DBVERSION_70
 *     if verstr == u'7.1':
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_verstr, ((PyObject *)__pyx_kp_u_101), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1536
 *         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;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "_mssql.pyx":1537
 *     if verstr == u'7.0':
 *         return DBVERSION_70
 *     if verstr == u'7.1':             # <<<<<<<<<<<<<<
 *         return DBVERSION_71
 *     if verstr == u'7.2':
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_verstr, ((PyObject *)__pyx_kp_u_14), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1538
 *         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;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "_mssql.pyx":1539
 *     if verstr == u'7.1':
 *         return DBVERSION_71
 *     if verstr == u'7.2':             # <<<<<<<<<<<<<<
 *         return DBVERSION_72
 *     if verstr == u'8.0':
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_verstr, ((PyObject *)__pyx_kp_u_102), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1540
 *         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;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "_mssql.pyx":1541
 *     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 = PyObject_RichCompare(__pyx_v_verstr, ((PyObject *)__pyx_kp_u_103), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1542
 *         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;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "_mssql.pyx":1543
 *     if verstr == u'8.0':
 *         return DBVERSION_80
 *     raise MSSQLException('unrecognized tds version: %s' % verstr)             # <<<<<<<<<<<<<<
 * 
 * #######################
 */
  __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_104), __pyx_v_verstr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLException)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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":1548
 * ## 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_v_binascii = NULL;
  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;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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":1550
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "_mssql.pyx":1551
 * 
 *     if value == None:
 *         return b'NULL'             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, bool):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_n_b__NULL));
    __pyx_r = ((PyObject *)__pyx_n_b__NULL);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1553
 *         return b'NULL'
 * 
 *     if isinstance(value, bool):             # <<<<<<<<<<<<<<
 *         return '1' if value else '0'
 * 
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_value, ((PyObject*)__pyx_ptype_7cpython_4bool_bool)); 
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1554
 * 
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_3) {
      __Pyx_INCREF(((PyObject *)__pyx_kp_s__1));
      __pyx_t_1 = ((PyObject *)__pyx_kp_s__1);
    } else {
      __Pyx_INCREF(((PyObject *)__pyx_kp_s__0));
      __pyx_t_1 = ((PyObject *)__pyx_kp_s__0);
    }
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "_mssql.pyx":1556
 *         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":1557
 * 
 *     if isinstance(value, float):
 *         return repr(value).encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, (int, long, decimal.Decimal)):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyObject_Repr(__pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_charset);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_charset);
    __Pyx_GIVEREF(__pyx_v_charset);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "_mssql.pyx":1559
 *         return repr(value).encode(charset)
 * 
 *     if isinstance(value, (int, long, decimal.Decimal)):             # <<<<<<<<<<<<<<
 *         return str(value).encode(charset)
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__decimal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__Decimal); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)((PyObject*)(&PyInt_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyLong_Type))));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)((PyObject*)(&PyLong_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyLong_Type))));
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_value, ((PyObject *)__pyx_t_5)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1560
 * 
 *     if isinstance(value, (int, long, decimal.Decimal)):
 *         return str(value).encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, unicode):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_charset);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_charset);
    __Pyx_GIVEREF(__pyx_v_charset);
    __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "_mssql.pyx":1562
 *         return str(value).encode(charset)
 * 
 *     if isinstance(value, unicode):             # <<<<<<<<<<<<<<
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)
 * 
 */
  __pyx_t_3 = PyUnicode_Check(__pyx_v_value); 
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1563
 * 
 *     if isinstance(value, unicode):
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, (str, bytes)):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__replace); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_108), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_kp_s_105), __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Add(__pyx_t_4, ((PyObject *)__pyx_kp_s_106)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_charset);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_charset);
    __Pyx_GIVEREF(__pyx_v_charset);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "_mssql.pyx":1565
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)
 * 
 *     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_INCREF(__pyx_v_value);
  __pyx_t_5 = __pyx_v_value;
  __pyx_t_2 = PyString_Check(__pyx_t_5); 
  if (!__pyx_t_2) {
    __pyx_t_3 = PyBytes_Check(__pyx_t_5); 
    __pyx_t_6 = __pyx_t_3;
  } else {
    __pyx_t_6 = __pyx_t_2;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = (__pyx_t_6 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1567
 *     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_2 = (__Pyx_PySequence_Contains(((PyObject *)__pyx_kp_b_109), __pyx_v_value, Py_NE)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = (__pyx_t_2 != 0);
    if (__pyx_t_6) {

      /* "_mssql.pyx":1568
 *         # 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_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
        __Pyx_XGOTREF(__pyx_t_7);
        __Pyx_XGOTREF(__pyx_t_8);
        __Pyx_XGOTREF(__pyx_t_9);
        /*try:*/ {

          /* "_mssql.pyx":1569
 *         if b'\0' not in value:
 *             try:
 *                 value.decode('ascii')             # <<<<<<<<<<<<<<
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 *             except UnicodeDecodeError:
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__decode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1569; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_110), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1569; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "_mssql.pyx":1570
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_111), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_kp_b_106), __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_b_106)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_r = __pyx_t_5;
          __pyx_t_5 = 0;
          goto __pyx_L14_try_return;
        }
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L17_try_end;
        __pyx_L14_try_return:;
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
        goto __pyx_L0;
        __pyx_L10_error:;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "_mssql.pyx":1571
 *                 value.decode('ascii')
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 *             except UnicodeDecodeError:             # <<<<<<<<<<<<<<
 *                 pass
 * 
 */
        __pyx_t_10 = PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError);
        if (__pyx_t_10) {
          PyErr_Restore(0,0,0);
          goto __pyx_L11_exception_handled;
        }
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
        goto __pyx_L1_error;
        __pyx_L11_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
        __pyx_L17_try_end:;
      }
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "_mssql.pyx":1576
 *         # Python 3: handle bytes
 *         # @todo - Marc - hack hack hack
 *         if isinstance(value, bytes):             # <<<<<<<<<<<<<<
 *             import binascii
 *             return b'0x' + binascii.hexlify(value)
 */
    __pyx_t_6 = PyBytes_Check(__pyx_v_value); 
    __pyx_t_2 = (__pyx_t_6 != 0);
    if (__pyx_t_2) {

      /* "_mssql.pyx":1577
 *         # @todo - Marc - hack hack hack
 *         if isinstance(value, bytes):
 *             import binascii             # <<<<<<<<<<<<<<
 *             return b'0x' + binascii.hexlify(value)
 * 
 */
      __pyx_t_5 = __Pyx_Import(((PyObject *)__pyx_n_s__binascii), 0, -1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_v_binascii = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "_mssql.pyx":1578
 *         if isinstance(value, bytes):
 *             import binascii
 *             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_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_binascii, __pyx_n_s__hexlify); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_kp_b__0x), __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;
      goto __pyx_L18;
    }
    __pyx_L18:;

    /* "_mssql.pyx":1582
 *         # 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_2 = PyString_Check(__pyx_v_value); 
    __pyx_t_6 = (__pyx_t_2 != 0);
    if (__pyx_t_6) {

      /* "_mssql.pyx":1583
 *         # 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_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_112), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_kp_s__0x), __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;
      goto __pyx_L19;
    }
    __pyx_L19:;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "_mssql.pyx":1585
 *             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_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__datetime); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__datetime); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = PyObject_IsInstance(__pyx_v_value, __pyx_t_4); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = (__pyx_t_6 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1586
 * 
 *     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":1587
 *     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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__year); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__month); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__day); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);

    /* "_mssql.pyx":1588
 *         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_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__hour); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__minute); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s__second); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_13);

    /* "_mssql.pyx":1589
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1589; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_14 = PyTuple_New(7); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_14);
    PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_14, 5, __pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_14, 6, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_15);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_5 = 0;
    __pyx_t_11 = 0;
    __pyx_t_12 = 0;
    __pyx_t_13 = 0;
    __pyx_t_15 = 0;
    __pyx_t_15 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_113), ((PyObject *)__pyx_t_14)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_15));
    __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
    __pyx_r = ((PyObject *)__pyx_t_15);
    __pyx_t_15 = 0;
    goto __pyx_L0;
    goto __pyx_L20;
  }
  __pyx_L20:;

  /* "_mssql.pyx":1591
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1591; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_value, __pyx_t_14); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __pyx_t_6 = (__pyx_t_2 != 0);
  if (__pyx_t_6) {

    /* "_mssql.pyx":1592
 * 
 *     if isinstance(value, datetime.date):
 *         return "{d '%04d-%02d-%02d'} " % (             # <<<<<<<<<<<<<<
 *         value.year, value.month, value.day)
 * 
 */
    __Pyx_XDECREF(__pyx_r);

    /* "_mssql.pyx":1593
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_12 = PyTuple_New(3); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_14);
    PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_13);
    __pyx_t_14 = 0;
    __pyx_t_15 = 0;
    __pyx_t_13 = 0;
    __pyx_t_13 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_114), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_13));
    __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0;
    __pyx_r = ((PyObject *)__pyx_t_13);
    __pyx_t_13 = 0;
    goto __pyx_L0;
    goto __pyx_L21;
  }
  __pyx_L21:;

  /* "_mssql.pyx":1595
 *         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;

  __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_5);
  __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_AddTraceback("_mssql._quote_simple_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_binascii);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1597
 *     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;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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":1598
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_mssql.pyx":1600
 *     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":1601
 * 
 *     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;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1603
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyList_Type))));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)(&PyList_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyList_Type))));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyTuple_Type))));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)((PyObject*)(&PyTuple_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyTuple_Type))));
  __pyx_t_4 = PyObject_IsSubclass(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_3 = ((!(__pyx_t_4 != 0)) != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1604
 * 
 *     if not issubclass(type(data), (list, tuple)):
 *         raise ValueError('expected a simple type, a tuple or a list')             # <<<<<<<<<<<<<<
 * 
 *     quoted = []
 */
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_116), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "_mssql.pyx":1606
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_quoted = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_mssql.pyx":1607
 * 
 *     quoted = []
 *     for value in data:             # <<<<<<<<<<<<<<
 *         value = _quote_simple_value(value, charset)
 * 
 */
  if (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_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  for (;;) {
    if (!__pyx_t_6 && 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_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
      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_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_7)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF(__pyx_v_value);
    __pyx_v_value = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "_mssql.pyx":1608
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_v_value);
    __pyx_v_value = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "_mssql.pyx":1610
 *         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":1611
 * 
 *         if value is None:
 *             raise ValueError('found an unsupported type')             # <<<<<<<<<<<<<<
 * 
 *         quoted.append(value)
 */
      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_118), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1611; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "_mssql.pyx":1613
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_mssql.pyx":1614
 * 
 *         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_PyObject_GetAttrStr(((PyObject *)__pyx_kp_b_120), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(((PyObject *)__pyx_v_quoted));
  PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_quoted));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_quoted));
  __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
  __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_kp_b_119), __pyx_t_9); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PyNumber_Add(__pyx_t_7, ((PyObject *)__pyx_kp_b_121)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_r = __pyx_t_9;
  __pyx_t_9 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __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":1619
 * # 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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":1620
 * # 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_filename = __pyx_f[0]; __pyx_lineno = 1620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_mssql.pyx":1622
 *     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":1623
 * 
 *     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;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1625
 *         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 *)((PyObject*)(&PyDict_Type)))); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1626
 * 
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __Pyx_DECREF(__pyx_v_result);
    __pyx_v_result = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "_mssql.pyx":1627
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_7 = __Pyx_dict_iterator(__pyx_v_data, 0, ((PyObject *)__pyx_n_s__iteritems), (&__pyx_t_5), (&__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_XDECREF(__pyx_v_k);
      __pyx_v_k = __pyx_t_7;
      __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_v_v);
      __pyx_v_v = __pyx_t_8;
      __pyx_t_8 = 0;

      /* "_mssql.pyx":1628
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      if (PyObject_SetItem(__pyx_v_result, __pyx_v_k, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1629
 *         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;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "_mssql.pyx":1631
 *         return result
 * 
 *     if issubclass(type(data), tuple):             # <<<<<<<<<<<<<<
 *         result = []
 *         for v in data:
 */
  __pyx_t_2 = PyObject_IsSubclass(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)((PyObject*)(&PyTuple_Type)))); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "_mssql.pyx":1632
 * 
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_v_result);
    __pyx_v_result = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "_mssql.pyx":1633
 *     if issubclass(type(data), tuple):
 *         result = []
 *         for v in data:             # <<<<<<<<<<<<<<
 *             result.append(_quote_or_flatten(v, charset))
 *         return tuple(result)
 */
    if (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_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_11 = Py_TYPE(__pyx_t_1)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_11 && 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_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_1)) {
        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_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_8 = __pyx_t_11(__pyx_t_1);
        if (unlikely(!__pyx_t_8)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_8);
      }
      __Pyx_XDECREF(__pyx_v_v);
      __pyx_v_v = __pyx_t_8;
      __pyx_t_8 = 0;

      /* "_mssql.pyx":1634
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyObject_Append(__pyx_v_result, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_mssql.pyx":1635
 *         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 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_result);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_result);
    __Pyx_GIVEREF(__pyx_v_result);
    __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "_mssql.pyx":1637
 *         return tuple(result)
 * 
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')             # <<<<<<<<<<<<<<
 * 
 * _re_pos_param = re.compile(r'(%(s|d))')
 */
  __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_123), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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":1641
 * _re_pos_param = re.compile(r'(%(s|d))')
 * _re_name_param = re.compile(r'(%\(([^\)]+)\)s)')
 * 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;
  struct __pyx_opt_args_6_mssql__quote_data __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  Py_ssize_t __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  int __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_substitute_params", 0);
  __Pyx_INCREF(__pyx_v_toformat);

  /* "_mssql.pyx":1642
 * _re_name_param = re.compile(r'(%\(([^\)]+)\)s)')
 * 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":1643
 * 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;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1647
 *     if not issubclass(type(params),
 *             (bool, int, long, float, unicode, str, bytes,
 *             datetime.datetime, datetime.date, dict, tuple, decimal.Decimal)):             # <<<<<<<<<<<<<<
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(12); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)((PyObject*)__pyx_ptype_7cpython_4bool_bool)));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)__pyx_ptype_7cpython_4bool_bool)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)__pyx_ptype_7cpython_4bool_bool)));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)((PyObject*)(&PyInt_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyLong_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)((PyObject*)(&PyLong_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyLong_Type))));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyFloat_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)((PyObject*)(&PyFloat_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyFloat_Type))));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyUnicode_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)((PyObject*)(&PyUnicode_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyUnicode_Type))));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyBytes_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 6, ((PyObject *)((PyObject*)(&PyBytes_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyBytes_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 7, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 8, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyDict_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 9, ((PyObject *)((PyObject*)(&PyDict_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyDict_Type))));
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyTuple_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 10, ((PyObject *)((PyObject*)(&PyTuple_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyTuple_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 11, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_2 = PyObject_IsSubclass(((PyObject *)Py_TYPE(__pyx_v_params)), ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1648
 *             (bool, int, long, float, unicode, str, bytes,
 *             datetime.datetime, datetime.date, dict, tuple, decimal.Decimal)):
 *         raise ValueError("'params' arg (%r) can be only a tuple or a dictionary." % type(params))             # <<<<<<<<<<<<<<
 * 
 *     if charset:
 */
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_124), ((PyObject *)Py_TYPE(__pyx_v_params))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "_mssql.pyx":1650
 *         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_filename = __pyx_f[0]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "_mssql.pyx":1651
 * 
 *     if charset:
 *         quoted = _quote_data(params, charset)             # <<<<<<<<<<<<<<
 *     else:
 *         quoted = _quote_data(params)
 */
    __pyx_t_7.__pyx_n = 1;
    __pyx_t_7.charset = __pyx_v_charset;
    __pyx_t_3 = __pyx_f_6_mssql__quote_data(__pyx_v_params, &__pyx_t_7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_quoted = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "_mssql.pyx":1653
 *         quoted = _quote_data(params, charset)
 *     else:
 *         quoted = _quote_data(params)             # <<<<<<<<<<<<<<
 * 
 *     # positional string substitution now requires a tuple
 */
    __pyx_t_3 = __pyx_f_6_mssql__quote_data(__pyx_v_params, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_quoted = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L5:;

  /* "_mssql.pyx":1656
 * 
 *     # positional string substitution now requires a tuple
 *     if hasattr(quoted, 'startswith'):             # <<<<<<<<<<<<<<
 *         quoted = (quoted,)
 * 
 */
  __pyx_t_1 = PyObject_HasAttr(__pyx_v_quoted, ((PyObject *)__pyx_n_s__startswith)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "_mssql.pyx":1657
 *     # 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_filename = __pyx_f[0]; __pyx_lineno = 1657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_quoted);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_quoted);
    __Pyx_GIVEREF(__pyx_v_quoted);
    __Pyx_DECREF(__pyx_v_quoted);
    __pyx_v_quoted = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "_mssql.pyx":1659
 *         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":1660
 * 
 *     if isinstance(toformat, unicode):
 *         toformat = toformat.encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(params, dict):
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_toformat, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_charset);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_charset);
    __Pyx_GIVEREF(__pyx_v_charset);
    __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_v_toformat);
    __pyx_v_toformat = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "_mssql.pyx":1662
 *         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":1664
 *     if isinstance(params, dict):
 *         """ assume name based substitutions """
 *         offset = 0             # <<<<<<<<<<<<<<
 *         for match in _re_name_param.finditer(toformat.decode(charset)):
 *             param_key = match.group(2)
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_offset = __pyx_int_0;

    /* "_mssql.pyx":1665
 *         """ assume name based substitutions """
 *         offset = 0
 *         for match in _re_name_param.finditer(toformat.decode(charset)):             # <<<<<<<<<<<<<<
 *             param_key = match.group(2)
 * 
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s___re_name_param); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__finditer); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_toformat, __pyx_n_s__decode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_charset);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_charset);
    __Pyx_GIVEREF(__pyx_v_charset);
    __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) {
      __pyx_t_3 = __pyx_t_4; __Pyx_INCREF(__pyx_t_3); __pyx_t_8 = 0;
      __pyx_t_9 = NULL;
    } else {
      __pyx_t_8 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    for (;;) {
      if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_3)) {
        if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_3)) {
        if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_4 = __pyx_t_9(__pyx_t_3);
        if (unlikely(!__pyx_t_4)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_4);
      }
      __Pyx_XDECREF(__pyx_v_match);
      __pyx_v_match = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1666
 *         offset = 0
 *         for match in _re_name_param.finditer(toformat.decode(charset)):
 *             param_key = match.group(2)             # <<<<<<<<<<<<<<
 * 
 *             if not param_key in params:
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s__group); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_125), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_v_param_key);
      __pyx_v_param_key = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1668
 *             param_key = match.group(2)
 * 
 *             if not param_key in params:             # <<<<<<<<<<<<<<
 *                 raise ValueError('params dictionary did not contain value for placeholder: %s' % param_key)
 * 
 */
      __pyx_t_2 = (__Pyx_PySequence_Contains(__pyx_v_param_key, __pyx_v_params, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0);
      if (__pyx_t_1) {

        /* "_mssql.pyx":1669
 * 
 *             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_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_126), __pyx_v_param_key); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_6));
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_6));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
        __pyx_t_6 = 0;
        __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
        __Pyx_Raise(__pyx_t_6, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "_mssql.pyx":1678
 *             # 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_6 = PyObject_GetItem(__pyx_v_quoted, __pyx_v_param_key); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_v_param_val);
      __pyx_v_param_val = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1679
 *             # 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_10 = PyObject_Length(__pyx_v_param_val); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_10); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_v_param_val_len);
      __pyx_v_param_val_len = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "_mssql.pyx":1680
 *             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_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s__group); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_127), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_10 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_10); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_v_placeholder_len);
      __pyx_v_placeholder_len = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1681
 *             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_4 = PyNumber_Subtract(__pyx_v_param_val_len, __pyx_v_placeholder_len); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_v_offset_adjust);
      __pyx_v_offset_adjust = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1684
 * 
 *             # 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s__start); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_128), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_Add(__pyx_t_6, __pyx_v_offset); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_v_match_start);
      __pyx_v_match_start = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1685
 *             # 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s__end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_129), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_Add(__pyx_t_6, __pyx_v_offset); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_v_match_end);
      __pyx_v_match_end = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1686
 *             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_4 = __Pyx_PyObject_GetSlice(__pyx_v_toformat, 0, 0, NULL, &__pyx_v_match_start, NULL, 0, 0, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = ((PyObject *)__pyx_f_6_mssql_ensure_bytes(__pyx_v_param_val, NULL)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = PyNumber_Add(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_v_toformat, 0, 0, &__pyx_v_match_end, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1686; __pyx_clineno = __LINE__; goto __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(__pyx_v_toformat);
      __pyx_v_toformat = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1689
 * 
 *             # adjust the offset for the next usage
 *             offset += offset_adjust             # <<<<<<<<<<<<<<
 *     else:
 *         """ assume position based substitutions """
 */
      __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_offset, __pyx_v_offset_adjust); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_v_offset);
      __pyx_v_offset = __pyx_t_4;
      __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8;
  }
  /*else*/ {

    /* "_mssql.pyx":1692
 *     else:
 *         """ assume position based substitutions """
 *         offset = 0             # <<<<<<<<<<<<<<
 *         for count, match in enumerate(_re_pos_param.finditer(toformat.decode(charset))):
 *             # 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":1693
 *         """ assume position based substitutions """
 *         offset = 0
 *         for count, match in enumerate(_re_pos_param.finditer(toformat.decode(charset))):             # <<<<<<<<<<<<<<
 *             # calculate string positions so we can keep track of the offset to
 *             # be used in future substituations on this string.  This is
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_3 = __pyx_int_0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s___re_pos_param); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__finditer); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_toformat, __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_charset);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_charset);
    __Pyx_GIVEREF(__pyx_v_charset);
    __pyx_t_11 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_11);
    __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    if (PyList_CheckExact(__pyx_t_11) || PyTuple_CheckExact(__pyx_t_11)) {
      __pyx_t_5 = __pyx_t_11; __Pyx_INCREF(__pyx_t_5); __pyx_t_8 = 0;
      __pyx_t_9 = NULL;
    } else {
      __pyx_t_8 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext;
    }
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    for (;;) {
      if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_5)) {
        if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_11 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_11 = PySequence_ITEM(__pyx_t_5, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_5)) {
        if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_11 = PySequence_ITEM(__pyx_t_5, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_11 = __pyx_t_9(__pyx_t_5);
        if (unlikely(!__pyx_t_11)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_11);
      }
      __Pyx_XDECREF(__pyx_v_match);
      __pyx_v_match = __pyx_t_11;
      __pyx_t_11 = 0;
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_v_count);
      __pyx_v_count = __pyx_t_3;
      __pyx_t_11 = PyNumber_Add(__pyx_t_3, __pyx_int_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_3);
      __pyx_t_3 = __pyx_t_11;
      __pyx_t_11 = 0;

      /* "_mssql.pyx":1701
 *             # the length of the placeholder and the length of the value being
 *             # substituted
 *             try:             # <<<<<<<<<<<<<<
 *                 param_val = quoted[count]
 *             except IndexError:
 */
      {
        __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":1702
 *             # substituted
 *             try:
 *                 param_val = quoted[count]             # <<<<<<<<<<<<<<
 *             except IndexError:
 *                 raise ValueError('more placeholders in sql than params available')
 */
          __pyx_t_11 = PyObject_GetItem(__pyx_v_quoted, __pyx_v_count); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_XDECREF(__pyx_v_param_val);
          __pyx_v_param_val = __pyx_t_11;
          __pyx_t_11 = 0;
        }
        __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_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "_mssql.pyx":1703
 *             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 = 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_11, &__pyx_t_6, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GOTREF(__pyx_t_4);

          /* "_mssql.pyx":1704
 *                 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 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_131), NULL); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          goto __pyx_L15_exception_handled;
        }
        __pyx_L16_except_error:;
        __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_L15_exception_handled:;
        __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_L21_try_end:;
      }

      /* "_mssql.pyx":1705
 *             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_10 = PyObject_Length(__pyx_v_param_val); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_10); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_v_param_val_len);
      __pyx_v_param_val_len = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1706
 *                 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(__pyx_v_placeholder_len);
      __pyx_v_placeholder_len = __pyx_int_2;

      /* "_mssql.pyx":1707
 *             param_val_len = len(param_val)
 *             placeholder_len = 2
 *             offset_adjust = param_val_len - placeholder_len             # <<<<<<<<<<<<<<
 * 
 *             # do the string substitution
 */
      __pyx_t_4 = PyNumber_Subtract(__pyx_v_param_val_len, __pyx_v_placeholder_len); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_v_offset_adjust);
      __pyx_v_offset_adjust = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1710
 * 
 *             # 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s__start); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_132), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_Add(__pyx_t_6, __pyx_v_offset); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_v_match_start);
      __pyx_v_match_start = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1711
 *             # 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s__end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_133), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_Add(__pyx_t_6, __pyx_v_offset); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_v_match_end);
      __pyx_v_match_end = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1712
 *             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_4 = __Pyx_PyObject_GetSlice(__pyx_v_toformat, 0, 0, NULL, &__pyx_v_match_start, NULL, 0, 0, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = ((PyObject *)__pyx_f_6_mssql_ensure_bytes(__pyx_v_param_val, NULL)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_11 = PyNumber_Add(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_v_toformat, 0, 0, &__pyx_v_match_end, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = PyNumber_Add(__pyx_t_11, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __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(__pyx_v_toformat);
      __pyx_v_toformat = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "_mssql.pyx":1715
 *             #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_4 = PyNumber_InPlaceAdd(__pyx_v_offset, __pyx_v_offset_adjust); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_v_offset);
      __pyx_v_offset = __pyx_t_4;
      __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_L8:;

  /* "_mssql.pyx":1716
 *             # 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;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  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_XDECREF(__pyx_t_11);
  __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;
}

/* 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 = {__Pyx_NAMESTR("quote_simple_value"), (PyCFunction)__pyx_pw_6_mssql_5quote_simple_value, METH_O, __Pyx_DOCSTR(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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1720
 * # 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)
 * 
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("quote_simple_value", 0);

  /* "_mssql.pyx":1721
 * # 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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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 = {__Pyx_NAMESTR("quote_or_flatten"), (PyCFunction)__pyx_pw_6_mssql_7quote_or_flatten, METH_O, __Pyx_DOCSTR(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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1723
 *     return _quote_simple_value(value)
 * 
 * def quote_or_flatten(data):             # <<<<<<<<<<<<<<
 *     return _quote_or_flatten(data)
 * 
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("quote_or_flatten", 0);

  /* "_mssql.pyx":1724
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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 = {__Pyx_NAMESTR("quote_data"), (PyCFunction)__pyx_pw_6_mssql_9quote_data, METH_O, __Pyx_DOCSTR(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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1726
 *     return _quote_or_flatten(data)
 * 
 * def quote_data(data):             # <<<<<<<<<<<<<<
 *     return _quote_data(data)
 * 
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("quote_data", 0);

  /* "_mssql.pyx":1727
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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 = {__Pyx_NAMESTR("substitute_params"), (PyCFunction)__pyx_pw_6_mssql_11substitute_params, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1729
 *     return _quote_data(data)
 * 
 * def substitute_params(toformat, params, charset='utf8'):             # <<<<<<<<<<<<<<
 *     return _substitute_params(toformat, params, charset)
 * 
 */

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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("substitute_params", 0);

  /* "_mssql.pyx":1730
 * 
 * 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_filename = __pyx_f[0]; __pyx_lineno = 1730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* 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 = {__Pyx_NAMESTR("connect"), (PyCFunction)__pyx_pw_6_mssql_13connect, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_6_mssql_12connect(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1735
 * ## Compatibility Aliases ##
 * ###########################
 * def connect(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return MSSQLConnection(*args, **kwargs)
 * 
 */

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;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("connect", 0);

  /* "_mssql.pyx":1736
 * ###########################
 * def connect(*args, **kwargs):
 *     return MSSQLConnection(*args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * MssqlDatabaseException = MSSQLDatabaseException
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLConnection)), ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __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.connect", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_15get_max_connections(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6_mssql_14get_max_connections[] = "\n    Get maximum simultaneous connections db-lib will open to the server.\n    ";
static PyMethodDef __pyx_mdef_6_mssql_15get_max_connections = {__Pyx_NAMESTR("get_max_connections"), (PyCFunction)__pyx_pw_6_mssql_15get_max_connections, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6_mssql_14get_max_connections)};
static PyObject *__pyx_pw_6_mssql_15get_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_14get_max_connections(__pyx_self);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1745
 * ## Max Connections ##
 * #####################
 * def get_max_connections():             # <<<<<<<<<<<<<<
 *     """
 *     Get maximum simultaneous connections db-lib will open to the server.
 */

static PyObject *__pyx_pf_6_mssql_14get_max_connections(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_max_connections", 0);

  /* "_mssql.pyx":1749
 *     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 = PyInt_FromLong(dbgetmaxprocs()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_6_mssql_17set_max_connections(PyObject *__pyx_self, PyObject *__pyx_arg_limit); /*proto*/
static char __pyx_doc_6_mssql_16set_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_17set_max_connections = {__Pyx_NAMESTR("set_max_connections"), (PyCFunction)__pyx_pw_6_mssql_17set_max_connections, METH_O, __Pyx_DOCSTR(__pyx_doc_6_mssql_16set_max_connections)};
static PyObject *__pyx_pw_6_mssql_17set_max_connections(PyObject *__pyx_self, PyObject *__pyx_arg_limit) {
  int __pyx_v_limit;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_max_connections (wrapper)", 0);
  assert(__pyx_arg_limit); {
    __pyx_v_limit = __Pyx_PyInt_AsInt(__pyx_arg_limit); if (unlikely((__pyx_v_limit == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1751; __pyx_clineno = __LINE__; goto __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_16set_max_connections(__pyx_self, ((int)__pyx_v_limit));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1751
 *     return dbgetmaxprocs()
 * 
 * def set_max_connections(int limit):             # <<<<<<<<<<<<<<
 *     """
 *     Set maximum simultaneous connections db-lib will open to the server.
 */

static PyObject *__pyx_pf_6_mssql_16set_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":1758
 *     :type limit: int
 *     """
 *     dbsetmaxprocs(limit)             # <<<<<<<<<<<<<<
 * 
 * cdef void init_mssql():
 */
  dbsetmaxprocs(__pyx_v_limit);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_mssql.pyx":1760
 *     dbsetmaxprocs(limit)
 * 
 * cdef void init_mssql():             # <<<<<<<<<<<<<<
 *     cdef RETCODE rtc
 *     rtc = dbinit()
 */

static void __pyx_f_6_mssql_init_mssql(void) {
  RETCODE __pyx_v_rtc;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("init_mssql", 0);

  /* "_mssql.pyx":1762
 * cdef void init_mssql():
 *     cdef RETCODE rtc
 *     rtc = dbinit()             # <<<<<<<<<<<<<<
 *     if rtc == FAIL:
 *         raise MSSQLDriverException("Could not initialize communication layer")
 */
  __pyx_v_rtc = dbinit();

  /* "_mssql.pyx":1763
 *     cdef RETCODE rtc
 *     rtc = dbinit()
 *     if rtc == FAIL:             # <<<<<<<<<<<<<<
 *         raise MSSQLDriverException("Could not initialize communication layer")
 * 
 */
  __pyx_t_1 = ((__pyx_v_rtc == FAIL) != 0);
  if (__pyx_t_1) {

    /* "_mssql.pyx":1764
 *     rtc = dbinit()
 *     if rtc == FAIL:
 *         raise MSSQLDriverException("Could not initialize communication layer")             # <<<<<<<<<<<<<<
 * 
 *     dberrhandle(err_handler)
 */
    __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException)), ((PyObject *)__pyx_k_tuple_135), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1764; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "_mssql.pyx":1766
 *         raise MSSQLDriverException("Could not initialize communication layer")
 * 
 *     dberrhandle(err_handler)             # <<<<<<<<<<<<<<
 *     dbmsghandle(msg_handler)
 * 
 */
  dberrhandle(__pyx_f_6_mssql_err_handler);

  /* "_mssql.pyx":1767
 * 
 *     dberrhandle(err_handler)
 *     dbmsghandle(msg_handler)             # <<<<<<<<<<<<<<
 * 
 * init_mssql()
 */
  dbmsghandle(__pyx_f_6_mssql_msg_handler);

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("_mssql.init_mssql", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

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;
  o = (*t->tp_alloc)(t, 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;
  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) {
  struct __pyx_obj_6_mssql_MSSQLRowIterator *p = (struct __pyx_obj_6_mssql_MSSQLRowIterator *)o;
  PyObject* tmp;
  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[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_6_mssql_16MSSQLRowIterator_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLRowIterator = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("_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*/
  #else
  0, /*reserved*/
  #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*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
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;
  o = (*t->tp_alloc)(t, 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);
  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;
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_6_mssql_15MSSQLConnection_5__dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->column_names);
  Py_CLEAR(p->column_types);
  (*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;
  }
  return 0;
}

static int __pyx_tp_clear_6_mssql_MSSQLConnection(PyObject *o) {
  struct __pyx_obj_6_mssql_MSSQLConnection *p = (struct __pyx_obj_6_mssql_MSSQLConnection *)o;
  PyObject* tmp;
  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);
  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[] = {
  {__Pyx_NAMESTR("cancel"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_9cancel, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_8cancel)},
  {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_11close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_10close)},
  {__Pyx_NAMESTR("execute_non_query"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_13execute_non_query, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_12execute_non_query)},
  {__Pyx_NAMESTR("execute_query"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_15execute_query, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_14execute_query)},
  {__Pyx_NAMESTR("execute_row"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_17execute_row, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_16execute_row)},
  {__Pyx_NAMESTR("execute_scalar"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_19execute_scalar, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_18execute_scalar)},
  {__Pyx_NAMESTR("get_header"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_21get_header, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_20get_header)},
  {__Pyx_NAMESTR("init_procedure"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_23init_procedure, METH_O, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_22init_procedure)},
  {__Pyx_NAMESTR("nextresult"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_25nextresult, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_24nextresult)},
  {__Pyx_NAMESTR("select_db"), (PyCFunction)__pyx_pw_6_mssql_15MSSQLConnection_27select_db, METH_O, __Pyx_DOCSTR(__pyx_doc_6_mssql_15MSSQLConnection_26select_db)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6_mssql_MSSQLConnection[] = {
  {(char *)"charset", __pyx_getprop_6_mssql_15MSSQLConnection_charset, 0, __Pyx_DOCSTR(__pyx_k_136), 0},
  {(char *)"connected", __pyx_getprop_6_mssql_15MSSQLConnection_connected, 0, __Pyx_DOCSTR(__pyx_k_137), 0},
  {(char *)"identity", __pyx_getprop_6_mssql_15MSSQLConnection_identity, 0, __Pyx_DOCSTR(__pyx_k_138), 0},
  {(char *)"query_timeout", __pyx_getprop_6_mssql_15MSSQLConnection_query_timeout, __pyx_setprop_6_mssql_15MSSQLConnection_query_timeout, __Pyx_DOCSTR(__pyx_k_139), 0},
  {(char *)"rows_affected", __pyx_getprop_6_mssql_15MSSQLConnection_rows_affected, 0, __Pyx_DOCSTR(__pyx_k_140), 0},
  {(char *)"tds_version", __pyx_getprop_6_mssql_15MSSQLConnection_tds_version, 0, __Pyx_DOCSTR(__pyx_k_141), 0},
  {(char *)"debug_queries", __pyx_getprop_6_mssql_15MSSQLConnection_debug_queries, __pyx_setprop_6_mssql_15MSSQLConnection_debug_queries, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLConnection = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("_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*/
  #else
  0, /*reserved*/
  #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_7__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*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #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 (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 PyMethodDef __pyx_methods_6_mssql_MSSQLException[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLException = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("_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*/
  #else
  0, /*reserved*/
  #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*/
  __Pyx_DOCSTR("\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*/
  __pyx_methods_6_mssql_MSSQLException, /*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*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #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;
  o = (*t->tp_alloc)(t, 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;
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_6_mssql_20MSSQLStoredProcedure_3__dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(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) {
  struct __pyx_obj_6_mssql_MSSQLStoredProcedure *p = (struct __pyx_obj_6_mssql_MSSQLStoredProcedure *)o;
  PyObject* tmp;
  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[] = {
  {__Pyx_NAMESTR("bind"), (PyCFunction)__pyx_pw_6_mssql_20MSSQLStoredProcedure_5bind, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6_mssql_20MSSQLStoredProcedure_4bind)},
  {__Pyx_NAMESTR("execute"), (PyCFunction)__pyx_pw_6_mssql_20MSSQLStoredProcedure_7execute, METH_NOARGS, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6_mssql_MSSQLStoredProcedure[] = {
  {(char *)"connection", __pyx_getprop_6_mssql_20MSSQLStoredProcedure_connection, 0, __Pyx_DOCSTR(__pyx_k_142), 0},
  {(char *)"name", __pyx_getprop_6_mssql_20MSSQLStoredProcedure_name, 0, __Pyx_DOCSTR(__pyx_k_143), 0},
  {(char *)"parameters", __pyx_getprop_6_mssql_20MSSQLStoredProcedure_parameters, 0, __Pyx_DOCSTR(__pyx_k_144), 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLStoredProcedure = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("_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*/
  #else
  0, /*reserved*/
  #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*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #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 PyMethodDef __pyx_methods_6_mssql_MSSQLDriverException[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLDriverException = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("_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*/
  #else
  0, /*reserved*/
  #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*/
  __Pyx_DOCSTR("\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*/
  __pyx_methods_6_mssql_MSSQLDriverException, /*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*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #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 PyMethodDef __pyx_methods_6_mssql_MSSQLDatabaseException[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6_mssql_MSSQLDatabaseException[] = {
  {(char *)"message", __pyx_getprop_6_mssql_22MSSQLDatabaseException_message, 0, 0, 0},
  {(char *)"number", __pyx_getprop_6_mssql_22MSSQLDatabaseException_number, 0, 0, 0},
  {(char *)"severity", __pyx_getprop_6_mssql_22MSSQLDatabaseException_severity, 0, 0, 0},
  {(char *)"state", __pyx_getprop_6_mssql_22MSSQLDatabaseException_state, 0, 0, 0},
  {(char *)"line", __pyx_getprop_6_mssql_22MSSQLDatabaseException_line, 0, 0, 0},
  {(char *)"text", __pyx_getprop_6_mssql_22MSSQLDatabaseException_text, 0, 0, 0},
  {(char *)"srvname", __pyx_getprop_6_mssql_22MSSQLDatabaseException_srvname, 0, 0, 0},
  {(char *)"procname", __pyx_getprop_6_mssql_22MSSQLDatabaseException_procname, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6_mssql_MSSQLDatabaseException = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("_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*/
  #else
  0, /*reserved*/
  #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*/
  __Pyx_DOCSTR("\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*/
  __pyx_methods_6_mssql_MSSQLDatabaseException, /*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*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #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
    __Pyx_NAMESTR("_mssql"),
    __Pyx_DOCSTR(__pyx_k_145), /* 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_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_u_100, __pyx_k_100, sizeof(__pyx_k_100), 0, 1, 0, 0},
  {&__pyx_kp_u_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 1, 0, 0},
  {&__pyx_kp_u_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 1, 0, 0},
  {&__pyx_kp_u_103, __pyx_k_103, sizeof(__pyx_k_103), 0, 1, 0, 0},
  {&__pyx_kp_s_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 0, 1, 0},
  {&__pyx_kp_s_105, __pyx_k_105, sizeof(__pyx_k_105), 0, 0, 1, 0},
  {&__pyx_kp_b_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 0, 0, 0},
  {&__pyx_kp_s_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 0, 1, 0},
  {&__pyx_kp_b_107, __pyx_k_107, sizeof(__pyx_k_107), 0, 0, 0, 0},
  {&__pyx_kp_s_107, __pyx_k_107, sizeof(__pyx_k_107), 0, 0, 1, 0},
  {&__pyx_kp_b_109, __pyx_k_109, sizeof(__pyx_k_109), 0, 0, 0, 0},
  {&__pyx_kp_s_113, __pyx_k_113, sizeof(__pyx_k_113), 0, 0, 1, 0},
  {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0},
  {&__pyx_kp_s_115, __pyx_k_115, sizeof(__pyx_k_115), 0, 0, 1, 0},
  {&__pyx_kp_s_117, __pyx_k_117, sizeof(__pyx_k_117), 0, 0, 1, 0},
  {&__pyx_kp_b_119, __pyx_k_119, sizeof(__pyx_k_119), 0, 0, 0, 0},
  {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0},
  {&__pyx_kp_b_120, __pyx_k_120, sizeof(__pyx_k_120), 0, 0, 0, 0},
  {&__pyx_kp_b_121, __pyx_k_121, sizeof(__pyx_k_121), 0, 0, 0, 0},
  {&__pyx_kp_s_122, __pyx_k_122, sizeof(__pyx_k_122), 0, 0, 1, 0},
  {&__pyx_kp_s_124, __pyx_k_124, sizeof(__pyx_k_124), 0, 0, 1, 0},
  {&__pyx_kp_s_126, __pyx_k_126, sizeof(__pyx_k_126), 0, 0, 1, 0},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_kp_s_130, __pyx_k_130, sizeof(__pyx_k_130), 0, 0, 1, 0},
  {&__pyx_kp_s_134, __pyx_k_134, sizeof(__pyx_k_134), 0, 0, 1, 0},
  {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0},
  {&__pyx_kp_u_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 1, 0, 0},
  {&__pyx_kp_s_147, __pyx_k_147, sizeof(__pyx_k_147), 0, 0, 1, 0},
  {&__pyx_kp_s_150, __pyx_k_150, sizeof(__pyx_k_150), 0, 0, 1, 0},
  {&__pyx_kp_s_153, __pyx_k_153, sizeof(__pyx_k_153), 0, 0, 1, 0},
  {&__pyx_kp_s_155, __pyx_k_155, sizeof(__pyx_k_155), 0, 0, 1, 0},
  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
  {&__pyx_n_s_167, __pyx_k_167, sizeof(__pyx_k_167), 0, 0, 1, 1},
  {&__pyx_n_s_168, __pyx_k_168, sizeof(__pyx_k_168), 0, 0, 1, 1},
  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
  {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
  {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
  {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
  {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0},
  {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0},
  {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0},
  {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
  {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0},
  {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0},
  {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0},
  {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0},
  {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0},
  {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0},
  {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0},
  {&__pyx_kp_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 0},
  {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0},
  {&__pyx_kp_s_87, __pyx_k_87, sizeof(__pyx_k_87), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_kp_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 0},
  {&__pyx_kp_s_96, __pyx_k_96, sizeof(__pyx_k_96), 0, 0, 1, 0},
  {&__pyx_kp_s_98, __pyx_k_98, sizeof(__pyx_k_98), 0, 0, 1, 0},
  {&__pyx_kp_s__0, __pyx_k__0, sizeof(__pyx_k__0), 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_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_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__MssqlConnection, __pyx_k__MssqlConnection, sizeof(__pyx_k__MssqlConnection), 0, 0, 1, 1},
  {&__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_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_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_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
  {&__pyx_n_s__UUID, __pyx_k__UUID, sizeof(__pyx_k__UUID), 0, 0, 1, 1},
  {&__pyx_n_s__UnicodeDecodeError, __pyx_k__UnicodeDecodeError, sizeof(__pyx_k__UnicodeDecodeError), 0, 0, 1, 1},
  {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
  {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1},
  {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1},
  {&__pyx_n_s____import__, __pyx_k____import__, sizeof(__pyx_k____import__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____pyx_vtable__, __pyx_k____pyx_vtable__, sizeof(__pyx_k____pyx_vtable__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s____version__, __pyx_k____version__, sizeof(__pyx_k____version__), 0, 0, 1, 1},
  {&__pyx_n_s___mssql, __pyx_k___mssql, sizeof(__pyx_k___mssql), 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__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__compile, __pyx_k__compile, sizeof(__pyx_k__compile), 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_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__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__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 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__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_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_n_s__hour, __pyx_k__hour, sizeof(__pyx_k__hour), 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_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__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_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__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_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_n_s__pymssql, __pyx_k__pymssql, sizeof(__pyx_k__pymssql), 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__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__s, __pyx_k__s, sizeof(__pyx_k__s), 0, 0, 1, 1},
  {&__pyx_n_s__sa, __pyx_k__sa, sizeof(__pyx_k__sa), 0, 0, 1, 1},
  {&__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_wait_callback, __pyx_k__set_wait_callback, sizeof(__pyx_k__set_wait_callback), 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__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__toformat, __pyx_k__toformat, sizeof(__pyx_k__toformat), 0, 0, 1, 1},
  {&__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_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_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_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION >= 3
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #else
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s__xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_UnicodeDecodeError = __Pyx_GetBuiltinName(__pyx_n_s__UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "_mssql.pyx":405
 *             cdef RETCODE rtc
 *             if val < 0:
 *                 raise ValueError("The 'query_timeout' attribute must be >= 0.")             # <<<<<<<<<<<<<<
 * 
 *             # currently this will set it application wide :-(
 */
  __pyx_k_tuple_10 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_9)); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_10);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));

  /* "_mssql.pyx":461
 *         instance = ""
 *         if "\\" in server:
 *             server, instance = server.split("\\")             # <<<<<<<<<<<<<<
 * 
 *         if server in (".", "(local)"):
 */
  __pyx_k_tuple_17 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_16)); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_17);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17));

  /* "_mssql.pyx":470
 *         login = dblogin()
 *         if login == NULL:
 *             raise MSSQLDriverException("Out of memory")             # <<<<<<<<<<<<<<
 * 
 *         appname = appname or "pymssql"
 */
  __pyx_k_tuple_21 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_20)); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_21);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21));

  /* "_mssql.pyx":475
 * 
 *         # 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_k_tuple_22 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_3)); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_22);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22));

  /* "_mssql.pyx":477
 *         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_k_tuple_23 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_3)); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_23);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));

  /* "_mssql.pyx":479
 *         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_k_tuple_24 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_3)); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_24);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24));

  /* "_mssql.pyx":511
 *         # Set the character set name
 *         if charset:
 *             charset_bytes = charset.encode('utf-8')             # <<<<<<<<<<<<<<
 *             _charset = charset_bytes
 *             strncpy(self._charset, _charset, PYMSSQL_CHARSETBUFSIZE)
 */
  __pyx_k_tuple_27 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_3)); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_27);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27));

  /* "_mssql.pyx":519
 *         dbsetlogintime(login_timeout)
 * 
 *         cdef bytes server_bytes = server.encode('utf-8')             # <<<<<<<<<<<<<<
 *         cdef char *server_cstr = server_bytes
 * 
 */
  __pyx_k_tuple_28 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_3)); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_28);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28));

  /* "_mssql.pyx":532
 *             connection_object_list.remove(self)
 *             maybe_raise_MSSQLDatabaseException(None)
 *             raise MSSQLDriverException("Connection to the database failed for an unknown reason.")             # <<<<<<<<<<<<<<
 * 
 *         self._connected = 1
 */
  __pyx_k_tuple_31 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_30)); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_31);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31));

  /* "_mssql.pyx":554
 *         rtc = dbsqlexec(self.dbproc)
 *         if (rtc == FAIL):
 *             raise MSSQLDriverException("Could not set connection properties")             # <<<<<<<<<<<<<<
 * 
 *         db_cancel(self)
 */
  __pyx_k_tuple_35 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_34)); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_35);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35));

  /* "_mssql.pyx":668
 *                 <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_k_tuple_41 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_41);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41));

  /* "_mssql.pyx":756
 *         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_k_tuple_45 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_44)); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_45);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45));

  /* "_mssql.pyx":758
 *                 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_k_tuple_47 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_46)); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_47);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47));

  /* "_mssql.pyx":801
 * 
 *             if type(value) not in (decimal.Decimal, float):
 *                 raise TypeError('value can only be a Decimal')             # <<<<<<<<<<<<<<
 * 
 *             value = str(value)
 */
  __pyx_k_tuple_50 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_49)); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_50);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50));

  /* "_mssql.pyx":808
 *         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_k_tuple_52 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_52);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52));

  /* "_mssql.pyx":821
 *         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_k_tuple_54 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_53)); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_54);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54));

  /* "_mssql.pyx":830
 * 
 *         # No conversion was possible so raise an error
 *         raise MSSQLDriverException('Unable to convert value')             # <<<<<<<<<<<<<<
 * 
 *     cpdef execute_non_query(self, query_string, params=None):
 */
  __pyx_k_tuple_56 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_55)); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_56);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56));

  /* "_mssql.pyx":1155
 * 
 *             if data == NULL:
 *                 record += (None,)             # <<<<<<<<<<<<<<
 *                 continue
 * 
 */
  __pyx_k_tuple_81 = PyTuple_Pack(1, Py_None); if (unlikely(!__pyx_k_tuple_81)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_81);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_81));

  /* "_mssql.pyx":1218
 * 
 *         # 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_k_tuple_85 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_85)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_85);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_85));

  /* "_mssql.pyx":1250
 *         # 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_k_tuple_88 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_87)); if (unlikely(!__pyx_k_tuple_88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_88);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_88));

  /* "_mssql.pyx":1310
 *             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_k_tuple_91 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_20)); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_91);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_91));

  /* "_mssql.pyx":1344
 * 
 *         if param_name:
 *             param_name_bytes = param_name.encode('ascii')             # <<<<<<<<<<<<<<
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:
 */
  __pyx_k_tuple_92 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_92)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_92);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_92));

  /* "_mssql.pyx":1347
 *             param_name_cstr = param_name_bytes
 *             if self.had_positional:
 *                 raise MSSQLDriverException('Cannot bind named parameter after positional')             # <<<<<<<<<<<<<<
 *         else:
 *             param_name_cstr = ''
 */
  __pyx_k_tuple_94 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_93)); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_94);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94));

  /* "_mssql.pyx":1475
 *     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_k_tuple_99 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_98)); if (unlikely(!__pyx_k_tuple_99)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_99);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_99));

  /* "_mssql.pyx":1563
 * 
 *     if isinstance(value, unicode):
 *         return ("N'" + value.replace("'", "''") + "'").encode(charset)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(value, (str, bytes)):
 */
  __pyx_k_tuple_108 = PyTuple_Pack(2, ((PyObject *)__pyx_kp_s_106), ((PyObject *)__pyx_kp_s_107)); if (unlikely(!__pyx_k_tuple_108)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_108);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_108));

  /* "_mssql.pyx":1569
 *         if b'\0' not in value:
 *             try:
 *                 value.decode('ascii')             # <<<<<<<<<<<<<<
 *                 return b"'" + value.replace(b"'", b"''") + b"'"
 *             except UnicodeDecodeError:
 */
  __pyx_k_tuple_110 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_110)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_110);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_110));

  /* "_mssql.pyx":1570
 *             try:
 *                 value.decode('ascii')
 *                 return b"'" + value.replace(b"'", b"''") + b"'"             # <<<<<<<<<<<<<<
 *             except UnicodeDecodeError:
 *                 pass
 */
  __pyx_k_tuple_111 = PyTuple_Pack(2, ((PyObject *)__pyx_kp_b_106), ((PyObject *)__pyx_kp_b_107)); if (unlikely(!__pyx_k_tuple_111)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_111);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_111));

  /* "_mssql.pyx":1583
 *         # 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_k_tuple_112 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__hex)); if (unlikely(!__pyx_k_tuple_112)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_112);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_112));

  /* "_mssql.pyx":1604
 * 
 *     if not issubclass(type(data), (list, tuple)):
 *         raise ValueError('expected a simple type, a tuple or a list')             # <<<<<<<<<<<<<<
 * 
 *     quoted = []
 */
  __pyx_k_tuple_116 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_115)); if (unlikely(!__pyx_k_tuple_116)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_116);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_116));

  /* "_mssql.pyx":1611
 * 
 *         if value is None:
 *             raise ValueError('found an unsupported type')             # <<<<<<<<<<<<<<
 * 
 *         quoted.append(value)
 */
  __pyx_k_tuple_118 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_117)); if (unlikely(!__pyx_k_tuple_118)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_118);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_118));

  /* "_mssql.pyx":1637
 *         return tuple(result)
 * 
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')             # <<<<<<<<<<<<<<
 * 
 * _re_pos_param = re.compile(r'(%(s|d))')
 */
  __pyx_k_tuple_123 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_122)); if (unlikely(!__pyx_k_tuple_123)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_123);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_123));

  /* "_mssql.pyx":1666
 *         offset = 0
 *         for match in _re_name_param.finditer(toformat.decode(charset)):
 *             param_key = match.group(2)             # <<<<<<<<<<<<<<
 * 
 *             if not param_key in params:
 */
  __pyx_k_tuple_125 = PyTuple_Pack(1, __pyx_int_2); if (unlikely(!__pyx_k_tuple_125)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_125);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_125));

  /* "_mssql.pyx":1680
 *             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_k_tuple_127 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_k_tuple_127)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_127);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_127));

  /* "_mssql.pyx":1684
 * 
 *             # 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_k_tuple_128 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_k_tuple_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_128);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_128));

  /* "_mssql.pyx":1685
 *             # 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_k_tuple_129 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_k_tuple_129)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_129);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_129));

  /* "_mssql.pyx":1704
 *                 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_k_tuple_131 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_130)); if (unlikely(!__pyx_k_tuple_131)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_131);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_131));

  /* "_mssql.pyx":1710
 * 
 *             # 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_k_tuple_132 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_132);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132));

  /* "_mssql.pyx":1711
 *             # 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_k_tuple_133 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_k_tuple_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_133);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_133));

  /* "_mssql.pyx":1764
 *     rtc = dbinit()
 *     if rtc == FAIL:
 *         raise MSSQLDriverException("Could not initialize communication layer")             # <<<<<<<<<<<<<<
 * 
 *     dberrhandle(err_handler)
 */
  __pyx_k_tuple_135 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_134)); if (unlikely(!__pyx_k_tuple_135)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_135);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_135));

  /* "_mssql.pyx":70
 *     cdef int _row_count = 0
 * 
 * cdef bytes HOSTNAME = socket.gethostname().encode('utf-8')             # <<<<<<<<<<<<<<
 * 
 * # List to store the connection objects in
 */
  __pyx_k_tuple_146 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_3)); if (unlikely(!__pyx_k_tuple_146)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_146);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_146));

  /* "_mssql.pyx":171
 * wait_callback = None
 * 
 * def set_wait_callback(a_callable):             # <<<<<<<<<<<<<<
 *     global wait_callback
 * 
 */
  __pyx_k_tuple_148 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__a_callable)); if (unlikely(!__pyx_k_tuple_148)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_148);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_148));
  __pyx_k_codeobj_149 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_148, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_150, __pyx_n_s__set_wait_callback, 171, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_149)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1524
 *     return stripped
 * 
 * def remove_locale(bytes value):             # <<<<<<<<<<<<<<
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)
 */
  __pyx_k_tuple_151 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__value), ((PyObject *)__pyx_n_s__s), ((PyObject *)__pyx_n_s__l)); if (unlikely(!__pyx_k_tuple_151)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_151);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_151));
  __pyx_k_codeobj_152 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_151, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_150, __pyx_n_s__remove_locale, 1524, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_152)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1639
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')
 * 
 * _re_pos_param = re.compile(r'(%(s|d))')             # <<<<<<<<<<<<<<
 * _re_name_param = re.compile(r'(%\(([^\)]+)\)s)')
 * cdef _substitute_params(toformat, params, charset):
 */
  __pyx_k_tuple_154 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_153)); if (unlikely(!__pyx_k_tuple_154)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_154);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_154));

  /* "_mssql.pyx":1640
 * 
 * _re_pos_param = re.compile(r'(%(s|d))')
 * _re_name_param = re.compile(r'(%\(([^\)]+)\)s)')             # <<<<<<<<<<<<<<
 * cdef _substitute_params(toformat, params, charset):
 *     if params is None:
 */
  __pyx_k_tuple_156 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_155)); if (unlikely(!__pyx_k_tuple_156)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_156);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_156));

  /* "_mssql.pyx":1720
 * # 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_k_tuple_157 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__value)); if (unlikely(!__pyx_k_tuple_157)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_157);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_157));
  __pyx_k_codeobj_158 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_157, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_150, __pyx_n_s__quote_simple_value, 1720, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_158)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1723
 *     return _quote_simple_value(value)
 * 
 * def quote_or_flatten(data):             # <<<<<<<<<<<<<<
 *     return _quote_or_flatten(data)
 * 
 */
  __pyx_k_tuple_159 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__data)); if (unlikely(!__pyx_k_tuple_159)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_159);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_159));
  __pyx_k_codeobj_160 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_159, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_150, __pyx_n_s__quote_or_flatten, 1723, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_160)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1726
 *     return _quote_or_flatten(data)
 * 
 * def quote_data(data):             # <<<<<<<<<<<<<<
 *     return _quote_data(data)
 * 
 */
  __pyx_k_tuple_161 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__data)); if (unlikely(!__pyx_k_tuple_161)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_161);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_161));
  __pyx_k_codeobj_162 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_161, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_150, __pyx_n_s__quote_data, 1726, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_162)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1729
 *     return _quote_data(data)
 * 
 * def substitute_params(toformat, params, charset='utf8'):             # <<<<<<<<<<<<<<
 *     return _substitute_params(toformat, params, charset)
 * 
 */
  __pyx_k_tuple_163 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__toformat), ((PyObject *)__pyx_n_s__params), ((PyObject *)__pyx_n_s__charset)); if (unlikely(!__pyx_k_tuple_163)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_163);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_163));
  __pyx_k_codeobj_164 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_163, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_150, __pyx_n_s__substitute_params, 1729, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_164)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1735
 * ## Compatibility Aliases ##
 * ###########################
 * def connect(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return MSSQLConnection(*args, **kwargs)
 * 
 */
  __pyx_k_tuple_165 = PyTuple_Pack(4, ((PyObject *)__pyx_n_s__args), ((PyObject *)__pyx_n_s__kwargs), ((PyObject *)__pyx_n_s__args), ((PyObject *)__pyx_n_s__kwargs)); if (unlikely(!__pyx_k_tuple_165)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_165);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_165));
  __pyx_k_codeobj_166 = (PyObject*)__Pyx_PyCode_New(0, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_165, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_150, __pyx_n_s__connect, 1735, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_166)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1745
 * ## Max Connections ##
 * #####################
 * def get_max_connections():             # <<<<<<<<<<<<<<
 *     """
 *     Get maximum simultaneous connections db-lib will open to the server.
 */
  __pyx_k_codeobj_169 = (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_150, __pyx_n_s__get_max_connections, 1745, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_169)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1751
 *     return dbgetmaxprocs()
 * 
 * def set_max_connections(int limit):             # <<<<<<<<<<<<<<
 *     """
 *     Set maximum simultaneous connections db-lib will open to the server.
 */
  __pyx_k_tuple_170 = PyTuple_Pack(2, ((PyObject *)__pyx_n_s__limit), ((PyObject *)__pyx_n_s__limit)); if (unlikely(!__pyx_k_tuple_170)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_170);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_170));
  __pyx_k_codeobj_171 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_170, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_150, __pyx_n_s__set_max_connections, 1751, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_171)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1751; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_36 = PyInt_FromLong(36); if (unlikely(!__pyx_int_36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_60 = PyInt_FromLong(60); if (unlikely(!__pyx_int_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_104 = PyInt_FromLong(104); if (unlikely(!__pyx_int_104)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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
{
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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(__Pyx_NAMESTR("_mssql"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_145), 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "_mssql")) {
      if (unlikely(PyDict_SetItemString(modules, "_mssql", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main__mssql) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLRowIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "MSSQLRowIterator", (PyObject *)&__pyx_type_6_mssql_MSSQLRowIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6_mssql_MSSQLRowIterator = &__pyx_type_6_mssql_MSSQLRowIterator;
  __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))__pyx_f_6_mssql_15MSSQLConnection_fetch_next_row;
  __pyx_vtable_6_mssql_MSSQLConnection.fetch_next_row_dict = (PyObject *(*)(struct __pyx_obj_6_mssql_MSSQLConnection *, int))__pyx_f_6_mssql_15MSSQLConnection_fetch_next_row_dict;
  __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))__pyx_f_6_mssql_15MSSQLConnection_get_row;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLConnection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_6_mssql_MSSQLConnection.tp_dict, __pyx_vtabptr_6_mssql_MSSQLConnection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "MSSQLConnection", (PyObject *)&__pyx_type_6_mssql_MSSQLConnection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6_mssql_MSSQLConnection = &__pyx_type_6_mssql_MSSQLConnection;
  __pyx_ptype_6_mssql_Exception = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "Exception", sizeof(PyBaseExceptionObject), 0); if (unlikely(!__pyx_ptype_6_mssql_Exception)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "MSSQLException", (PyObject *)&__pyx_type_6_mssql_MSSQLException) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6_mssql_MSSQLException = &__pyx_type_6_mssql_MSSQLException;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLStoredProcedure) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "MSSQLStoredProcedure", (PyObject *)&__pyx_type_6_mssql_MSSQLStoredProcedure) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6_mssql_MSSQLStoredProcedure = &__pyx_type_6_mssql_MSSQLStoredProcedure;
  __pyx_type_6_mssql_MSSQLDriverException.tp_base = __pyx_ptype_6_mssql_MSSQLException;
  if (PyType_Ready(&__pyx_type_6_mssql_MSSQLDriverException) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "MSSQLDriverException", (PyObject *)&__pyx_type_6_mssql_MSSQLDriverException) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "MSSQLDatabaseException", (PyObject *)&__pyx_type_6_mssql_MSSQLDatabaseException) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "_mssql.pyx":40
 * from cpython cimport PY_MAJOR_VERSION, PY_MINOR_VERSION
 * 
 * if PY_MAJOR_VERSION >= 2 and PY_MINOR_VERSION >= 5:             # <<<<<<<<<<<<<<
 *     import uuid
 * 
 */
  __pyx_t_1 = ((PY_MAJOR_VERSION >= 2) != 0);
  if (__pyx_t_1) {
    __pyx_t_2 = ((PY_MINOR_VERSION >= 5) != 0);
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "_mssql.pyx":41
 * 
 * if PY_MAJOR_VERSION >= 2 and PY_MINOR_VERSION >= 5:
 *     import uuid             # <<<<<<<<<<<<<<
 * 
 * import os
 */
    __pyx_t_4 = __Pyx_Import(((PyObject *)__pyx_n_s__uuid), 0, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_d, __pyx_n_s__uuid, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "_mssql.pyx":43
 *     import uuid
 * 
 * import os             # <<<<<<<<<<<<<<
 * import sys
 * import socket
 */
  __pyx_t_4 = __Pyx_Import(((PyObject *)__pyx_n_s__os), 0, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__os, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":44
 * 
 * import os
 * import sys             # <<<<<<<<<<<<<<
 * import socket
 * import decimal
 */
  __pyx_t_4 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), 0, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__sys, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":45
 * import os
 * import sys
 * import socket             # <<<<<<<<<<<<<<
 * import decimal
 * import datetime
 */
  __pyx_t_4 = __Pyx_Import(((PyObject *)__pyx_n_s__socket), 0, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__socket, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":46
 * import sys
 * import socket
 * import decimal             # <<<<<<<<<<<<<<
 * import datetime
 * import re
 */
  __pyx_t_4 = __Pyx_Import(((PyObject *)__pyx_n_s__decimal), 0, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__decimal, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":47
 * import socket
 * import decimal
 * import datetime             # <<<<<<<<<<<<<<
 * import re
 * 
 */
  __pyx_t_4 = __Pyx_Import(((PyObject *)__pyx_n_s__datetime), 0, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__datetime, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":48
 * import decimal
 * import datetime
 * import re             # <<<<<<<<<<<<<<
 * 
 * from sqlfront cimport *
 */
  __pyx_t_4 = __Pyx_Import(((PyObject *)__pyx_n_s__re), 0, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__re, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":60
 * 
 * # 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":61
 * # 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":62
 * 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":63
 * 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)
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 */
  __pyx_v_6_mssql__mssql_last_msg_line = 0;

  /* "_mssql.pyx":64
 * 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)             # <<<<<<<<<<<<<<
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * cdef char *_mssql_last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 */
  __pyx_v_6_mssql__mssql_last_msg_str = ((char *)PyMem_Malloc(8192));

  /* "_mssql.pyx":65
 * cdef int _mssql_last_msg_line = 0
 * cdef char *_mssql_last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 * cdef char *_mssql_last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * IF PYMSSQL_DEBUG == 1:
 */
  __pyx_v_6_mssql__mssql_last_msg_srv = ((char *)PyMem_Malloc(8192));

  /* "_mssql.pyx":66
 * cdef char *_mssql_last_msg_str = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * cdef char *_mssql_last_msg_srv = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)
 * cdef char *_mssql_last_msg_proc = <char *>PyMem_Malloc(PYMSSQL_MSGSIZE)             # <<<<<<<<<<<<<<
 * IF PYMSSQL_DEBUG == 1:
 *     cdef int _row_count = 0
 */
  __pyx_v_6_mssql__mssql_last_msg_proc = ((char *)PyMem_Malloc(8192));

  /* "_mssql.pyx":70
 *     cdef int _row_count = 0
 * 
 * cdef bytes HOSTNAME = socket.gethostname().encode('utf-8')             # <<<<<<<<<<<<<<
 * 
 * # List to store the connection objects in
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__socket); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__gethostname); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_146), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __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 bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_XGOTREF(((PyObject *)__pyx_v_6_mssql_HOSTNAME));
  __Pyx_DECREF(((PyObject *)__pyx_v_6_mssql_HOSTNAME));
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_v_6_mssql_HOSTNAME = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "_mssql.pyx":73
 * 
 * # List to store the connection objects in
 * cdef list connection_object_list = list()             # <<<<<<<<<<<<<<
 * 
 * # Store the 32bit max int
 */
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_XGOTREF(((PyObject *)__pyx_v_6_mssql_connection_object_list));
  __Pyx_DECREF(((PyObject *)__pyx_v_6_mssql_connection_object_list));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  __pyx_v_6_mssql_connection_object_list = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "_mssql.pyx":76
 * 
 * # Store the 32bit max int
 * cdef int MAX_INT = 2147483647             # <<<<<<<<<<<<<<
 * 
 * # Store the module version
 */
  __pyx_v_6_mssql_MAX_INT = 2147483647;

  /* "_mssql.pyx":79
 * 
 * # Store the module version
 * __version__ = '1.9.909'             # <<<<<<<<<<<<<<
 * 
 * #############################
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_147)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":84
 * ## DB-API type definitions ##
 * #############################
 * STRING = 1             # <<<<<<<<<<<<<<
 * BINARY = 2
 * NUMBER = 3
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__STRING, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":85
 * #############################
 * STRING = 1
 * BINARY = 2             # <<<<<<<<<<<<<<
 * NUMBER = 3
 * DATETIME = 4
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__BINARY, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":86
 * STRING = 1
 * BINARY = 2
 * NUMBER = 3             # <<<<<<<<<<<<<<
 * DATETIME = 4
 * DECIMAL = 5
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__NUMBER, __pyx_int_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":87
 * BINARY = 2
 * NUMBER = 3
 * DATETIME = 4             # <<<<<<<<<<<<<<
 * DECIMAL = 5
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__DATETIME, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":88
 * NUMBER = 3
 * DATETIME = 4
 * DECIMAL = 5             # <<<<<<<<<<<<<<
 * 
 * ##################
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__DECIMAL, __pyx_int_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":93
 * ## DB-LIB types ##
 * ##################
 * SQLBINARY = SYBBINARY             # <<<<<<<<<<<<<<
 * SQLBIT = SYBBIT
 * SQLBITN = 104
 */
  __pyx_t_4 = PyInt_FromLong(SYBBINARY); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLBINARY, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":94
 * ##################
 * SQLBINARY = SYBBINARY
 * SQLBIT = SYBBIT             # <<<<<<<<<<<<<<
 * SQLBITN = 104
 * SQLCHAR = SYBCHAR
 */
  __pyx_t_4 = PyInt_FromLong(SYBBIT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLBIT, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":95
 * SQLBINARY = SYBBINARY
 * SQLBIT = SYBBIT
 * SQLBITN = 104             # <<<<<<<<<<<<<<
 * SQLCHAR = SYBCHAR
 * SQLDATETIME = SYBDATETIME
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLBITN, __pyx_int_104) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":96
 * SQLBIT = SYBBIT
 * SQLBITN = 104
 * SQLCHAR = SYBCHAR             # <<<<<<<<<<<<<<
 * SQLDATETIME = SYBDATETIME
 * SQLDATETIM4 = SYBDATETIME4
 */
  __pyx_t_4 = PyInt_FromLong(SYBCHAR); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLCHAR, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":97
 * SQLBITN = 104
 * SQLCHAR = SYBCHAR
 * SQLDATETIME = SYBDATETIME             # <<<<<<<<<<<<<<
 * SQLDATETIM4 = SYBDATETIME4
 * SQLDATETIMN = SYBDATETIMN
 */
  __pyx_t_4 = PyInt_FromLong(SYBDATETIME); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLDATETIME, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":98
 * SQLCHAR = SYBCHAR
 * SQLDATETIME = SYBDATETIME
 * SQLDATETIM4 = SYBDATETIME4             # <<<<<<<<<<<<<<
 * SQLDATETIMN = SYBDATETIMN
 * SQLDECIMAL = SYBDECIMAL
 */
  __pyx_t_4 = PyInt_FromLong(SYBDATETIME4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLDATETIM4, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":99
 * SQLDATETIME = SYBDATETIME
 * SQLDATETIM4 = SYBDATETIME4
 * SQLDATETIMN = SYBDATETIMN             # <<<<<<<<<<<<<<
 * SQLDECIMAL = SYBDECIMAL
 * SQLFLT4 = SYBREAL
 */
  __pyx_t_4 = PyInt_FromLong(SYBDATETIMN); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLDATETIMN, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":100
 * SQLDATETIM4 = SYBDATETIME4
 * SQLDATETIMN = SYBDATETIMN
 * SQLDECIMAL = SYBDECIMAL             # <<<<<<<<<<<<<<
 * SQLFLT4 = SYBREAL
 * SQLFLT8 = SYBFLT8
 */
  __pyx_t_4 = PyInt_FromLong(SYBDECIMAL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLDECIMAL, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":101
 * SQLDATETIMN = SYBDATETIMN
 * SQLDECIMAL = SYBDECIMAL
 * SQLFLT4 = SYBREAL             # <<<<<<<<<<<<<<
 * SQLFLT8 = SYBFLT8
 * SQLFLTN = SYBFLTN
 */
  __pyx_t_4 = PyInt_FromLong(SYBREAL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLFLT4, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":102
 * SQLDECIMAL = SYBDECIMAL
 * SQLFLT4 = SYBREAL
 * SQLFLT8 = SYBFLT8             # <<<<<<<<<<<<<<
 * SQLFLTN = SYBFLTN
 * SQLIMAGE = SYBIMAGE
 */
  __pyx_t_4 = PyInt_FromLong(SYBFLT8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLFLT8, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":103
 * SQLFLT4 = SYBREAL
 * SQLFLT8 = SYBFLT8
 * SQLFLTN = SYBFLTN             # <<<<<<<<<<<<<<
 * SQLIMAGE = SYBIMAGE
 * SQLINT1 = SYBINT1
 */
  __pyx_t_4 = PyInt_FromLong(SYBFLTN); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLFLTN, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":104
 * SQLFLT8 = SYBFLT8
 * SQLFLTN = SYBFLTN
 * SQLIMAGE = SYBIMAGE             # <<<<<<<<<<<<<<
 * SQLINT1 = SYBINT1
 * SQLINT2 = SYBINT2
 */
  __pyx_t_4 = PyInt_FromLong(SYBIMAGE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLIMAGE, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":105
 * SQLFLTN = SYBFLTN
 * SQLIMAGE = SYBIMAGE
 * SQLINT1 = SYBINT1             # <<<<<<<<<<<<<<
 * SQLINT2 = SYBINT2
 * SQLINT4 = SYBINT4
 */
  __pyx_t_4 = PyInt_FromLong(SYBINT1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLINT1, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":106
 * SQLIMAGE = SYBIMAGE
 * SQLINT1 = SYBINT1
 * SQLINT2 = SYBINT2             # <<<<<<<<<<<<<<
 * SQLINT4 = SYBINT4
 * SQLINT8 = SYBINT8
 */
  __pyx_t_4 = PyInt_FromLong(SYBINT2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLINT2, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":107
 * SQLINT1 = SYBINT1
 * SQLINT2 = SYBINT2
 * SQLINT4 = SYBINT4             # <<<<<<<<<<<<<<
 * SQLINT8 = SYBINT8
 * SQLINTN = SYBINTN
 */
  __pyx_t_4 = PyInt_FromLong(SYBINT4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLINT4, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":108
 * SQLINT2 = SYBINT2
 * SQLINT4 = SYBINT4
 * SQLINT8 = SYBINT8             # <<<<<<<<<<<<<<
 * SQLINTN = SYBINTN
 * SQLMONEY = SYBMONEY
 */
  __pyx_t_4 = PyInt_FromLong(SYBINT8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLINT8, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":109
 * SQLINT4 = SYBINT4
 * SQLINT8 = SYBINT8
 * SQLINTN = SYBINTN             # <<<<<<<<<<<<<<
 * SQLMONEY = SYBMONEY
 * SQLMONEY4 = SYBMONEY4
 */
  __pyx_t_4 = PyInt_FromLong(SYBINTN); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLINTN, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":110
 * SQLINT8 = SYBINT8
 * SQLINTN = SYBINTN
 * SQLMONEY = SYBMONEY             # <<<<<<<<<<<<<<
 * SQLMONEY4 = SYBMONEY4
 * SQLMONEYN = SYBMONEYN
 */
  __pyx_t_4 = PyInt_FromLong(SYBMONEY); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLMONEY, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":111
 * SQLINTN = SYBINTN
 * SQLMONEY = SYBMONEY
 * SQLMONEY4 = SYBMONEY4             # <<<<<<<<<<<<<<
 * SQLMONEYN = SYBMONEYN
 * SQLNUMERIC = SYBNUMERIC
 */
  __pyx_t_4 = PyInt_FromLong(SYBMONEY4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLMONEY4, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":112
 * SQLMONEY = SYBMONEY
 * SQLMONEY4 = SYBMONEY4
 * SQLMONEYN = SYBMONEYN             # <<<<<<<<<<<<<<
 * SQLNUMERIC = SYBNUMERIC
 * SQLREAL = SYBREAL
 */
  __pyx_t_4 = PyInt_FromLong(SYBMONEYN); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLMONEYN, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":113
 * SQLMONEY4 = SYBMONEY4
 * SQLMONEYN = SYBMONEYN
 * SQLNUMERIC = SYBNUMERIC             # <<<<<<<<<<<<<<
 * SQLREAL = SYBREAL
 * SQLTEXT = SYBTEXT
 */
  __pyx_t_4 = PyInt_FromLong(SYBNUMERIC); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLNUMERIC, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":114
 * SQLMONEYN = SYBMONEYN
 * SQLNUMERIC = SYBNUMERIC
 * SQLREAL = SYBREAL             # <<<<<<<<<<<<<<
 * SQLTEXT = SYBTEXT
 * SQLVARBINARY = SYBVARBINARY
 */
  __pyx_t_4 = PyInt_FromLong(SYBREAL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLREAL, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":115
 * SQLNUMERIC = SYBNUMERIC
 * SQLREAL = SYBREAL
 * SQLTEXT = SYBTEXT             # <<<<<<<<<<<<<<
 * SQLVARBINARY = SYBVARBINARY
 * SQLVARCHAR = SYBVARCHAR
 */
  __pyx_t_4 = PyInt_FromLong(SYBTEXT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLTEXT, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":116
 * SQLREAL = SYBREAL
 * SQLTEXT = SYBTEXT
 * SQLVARBINARY = SYBVARBINARY             # <<<<<<<<<<<<<<
 * SQLVARCHAR = SYBVARCHAR
 * SQLUUID = 36
 */
  __pyx_t_4 = PyInt_FromLong(SYBVARBINARY); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLVARBINARY, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":117
 * SQLTEXT = SYBTEXT
 * SQLVARBINARY = SYBVARBINARY
 * SQLVARCHAR = SYBVARCHAR             # <<<<<<<<<<<<<<
 * SQLUUID = 36
 * 
 */
  __pyx_t_4 = PyInt_FromLong(SYBVARCHAR); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLVARCHAR, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":118
 * SQLVARBINARY = SYBVARBINARY
 * SQLVARCHAR = SYBVARCHAR
 * SQLUUID = 36             # <<<<<<<<<<<<<<
 * 
 * #######################
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__SQLUUID, __pyx_int_36) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":165
 * 
 * # 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_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":167
 * 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_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":169
 * 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_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":171
 * wait_callback = None
 * 
 * def set_wait_callback(a_callable):             # <<<<<<<<<<<<<<
 *     global wait_callback
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_1set_wait_callback, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__set_wait_callback, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1524
 *     return stripped
 * 
 * def remove_locale(bytes value):             # <<<<<<<<<<<<<<
 *     cdef char *s = <char*>value
 *     cdef size_t l = strlen(s)
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_3remove_locale, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__remove_locale, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1639
 *     raise ValueError('expected a simple type, a tuple or a dictionary.')
 * 
 * _re_pos_param = re.compile(r'(%(s|d))')             # <<<<<<<<<<<<<<
 * _re_name_param = re.compile(r'(%\(([^\)]+)\)s)')
 * cdef _substitute_params(toformat, params, charset):
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__re); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__compile); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_154), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s___re_pos_param, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1640
 * 
 * _re_pos_param = re.compile(r'(%(s|d))')
 * _re_name_param = re.compile(r'(%\(([^\)]+)\)s)')             # <<<<<<<<<<<<<<
 * cdef _substitute_params(toformat, params, charset):
 *     if params is None:
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__re); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__compile); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_156), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s___re_name_param, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1720
 * # 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_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_5quote_simple_value, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__quote_simple_value, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1723
 *     return _quote_simple_value(value)
 * 
 * def quote_or_flatten(data):             # <<<<<<<<<<<<<<
 *     return _quote_or_flatten(data)
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_7quote_or_flatten, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__quote_or_flatten, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1726
 *     return _quote_or_flatten(data)
 * 
 * def quote_data(data):             # <<<<<<<<<<<<<<
 *     return _quote_data(data)
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_9quote_data, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__quote_data, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1729
 *     return _quote_data(data)
 * 
 * def substitute_params(toformat, params, charset='utf8'):             # <<<<<<<<<<<<<<
 *     return _substitute_params(toformat, params, charset)
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_11substitute_params, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__substitute_params, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1735
 * ## Compatibility Aliases ##
 * ###########################
 * def connect(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return MSSQLConnection(*args, **kwargs)
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_13connect, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__connect, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1738
 *     return MSSQLConnection(*args, **kwargs)
 * 
 * MssqlDatabaseException = MSSQLDatabaseException             # <<<<<<<<<<<<<<
 * MssqlDriverException = MSSQLDriverException
 * MssqlConnection = MSSQLConnection
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_167, ((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDatabaseException))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1739
 * 
 * MssqlDatabaseException = MSSQLDatabaseException
 * MssqlDriverException = MSSQLDriverException             # <<<<<<<<<<<<<<
 * MssqlConnection = MSSQLConnection
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_168, ((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLDriverException))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1740
 * MssqlDatabaseException = MSSQLDatabaseException
 * MssqlDriverException = MSSQLDriverException
 * MssqlConnection = MSSQLConnection             # <<<<<<<<<<<<<<
 * 
 * #####################
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__MssqlConnection, ((PyObject *)((PyObject*)__pyx_ptype_6_mssql_MSSQLConnection))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "_mssql.pyx":1745
 * ## Max Connections ##
 * #####################
 * def get_max_connections():             # <<<<<<<<<<<<<<
 *     """
 *     Get maximum simultaneous connections db-lib will open to the server.
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_15get_max_connections, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__get_max_connections, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1751
 *     return dbgetmaxprocs()
 * 
 * def set_max_connections(int limit):             # <<<<<<<<<<<<<<
 *     """
 *     Set maximum simultaneous connections db-lib will open to the server.
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_6_mssql_17set_max_connections, NULL, __pyx_n_s___mssql); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__set_max_connections, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_mssql.pyx":1769
 *     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_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_d, __pyx_n_s____test__, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  if (__pyx_m) {
    __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 */
#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 /* CYTHON_REFNANNY */

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 '%s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    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 (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
        goto bad;
    #endif
    Py_INCREF(local_type);
    Py_INCREF(local_value);
    Py_INCREF(local_tb);
    *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;
    /* Make sure tstate is in a consistent state when we XDECREF
       these objects (DECREF may run arbitrary code). */
    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;
}

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (result) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    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);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #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);
    }
}

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
}

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,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

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,
                 "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_Format(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;
}

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))) {
        length = strlen(cstring);
        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);
    }
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    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 PY_VERSION_HEX < 0x02050000
    if (PyClass_Check(type)) {
    #else
    if (PyType_Check(type)) {
    #endif
#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;
        #if PY_VERSION_HEX < 0x02050000
        if (PyInstance_Check(type)) {
            type = (PyObject*) ((PyInstanceObject*)type)->in_class;
            Py_INCREF(type);
        } else {
            type = 0;
            PyErr_SetString(PyExc_TypeError,
                "raise: exception must be an old-style class or instance");
            goto raise_error;
        }
        #else
        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;
        }
        #endif
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else /* Python 3+ */
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 *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 = PyEval_CallObject(type, args);
        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) {
        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);
        }
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CPYTHON_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,
        "%s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

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);
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%s to unpack",
                 index, (index == 1) ? "" : "s");
}

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
}

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;
}

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,
                                                              int wraparound, 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,
                                                              int wraparound, 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, int wraparound, 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))
                        PyErr_Clear();
                    else
                        return NULL;
                }
            }
            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));
}

static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
    int r;
    if (!j) return -1;
    r = PyObject_SetItem(o, j, v);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
                                               int is_list, int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
        if ((!boundscheck) || likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
            PyObject* old = PyList_GET_ITEM(o, n);
            Py_INCREF(v);
            PyList_SET_ITEM(o, n, v);
            Py_DECREF(old);
            return 1;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_ass_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))
                        PyErr_Clear();
                    else
                        return -1;
                }
            }
            return m->sq_ass_item(o, i, v);
        }
    }
#else
#if CYTHON_COMPILING_IN_PYPY
    if (is_list || (PySequence_Check(o) && !PyDict_Check(o))) {
#else
    if (is_list || PySequence_Check(o)) {
#endif
        return PySequence_SetItem(o, i, v);
    }
#endif
    return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
}

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (Py_TYPE(obj) == type) return 1;
    }
    else {
        if (PyObject_TypeCheck(obj, type)) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%s' has incorrect type (expected %s, got %s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

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);
    }
}

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;
}

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, Py_ssize_t orig_length, 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;
}

static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return NULL;
        Py_INCREF(Py_None);
        return Py_None; /* this is just to have an accurate signature */
    } else {
        return __Pyx_PyObject_CallMethod1(L, __pyx_n_s__append, x);
    }
}

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))
                    PyErr_Clear();
                else
                    goto bad;
            }
        }
        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;
}

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);
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    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;
}

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
#else
    PyErr_GetExcInfo(type, value, tb);
#endif
}
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    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);
#else
    PyErr_SetExcInfo(type, value, tb);
#endif
}

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_VERSION_HEX >= 0x02050000
    {
        #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; /* try absolute import on failure */
        }
        #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
        }
    }
    #else
    if (level>0) {
        PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
        goto bad;
    }
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
    #endif
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_PY_LONG_LONG(PY_LONG_LONG val) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = (PY_LONG_LONG)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(PY_LONG_LONG) == sizeof(char))  ||
        (sizeof(PY_LONG_LONG) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(PY_LONG_LONG) == sizeof(int)) ||
               (sizeof(PY_LONG_LONG) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(PY_LONG_LONG) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(PY_LONG_LONG),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_DBINT(DBINT val) {
    const DBINT neg_one = (DBINT)-1, const_zero = (DBINT)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(DBINT) == sizeof(char))  ||
        (sizeof(DBINT) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(DBINT) == sizeof(int)) ||
               (sizeof(DBINT) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(DBINT) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(DBINT),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_from_py_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 = const_zero < neg_one;
    if (sizeof(PY_LONG_LONG) == sizeof(char)) {
        if (is_unsigned)
            return (PY_LONG_LONG)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (PY_LONG_LONG)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(PY_LONG_LONG) == sizeof(short)) {
        if (is_unsigned)
            return (PY_LONG_LONG)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (PY_LONG_LONG)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(PY_LONG_LONG) == sizeof(int)) {
        if (is_unsigned)
            return (PY_LONG_LONG)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (PY_LONG_LONG)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(PY_LONG_LONG) == sizeof(long)) {
        if (is_unsigned)
            return (PY_LONG_LONG)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (PY_LONG_LONG)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(PY_LONG_LONG) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (PY_LONG_LONG)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (PY_LONG_LONG)__Pyx_PyInt_AsSignedLongLong(x);
    }  else {
        #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_Int(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;
    }
}

static CYTHON_INLINE DBINT __Pyx_PyInt_from_py_DBINT(PyObject* x) {
    const DBINT neg_one = (DBINT)-1, const_zero = (DBINT)0;
    const int is_unsigned = const_zero < neg_one;
    if (sizeof(DBINT) == sizeof(char)) {
        if (is_unsigned)
            return (DBINT)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (DBINT)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(DBINT) == sizeof(short)) {
        if (is_unsigned)
            return (DBINT)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (DBINT)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(DBINT) == sizeof(int)) {
        if (is_unsigned)
            return (DBINT)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (DBINT)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(DBINT) == sizeof(long)) {
        if (is_unsigned)
            return (DBINT)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (DBINT)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(DBINT) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (DBINT)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (DBINT)__Pyx_PyInt_AsSignedLongLong(x);
    }  else {
        #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_Int(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;
    }
}

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(unsigned long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (unsigned long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return (unsigned long)PyLong_AsUnsignedLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(unsigned long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(unsigned long) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(unsigned long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (unsigned long)PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(unsigned PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(unsigned PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return (long)PyLong_AsUnsignedLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(long) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (long)PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(signed long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (signed long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return (signed long)PyLong_AsUnsignedLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(signed long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(signed long) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(signed long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (signed long)PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(signed PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(signed PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

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);
        #if PY_VERSION_HEX < 0x02050000
        return PyErr_Warn(NULL, message);
        #else
        return PyErr_WarnEx(NULL, message, 1);
        #endif
    }
    return 0;
}

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 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    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;
}

#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

#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,
            "%s.%s 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",
            module_name, class_name);
        #if PY_VERSION_HEX < 0x02050000
        if (PyErr_Warn(NULL, warning) < 0) goto bad;
        #else
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
        #endif
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%s.%s has the wrong size, try recompiling",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

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) / 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, 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);
}

#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,            /*int argcount,*/
        0,            /*int kwonlyargcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __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,      /*int firstlineno,*/
        __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;
    PyObject *py_globals = 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_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*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);
}

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  /* Python 3+ has unicode identifiers */
        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(char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, 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 __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 /*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else /* PY_VERSION_HEX < 0x03030000 */
        if (PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_DATA_SIZE(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
        return PyUnicode_AsUTF8AndSize(o, length);
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
#endif /* PY_VERSION_HEX < 0x03030000 */
    } else
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII  || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (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_Int(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 Py_INCREF(x), 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,
                   "__%s__ returned non-%s (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 = 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) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       if ((val != (unsigned PY_LONG_LONG)-1) || !PyErr_Occurred())
           PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
