|
1 | 1 | cdef enum ConnectionStatus: |
2 | | - CONNECTION_OK = 0 |
3 | | - CONNECTION_BAD = 1 |
4 | | - CONNECTION_STARTED = 2 # Waiting for connection to be made. |
5 | | - CONNECTION_MADE = 3 # Connection OK; waiting to send. |
6 | | - CONNECTION_AWAITING_RESPONSE = 4 # Waiting for a response from the |
7 | | - # postmaster. |
8 | | - CONNECTION_AUTH_OK = 5 # Received authentication; waiting for |
9 | | - # backend startup. |
10 | | - CONNECTION_SETENV = 6 # Negotiating environment. |
11 | | - CONNECTION_SSL_STARTUP = 7 # Negotiating SSL. |
12 | | - CONNECTION_NEEDED = 8 # Internal state: connect() needed |
13 | | - |
14 | | -cdef enum AsyncStatus: |
15 | | - # defines the state of the query-execution state machine |
16 | | - PGASYNC_IDLE = 0 # nothing's happening, dude |
17 | | - PGASYNC_BUSY = 1 # query in progress |
18 | | - PGASYNC_READY = 2 # result ready for PQgetResult |
19 | | - PGASYNC_COPY_IN = 3 # Copy In data transfer in progress |
20 | | - PGASYNC_COPY_OUT = 4 # Copy Out data transfer in progress |
21 | | - PGASYNC_COPY_BOTH = 5 # Copy In/Out data transfer in progress |
22 | | - |
23 | | -cdef enum QueryClass: |
24 | | - # tracks which query protocol we are now executing |
25 | | - PGQUERY_SIMPLE = 0 # simple Query protocol (PQexec) |
26 | | - PGQUERY_EXTENDED = 1 # full Extended protocol (PQexecParams) |
27 | | - PGQUERY_PREPARE = 2 # Parse only (PQprepare) |
28 | | - PGQUERY_DESCRIBE = 3 # Describe Statement or Portal |
29 | | - PGQUERY_CLOSE = 4 |
30 | | - |
31 | | -cdef enum ExecStatusType: |
32 | | - PGRES_EMPTY_QUERY = 0 # empty query string was executed |
33 | | - PGRES_COMMAND_OK = 1 # a query command that doesn't return |
34 | | - # anything was executed properly by the |
35 | | - # backend |
36 | | - PGRES_TUPLES_OK = 2 # a query command that returns tuples was |
37 | | - # executed properly by the backend, |
38 | | - # PGresult contains the result tuples |
39 | | - PGRES_COPY_OUT = 3 # Copy Out data transfer in progress |
40 | | - PGRES_COPY_IN = 4 # Copy In data transfer in progress |
41 | | - PGRES_BAD_RESPONSE = 5 # an unexpected response was recv'd from |
42 | | - # the backend |
43 | | - PGRES_NONFATAL_ERROR = 6 # notice or warning message |
44 | | - PGRES_FATAL_ERROR = 7 # query failed |
45 | | - PGRES_COPY_BOTH = 8 # Copy In/Out data transfer in progress |
46 | | - PGRES_SINGLE_TUPLE = 9 # single tuple from larger resultset |
| 2 | + CONNECTION_OK = 1 |
| 3 | + CONNECTION_BAD = 2 |
| 4 | + CONNECTION_STARTED = 3 # Waiting for connection to be made. |
47 | 5 |
|
48 | | -cdef enum TransactionStatus: |
49 | | - PQTRANS_IDLE = 0 # connection idle |
50 | | - PQTRANS_ACTIVE = 1 # command in progress |
51 | | - PQTRANS_INTRANS = 2 # idle, within transaction block |
52 | | - PQTRANS_INERROR = 3 # idle, within failed transaction |
53 | | - PQTRANS_UNKNOWN = 4 # cannot determine status |
54 | 6 |
|
55 | | -cdef enum MessageDispatchLoop: |
56 | | - DISPATCH_CONTINUE = 0 |
57 | | - DISPATCH_STOP = 1 |
58 | | - DISPATCH_CONTINUE_NO_DISCARD = 2 |
| 7 | +cdef enum ProtocolState: |
| 8 | + PROTOCOL_IDLE = 0 |
59 | 9 |
|
| 10 | + PROTOCOL_FAILED = 1 |
60 | 11 |
|
61 | | -cdef class Result: |
62 | | - cdef: |
63 | | - ExecStatusType status |
| 12 | + PROTOCOL_ERROR_CONSUME = 2 |
| 13 | + |
| 14 | + PROTOCOL_AUTH = 10 |
| 15 | + PROTOCOL_PREPARE = 11 |
| 16 | + PROTOCOL_BIND_EXECUTE = 12 |
| 17 | + PROTOCOL_CLOSE_STMT_PORTAL = 13 |
| 18 | + PROTOCOL_SIMPLE_QUERY = 14 |
64 | 19 |
|
65 | | - # message broken into fields |
66 | | - dict err_fields |
67 | | - # text of triggering query, if available |
68 | | - str err_query |
69 | 20 |
|
70 | | - # cmd status from the query |
71 | | - bytes cmd_status |
| 21 | +cdef enum ResultType: |
| 22 | + RESULT_OK = 1 |
| 23 | + RESULT_FAILED = 2 |
72 | 24 |
|
73 | | - object parameters_desc |
74 | | - object row_desc |
75 | | - list rows |
76 | 25 |
|
77 | | - @staticmethod |
78 | | - cdef Result new(ExecStatusType status) |
| 26 | +cdef enum TransactionStatus: |
| 27 | + PQTRANS_IDLE = 0 # connection idle |
| 28 | + PQTRANS_ACTIVE = 1 # command in progress |
| 29 | + PQTRANS_INTRANS = 2 # idle, within transaction block |
| 30 | + PQTRANS_INERROR = 3 # idle, within failed transaction |
| 31 | + PQTRANS_UNKNOWN = 4 # cannot determine status |
79 | 32 |
|
80 | 33 |
|
81 | 34 | ctypedef object (*decode_row_method)(object, const char*, int32_t) |
82 | 35 |
|
83 | 36 |
|
84 | 37 | cdef class CoreProtocol: |
85 | 38 | cdef: |
86 | | - object transport |
87 | 39 | ReadBuffer buffer |
| 40 | + bint _skip_discard |
88 | 41 |
|
89 | | - ####### Options: |
| 42 | + ConnectionStatus con_status |
| 43 | + ProtocolState state |
| 44 | + TransactionStatus xact_status |
90 | 45 |
|
91 | | - str _user |
92 | | - str _password |
93 | | - str _dbname |
94 | | - str _encoding |
| 46 | + str encoding |
95 | 47 |
|
96 | | - ####### Connection State: |
97 | | - int _backend_pid |
98 | | - int _backend_secret |
99 | | - |
100 | | - # result being constructed |
101 | | - Result _result |
| 48 | + object transport |
102 | 49 |
|
103 | | - ConnectionStatus _status |
104 | | - AsyncStatus _async_status |
105 | | - QueryClass _query_class |
106 | | - TransactionStatus _xact_status |
| 50 | + # Dict with all connection arguments |
| 51 | + dict con_args |
| 52 | + |
| 53 | + int32_t backend_pid |
| 54 | + int32_t backend_secret |
| 55 | + |
| 56 | + ## Result |
| 57 | + ResultType result_type |
| 58 | + object result |
| 59 | + bytes result_param_desc |
| 60 | + bytes result_row_desc |
| 61 | + bytes result_status_msg |
| 62 | + |
| 63 | + cdef _process__auth(self, char mtype) |
| 64 | + cdef _process__prepare(self, char mtype) |
| 65 | + cdef _process__bind_exec(self, char mtype) |
| 66 | + cdef _process__close_stmt_portal(self, char mtype) |
| 67 | + cdef _process__simple_query(self, char mtype) |
| 68 | + |
| 69 | + cdef _parse_msg_authentication(self) |
| 70 | + cdef _parse_msg_parameter_status(self) |
| 71 | + cdef _parse_msg_backend_key_data(self) |
| 72 | + cdef _parse_msg_ready_for_query(self) |
| 73 | + cdef _parse_data_msgs(self) |
| 74 | + cdef _parse_msg_error_response(self, is_error) |
| 75 | + cdef _parse_msg_command_complete(self) |
| 76 | + |
| 77 | + cdef _write(self, buf) |
| 78 | + cdef inline _write_sync_message(self) |
107 | 79 |
|
108 | | - WriteBuffer _after_sync |
| 80 | + cdef _read_server_messages(self) |
109 | 81 |
|
110 | | - cdef inline _write(self, WriteBuffer buf) |
111 | | - cdef inline _write_sync_message(self) |
112 | | - cdef inline _read_server_messages(self) |
113 | | - cdef inline MessageDispatchLoop _dispatch_server_message(self, char mtype) |
114 | | - cdef _parse_server_authentication(self) |
115 | | - cdef _parse_server_parameter_status(self) |
116 | | - cdef _parse_server_backend_key_data(self) |
117 | | - cdef _parse_server_parameter_description(self) |
118 | | - cdef _parse_server_ready_for_query(self) |
119 | | - cdef _parse_server_row_description(self) |
120 | | - cdef _parse_server_data_rows(self) |
121 | | - cdef _parse_server_error_response(self, is_error) |
122 | | - cdef _fatal_error(self, exc) |
123 | 82 | cdef _push_result(self) |
124 | | - cdef _sync(self) |
125 | | - cdef _ensure_ready_state(self) |
| 83 | + cdef _reset_result(self) |
| 84 | + cdef _set_state(self, ProtocolState new_state) |
| 85 | + |
| 86 | + cdef _ensure_connected(self) |
126 | 87 |
|
127 | 88 | cdef _connect(self) |
128 | | - cdef _query(self, str query) |
129 | 89 | cdef _prepare(self, str stmt_name, str query) |
130 | | - cdef _bind(self, str portal_name, str stmt_name, |
131 | | - WriteBuffer bind_data, int32_t limit) |
| 90 | + cdef _bind_and_execute(self, str portal_name, str stmt_name, |
| 91 | + WriteBuffer bind_data, int32_t limit) |
132 | 92 | cdef _close(self, str name, bint is_portal) |
| 93 | + cdef _simple_query(self, str query) |
133 | 94 |
|
134 | 95 | cdef _decode_row(self, const char* buf, int32_t buf_len) |
135 | 96 |
|
136 | | - cdef _on_result(self, Result result) |
137 | | - cdef _on_fatal_error(self, exc) |
| 97 | + cdef _on_result(self) |
| 98 | + cdef _set_server_parameter(self, name, val) |
138 | 99 | cdef _on_connection_lost(self, exc) |
139 | | - cdef _set_server_parameter(self, key, val) |
0 commit comments