Format: text/x-python
⬇ Download File (9.6 KB)
   1  # ADO enumerated constants documented on MSDN:
   2  # https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/ado-enumerated-constants
   3  # TODO: Update to https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/ado-enumerated-constants
   4  
   5  # IsolationLevelEnum
   6  adXactUnspecified = -1
   7  adXactBrowse = 0x100
   8  adXactChaos = 0x10
   9  adXactCursorStability = 0x1000
  10  adXactIsolated = 0x100000
  11  adXactReadCommitted = 0x1000
  12  adXactReadUncommitted = 0x100
  13  adXactRepeatableRead = 0x10000
  14  adXactSerializable = 0x100000
  15  
  16  # CursorLocationEnum
  17  adUseClient = 3
  18  adUseServer = 2
  19  
  20  # CursorTypeEnum
  21  adOpenDynamic = 2
  22  adOpenForwardOnly = 0
  23  adOpenKeyset = 1
  24  adOpenStatic = 3
  25  adOpenUnspecified = -1
  26  
  27  # CommandTypeEnum
  28  adCmdText = 1
  29  adCmdStoredProc = 4
  30  adSchemaTables = 20
  31  
  32  # ParameterDirectionEnum
  33  adParamInput = 1
  34  adParamInputOutput = 3
  35  adParamOutput = 2
  36  adParamReturnValue = 4
  37  adParamUnknown = 0
  38  directions = {
  39      0: "Unknown",
  40      1: "Input",
  41      2: "Output",
  42      3: "InputOutput",
  43      4: "Return",
  44  }
  45  
  46  
  47  def ado_direction_name(ado_dir):
  48      try:
  49          return "adParam" + directions[ado_dir]
  50      except:
  51          return f"unknown direction ({ado_dir})"
  52  
  53  
  54  # ObjectStateEnum
  55  adStateClosed = 0
  56  adStateOpen = 1
  57  adStateConnecting = 2
  58  adStateExecuting = 4
  59  adStateFetching = 8
  60  
  61  # FieldAttributeEnum
  62  adFldMayBeNull = 0x40
  63  
  64  # ConnectModeEnum
  65  adModeUnknown = 0
  66  adModeRead = 1
  67  adModeWrite = 2
  68  adModeReadWrite = 3
  69  adModeShareDenyRead = 4
  70  adModeShareDenyWrite = 8
  71  adModeShareExclusive = 12
  72  adModeShareDenyNone = 16
  73  adModeRecursive = 0x400000
  74  
  75  # XactAttributeEnum
  76  adXactCommitRetaining = 131072
  77  adXactAbortRetaining = 262144
  78  
  79  ado_error_TIMEOUT = -2147217871
  80  
  81  # DataTypeEnum - ADO Data types documented at:
  82  # http://msdn2.microsoft.com/en-us/library/ms675318.aspx
  83  # TODO: Update to https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/datatypeenum
  84  adArray = 0x2000
  85  adEmpty = 0x0
  86  adBSTR = 0x8
  87  adBigInt = 0x14
  88  adBinary = 0x80
  89  adBoolean = 0xB
  90  adChapter = 0x88
  91  adChar = 0x81
  92  adCurrency = 0x6
  93  adDBDate = 0x85
  94  adDBTime = 0x86
  95  adDBTimeStamp = 0x87
  96  adDate = 0x7
  97  adDecimal = 0xE
  98  adDouble = 0x5
  99  adError = 0xA
 100  adFileTime = 0x40
 101  adGUID = 0x48
 102  adIDispatch = 0x9
 103  adIUnknown = 0xD
 104  adInteger = 0x3
 105  adLongVarBinary = 0xCD
 106  adLongVarChar = 0xC9
 107  adLongVarWChar = 0xCB
 108  adNumeric = 0x83
 109  adPropVariant = 0x8A
 110  adSingle = 0x4
 111  adSmallInt = 0x2
 112  adTinyInt = 0x10
 113  adUnsignedBigInt = 0x15
 114  adUnsignedInt = 0x13
 115  adUnsignedSmallInt = 0x12
 116  adUnsignedTinyInt = 0x11
 117  adUserDefined = 0x84
 118  adVarBinary = 0xCC
 119  adVarChar = 0xC8
 120  adVarNumeric = 0x8B
 121  adVarWChar = 0xCA
 122  adVariant = 0xC
 123  adWChar = 0x82
 124  # Additional constants used by introspection but not ADO itself
 125  AUTO_FIELD_MARKER = -1000
 126  
 127  adTypeNames = {
 128      adBSTR: "adBSTR",
 129      adBigInt: "adBigInt",
 130      adBinary: "adBinary",
 131      adBoolean: "adBoolean",
 132      adChapter: "adChapter",
 133      adChar: "adChar",
 134      adCurrency: "adCurrency",
 135      adDBDate: "adDBDate",
 136      adDBTime: "adDBTime",
 137      adDBTimeStamp: "adDBTimeStamp",
 138      adDate: "adDate",
 139      adDecimal: "adDecimal",
 140      adDouble: "adDouble",
 141      adEmpty: "adEmpty",
 142      adError: "adError",
 143      adFileTime: "adFileTime",
 144      adGUID: "adGUID",
 145      adIDispatch: "adIDispatch",
 146      adIUnknown: "adIUnknown",
 147      adInteger: "adInteger",
 148      adLongVarBinary: "adLongVarBinary",
 149      adLongVarChar: "adLongVarChar",
 150      adLongVarWChar: "adLongVarWChar",
 151      adNumeric: "adNumeric",
 152      adPropVariant: "adPropVariant",
 153      adSingle: "adSingle",
 154      adSmallInt: "adSmallInt",
 155      adTinyInt: "adTinyInt",
 156      adUnsignedBigInt: "adUnsignedBigInt",
 157      adUnsignedInt: "adUnsignedInt",
 158      adUnsignedSmallInt: "adUnsignedSmallInt",
 159      adUnsignedTinyInt: "adUnsignedTinyInt",
 160      adUserDefined: "adUserDefined",
 161      adVarBinary: "adVarBinary",
 162      adVarChar: "adVarChar",
 163      adVarNumeric: "adVarNumeric",
 164      adVarWChar: "adVarWChar",
 165      adVariant: "adVariant",
 166      adWChar: "adWChar",
 167  }
 168  
 169  
 170  def ado_type_name(ado_type):
 171      return adTypeNames.get(ado_type, f"unknown type ({ado_type})")
 172  
 173  
 174  # here in decimal, sorted by value
 175  # adEmpty 0 Specifies no value (DBTYPE_EMPTY).
 176  # adSmallInt 2 Indicates a two-byte signed integer (DBTYPE_I2).
 177  # adInteger 3 Indicates a four-byte signed integer (DBTYPE_I4).
 178  # adSingle 4 Indicates a single-precision floating-point value (DBTYPE_R4).
 179  # adDouble 5 Indicates a double-precision floating-point value (DBTYPE_R8).
 180  # adCurrency 6 Indicates a currency value (DBTYPE_CY). Currency is a fixed-point number
 181  #   with four digits to the right of the decimal point. It is stored in an eight-byte signed integer scaled by 10,000.
 182  # adDate 7 Indicates a date value (DBTYPE_DATE). A date is stored as a double, the whole part of which is
 183  #   the number of days since December 30, 1899, and the fractional part of which is the fraction of a day.
 184  # adBSTR 8 Indicates a null-terminated character string (Unicode) (DBTYPE_BSTR).
 185  # adIDispatch 9 Indicates a pointer to an IDispatch interface on a COM object (DBTYPE_IDISPATCH).
 186  # adError 10 Indicates a 32-bit error code (DBTYPE_ERROR).
 187  # adBoolean 11 Indicates a boolean value (DBTYPE_BOOL).
 188  # adVariant 12 Indicates an Automation Variant (DBTYPE_VARIANT).
 189  # adIUnknown 13 Indicates a pointer to an IUnknown interface on a COM object (DBTYPE_IUNKNOWN).
 190  # adDecimal 14 Indicates an exact numeric value with a fixed precision and scale (DBTYPE_DECIMAL).
 191  # adTinyInt 16 Indicates a one-byte signed integer (DBTYPE_I1).
 192  # adUnsignedTinyInt 17 Indicates a one-byte unsigned integer (DBTYPE_UI1).
 193  # adUnsignedSmallInt 18 Indicates a two-byte unsigned integer (DBTYPE_UI2).
 194  # adUnsignedInt 19 Indicates a four-byte unsigned integer (DBTYPE_UI4).
 195  # adBigInt 20 Indicates an eight-byte signed integer (DBTYPE_I8).
 196  # adUnsignedBigInt 21 Indicates an eight-byte unsigned integer (DBTYPE_UI8).
 197  # adFileTime 64 Indicates a 64-bit value representing the number of 100-nanosecond intervals since
 198  #    January 1, 1601 (DBTYPE_FILETIME).
 199  # adGUID 72 Indicates a globally unique identifier (GUID) (DBTYPE_GUID).
 200  # adBinary 128 Indicates a binary value (DBTYPE_BYTES).
 201  # adChar 129 Indicates a string value (DBTYPE_STR).
 202  # adWChar 130 Indicates a null-terminated Unicode character string (DBTYPE_WSTR).
 203  # adNumeric 131 Indicates an exact numeric value with a fixed precision and scale (DBTYPE_NUMERIC).
 204  #   adUserDefined 132 Indicates a user-defined variable (DBTYPE_UDT).
 205  # adUserDefined 132 Indicates a user-defined variable (DBTYPE_UDT).
 206  # adDBDate 133 Indicates a date value (yyyymmdd) (DBTYPE_DBDATE).
 207  # adDBTime 134 Indicates a time value (hhmmss) (DBTYPE_DBTIME).
 208  # adDBTimeStamp 135 Indicates a date/time stamp (yyyymmddhhmmss plus a fraction in billionths) (DBTYPE_DBTIMESTAMP).
 209  # adChapter 136 Indicates a four-byte chapter value that identifies rows in a child rowset (DBTYPE_HCHAPTER).
 210  # adPropVariant 138 Indicates an Automation PROPVARIANT (DBTYPE_PROP_VARIANT).
 211  # adVarNumeric 139 Indicates a numeric value (Parameter object only).
 212  # adVarChar 200 Indicates a string value (Parameter object only).
 213  # adLongVarChar 201 Indicates a long string value (Parameter object only).
 214  # adVarWChar 202 Indicates a null-terminated Unicode character string (Parameter object only).
 215  # adLongVarWChar 203 Indicates a long null-terminated Unicode string value (Parameter object only).
 216  # adVarBinary 204 Indicates a binary value (Parameter object only).
 217  # adLongVarBinary 205 Indicates a long binary value (Parameter object only).
 218  # adArray (Does not apply to ADOX.) 0x2000 A flag value, always combined with another data type constant,
 219  #   that indicates an array of that other data type.
 220  
 221  # Error codes to names
 222  adoErrors = {
 223      0xE7B: "adErrBoundToCommand",
 224      0xE94: "adErrCannotComplete",
 225      0xEA4: "adErrCantChangeConnection",
 226      0xC94: "adErrCantChangeProvider",
 227      0xE8C: "adErrCantConvertvalue",
 228      0xE8D: "adErrCantCreate",
 229      0xEA3: "adErrCatalogNotSet",
 230      0xE8E: "adErrColumnNotOnThisRow",
 231      0xD5D: "adErrDataConversion",
 232      0xE89: "adErrDataOverflow",
 233      0xE9A: "adErrDelResOutOfScope",
 234      0xEA6: "adErrDenyNotSupported",
 235      0xEA7: "adErrDenyTypeNotSupported",
 236      0xCB3: "adErrFeatureNotAvailable",
 237      0xEA5: "adErrFieldsUpdateFailed",
 238      0xC93: "adErrIllegalOperation",
 239      0xCAE: "adErrInTransaction",
 240      0xE87: "adErrIntegrityViolation",
 241      0xBB9: "adErrInvalidArgument",
 242      0xE7D: "adErrInvalidConnection",
 243      0xE7C: "adErrInvalidParamInfo",
 244      0xE82: "adErrInvalidTransaction",
 245      0xE91: "adErrInvalidURL",
 246      0xCC1: "adErrItemNotFound",
 247      0xBCD: "adErrNoCurrentRecord",
 248      0xE83: "adErrNotExecuting",
 249      0xE7E: "adErrNotReentrant",
 250      0xE78: "adErrObjectClosed",
 251      0xD27: "adErrObjectInCollection",
 252      0xD5C: "adErrObjectNotSet",
 253      0xE79: "adErrObjectOpen",
 254      0xBBA: "adErrOpeningFile",
 255      0xE80: "adErrOperationCancelled",
 256      0xE96: "adErrOutOfSpace",
 257      0xE88: "adErrPermissionDenied",
 258      0xE9E: "adErrPropConflicting",
 259      0xE9B: "adErrPropInvalidColumn",
 260      0xE9C: "adErrPropInvalidOption",
 261      0xE9D: "adErrPropInvalidValue",
 262      0xE9F: "adErrPropNotAllSettable",
 263      0xEA0: "adErrPropNotSet",
 264      0xEA1: "adErrPropNotSettable",
 265      0xEA2: "adErrPropNotSupported",
 266      0xBB8: "adErrProviderFailed",
 267      0xE7A: "adErrProviderNotFound",
 268      0xBBB: "adErrReadFile",
 269      0xE93: "adErrResourceExists",
 270      0xE92: "adErrResourceLocked",
 271      0xE97: "adErrResourceOutOfScope",
 272      0xE8A: "adErrSchemaViolation",
 273      0xE8B: "adErrSignMismatch",
 274      0xE81: "adErrStillConnecting",
 275      0xE7F: "adErrStillExecuting",
 276      0xE90: "adErrTreePermissionDenied",
 277      0xE8F: "adErrURLDoesNotExist",
 278      0xE99: "adErrURLNamedRowDoesNotExist",
 279      0xE98: "adErrUnavailable",
 280      0xE84: "adErrUnsafeOperation",
 281      0xE95: "adErrVolumeNotFound",
 282      0xBBC: "adErrWriteFile",
 283  }
 284