コード例 #1
0
ファイル: typecasts.py プロジェクト: smira/psycopg2-ctypes
def parse_binary(value, length, cursor):
    to_length = libpq.c_uint()
    s = libpq.PQunescapeBytea(value, libpq.pointer(to_length))
    try:
        res = buffer(s[:to_length.value])
    finally:
        libpq.PQfreemem(s)
    return res
コード例 #2
0
ファイル: typecasts.py プロジェクト: ovidiucp/psycopg2-ctypes
def parse_binary(value, length, cursor):
    to_length = libpq.c_uint()
    s = libpq.PQunescapeBytea(value, libpq.pointer(to_length))
    try:
        res = buffer(s[:to_length.value])
    finally:
        libpq.PQfreemem(s)
    return res
コード例 #3
0
ファイル: adapters.py プロジェクト: nanonyme/psycopg2-ctypes
    def getquoted(self):
        if self._wrapped is None:
            return "NULL"

        to_length = libpq.c_uint()

        if self._conn:
            data_pointer = libpq.PQescapeByteaConn(
                self._conn._pgconn, str(self._wrapped), len(self._wrapped), libpq.pointer(to_length)
            )
        else:
            data_pointer = libpq.PQescapeBytea(self._wrapped, len(self._wrapped), libpq.pointer(to_length))

        data = data_pointer[: to_length.value - 1]
        libpq.PQfreemem(data_pointer)

        if self._conn and self._conn._equote:
            return r"E'%s'::bytea" % data

        return r"'%s'::bytea" % data
コード例 #4
0
    def getquoted(self):
        if self._wrapped is None:
            return 'NULL'

        to_length = libpq.c_uint()

        if self._conn:
            data_pointer = libpq.PQescapeByteaConn(self._conn._pgconn,
                                                   str(self._wrapped),
                                                   len(self._wrapped),
                                                   libpq.pointer(to_length))
        else:
            data_pointer = libpq.PQescapeBytea(self._wrapped,
                                               len(self._wrapped),
                                               libpq.pointer(to_length))

        data = data_pointer[:to_length.value - 1]
        libpq.PQfreemem(data_pointer)

        if self._conn and self._conn._equote:
            return r"E'%s'::bytea" % data

        return r"'%s'::bytea" % data