codekingpro/portable-devtools
114k
1"""2libpq enum definitions for psycopg3"""4 5# Copyright (C) 2020 The Psycopg Team6 7from enum import IntEnum, IntFlag, auto8 9 10class ConnStatus(IntEnum):11 """12 Current status of the connection.13 """14 15 __module__ = "psycopg.pq"16 17 OK = 018 """The connection is in a working state."""19 BAD = auto()20 """The connection is closed."""21 22 STARTED = auto()23 MADE = auto()24 AWAITING_RESPONSE = auto()25 AUTH_OK = auto()26 SETENV = auto()27 SSL_STARTUP = auto()28 NEEDED = auto()29 CHECK_WRITABLE = auto()30 CONSUME = auto()31 GSS_STARTUP = auto()32 CHECK_TARGET = auto()33 CHECK_STANDBY = auto()34 35 36class PollingStatus(IntEnum):37 """38 The status of the socket during a connection.39 40 If ``READING`` or ``WRITING`` you may select before polling again.41 """42 43 __module__ = "psycopg.pq"44 45 FAILED = 046 """Connection attempt failed."""47 READING = auto()48 """Will have to wait before reading new data."""49 WRITING = auto()50 """Will have to wait before writing new data."""51 OK = auto()52 """Connection completed."""53 54 ACTIVE = auto()55 56 57class ExecStatus(IntEnum):58 """59 The status of a command.60 """61 62 __module__ = "psycopg.pq"63 64 EMPTY_QUERY = 065 """The string sent to the server was empty."""66 67 COMMAND_OK = auto()68 """Successful completion of a command returning no data."""69 70 TUPLES_OK = auto()71 """72 Successful completion of a command returning data (such as a SELECT or SHOW).73 """74 75 COPY_OUT = auto()76 """Copy Out (from server) data transfer started."""77 78 COPY_IN = auto()79 """Copy In (to server) data transfer started."""80 81 BAD_RESPONSE = auto()82 """The server's response was not understood."""83 84 NONFATAL_ERROR = auto()85 """A nonfatal error (a notice or warning) occurred."""86 87 FATAL_ERROR = auto()88 """A fatal error occurred."""89 90 COPY_BOTH = auto()91 """92 Copy In/Out (to and from server) data transfer started.93 94 This feature is currently used only for streaming replication, so this95 status should not occur in ordinary applications.96 """97 98 SINGLE_TUPLE = auto()99 """100 The PGresult contains a single result tuple from the current command.101 102 This status occurs only when single-row mode has been selected for the103 query.104 """105 106 PIPELINE_SYNC = auto()107 """108 The PGresult represents a synchronization point in pipeline mode,109 requested by PQpipelineSync.110 111 This status occurs only when pipeline mode has been selected.112 """113 114 PIPELINE_ABORTED = auto()115 """116 The PGresult represents a pipeline that has received an error from the server.117 118 PQgetResult must be called repeatedly, and each time it will return this119 status code until the end of the current pipeline, at which point it will120 return PGRES_PIPELINE_SYNC and normal processing can resume.121 """122 123 124class TransactionStatus(IntEnum):125 """126 The transaction status of a connection.127 """128 129 __module__ = "psycopg.pq"130 131 IDLE = 0132 """Connection ready, no transaction active."""133 134 ACTIVE = auto()135 """A command is in progress."""136 137 INTRANS = auto()138 """Connection idle in an open transaction."""139 140 INERROR = auto()141 """An error happened in the current transaction."""142 143 UNKNOWN = auto()144 """Unknown connection state, broken connection."""145 146 147class Ping(IntEnum):148 """Response from a ping attempt."""149 150 __module__ = "psycopg.pq"151 152 OK = 0153 """154 The server is running and appears to be accepting connections.155 """156 157 REJECT = auto()158 """159 The server is running but is in a state that disallows connections.160 """161 162 NO_RESPONSE = auto()163 """164 The server could not be contacted.165 """166 167 NO_ATTEMPT = auto()168 """169 No attempt was made to contact the server.170 """171 172 173class PipelineStatus(IntEnum):174 """Pipeline mode status of the libpq connection."""175 176 __module__ = "psycopg.pq"177 178 OFF = 0179 """180 The libpq connection is *not* in pipeline mode.181 """182 ON = auto()183 """184 The libpq connection is in pipeline mode.185 """186 ABORTED = auto()187 """188 The libpq connection is in pipeline mode and an error occurred while189 processing the current pipeline. The aborted flag is cleared when190 PQgetResult returns a result of type PGRES_PIPELINE_SYNC.191 """192 193 194class DiagnosticField(IntEnum):195 """196 Fields in an error report.197 """198 199 __module__ = "psycopg.pq"200 201 # from postgres_ext.h202 SEVERITY = ord("S")203 SEVERITY_NONLOCALIZED = ord("V")204 SQLSTATE = ord("C")205 MESSAGE_PRIMARY = ord("M")206 MESSAGE_DETAIL = ord("D")207 MESSAGE_HINT = ord("H")208 STATEMENT_POSITION = ord("P")209 INTERNAL_POSITION = ord("p")210 INTERNAL_QUERY = ord("q")211 CONTEXT = ord("W")212 SCHEMA_NAME = ord("s")213 TABLE_NAME = ord("t")214 COLUMN_NAME = ord("c")215 DATATYPE_NAME = ord("d")216 CONSTRAINT_NAME = ord("n")217 SOURCE_FILE = ord("F")218 SOURCE_LINE = ord("L")219 SOURCE_FUNCTION = ord("R")220 221 222class Format(IntEnum):223 """224 Enum representing the format of a query argument or return value.225 226 These values are only the ones managed by the libpq. `~psycopg` may also227 support automatically-chosen values: see `psycopg.adapt.PyFormat`.228 """229 230 __module__ = "psycopg.pq"231 232 TEXT = 0233 """Text parameter."""234 BINARY = 1235 """Binary parameter."""236 237 238class Trace(IntFlag):239 """240 Enum to control tracing of the client/server communication.241 """242 243 __module__ = "psycopg.pq"244 245 SUPPRESS_TIMESTAMPS = 1246 """Do not include timestamps in messages."""247 248 REGRESS_MODE = 2249 """Redact some fields, e.g. OIDs, from messages."""250 