From 5380cb3f932069d5c083b1f12a78513fc7237e91 Mon Sep 17 00:00:00 2001 From: zhanghaitao3 <1085912315@qq.com> Date: Tue, 2 Dec 2025 02:07:34 +0800 Subject: [PATCH 1/5] Code refactoring, all content except Cpython --- .github/workflows/install-krb5.sh | 42 --------------- .github/workflows/install-postgres.sh | 62 ----------------------- async_gaussdb/protocol/codecs/array.pyx | 12 ++--- async_gaussdb/protocol/codecs/pgproto.pyx | 2 +- async_gaussdb/protocol/coreproto.pyx | 4 +- async_gaussdb/protocol/pgtypes.pxi | 4 +- async_gaussdb/protocol/protocol.pxd | 2 +- async_gaussdb/protocol/protocol.pyx | 6 +-- 8 files changed, 15 insertions(+), 119 deletions(-) delete mode 100755 .github/workflows/install-krb5.sh delete mode 100755 .github/workflows/install-postgres.sh diff --git a/.github/workflows/install-krb5.sh b/.github/workflows/install-krb5.sh deleted file mode 100755 index bdb5744d..00000000 --- a/.github/workflows/install-krb5.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -set -Eexuo pipefail -shopt -s nullglob - -if [[ $OSTYPE == linux* ]]; then - if [ "$(id -u)" = "0" ]; then - SUDO= - else - SUDO=sudo - fi - - if [ -e /etc/os-release ]; then - source /etc/os-release - elif [ -e /etc/centos-release ]; then - ID="centos" - VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.) - else - echo "install-krb5.sh: cannot determine which Linux distro this is" >&2 - exit 1 - fi - - if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then - export DEBIAN_FRONTEND=noninteractive - - $SUDO apt-get update - $SUDO apt-get install -y --no-install-recommends \ - libkrb5-dev krb5-user krb5-kdc krb5-admin-server - elif [ "${ID}" = "almalinux" ]; then - $SUDO dnf install -y krb5-server krb5-workstation krb5-libs krb5-devel - elif [ "${ID}" = "centos" ]; then - $SUDO yum install -y krb5-server krb5-workstation krb5-libs krb5-devel - elif [ "${ID}" = "alpine" ]; then - $SUDO apk add krb5 krb5-server krb5-dev - else - echo "install-krb5.sh: Unsupported linux distro: ${distro}" >&2 - exit 1 - fi -else - echo "install-krb5.sh: unsupported OS: ${OSTYPE}" >&2 - exit 1 -fi diff --git a/.github/workflows/install-postgres.sh b/.github/workflows/install-postgres.sh deleted file mode 100755 index 9b7cb0c9..00000000 --- a/.github/workflows/install-postgres.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -set -Eexuo pipefail -shopt -s nullglob - -if [[ $OSTYPE == linux* ]]; then - GAUSSDBVERSION=${PGVERSION:-12} - - if [ -e /etc/os-release ]; then - source /etc/os-release - elif [ -e /etc/centos-release ]; then - ID="centos" - VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.) - else - echo "install-postgres.sh: cannot determine which Linux distro this is" >&2 - exit 1 - fi - - if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then - export DEBIAN_FRONTEND=noninteractive - - apt-get install -y --no-install-recommends curl gnupg ca-certificates - curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - - mkdir -p /etc/apt/sources.list.d/ - echo "deb https://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" \ - >> /etc/apt/sources.list.d/pgdg.list - apt-get update - apt-get install -y --no-install-recommends \ - "postgresql-${PGVERSION}" \ - "postgresql-contrib-${PGVERSION}" - elif [ "${ID}" = "almalinux" ]; then - yum install -y \ - "postgresql-server" \ - "postgresql-devel" \ - "postgresql-contrib" - elif [ "${ID}" = "centos" ]; then - el="EL-${VERSION_ID%.*}-$(arch)" - baseurl="https://download.postgresql.org/pub/repos/yum/reporpms" - yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm" - if [ ${VERSION_ID%.*} -ge 8 ]; then - dnf -qy module disable postgresql - fi - yum install -y \ - "postgresql${PGVERSION}-server" \ - "postgresql${PGVERSION}-contrib" - ln -s "/usr/pgsql-${PGVERSION}/bin/pg_config" "/usr/local/bin/pg_config" - elif [ "${ID}" = "alpine" ]; then - apk add shadow postgresql postgresql-dev postgresql-contrib - else - echo "install-postgres.sh: unsupported Linux distro: ${distro}" >&2 - exit 1 - fi - - useradd -m -s /bin/bash apgtest - -elif [[ $OSTYPE == darwin* ]]; then - brew install postgresql - -else - echo "install-postgres.sh: unsupported OS: ${OSTYPE}" >&2 - exit 1 -fi diff --git a/async_gaussdb/protocol/codecs/array.pyx b/async_gaussdb/protocol/codecs/array.pyx index 85dfcdf9..8d7219c1 100644 --- a/async_gaussdb/protocol/codecs/array.pyx +++ b/async_gaussdb/protocol/codecs/array.pyx @@ -419,7 +419,7 @@ cdef textarray_decode(ConnectionSettings settings, FRBuffer *buf, # Make a copy of array data since we will be mutating it for # the purposes of element decoding. - s = gaussdbproto.text_decode(settings, buf) + s = pgproto.text_decode(settings, buf) array_text = cpythonx.PyUnicode_AsUCS4Copy(s) try: @@ -648,7 +648,7 @@ cdef _textarray_decode(ConnectionSettings settings, # Prepare the element buffer and call the text decoder # for the element type. - gaussdbproto.as_pg_string_and_size( + pgproto.as_pg_string_and_size( settings, item_text, &pg_item_str, &pg_item_len) frb_init(&item_buf, pg_item_str, pg_item_len) item = decoder(settings, &item_buf, decoder_arg) @@ -822,12 +822,12 @@ cdef _infer_array_dims(const Py_UCS4 *array_text, cdef uint4_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj, const void *arg): - return gaussdbproto.uint4_encode(settings, buf, obj) + return pgproto.uint4_encode(settings, buf, obj) cdef uint4_decode_ex(ConnectionSettings settings, FRBuffer *buf, const void *arg): - return gaussdbproto.uint4_decode(settings, buf) + return pgproto.uint4_decode(settings, buf) cdef arrayoid_encode(ConnectionSettings settings, WriteBuffer buf, items): @@ -841,12 +841,12 @@ cdef arrayoid_decode(ConnectionSettings settings, FRBuffer *buf): cdef text_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj, const void *arg): - return gaussdbproto.text_encode(settings, buf, obj) + return pgproto.text_encode(settings, buf, obj) cdef text_decode_ex(ConnectionSettings settings, FRBuffer *buf, const void *arg): - return gaussdbproto.text_decode(settings, buf) + return pgproto.text_decode(settings, buf) cdef arraytext_encode(ConnectionSettings settings, WriteBuffer buf, items): diff --git a/async_gaussdb/protocol/codecs/pgproto.pyx b/async_gaussdb/protocol/codecs/pgproto.pyx index 0dedc989..c55de8aa 100644 --- a/async_gaussdb/protocol/codecs/pgproto.pyx +++ b/async_gaussdb/protocol/codecs/pgproto.pyx @@ -385,7 +385,7 @@ cdef init_txid_codecs(): pgproto.text_decode, PG_FORMAT_TEXT) - register_core_codec(PG_SNAPSHOTOID, + register_core_codec(pg_snapshotOID, pgproto.pg_snapshot_encode, pgproto.pg_snapshot_decode, PG_FORMAT_BINARY) diff --git a/async_gaussdb/protocol/coreproto.pyx b/async_gaussdb/protocol/coreproto.pyx index 9d64c9f2..f806dd38 100644 --- a/async_gaussdb/protocol/coreproto.pyx +++ b/async_gaussdb/protocol/coreproto.pyx @@ -513,7 +513,7 @@ cdef class CoreProtocol: object row bytes mem - if PG_DEBUG: + if GAUSSDB_DEBUG: if buf.get_message_type() != b'D': raise apg_exc.InternalClientError( '_parse_data_msgs: first message is not "D"') @@ -523,7 +523,7 @@ cdef class CoreProtocol: buf.discard_message() return - if PG_DEBUG: + if GAUSSDB_DEBUG: if type(self.result) is not list: raise apg_exc.InternalClientError( '_parse_data_msgs: result is not a list, but {!r}'. diff --git a/async_gaussdb/protocol/pgtypes.pxi b/async_gaussdb/protocol/pgtypes.pxi index e9bb782f..5f8d9ec4 100644 --- a/async_gaussdb/protocol/pgtypes.pxi +++ b/async_gaussdb/protocol/pgtypes.pxi @@ -106,7 +106,7 @@ DEF ANYCOMPATIBLEMULTIRANGEOID = 4538 DEF PG_BRIN_BLOOM_SUMMARYOID = 4600 DEF PG_BRIN_MINMAX_MULTI_SUMMARYOID = 4601 DEF PG_MCV_LISTOID = 5017 -DEF PG_SNAPSHOTOID = 5038 +DEF pg_snapshotOID = 5038 DEF XID8OID = 5069 DEF ANYCOMPATIBLEOID = 5077 DEF ANYCOMPATIBLEARRAYOID = 5078 @@ -175,7 +175,7 @@ BUILTIN_TYPE_OID_MAP = { PG_MCV_LISTOID: 'pg_mcv_list', PG_NDISTINCTOID: 'pg_ndistinct', PG_NODE_TREEOID: 'pg_node_tree', - PG_SNAPSHOTOID: 'pg_snapshot', + pg_snapshotOID: 'pg_snapshot', POINTOID: 'point', POLYGONOID: 'polygon', RECORDOID: 'record', diff --git a/async_gaussdb/protocol/protocol.pxd b/async_gaussdb/protocol/protocol.pxd index 76865e0e..24ebce86 100644 --- a/async_gaussdb/protocol/protocol.pxd +++ b/async_gaussdb/protocol/protocol.pxd @@ -8,7 +8,7 @@ from libc.stdint cimport int16_t, int32_t, uint16_t, \ uint32_t, int64_t, uint64_t -from async_gaussdb.pgproto.debug cimport PG_DEBUG +from async_gaussdb.pgproto.debug cimport GAUSSDB_DEBUG from async_gaussdb.pgproto.pgproto cimport ( WriteBuffer, diff --git a/async_gaussdb/protocol/protocol.pyx b/async_gaussdb/protocol/protocol.pyx index ccb5b0e1..7fb687c1 100644 --- a/async_gaussdb/protocol/protocol.pyx +++ b/async_gaussdb/protocol/protocol.pyx @@ -804,7 +804,7 @@ cdef class BaseProtocol(CoreProtocol): waiter.set_result(True) cdef _on_result__prepare(self, object waiter): - if PG_DEBUG: + if GAUSSDB_DEBUG: if self.statement is None: raise apg_exc.InternalClientError( '_on_result__prepare: statement is None') @@ -851,7 +851,7 @@ cdef class BaseProtocol(CoreProtocol): waiter.set_result(status_msg) cdef _decode_row(self, const char* buf, ssize_t buf_len): - if PG_DEBUG: + if GAUSSDB_DEBUG: if self.statement is None: raise apg_exc.InternalClientError( '_decode_row: statement is None') @@ -863,7 +863,7 @@ cdef class BaseProtocol(CoreProtocol): self.waiter = None if waiter is None: - if PG_DEBUG: + if GAUSSDB_DEBUG: raise apg_exc.InternalClientError('_on_result: waiter is None') if self.state == PROTOCOL_COPY_OUT_DATA or \ From 75e230dafc06388b629a5e6612ad8e88793cd7a0 Mon Sep 17 00:00:00 2001 From: zhanghaitao3 <1085912315@qq.com> Date: Tue, 2 Dec 2025 02:11:00 +0800 Subject: [PATCH 2/5] Code refactoring, all content except Cpython --- .github/workflows/install-krb5.sh | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/install-krb5.sh diff --git a/.github/workflows/install-krb5.sh b/.github/workflows/install-krb5.sh new file mode 100644 index 00000000..bdb5744d --- /dev/null +++ b/.github/workflows/install-krb5.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -Eexuo pipefail +shopt -s nullglob + +if [[ $OSTYPE == linux* ]]; then + if [ "$(id -u)" = "0" ]; then + SUDO= + else + SUDO=sudo + fi + + if [ -e /etc/os-release ]; then + source /etc/os-release + elif [ -e /etc/centos-release ]; then + ID="centos" + VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.) + else + echo "install-krb5.sh: cannot determine which Linux distro this is" >&2 + exit 1 + fi + + if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then + export DEBIAN_FRONTEND=noninteractive + + $SUDO apt-get update + $SUDO apt-get install -y --no-install-recommends \ + libkrb5-dev krb5-user krb5-kdc krb5-admin-server + elif [ "${ID}" = "almalinux" ]; then + $SUDO dnf install -y krb5-server krb5-workstation krb5-libs krb5-devel + elif [ "${ID}" = "centos" ]; then + $SUDO yum install -y krb5-server krb5-workstation krb5-libs krb5-devel + elif [ "${ID}" = "alpine" ]; then + $SUDO apk add krb5 krb5-server krb5-dev + else + echo "install-krb5.sh: Unsupported linux distro: ${distro}" >&2 + exit 1 + fi +else + echo "install-krb5.sh: unsupported OS: ${OSTYPE}" >&2 + exit 1 +fi From bb012691481108941361a47f53198838b2a1f201 Mon Sep 17 00:00:00 2001 From: zhanghaitao3 <1085912315@qq.com> Date: Tue, 2 Dec 2025 09:46:38 +0800 Subject: [PATCH 3/5] refactor: remove gaussdbproto submodule and include as regular directory --- .gitmodules | 6 +- Makefile | 6 +- async_gaussdb/pgproto | 1 - async_gaussdb/protocol/codecs/array.pyx | 24 +- async_gaussdb/protocol/codecs/base.pxd | 10 +- async_gaussdb/protocol/codecs/base.pyx | 124 ++--- .../protocol/codecs/gaussdbproto.pyx | 490 ++++++++++++++++++ async_gaussdb/protocol/codecs/pgproto.pyx | 490 ------------------ async_gaussdb/protocol/codecs/record.pyx | 2 +- async_gaussdb/protocol/coreproto.pyx | 20 +- async_gaussdb/protocol/encodings.pyx | 4 +- .../{pgtypes.pxi => gaussdbtypes.pxi} | 36 +- async_gaussdb/protocol/protocol.pxd | 8 +- async_gaussdb/protocol/protocol.pyi | 6 +- async_gaussdb/protocol/protocol.pyx | 20 +- async_gaussdb/protocol/settings.pxd | 2 +- async_gaussdb/protocol/settings.pyx | 22 +- async_gaussdb/types.py | 2 +- setup.py | 6 +- tests/test_codecs.py | 2 +- tools/generate_type_map.py | 2 +- 21 files changed, 641 insertions(+), 642 deletions(-) delete mode 160000 async_gaussdb/pgproto create mode 100644 async_gaussdb/protocol/codecs/gaussdbproto.pyx delete mode 100644 async_gaussdb/protocol/codecs/pgproto.pyx rename async_gaussdb/protocol/{pgtypes.pxi => gaussdbtypes.pxi} (89%) diff --git a/.gitmodules b/.gitmodules index 3c92fa51..8e1de421 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "async_gaussdb/pgproto"] - path = async_gaussdb/pgproto - url = https://github.com/MagicStack/py-pgproto.git +[submodule "async_gaussdb/gaussdbproto"] + path = async_gaussdb/gaussdbproto + url = https://github.com/MagicStack/py-gaussdbproto.git diff --git a/Makefile b/Makefile index 3b66ac9a..1a61dc18 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,9 @@ all: compile clean: rm -fr dist/ doc/_build/ - rm -fr async_gaussdb/pgproto/*.c async_gaussdb/pgproto/*.html - rm -fr async_gaussdb/pgproto/codecs/*.html - rm -fr async_gaussdb/pgproto/*.so + rm -fr async_gaussdb/gaussdbproto/*.c async_gaussdb/gaussdbproto/*.html + rm -fr async_gaussdb/gaussdbproto/codecs/*.html + rm -fr async_gaussdb/gaussdbproto/*.so rm -fr async_gaussdb/protocol/*.c async_gaussdb/protocol/*.html rm -fr async_gaussdb/protocol/*.so build *.egg-info rm -fr async_gaussdb/protocol/codecs/*.html diff --git a/async_gaussdb/pgproto b/async_gaussdb/pgproto deleted file mode 160000 index 1c3cad14..00000000 --- a/async_gaussdb/pgproto +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1c3cad14d53c8f3088106f4eab8f612b7293569b diff --git a/async_gaussdb/protocol/codecs/array.pyx b/async_gaussdb/protocol/codecs/array.pyx index 8d7219c1..dfc4ca11 100644 --- a/async_gaussdb/protocol/codecs/array.pyx +++ b/async_gaussdb/protocol/codecs/array.pyx @@ -419,7 +419,7 @@ cdef textarray_decode(ConnectionSettings settings, FRBuffer *buf, # Make a copy of array data since we will be mutating it for # the purposes of element decoding. - s = pgproto.text_decode(settings, buf) + s = gaussdbproto.text_decode(settings, buf) array_text = cpythonx.PyUnicode_AsUCS4Copy(s) try: @@ -467,8 +467,8 @@ cdef _textarray_decode(ConnectionSettings settings, object item str item_text FRBuffer item_buf - char *pg_item_str - ssize_t pg_item_len + char *gaussdb_item_str + ssize_t gaussdb_item_len ptr = array_text @@ -648,9 +648,9 @@ cdef _textarray_decode(ConnectionSettings settings, # Prepare the element buffer and call the text decoder # for the element type. - pgproto.as_pg_string_and_size( - settings, item_text, &pg_item_str, &pg_item_len) - frb_init(&item_buf, pg_item_str, pg_item_len) + gaussdbproto.as_gaussdb_string_and_size( + settings, item_text, &gaussdb_item_str, &gaussdb_item_len) + frb_init(&item_buf, gaussdb_item_str, gaussdb_item_len) item = decoder(settings, &item_buf, decoder_arg) # Place the decoded element in the array. @@ -822,12 +822,12 @@ cdef _infer_array_dims(const Py_UCS4 *array_text, cdef uint4_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj, const void *arg): - return pgproto.uint4_encode(settings, buf, obj) + return gaussdbproto.uint4_encode(settings, buf, obj) cdef uint4_decode_ex(ConnectionSettings settings, FRBuffer *buf, const void *arg): - return pgproto.uint4_decode(settings, buf) + return gaussdbproto.uint4_decode(settings, buf) cdef arrayoid_encode(ConnectionSettings settings, WriteBuffer buf, items): @@ -841,12 +841,12 @@ cdef arrayoid_decode(ConnectionSettings settings, FRBuffer *buf): cdef text_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj, const void *arg): - return pgproto.text_encode(settings, buf, obj) + return gaussdbproto.text_encode(settings, buf, obj) cdef text_decode_ex(ConnectionSettings settings, FRBuffer *buf, const void *arg): - return pgproto.text_decode(settings, buf) + return gaussdbproto.text_decode(settings, buf) cdef arraytext_encode(ConnectionSettings settings, WriteBuffer buf, items): @@ -865,11 +865,11 @@ cdef init_array_codecs(): register_core_codec(_OIDOID, &arrayoid_encode, &arrayoid_decode, - PG_FORMAT_BINARY) + GAUSSDB_FORMAT_BINARY) register_core_codec(_TEXTOID, &arraytext_encode, &arraytext_decode, - PG_FORMAT_BINARY) + GAUSSDB_FORMAT_BINARY) init_array_codecs() diff --git a/async_gaussdb/protocol/codecs/base.pxd b/async_gaussdb/protocol/codecs/base.pxd index 1cfed833..bb9b0206 100644 --- a/async_gaussdb/protocol/codecs/base.pxd +++ b/async_gaussdb/protocol/codecs/base.pxd @@ -33,14 +33,14 @@ cdef enum CodecType: cdef enum ServerDataFormat: - PG_FORMAT_ANY = -1 - PG_FORMAT_TEXT = 0 - PG_FORMAT_BINARY = 1 + GAUSSDB_FORMAT_ANY = -1 + GAUSSDB_FORMAT_TEXT = 0 + GAUSSDB_FORMAT_BINARY = 1 cdef enum ClientExchangeFormat: - PG_XFORMAT_OBJECT = 1 - PG_XFORMAT_TUPLE = 2 + GAUSSDB_XFORMAT_OBJECT = 1 + GAUSSDB_XFORMAT_TUPLE = 2 cdef class Codec: diff --git a/async_gaussdb/protocol/codecs/base.pyx b/async_gaussdb/protocol/codecs/base.pyx index 44622959..98c12b6f 100644 --- a/async_gaussdb/protocol/codecs/base.pyx +++ b/async_gaussdb/protocol/codecs/base.pyx @@ -76,28 +76,28 @@ cdef class Codec: self.encoder = &self.encode_scalar self.decoder = &self.decode_scalar elif type == CODEC_ARRAY: - if format == PG_FORMAT_BINARY: + if format == GAUSSDB_FORMAT_BINARY: self.encoder = &self.encode_array self.decoder = &self.decode_array else: self.encoder = &self.encode_array_text self.decoder = &self.decode_array_text elif type == CODEC_RANGE: - if format != PG_FORMAT_BINARY: + if format != GAUSSDB_FORMAT_BINARY: raise exceptions.UnsupportedClientFeatureError( 'cannot decode type "{}"."{}": text encoding of ' 'range types is not supported'.format(schema, name)) self.encoder = &self.encode_range self.decoder = &self.decode_range elif type == CODEC_MULTIRANGE: - if format != PG_FORMAT_BINARY: + if format != GAUSSDB_FORMAT_BINARY: raise exceptions.UnsupportedClientFeatureError( 'cannot decode type "{}"."{}": text encoding of ' 'range types is not supported'.format(schema, name)) self.encoder = &self.encode_multirange self.decoder = &self.decode_multirange elif type == CODEC_COMPOSITE: - if format != PG_FORMAT_BINARY: + if format != GAUSSDB_FORMAT_BINARY: raise exceptions.UnsupportedClientFeatureError( 'cannot decode type "{}"."{}": text encoding of ' 'composite types is not supported'.format(schema, name)) @@ -205,15 +205,15 @@ cdef class Codec: cdef encode_in_python(self, ConnectionSettings settings, WriteBuffer buf, object obj): data = self.py_encoder(obj) - if self.xformat == PG_XFORMAT_OBJECT: - if self.format == PG_FORMAT_BINARY: - pgproto.bytea_encode(settings, buf, data) - elif self.format == PG_FORMAT_TEXT: - pgproto.text_encode(settings, buf, data) + if self.xformat == GAUSSDB_XFORMAT_OBJECT: + if self.format == GAUSSDB_FORMAT_BINARY: + gaussdbproto.bytea_encode(settings, buf, data) + elif self.format == GAUSSDB_FORMAT_TEXT: + gaussdbproto.text_encode(settings, buf, data) else: raise exceptions.InternalClientError( 'unexpected data format: {}'.format(self.format)) - elif self.xformat == PG_XFORMAT_TUPLE: + elif self.xformat == GAUSSDB_XFORMAT_TUPLE: if self.base_codec is not None: self.base_codec.encode(settings, buf, data) else: @@ -307,15 +307,15 @@ cdef class Codec: cdef decode_in_python(self, ConnectionSettings settings, FRBuffer *buf): - if self.xformat == PG_XFORMAT_OBJECT: - if self.format == PG_FORMAT_BINARY: - data = pgproto.bytea_decode(settings, buf) - elif self.format == PG_FORMAT_TEXT: - data = pgproto.text_decode(settings, buf) + if self.xformat == GAUSSDB_XFORMAT_OBJECT: + if self.format == GAUSSDB_FORMAT_BINARY: + data = gaussdbproto.bytea_decode(settings, buf) + elif self.format == GAUSSDB_FORMAT_TEXT: + data = gaussdbproto.text_decode(settings, buf) else: raise exceptions.InternalClientError( 'unexpected data format: {}'.format(self.format)) - elif self.xformat == PG_XFORMAT_TUPLE: + elif self.xformat == GAUSSDB_XFORMAT_TUPLE: if self.base_codec is not None: data = self.base_codec.decode(settings, buf) else: @@ -374,7 +374,7 @@ cdef class Codec: return False cdef is_binary(self): - return self.format == PG_FORMAT_BINARY + return self.format == GAUSSDB_FORMAT_BINARY def __repr__(self): return ''.format( @@ -391,7 +391,7 @@ cdef class Codec: cdef Codec codec codec = Codec(oid) codec.init(name, schema, 'array', CODEC_ARRAY, element_codec.format, - PG_XFORMAT_OBJECT, NULL, NULL, None, None, None, + GAUSSDB_XFORMAT_OBJECT, NULL, NULL, None, None, None, element_codec, None, None, None, element_delimiter) return codec @@ -403,7 +403,7 @@ cdef class Codec: cdef Codec codec codec = Codec(oid) codec.init(name, schema, 'range', CODEC_RANGE, element_codec.format, - PG_XFORMAT_OBJECT, NULL, NULL, None, None, None, + GAUSSDB_XFORMAT_OBJECT, NULL, NULL, None, None, None, element_codec, None, None, None, 0) return codec @@ -415,7 +415,7 @@ cdef class Codec: cdef Codec codec codec = Codec(oid) codec.init(name, schema, 'multirange', CODEC_MULTIRANGE, - element_codec.format, PG_XFORMAT_OBJECT, NULL, NULL, None, + element_codec.format, GAUSSDB_XFORMAT_OBJECT, NULL, NULL, None, None, None, element_codec, None, None, None, 0) return codec @@ -430,7 +430,7 @@ cdef class Codec: cdef Codec codec codec = Codec(oid) codec.init(name, schema, 'composite', CODEC_COMPOSITE, - format, PG_XFORMAT_OBJECT, NULL, NULL, None, None, None, + format, GAUSSDB_XFORMAT_OBJECT, NULL, NULL, None, None, None, None, element_type_oids, element_names, element_codecs, 0) return codec @@ -502,7 +502,7 @@ cdef class DataCodecConfig: for ti in types: oid = ti['oid'] - if self.get_codec(oid, PG_FORMAT_ANY) is not None: + if self.get_codec(oid, GAUSSDB_FORMAT_ANY) is not None: continue name = ti['name'] @@ -523,7 +523,7 @@ cdef class DataCodecConfig: name = name[1:] name = '{}[]'.format(name) - elem_codec = self.get_codec(array_element_oid, PG_FORMAT_ANY) + elem_codec = self.get_codec(array_element_oid, GAUSSDB_FORMAT_ANY) if elem_codec is None: elem_codec = self.declare_fallback_codec( array_element_oid, ti['elemtype_name'], schema) @@ -545,11 +545,11 @@ cdef class DataCodecConfig: has_text_elements = False for typoid in comp_type_attrs: - elem_codec = self.get_codec(typoid, PG_FORMAT_ANY) + elem_codec = self.get_codec(typoid, GAUSSDB_FORMAT_ANY) if elem_codec is None: raise exceptions.InternalClientError( f'no codec for composite attribute type {typoid}') - if elem_codec.format is PG_FORMAT_TEXT: + if elem_codec.format is GAUSSDB_FORMAT_TEXT: has_text_elements = True comp_elem_codecs.append(elem_codec) @@ -560,9 +560,9 @@ cdef class DataCodecConfig: # If at least one element is text-encoded, we must # encode the whole composite as text. if has_text_elements: - elem_format = PG_FORMAT_TEXT + elem_format = GAUSSDB_FORMAT_TEXT else: - elem_format = PG_FORMAT_BINARY + elem_format = GAUSSDB_FORMAT_BINARY self._derived_type_codecs[oid, elem_format] = \ Codec.new_composite_codec( @@ -576,7 +576,7 @@ cdef class DataCodecConfig: raise exceptions.InternalClientError( f'type record missing base type for domain {oid}') - elem_codec = self.get_codec(base_type, PG_FORMAT_ANY) + elem_codec = self.get_codec(base_type, GAUSSDB_FORMAT_ANY) if elem_codec is None: elem_codec = self.declare_fallback_codec( base_type, ti['basetype_name'], schema) @@ -590,7 +590,7 @@ cdef class DataCodecConfig: raise exceptions.InternalClientError( f'type record missing base type for range {oid}') - elem_codec = self.get_codec(range_subtype_oid, PG_FORMAT_ANY) + elem_codec = self.get_codec(range_subtype_oid, GAUSSDB_FORMAT_ANY) if elem_codec is None: elem_codec = self.declare_fallback_codec( range_subtype_oid, ti['range_subtype_name'], schema) @@ -605,7 +605,7 @@ cdef class DataCodecConfig: raise exceptions.InternalClientError( f'type record missing base type for multirange {oid}') - elem_codec = self.get_codec(range_subtype_oid, PG_FORMAT_ANY) + elem_codec = self.get_codec(range_subtype_oid, GAUSSDB_FORMAT_ANY) if elem_codec is None: elem_codec = self.declare_fallback_codec( range_subtype_oid, ti['range_subtype_name'], schema) @@ -616,7 +616,7 @@ cdef class DataCodecConfig: elif ti['kind'] == b'e': # Enum types are essentially text self._set_builtin_type_codec(oid, name, schema, 'scalar', - TEXTOID, PG_FORMAT_ANY) + TEXTOID, GAUSSDB_FORMAT_ANY) else: self.declare_fallback_codec(oid, name, schema) @@ -636,13 +636,13 @@ cdef class DataCodecConfig: if typeinfos: self.add_types(typeinfos) - if format == PG_FORMAT_ANY: - formats = (PG_FORMAT_TEXT, PG_FORMAT_BINARY) + if format == GAUSSDB_FORMAT_ANY: + formats = (GAUSSDB_FORMAT_TEXT, GAUSSDB_FORMAT_BINARY) else: formats = (format,) for fmt in formats: - if xformat == PG_XFORMAT_TUPLE: + if xformat == GAUSSDB_XFORMAT_TUPLE: if typekind == "scalar": core_codec = get_core_codec(oid, fmt, xformat) if core_codec is None: @@ -666,12 +666,12 @@ cdef class DataCodecConfig: typename)) def remove_python_codec(self, typeoid, typename, typeschema): - for fmt in (PG_FORMAT_BINARY, PG_FORMAT_TEXT): + for fmt in (GAUSSDB_FORMAT_BINARY, GAUSSDB_FORMAT_TEXT): self._custom_type_codecs.pop((typeoid, fmt), None) self.clear_type_cache() def _set_builtin_type_codec(self, typeoid, typename, typeschema, typekind, - alias_to, format=PG_FORMAT_ANY): + alias_to, format=GAUSSDB_FORMAT_ANY): cdef: Codec codec Codec target_codec @@ -679,8 +679,8 @@ cdef class DataCodecConfig: uint32_t alias_oid = 0 bint codec_set = False - if format == PG_FORMAT_ANY: - formats = (PG_FORMAT_BINARY, PG_FORMAT_TEXT) + if format == GAUSSDB_FORMAT_ANY: + formats = (GAUSSDB_FORMAT_BINARY, GAUSSDB_FORMAT_TEXT) else: formats = (format,) @@ -708,9 +708,9 @@ cdef class DataCodecConfig: codec_set = True if not codec_set: - if format == PG_FORMAT_BINARY: + if format == GAUSSDB_FORMAT_BINARY: codec_str = 'binary' - elif format == PG_FORMAT_TEXT: + elif format == GAUSSDB_FORMAT_TEXT: codec_str = 'text' else: codec_str = 'text or binary' @@ -720,7 +720,7 @@ cdef class DataCodecConfig: f'there is no {codec_str} codec for {alias_to}') def set_builtin_type_codec(self, typeoid, typename, typeschema, typekind, - alias_to, format=PG_FORMAT_ANY): + alias_to, format=GAUSSDB_FORMAT_ANY): self._set_builtin_type_codec(typeoid, typename, typeschema, typekind, alias_to, format) self.clear_type_cache() @@ -747,9 +747,9 @@ cdef class DataCodecConfig: # using Connection.set_type_codec(). # self._set_builtin_type_codec(oid, name, schema, 'scalar', - TEXTOID, PG_FORMAT_TEXT) + TEXTOID, GAUSSDB_FORMAT_TEXT) - codec = self.get_codec(oid, PG_FORMAT_TEXT) + codec = self.get_codec(oid, GAUSSDB_FORMAT_TEXT) return codec @@ -757,16 +757,16 @@ cdef class DataCodecConfig: bint ignore_custom_codec=False): cdef Codec codec - if format == PG_FORMAT_ANY: + if format == GAUSSDB_FORMAT_ANY: codec = self.get_codec( - oid, PG_FORMAT_BINARY, ignore_custom_codec) + oid, GAUSSDB_FORMAT_BINARY, ignore_custom_codec) if codec is None: codec = self.get_codec( - oid, PG_FORMAT_TEXT, ignore_custom_codec) + oid, GAUSSDB_FORMAT_TEXT, ignore_custom_codec) return codec else: if not ignore_custom_codec: - codec = self.get_custom_codec(oid, PG_FORMAT_ANY) + codec = self.get_custom_codec(oid, GAUSSDB_FORMAT_ANY) if codec is not None: if codec.format != format: # The codec for this OID has been overridden by @@ -792,10 +792,10 @@ cdef class DataCodecConfig: ): cdef Codec codec - if format == PG_FORMAT_ANY: - codec = self.get_custom_codec(oid, PG_FORMAT_BINARY) + if format == GAUSSDB_FORMAT_ANY: + codec = self.get_custom_codec(oid, GAUSSDB_FORMAT_BINARY) if codec is None: - codec = self.get_custom_codec(oid, PG_FORMAT_TEXT) + codec = self.get_custom_codec(oid, GAUSSDB_FORMAT_TEXT) else: codec = self._custom_type_codecs.get((oid, format)) @@ -804,15 +804,15 @@ cdef class DataCodecConfig: cdef inline Codec get_core_codec( uint32_t oid, ServerDataFormat format, - ClientExchangeFormat xformat=PG_XFORMAT_OBJECT): + ClientExchangeFormat xformat=GAUSSDB_XFORMAT_OBJECT): cdef: void *ptr = NULL if oid > MAXSUPPORTEDOID: return None - if format == PG_FORMAT_BINARY: + if format == GAUSSDB_FORMAT_BINARY: ptr = binary_codec_map[oid * xformat] - elif format == PG_FORMAT_TEXT: + elif format == GAUSSDB_FORMAT_TEXT: ptr = text_codec_map[oid * xformat] if ptr is NULL: @@ -823,15 +823,15 @@ cdef inline Codec get_core_codec( cdef inline Codec get_any_core_codec( uint32_t oid, ServerDataFormat format, - ClientExchangeFormat xformat=PG_XFORMAT_OBJECT): - """A version of get_core_codec that accepts PG_FORMAT_ANY.""" + ClientExchangeFormat xformat=GAUSSDB_XFORMAT_OBJECT): + """A version of get_core_codec that accepts GAUSSDB_FORMAT_ANY.""" cdef: Codec codec - if format == PG_FORMAT_ANY: - codec = get_core_codec(oid, PG_FORMAT_BINARY, xformat) + if format == GAUSSDB_FORMAT_ANY: + codec = get_core_codec(oid, GAUSSDB_FORMAT_BINARY, xformat) if codec is None: - codec = get_core_codec(oid, PG_FORMAT_TEXT, xformat) + codec = get_core_codec(oid, GAUSSDB_FORMAT_TEXT, xformat) else: codec = get_core_codec(oid, format, xformat) @@ -846,7 +846,7 @@ cdef register_core_codec(uint32_t oid, encode_func encode, decode_func decode, ServerDataFormat format, - ClientExchangeFormat xformat=PG_XFORMAT_OBJECT): + ClientExchangeFormat xformat=GAUSSDB_XFORMAT_OBJECT): if oid > MAXSUPPORTEDOID: raise exceptions.InternalClientError( @@ -866,9 +866,9 @@ cdef register_core_codec(uint32_t oid, encode, decode, None, None, None, None, None, None, None, 0) cpython.Py_INCREF(codec) # immortalize - if format == PG_FORMAT_BINARY: + if format == GAUSSDB_FORMAT_BINARY: binary_codec_map[oid * xformat] = codec - elif format == PG_FORMAT_TEXT: + elif format == GAUSSDB_FORMAT_TEXT: text_codec_map[oid * xformat] = codec else: raise exceptions.InternalClientError( @@ -886,7 +886,7 @@ cdef register_extra_codec(str name, kind = 'scalar' codec = Codec(INVALIDOID) - codec.init(name, None, kind, CODEC_C, format, PG_XFORMAT_OBJECT, + codec.init(name, None, kind, CODEC_C, format, GAUSSDB_XFORMAT_OBJECT, encode, decode, None, None, None, None, None, None, None, 0) EXTRA_CODECS[name, format] = codec diff --git a/async_gaussdb/protocol/codecs/gaussdbproto.pyx b/async_gaussdb/protocol/codecs/gaussdbproto.pyx new file mode 100644 index 00000000..808187b6 --- /dev/null +++ b/async_gaussdb/protocol/codecs/gaussdbproto.pyx @@ -0,0 +1,490 @@ +# Copyright (C) 2016-present the asyncpg authors and contributors +# +# +# This module is part of asyncpg and is released under +# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0 + + +cdef init_bits_codecs(): + register_core_codec(BITOID, + gaussdbproto.bits_encode, + gaussdbproto.bits_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(VARBITOID, + gaussdbproto.bits_encode, + gaussdbproto.bits_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_bytea_codecs(): + register_core_codec(BYTEAOID, + gaussdbproto.bytea_encode, + gaussdbproto.bytea_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(CHAROID, + gaussdbproto.bytea_encode, + gaussdbproto.bytea_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_datetime_codecs(): + register_core_codec(DATEOID, + gaussdbproto.date_encode, + gaussdbproto.date_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(DATEOID, + gaussdbproto.date_encode_tuple, + gaussdbproto.date_decode_tuple, + GAUSSDB_FORMAT_BINARY, + GAUSSDB_XFORMAT_TUPLE) + + register_core_codec(TIMEOID, + gaussdbproto.time_encode, + gaussdbproto.time_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(TIMEOID, + gaussdbproto.time_encode_tuple, + gaussdbproto.time_decode_tuple, + GAUSSDB_FORMAT_BINARY, + GAUSSDB_XFORMAT_TUPLE) + + register_core_codec(TIMETZOID, + gaussdbproto.timetz_encode, + gaussdbproto.timetz_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(TIMETZOID, + gaussdbproto.timetz_encode_tuple, + gaussdbproto.timetz_decode_tuple, + GAUSSDB_FORMAT_BINARY, + GAUSSDB_XFORMAT_TUPLE) + + register_core_codec(TIMESTAMPOID, + gaussdbproto.timestamp_encode, + gaussdbproto.timestamp_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(TIMESTAMPOID, + gaussdbproto.timestamp_encode_tuple, + gaussdbproto.timestamp_decode_tuple, + GAUSSDB_FORMAT_BINARY, + GAUSSDB_XFORMAT_TUPLE) + + register_core_codec(TIMESTAMPTZOID, + gaussdbproto.timestamptz_encode, + gaussdbproto.timestamptz_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(TIMESTAMPTZOID, + gaussdbproto.timestamp_encode_tuple, + gaussdbproto.timestamp_decode_tuple, + GAUSSDB_FORMAT_BINARY, + GAUSSDB_XFORMAT_TUPLE) + + register_core_codec(INTERVALOID, + gaussdbproto.interval_encode, + gaussdbproto.interval_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(INTERVALOID, + gaussdbproto.interval_encode_tuple, + gaussdbproto.interval_decode_tuple, + GAUSSDB_FORMAT_BINARY, + GAUSSDB_XFORMAT_TUPLE) + + # For obsolete abstime/reltime/tinterval, we do not bother to + # interpret the value, and simply return and pass it as text. + # + register_core_codec(ABSTIMEOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + register_core_codec(RELTIMEOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + register_core_codec(TINTERVALOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + +cdef init_float_codecs(): + register_core_codec(FLOAT4OID, + gaussdbproto.float4_encode, + gaussdbproto.float4_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(FLOAT8OID, + gaussdbproto.float8_encode, + gaussdbproto.float8_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_geometry_codecs(): + register_core_codec(BOXOID, + gaussdbproto.box_encode, + gaussdbproto.box_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(LINEOID, + gaussdbproto.line_encode, + gaussdbproto.line_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(LSEGOID, + gaussdbproto.lseg_encode, + gaussdbproto.lseg_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(POINTOID, + gaussdbproto.point_encode, + gaussdbproto.point_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(PATHOID, + gaussdbproto.path_encode, + gaussdbproto.path_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(POLYGONOID, + gaussdbproto.poly_encode, + gaussdbproto.poly_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(CIRCLEOID, + gaussdbproto.circle_encode, + gaussdbproto.circle_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_hstore_codecs(): + register_extra_codec('pg_contrib.hstore', + gaussdbproto.hstore_encode, + gaussdbproto.hstore_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_json_codecs(): + register_core_codec(JSONOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_BINARY) + register_core_codec(JSONBOID, + gaussdbproto.jsonb_encode, + gaussdbproto.jsonb_decode, + GAUSSDB_FORMAT_BINARY) + register_core_codec(JSONPATHOID, + gaussdbproto.jsonpath_encode, + gaussdbproto.jsonpath_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_int_codecs(): + + register_core_codec(BOOLOID, + gaussdbproto.bool_encode, + gaussdbproto.bool_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(INT2OID, + gaussdbproto.int2_encode, + gaussdbproto.int2_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(INT4OID, + gaussdbproto.int4_encode, + gaussdbproto.int4_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(INT8OID, + gaussdbproto.int8_encode, + gaussdbproto.int8_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_pseudo_codecs(): + # Void type is returned by SELECT void_returning_function() + register_core_codec(VOIDOID, + gaussdbproto.void_encode, + gaussdbproto.void_decode, + GAUSSDB_FORMAT_BINARY) + + # Unknown type, always decoded as text + register_core_codec(UNKNOWNOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + # OID and friends + oid_types = [ + OIDOID, CIDOID + ] + + for oid_type in oid_types: + register_core_codec(oid_type, + gaussdbproto.uint4_encode, + gaussdbproto.uint4_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(XIDOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + # 64-bit OID types + oid8_types = [ + XID8OID, + ] + + for oid_type in oid8_types: + register_core_codec(oid_type, + gaussdbproto.uint8_encode, + gaussdbproto.uint8_decode, + GAUSSDB_FORMAT_BINARY) + + # reg* types -- these are really system catalog OIDs, but + # allow the catalog object name as an input. We could just + # decode these as OIDs, but handling them as text seems more + # useful. + # + reg_types = [ + REGPROCOID, REGPROCEDUREOID, REGOPEROID, REGOPERATOROID, + REGCLASSOID, REGTYPEOID, REGCONFIGOID, REGDICTIONARYOID, + REGNAMESPACEOID, REGROLEOID, REFCURSOROID, REGCOLLATIONOID, + ] + + for reg_type in reg_types: + register_core_codec(reg_type, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + # cstring type is used by GaussDB' I/O functions + register_core_codec(CSTRINGOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_BINARY) + + # various system pseudotypes with no I/O + no_io_types = [ + ANYOID, TRIGGEROID, EVENT_TRIGGEROID, LANGUAGE_HANDLEROID, + FDW_HANDLEROID, TSM_HANDLEROID, INTERNALOID, OPAQUEOID, + ANYELEMENTOID, ANYNONARRAYOID, ANYCOMPATIBLEOID, + ANYCOMPATIBLEARRAYOID, ANYCOMPATIBLENONARRAYOID, + ANYCOMPATIBLERANGEOID, ANYCOMPATIBLEMULTIRANGEOID, + ANYRANGEOID, ANYMULTIRANGEOID, ANYARRAYOID, + GAUSSDB_DDL_COMMANDOID, INDEX_AM_HANDLEROID, TABLE_AM_HANDLEROID, + ] + + register_core_codec(ANYENUMOID, + NULL, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + for no_io_type in no_io_types: + register_core_codec(no_io_type, + NULL, + NULL, + GAUSSDB_FORMAT_BINARY) + + # ACL specification string + register_core_codec(ACLITEMOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + # GaussDB' serialized expression tree type + register_core_codec(GAUSSDB_NODE_TREEOID, + NULL, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + # pg_lsn type -- a pointer to a location in the XLOG. + register_core_codec(GAUSSDB_LSNOID, + gaussdbproto.int8_encode, + gaussdbproto.int8_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(SMGROID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + # pg_dependencies and pg_ndistinct are special types + # used in pg_statistic_ext columns. + register_core_codec(GAUSSDB_DEPENDENCIESOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + register_core_codec(GAUSSDB_NDISTINCTOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + # pg_mcv_list is a special type used in pg_statistic_ext_data + # system catalog + register_core_codec(GAUSSDB_MCV_LISTOID, + gaussdbproto.bytea_encode, + gaussdbproto.bytea_decode, + GAUSSDB_FORMAT_BINARY) + + # These two are internal to BRIN index support and are unlikely + # to be sent, but since I/O functions for these exist, add decoders + # nonetheless. + register_core_codec(GAUSSDB_BRIN_BLOOM_SUMMARYOID, + NULL, + gaussdbproto.bytea_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(GAUSSDB_BRIN_MINMAX_MULTI_SUMMARYOID, + NULL, + gaussdbproto.bytea_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_text_codecs(): + textoids = [ + NAMEOID, + BPCHAROID, + VARCHAROID, + TEXTOID, + XMLOID + ] + + for oid in textoids: + register_core_codec(oid, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(oid, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + +cdef init_tid_codecs(): + register_core_codec(TIDOID, + gaussdbproto.tid_encode, + gaussdbproto.tid_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_txid_codecs(): + + register_core_codec(TXID_SNAPSHOTOID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + register_core_codec(GAUSSDB_SNAPSHOTOID, + gaussdbproto.gaussdb_snapshot_encode, + gaussdbproto.gaussdb_snapshot_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_tsearch_codecs(): + ts_oids = [ + TSQUERYOID, + TSVECTOROID, + ] + + for oid in ts_oids: + register_core_codec(oid, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + register_core_codec(GTSVECTOROID, + NULL, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + +cdef init_uuid_codecs(): + register_core_codec(UUIDOID, + gaussdbproto.uuid_encode, + gaussdbproto.uuid_decode, + GAUSSDB_FORMAT_BINARY) + + +cdef init_numeric_codecs(): + register_core_codec(NUMERICOID, + gaussdbproto.numeric_encode_text, + gaussdbproto.numeric_decode_text, + GAUSSDB_FORMAT_TEXT) + + register_core_codec(NUMERICOID, + gaussdbproto.numeric_encode_binary, + gaussdbproto.numeric_decode_binary, + GAUSSDB_FORMAT_BINARY) + + +cdef init_network_codecs(): + register_core_codec(CIDROID, + gaussdbproto.cidr_encode, + gaussdbproto.cidr_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(INETOID, + gaussdbproto.inet_encode, + gaussdbproto.inet_decode, + GAUSSDB_FORMAT_BINARY) + + register_core_codec(MACADDROID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + register_core_codec(MACADDR8OID, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + +cdef init_monetary_codecs(): + moneyoids = [ + MONEYOID, + ] + + for oid in moneyoids: + register_core_codec(oid, + gaussdbproto.text_encode, + gaussdbproto.text_decode, + GAUSSDB_FORMAT_TEXT) + + +cdef init_all_gaussdbproto_codecs(): + # Builtin types, in lexicographical order. + init_bits_codecs() + init_bytea_codecs() + init_datetime_codecs() + init_float_codecs() + init_geometry_codecs() + init_int_codecs() + init_json_codecs() + init_monetary_codecs() + init_network_codecs() + init_numeric_codecs() + init_text_codecs() + init_tid_codecs() + init_tsearch_codecs() + init_txid_codecs() + init_uuid_codecs() + + # Various pseudotypes and system types + init_pseudo_codecs() + + # contrib + init_hstore_codecs() + + +init_all_gaussdbproto_codecs() diff --git a/async_gaussdb/protocol/codecs/pgproto.pyx b/async_gaussdb/protocol/codecs/pgproto.pyx deleted file mode 100644 index 0dedc989..00000000 --- a/async_gaussdb/protocol/codecs/pgproto.pyx +++ /dev/null @@ -1,490 +0,0 @@ -# Copyright (C) 2016-present the asyncpg authors and contributors -# -# -# This module is part of asyncpg and is released under -# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0 - - -cdef init_bits_codecs(): - register_core_codec(BITOID, - pgproto.bits_encode, - pgproto.bits_decode, - PG_FORMAT_BINARY) - - register_core_codec(VARBITOID, - pgproto.bits_encode, - pgproto.bits_decode, - PG_FORMAT_BINARY) - - -cdef init_bytea_codecs(): - register_core_codec(BYTEAOID, - pgproto.bytea_encode, - pgproto.bytea_decode, - PG_FORMAT_BINARY) - - register_core_codec(CHAROID, - pgproto.bytea_encode, - pgproto.bytea_decode, - PG_FORMAT_BINARY) - - -cdef init_datetime_codecs(): - register_core_codec(DATEOID, - pgproto.date_encode, - pgproto.date_decode, - PG_FORMAT_BINARY) - - register_core_codec(DATEOID, - pgproto.date_encode_tuple, - pgproto.date_decode_tuple, - PG_FORMAT_BINARY, - PG_XFORMAT_TUPLE) - - register_core_codec(TIMEOID, - pgproto.time_encode, - pgproto.time_decode, - PG_FORMAT_BINARY) - - register_core_codec(TIMEOID, - pgproto.time_encode_tuple, - pgproto.time_decode_tuple, - PG_FORMAT_BINARY, - PG_XFORMAT_TUPLE) - - register_core_codec(TIMETZOID, - pgproto.timetz_encode, - pgproto.timetz_decode, - PG_FORMAT_BINARY) - - register_core_codec(TIMETZOID, - pgproto.timetz_encode_tuple, - pgproto.timetz_decode_tuple, - PG_FORMAT_BINARY, - PG_XFORMAT_TUPLE) - - register_core_codec(TIMESTAMPOID, - pgproto.timestamp_encode, - pgproto.timestamp_decode, - PG_FORMAT_BINARY) - - register_core_codec(TIMESTAMPOID, - pgproto.timestamp_encode_tuple, - pgproto.timestamp_decode_tuple, - PG_FORMAT_BINARY, - PG_XFORMAT_TUPLE) - - register_core_codec(TIMESTAMPTZOID, - pgproto.timestamptz_encode, - pgproto.timestamptz_decode, - PG_FORMAT_BINARY) - - register_core_codec(TIMESTAMPTZOID, - pgproto.timestamp_encode_tuple, - pgproto.timestamp_decode_tuple, - PG_FORMAT_BINARY, - PG_XFORMAT_TUPLE) - - register_core_codec(INTERVALOID, - pgproto.interval_encode, - pgproto.interval_decode, - PG_FORMAT_BINARY) - - register_core_codec(INTERVALOID, - pgproto.interval_encode_tuple, - pgproto.interval_decode_tuple, - PG_FORMAT_BINARY, - PG_XFORMAT_TUPLE) - - # For obsolete abstime/reltime/tinterval, we do not bother to - # interpret the value, and simply return and pass it as text. - # - register_core_codec(ABSTIMEOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - register_core_codec(RELTIMEOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - register_core_codec(TINTERVALOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - -cdef init_float_codecs(): - register_core_codec(FLOAT4OID, - pgproto.float4_encode, - pgproto.float4_decode, - PG_FORMAT_BINARY) - - register_core_codec(FLOAT8OID, - pgproto.float8_encode, - pgproto.float8_decode, - PG_FORMAT_BINARY) - - -cdef init_geometry_codecs(): - register_core_codec(BOXOID, - pgproto.box_encode, - pgproto.box_decode, - PG_FORMAT_BINARY) - - register_core_codec(LINEOID, - pgproto.line_encode, - pgproto.line_decode, - PG_FORMAT_BINARY) - - register_core_codec(LSEGOID, - pgproto.lseg_encode, - pgproto.lseg_decode, - PG_FORMAT_BINARY) - - register_core_codec(POINTOID, - pgproto.point_encode, - pgproto.point_decode, - PG_FORMAT_BINARY) - - register_core_codec(PATHOID, - pgproto.path_encode, - pgproto.path_decode, - PG_FORMAT_BINARY) - - register_core_codec(POLYGONOID, - pgproto.poly_encode, - pgproto.poly_decode, - PG_FORMAT_BINARY) - - register_core_codec(CIRCLEOID, - pgproto.circle_encode, - pgproto.circle_decode, - PG_FORMAT_BINARY) - - -cdef init_hstore_codecs(): - register_extra_codec('pg_contrib.hstore', - pgproto.hstore_encode, - pgproto.hstore_decode, - PG_FORMAT_BINARY) - - -cdef init_json_codecs(): - register_core_codec(JSONOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_BINARY) - register_core_codec(JSONBOID, - pgproto.jsonb_encode, - pgproto.jsonb_decode, - PG_FORMAT_BINARY) - register_core_codec(JSONPATHOID, - pgproto.jsonpath_encode, - pgproto.jsonpath_decode, - PG_FORMAT_BINARY) - - -cdef init_int_codecs(): - - register_core_codec(BOOLOID, - pgproto.bool_encode, - pgproto.bool_decode, - PG_FORMAT_BINARY) - - register_core_codec(INT2OID, - pgproto.int2_encode, - pgproto.int2_decode, - PG_FORMAT_BINARY) - - register_core_codec(INT4OID, - pgproto.int4_encode, - pgproto.int4_decode, - PG_FORMAT_BINARY) - - register_core_codec(INT8OID, - pgproto.int8_encode, - pgproto.int8_decode, - PG_FORMAT_BINARY) - - -cdef init_pseudo_codecs(): - # Void type is returned by SELECT void_returning_function() - register_core_codec(VOIDOID, - pgproto.void_encode, - pgproto.void_decode, - PG_FORMAT_BINARY) - - # Unknown type, always decoded as text - register_core_codec(UNKNOWNOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - # OID and friends - oid_types = [ - OIDOID, CIDOID - ] - - for oid_type in oid_types: - register_core_codec(oid_type, - pgproto.uint4_encode, - pgproto.uint4_decode, - PG_FORMAT_BINARY) - - register_core_codec(XIDOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - # 64-bit OID types - oid8_types = [ - XID8OID, - ] - - for oid_type in oid8_types: - register_core_codec(oid_type, - pgproto.uint8_encode, - pgproto.uint8_decode, - PG_FORMAT_BINARY) - - # reg* types -- these are really system catalog OIDs, but - # allow the catalog object name as an input. We could just - # decode these as OIDs, but handling them as text seems more - # useful. - # - reg_types = [ - REGPROCOID, REGPROCEDUREOID, REGOPEROID, REGOPERATOROID, - REGCLASSOID, REGTYPEOID, REGCONFIGOID, REGDICTIONARYOID, - REGNAMESPACEOID, REGROLEOID, REFCURSOROID, REGCOLLATIONOID, - ] - - for reg_type in reg_types: - register_core_codec(reg_type, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - # cstring type is used by GaussDB' I/O functions - register_core_codec(CSTRINGOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_BINARY) - - # various system pseudotypes with no I/O - no_io_types = [ - ANYOID, TRIGGEROID, EVENT_TRIGGEROID, LANGUAGE_HANDLEROID, - FDW_HANDLEROID, TSM_HANDLEROID, INTERNALOID, OPAQUEOID, - ANYELEMENTOID, ANYNONARRAYOID, ANYCOMPATIBLEOID, - ANYCOMPATIBLEARRAYOID, ANYCOMPATIBLENONARRAYOID, - ANYCOMPATIBLERANGEOID, ANYCOMPATIBLEMULTIRANGEOID, - ANYRANGEOID, ANYMULTIRANGEOID, ANYARRAYOID, - PG_DDL_COMMANDOID, INDEX_AM_HANDLEROID, TABLE_AM_HANDLEROID, - ] - - register_core_codec(ANYENUMOID, - NULL, - pgproto.text_decode, - PG_FORMAT_TEXT) - - for no_io_type in no_io_types: - register_core_codec(no_io_type, - NULL, - NULL, - PG_FORMAT_BINARY) - - # ACL specification string - register_core_codec(ACLITEMOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - # GaussDB' serialized expression tree type - register_core_codec(PG_NODE_TREEOID, - NULL, - pgproto.text_decode, - PG_FORMAT_TEXT) - - # pg_lsn type -- a pointer to a location in the XLOG. - register_core_codec(PG_LSNOID, - pgproto.int8_encode, - pgproto.int8_decode, - PG_FORMAT_BINARY) - - register_core_codec(SMGROID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - # pg_dependencies and pg_ndistinct are special types - # used in pg_statistic_ext columns. - register_core_codec(PG_DEPENDENCIESOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - register_core_codec(PG_NDISTINCTOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - # pg_mcv_list is a special type used in pg_statistic_ext_data - # system catalog - register_core_codec(PG_MCV_LISTOID, - pgproto.bytea_encode, - pgproto.bytea_decode, - PG_FORMAT_BINARY) - - # These two are internal to BRIN index support and are unlikely - # to be sent, but since I/O functions for these exist, add decoders - # nonetheless. - register_core_codec(PG_BRIN_BLOOM_SUMMARYOID, - NULL, - pgproto.bytea_decode, - PG_FORMAT_BINARY) - - register_core_codec(PG_BRIN_MINMAX_MULTI_SUMMARYOID, - NULL, - pgproto.bytea_decode, - PG_FORMAT_BINARY) - - -cdef init_text_codecs(): - textoids = [ - NAMEOID, - BPCHAROID, - VARCHAROID, - TEXTOID, - XMLOID - ] - - for oid in textoids: - register_core_codec(oid, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_BINARY) - - register_core_codec(oid, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - -cdef init_tid_codecs(): - register_core_codec(TIDOID, - pgproto.tid_encode, - pgproto.tid_decode, - PG_FORMAT_BINARY) - - -cdef init_txid_codecs(): - - register_core_codec(TXID_SNAPSHOTOID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - register_core_codec(PG_SNAPSHOTOID, - pgproto.pg_snapshot_encode, - pgproto.pg_snapshot_decode, - PG_FORMAT_BINARY) - - -cdef init_tsearch_codecs(): - ts_oids = [ - TSQUERYOID, - TSVECTOROID, - ] - - for oid in ts_oids: - register_core_codec(oid, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - register_core_codec(GTSVECTOROID, - NULL, - pgproto.text_decode, - PG_FORMAT_TEXT) - - -cdef init_uuid_codecs(): - register_core_codec(UUIDOID, - pgproto.uuid_encode, - pgproto.uuid_decode, - PG_FORMAT_BINARY) - - -cdef init_numeric_codecs(): - register_core_codec(NUMERICOID, - pgproto.numeric_encode_text, - pgproto.numeric_decode_text, - PG_FORMAT_TEXT) - - register_core_codec(NUMERICOID, - pgproto.numeric_encode_binary, - pgproto.numeric_decode_binary, - PG_FORMAT_BINARY) - - -cdef init_network_codecs(): - register_core_codec(CIDROID, - pgproto.cidr_encode, - pgproto.cidr_decode, - PG_FORMAT_BINARY) - - register_core_codec(INETOID, - pgproto.inet_encode, - pgproto.inet_decode, - PG_FORMAT_BINARY) - - register_core_codec(MACADDROID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - register_core_codec(MACADDR8OID, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - -cdef init_monetary_codecs(): - moneyoids = [ - MONEYOID, - ] - - for oid in moneyoids: - register_core_codec(oid, - pgproto.text_encode, - pgproto.text_decode, - PG_FORMAT_TEXT) - - -cdef init_all_pgproto_codecs(): - # Builtin types, in lexicographical order. - init_bits_codecs() - init_bytea_codecs() - init_datetime_codecs() - init_float_codecs() - init_geometry_codecs() - init_int_codecs() - init_json_codecs() - init_monetary_codecs() - init_network_codecs() - init_numeric_codecs() - init_text_codecs() - init_tid_codecs() - init_tsearch_codecs() - init_txid_codecs() - init_uuid_codecs() - - # Various pseudotypes and system types - init_pseudo_codecs() - - # contrib - init_hstore_codecs() - - -init_all_pgproto_codecs() diff --git a/async_gaussdb/protocol/codecs/record.pyx b/async_gaussdb/protocol/codecs/record.pyx index 2ba7b17a..651590cd 100644 --- a/async_gaussdb/protocol/codecs/record.pyx +++ b/async_gaussdb/protocol/codecs/record.pyx @@ -66,6 +66,6 @@ cdef init_record_codecs(): register_core_codec(RECORDOID, anonymous_record_encode, anonymous_record_decode, - PG_FORMAT_BINARY) + GAUSSDB_FORMAT_BINARY) init_record_codecs() diff --git a/async_gaussdb/protocol/coreproto.pyx b/async_gaussdb/protocol/coreproto.pyx index 9d64c9f2..6919de17 100644 --- a/async_gaussdb/protocol/coreproto.pyx +++ b/async_gaussdb/protocol/coreproto.pyx @@ -56,10 +56,10 @@ cdef class CoreProtocol: cdef: char mtype ProtocolState state - pgproto.take_message_method take_message = \ - self.buffer.take_message - pgproto.get_message_type_method get_message_type= \ - self.buffer.get_message_type + gaussdbproto.take_message_method take_message = \ + self.buffer.take_message + gaussdbproto.get_message_type_method get_message_type= \ + self.buffer.get_message_type while take_message(self.buffer) == 1: mtype = get_message_type(self.buffer) @@ -503,17 +503,17 @@ cdef class CoreProtocol: list rows decode_row_method decoder = self._decode_row - pgproto.try_consume_message_method try_consume_message = \ - buf.try_consume_message - pgproto.take_message_type_method take_message_type = \ - buf.take_message_type + gaussdbproto.try_consume_message_method try_consume_message = \ + buf.try_consume_message + gaussdbproto.take_message_type_method take_message_type = \ + buf.take_message_type const char* cbuf ssize_t cbuf_len object row bytes mem - if PG_DEBUG: + if GAUSSDB_DEBUG: if buf.get_message_type() != b'D': raise apg_exc.InternalClientError( '_parse_data_msgs: first message is not "D"') @@ -523,7 +523,7 @@ cdef class CoreProtocol: buf.discard_message() return - if PG_DEBUG: + if GAUSSDB_DEBUG: if type(self.result) is not list: raise apg_exc.InternalClientError( '_parse_data_msgs: result is not a list, but {!r}'. diff --git a/async_gaussdb/protocol/encodings.pyx b/async_gaussdb/protocol/encodings.pyx index a0bd8534..16532bef 100644 --- a/async_gaussdb/protocol/encodings.pyx +++ b/async_gaussdb/protocol/encodings.pyx @@ -58,5 +58,5 @@ cdef dict ENCODINGS_MAP = { } -cdef get_python_encoding(pg_encoding): - return ENCODINGS_MAP.get(pg_encoding.lower(), pg_encoding.lower()) +cdef get_python_encoding(gaussdb_encoding): + return ENCODINGS_MAP.get(gaussdb_encoding.lower(), gaussdb_encoding.lower()) diff --git a/async_gaussdb/protocol/pgtypes.pxi b/async_gaussdb/protocol/gaussdbtypes.pxi similarity index 89% rename from async_gaussdb/protocol/pgtypes.pxi rename to async_gaussdb/protocol/gaussdbtypes.pxi index e9bb782f..32e353a8 100644 --- a/async_gaussdb/protocol/pgtypes.pxi +++ b/async_gaussdb/protocol/gaussdbtypes.pxi @@ -25,10 +25,10 @@ DEF OIDOID = 26 DEF TIDOID = 27 DEF XIDOID = 28 DEF CIDOID = 29 -DEF PG_DDL_COMMANDOID = 32 +DEF GAUSSDB_DDL_COMMANDOID = 32 DEF JSONOID = 114 DEF XMLOID = 142 -DEF PG_NODE_TREEOID = 194 +DEF GAUSSDB_NODE_TREEOID = 194 DEF SMGROID = 210 DEF TABLE_AM_HANDLEROID = 269 DEF INDEX_AM_HANDLEROID = 325 @@ -84,10 +84,10 @@ DEF ANYNONARRAYOID = 2776 DEF UUIDOID = 2950 DEF TXID_SNAPSHOTOID = 2970 DEF FDW_HANDLEROID = 3115 -DEF PG_LSNOID = 3220 +DEF GAUSSDB_LSNOID = 3220 DEF TSM_HANDLEROID = 3310 -DEF PG_NDISTINCTOID = 3361 -DEF PG_DEPENDENCIESOID = 3402 +DEF GAUSSDB_NDISTINCTOID = 3361 +DEF GAUSSDB_DEPENDENCIESOID = 3402 DEF ANYENUMOID = 3500 DEF TSVECTOROID = 3614 DEF TSQUERYOID = 3615 @@ -103,10 +103,10 @@ DEF REGROLEOID = 4096 DEF REGCOLLATIONOID = 4191 DEF ANYMULTIRANGEOID = 4537 DEF ANYCOMPATIBLEMULTIRANGEOID = 4538 -DEF PG_BRIN_BLOOM_SUMMARYOID = 4600 -DEF PG_BRIN_MINMAX_MULTI_SUMMARYOID = 4601 -DEF PG_MCV_LISTOID = 5017 -DEF PG_SNAPSHOTOID = 5038 +DEF GAUSSDB_BRIN_BLOOM_SUMMARYOID = 4600 +DEF GAUSSDB_BRIN_MINMAX_MULTI_SUMMARYOID = 4601 +DEF GAUSSDB_MCV_LISTOID = 5017 +DEF GAUSSDB_SNAPSHOTOID = 5038 DEF XID8OID = 5069 DEF ANYCOMPATIBLEOID = 5077 DEF ANYCOMPATIBLEARRAYOID = 5078 @@ -167,15 +167,15 @@ BUILTIN_TYPE_OID_MAP = { OIDOID: 'oid', OPAQUEOID: 'opaque', PATHOID: 'path', - PG_BRIN_BLOOM_SUMMARYOID: 'pg_brin_bloom_summary', - PG_BRIN_MINMAX_MULTI_SUMMARYOID: 'pg_brin_minmax_multi_summary', - PG_DDL_COMMANDOID: 'pg_ddl_command', - PG_DEPENDENCIESOID: 'pg_dependencies', - PG_LSNOID: 'pg_lsn', - PG_MCV_LISTOID: 'pg_mcv_list', - PG_NDISTINCTOID: 'pg_ndistinct', - PG_NODE_TREEOID: 'pg_node_tree', - PG_SNAPSHOTOID: 'pg_snapshot', + GAUSSDB_BRIN_BLOOM_SUMMARYOID: 'gaussdb_brin_bloom_summary', + GAUSSDB_BRIN_MINMAX_MULTI_SUMMARYOID: 'gaussdb_brin_minmax_multi_summary', + GAUSSDB_DDL_COMMANDOID: 'gaussdb_ddl_command', + GAUSSDB_DEPENDENCIESOID: 'gaussdb_dependencies', + GAUSSDB_LSNOID: 'gaussdb_lsn', + GAUSSDB_MCV_LISTOID: 'gaussdb_mcv_list', + GAUSSDB_NDISTINCTOID: 'gaussdb_ndistinct', + GAUSSDB_NODE_TREEOID: 'gaussdb_node_tree', + GAUSSDB_SNAPSHOTOID: 'gaussdb_snapshot', POINTOID: 'point', POLYGONOID: 'polygon', RECORDOID: 'record', diff --git a/async_gaussdb/protocol/protocol.pxd b/async_gaussdb/protocol/protocol.pxd index 76865e0e..9c803804 100644 --- a/async_gaussdb/protocol/protocol.pxd +++ b/async_gaussdb/protocol/protocol.pxd @@ -8,18 +8,18 @@ from libc.stdint cimport int16_t, int32_t, uint16_t, \ uint32_t, int64_t, uint64_t -from async_gaussdb.pgproto.debug cimport PG_DEBUG +from async_gaussdb.gaussdbproto.debug cimport GAUSSDB_DEBUG -from async_gaussdb.pgproto.pgproto cimport ( +from async_gaussdb.gaussdbproto.gaussdbproto cimport ( WriteBuffer, ReadBuffer, FRBuffer, ) -from async_gaussdb.pgproto cimport pgproto +from async_gaussdb.gaussdbproto cimport gaussdbproto include "consts.pxi" -include "pgtypes.pxi" +include "gaussdbtypes.pxi" include "codecs/base.pxd" include "settings.pxd" diff --git a/async_gaussdb/protocol/protocol.pyi b/async_gaussdb/protocol/protocol.pyi index 016b91f3..0777d5c3 100644 --- a/async_gaussdb/protocol/protocol.pyi +++ b/async_gaussdb/protocol/protocol.pyi @@ -17,10 +17,10 @@ from typing import ( ) from typing_extensions import TypeAlias -import async_gaussdb.pgproto.pgproto +import async_gaussdb.gaussdbproto.gaussdbproto from ..connect_utils import _ConnectionParameters -from ..pgproto.pgproto import WriteBuffer +from ..gaussdbproto.gaussdbproto import WriteBuffer from ..types import Attribute, Type _T = TypeVar('_T') @@ -40,7 +40,7 @@ NO_TIMEOUT: Final[_NoTimeoutType] hashlib_md5 = md5 @final -class ConnectionSettings(async_gaussdb.pgproto.pgproto.CodecContext): +class ConnectionSettings(async_gaussdb.gaussdbproto.gaussdbproto.CodecContext): __pyx_vtable__: Any def __init__(self, conn_key: object) -> None: ... def add_python_codec( diff --git a/async_gaussdb/protocol/protocol.pyx b/async_gaussdb/protocol/protocol.pyx index ccb5b0e1..783f3215 100644 --- a/async_gaussdb/protocol/protocol.pyx +++ b/async_gaussdb/protocol/protocol.pyx @@ -18,7 +18,7 @@ import socket import time import weakref -from async_gaussdb.pgproto.pgproto cimport ( +from async_gaussdb.gaussdbproto.gaussdbproto cimport ( WriteBuffer, ReadBuffer, @@ -32,7 +32,7 @@ from async_gaussdb.pgproto.pgproto cimport ( frb_get_len, ) -from async_gaussdb.pgproto cimport pgproto +from async_gaussdb.gaussdbproto cimport gaussdbproto from async_gaussdb.protocol cimport cpythonx from async_gaussdb.protocol cimport record @@ -45,11 +45,11 @@ from async_gaussdb import compat from async_gaussdb import types as apg_types from async_gaussdb import exceptions as apg_exc -from async_gaussdb.pgproto cimport hton +from async_gaussdb.gaussdbproto cimport hton include "consts.pxi" -include "pgtypes.pxi" +include "gaussdbtypes.pxi" include "encodings.pyx" include "settings.pyx" @@ -57,8 +57,8 @@ include "settings.pyx" include "codecs/base.pyx" include "codecs/textutils.pyx" -# register codecs provided by pgproto -include "codecs/pgproto.pyx" +# register codecs provided by gaussdbproto +include "codecs/gaussdbproto.pyx" # nonscalar include "codecs/array.pyx" @@ -476,7 +476,7 @@ cdef class BaseProtocol(CoreProtocol): for codec in codecs: if (not codec.has_encoder() or - codec.format != PG_FORMAT_BINARY): + codec.format != GAUSSDB_FORMAT_BINARY): raise apg_exc.InternalClientError( 'no binary format encoder for ' 'type {} (OID {})'.format(codec.name, codec.oid)) @@ -804,7 +804,7 @@ cdef class BaseProtocol(CoreProtocol): waiter.set_result(True) cdef _on_result__prepare(self, object waiter): - if PG_DEBUG: + if GAUSSDB_DEBUG: if self.statement is None: raise apg_exc.InternalClientError( '_on_result__prepare: statement is None') @@ -851,7 +851,7 @@ cdef class BaseProtocol(CoreProtocol): waiter.set_result(status_msg) cdef _decode_row(self, const char* buf, ssize_t buf_len): - if PG_DEBUG: + if GAUSSDB_DEBUG: if self.statement is None: raise apg_exc.InternalClientError( '_decode_row: statement is None') @@ -863,7 +863,7 @@ cdef class BaseProtocol(CoreProtocol): self.waiter = None if waiter is None: - if PG_DEBUG: + if GAUSSDB_DEBUG: raise apg_exc.InternalClientError('_on_result: waiter is None') if self.state == PROTOCOL_COPY_OUT_DATA or \ diff --git a/async_gaussdb/protocol/settings.pxd b/async_gaussdb/protocol/settings.pxd index 0a1a5f6f..985cec58 100644 --- a/async_gaussdb/protocol/settings.pxd +++ b/async_gaussdb/protocol/settings.pxd @@ -5,7 +5,7 @@ # the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0 -cdef class ConnectionSettings(pgproto.CodecContext): +cdef class ConnectionSettings(gaussdbproto.CodecContext): cdef: str _encoding object _codec diff --git a/async_gaussdb/protocol/settings.pyx b/async_gaussdb/protocol/settings.pyx index 47c72f27..e5dee9bd 100644 --- a/async_gaussdb/protocol/settings.pyx +++ b/async_gaussdb/protocol/settings.pyx @@ -9,7 +9,7 @@ from async_gaussdb import exceptions @cython.final -cdef class ConnectionSettings(pgproto.CodecContext): +cdef class ConnectionSettings(gaussdbproto.CodecContext): def __cinit__(self): self._encoding = 'utf-8' @@ -43,14 +43,14 @@ cdef class ConnectionSettings(pgproto.CodecContext): ClientExchangeFormat xformat if format == 'binary': - _format = PG_FORMAT_BINARY - xformat = PG_XFORMAT_OBJECT + _format = GAUSSDB_FORMAT_BINARY + xformat = GAUSSDB_XFORMAT_OBJECT elif format == 'text': - _format = PG_FORMAT_TEXT - xformat = PG_XFORMAT_OBJECT + _format = GAUSSDB_FORMAT_TEXT + xformat = GAUSSDB_XFORMAT_OBJECT elif format == 'tuple': - _format = PG_FORMAT_ANY - xformat = PG_XFORMAT_TUPLE + _format = GAUSSDB_FORMAT_ANY + xformat = GAUSSDB_XFORMAT_TUPLE else: raise exceptions.InterfaceError( 'invalid `format` argument, expected {}, got {!r}'.format( @@ -74,11 +74,11 @@ cdef class ConnectionSettings(pgproto.CodecContext): ServerDataFormat _format if format is None: - _format = PG_FORMAT_ANY + _format = GAUSSDB_FORMAT_ANY elif format == 'binary': - _format = PG_FORMAT_BINARY + _format = GAUSSDB_FORMAT_BINARY elif format == 'text': - _format = PG_FORMAT_TEXT + _format = GAUSSDB_FORMAT_TEXT else: raise exceptions.InterfaceError( 'invalid `format` argument, expected {}, got {!r}'.format( @@ -89,7 +89,7 @@ cdef class ConnectionSettings(pgproto.CodecContext): typekind, alias_to, _format) cpdef inline Codec get_data_codec(self, uint32_t oid, - ServerDataFormat format=PG_FORMAT_ANY, + ServerDataFormat format=GAUSSDB_FORMAT_ANY, bint ignore_custom_codec=False): return self._data_codecs.get_codec(oid, format, ignore_custom_codec) diff --git a/async_gaussdb/types.py b/async_gaussdb/types.py index 8565209e..acedb638 100644 --- a/async_gaussdb/types.py +++ b/async_gaussdb/types.py @@ -8,7 +8,7 @@ import typing -from async_gaussdb.pgproto.types import ( +from async_gaussdb.gaussdbproto.types import ( BitString, Point, Path, Polygon, Box, Line, LineSegment, Circle, ) diff --git a/setup.py b/setup.py index 985ea71e..1c6497b2 100644 --- a/setup.py +++ b/setup.py @@ -235,8 +235,8 @@ def finalize_options(self): version=VERSION, ext_modules=[ setuptools.extension.Extension( - "async_gaussdb.pgproto.pgproto", - ["async_gaussdb/pgproto/pgproto.pyx"], + "async_gaussdb.gaussdbproto.gaussdbproto", + ["async_gaussdb/gaussdbproto/gaussdbproto.pyx"], extra_compile_args=CFLAGS, extra_link_args=LDFLAGS), @@ -244,7 +244,7 @@ def finalize_options(self): "async_gaussdb.protocol.protocol", ["async_gaussdb/protocol/record/recordobj.c", "async_gaussdb/protocol/protocol.pyx"], - include_dirs=['async_gaussdb/pgproto/'], + include_dirs=['async_gaussdb/gaussdbproto/'], extra_compile_args=CFLAGS, extra_link_args=LDFLAGS), ], diff --git a/tests/test_codecs.py b/tests/test_codecs.py index 0cc0a918..83504537 100644 --- a/tests/test_codecs.py +++ b/tests/test_codecs.py @@ -392,7 +392,7 @@ def _system_timezone(): ('txid_snapshot', 'txid_snapshot', [ "100:1000:100,200,300,400" ]), - ('pg_snapshot', 'pg_snapshot', [ + ('gaussdb_snapshot', 'gaussdb_snapshot', [ (100, 1000, (100, 200, 300, 400)) ], (13, 0)), ('xid', 'xid', ( diff --git a/tools/generate_type_map.py b/tools/generate_type_map.py index 16ecb08b..93ed9a6c 100755 --- a/tools/generate_type_map.py +++ b/tools/generate_type_map.py @@ -113,7 +113,7 @@ async def runner(args): def main(): parser = argparse.ArgumentParser( - description='generate protocol/pgtypes.pxi from pg_catalog.pg_types') + description='generate protocol/gaussdbtypes.pxi from pg_catalog.pg_types') parser.add_argument( '--gaussdbhost', type=str, default='127.0.0.1', help='GaussDBSQL server host') From b6757a6fec46b66c61a00fb4b707cfa05d56b115 Mon Sep 17 00:00:00 2001 From: zhanghaitao3 <1085912315@qq.com> Date: Tue, 2 Dec 2025 10:58:00 +0800 Subject: [PATCH 4/5] refactor: convert submodule gaussdbproto to regular directory --- .github/workflows/install-krb5.sh | 0 async_gaussdb/gaussdbproto/AUTHORS | 6 ------ async_gaussdb/gaussdbproto/README.rst | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) mode change 100644 => 100755 .github/workflows/install-krb5.sh delete mode 100644 async_gaussdb/gaussdbproto/AUTHORS diff --git a/.github/workflows/install-krb5.sh b/.github/workflows/install-krb5.sh old mode 100644 new mode 100755 diff --git a/async_gaussdb/gaussdbproto/AUTHORS b/async_gaussdb/gaussdbproto/AUTHORS deleted file mode 100644 index 64bc938f..00000000 --- a/async_gaussdb/gaussdbproto/AUTHORS +++ /dev/null @@ -1,6 +0,0 @@ -Main contributors -================= - -MagicStack Inc.: - Elvis Pranskevichus - Yury Selivanov diff --git a/async_gaussdb/gaussdbproto/README.rst b/async_gaussdb/gaussdbproto/README.rst index f232582b..1f8404b5 100644 --- a/async_gaussdb/gaussdbproto/README.rst +++ b/async_gaussdb/gaussdbproto/README.rst @@ -1 +1 @@ -Low-level IO utilities for PosgtreSQL drivers. +Low-level IO utilities for GAUSSDB drivers. From 089591046f03c31d004a71d3ed1ac0c792ba2437 Mon Sep 17 00:00:00 2001 From: zhanghaitao3 <1085912315@qq.com> Date: Tue, 2 Dec 2025 11:04:07 +0800 Subject: [PATCH 5/5] refactor: convert submodule gaussdbproto to regular directory --- async_gaussdb/protocol/codecs/array.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/async_gaussdb/protocol/codecs/array.pyx b/async_gaussdb/protocol/codecs/array.pyx index 7a89306c..dfc4ca11 100644 --- a/async_gaussdb/protocol/codecs/array.pyx +++ b/async_gaussdb/protocol/codecs/array.pyx @@ -419,7 +419,7 @@ cdef textarray_decode(ConnectionSettings settings, FRBuffer *buf, # Make a copy of array data since we will be mutating it for # the purposes of element decoding. - s = pgproto.text_decode(settings, buf) + s = gaussdbproto.text_decode(settings, buf) array_text = cpythonx.PyUnicode_AsUCS4Copy(s) try: @@ -822,12 +822,12 @@ cdef _infer_array_dims(const Py_UCS4 *array_text, cdef uint4_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj, const void *arg): - return pgproto.uint4_encode(settings, buf, obj) + return gaussdbproto.uint4_encode(settings, buf, obj) cdef uint4_decode_ex(ConnectionSettings settings, FRBuffer *buf, const void *arg): - return pgproto.uint4_decode(settings, buf) + return gaussdbproto.uint4_decode(settings, buf) cdef arrayoid_encode(ConnectionSettings settings, WriteBuffer buf, items): @@ -841,12 +841,12 @@ cdef arrayoid_decode(ConnectionSettings settings, FRBuffer *buf): cdef text_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj, const void *arg): - return pgproto.text_encode(settings, buf, obj) + return gaussdbproto.text_encode(settings, buf, obj) cdef text_decode_ex(ConnectionSettings settings, FRBuffer *buf, const void *arg): - return pgproto.text_decode(settings, buf) + return gaussdbproto.text_decode(settings, buf) cdef arraytext_encode(ConnectionSettings settings, WriteBuffer buf, items):