當前位置: 首頁>>代碼示例>>Python>>正文


Python psycopg2.Binary方法代碼示例

本文整理匯總了Python中psycopg2.Binary方法的典型用法代碼示例。如果您正苦於以下問題:Python psycopg2.Binary方法的具體用法?Python psycopg2.Binary怎麽用?Python psycopg2.Binary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在psycopg2的用法示例。


在下文中一共展示了psycopg2.Binary方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_binary

# 需要導入模塊: import psycopg2 [as 別名]
# 或者: from psycopg2 import Binary [as 別名]
def test_binary(self):
        data = b("""some data with \000\013 binary
        stuff into, 'quotes' and \\ a backslash too.
        """)
        if sys.version_info[0] < 3:
            data += "".join(map(chr, range(256)))
        else:
            data += bytes(range(256))

        curs = self.conn.cursor()
        curs.execute("SELECT %s::bytea;", (psycopg2.Binary(data),))
        if sys.version_info[0] < 3:
            res = str(curs.fetchone()[0])
        else:
            res = curs.fetchone()[0].tobytes()

        if res[0] in (b('x'), ord(b('x'))) and self.conn.server_version >= 90000:
            return self.skipTest(
                "bytea broken with server >= 9.0, libpq < 9")

        self.assertEqual(res, data)
        self.assert_(not self.conn.notices) 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:24,代碼來源:test_quote.py

示例2: __init__

# 需要導入模塊: import psycopg2 [as 別名]
# 或者: from psycopg2 import Binary [as 別名]
def __init__(self, geom):
        "Initializes on the geometry."
        # Getting the WKB (in string form, to allow easy pickling of
        # the adaptor) and the SRID from the geometry.
        self.ewkb = bytes(geom.ewkb)
        self.srid = geom.srid
        self._adapter = Binary(self.ewkb) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:9,代碼來源:adapter.py

示例3: __init__

# 需要導入模塊: import psycopg2 [as 別名]
# 或者: from psycopg2 import Binary [as 別名]
def __init__(self, geom, geography=False):
        "Initializes on the geometry."
        # Getting the WKB (in string form, to allow easy pickling of
        # the adaptor) and the SRID from the geometry.
        self.ewkb = bytes(geom.ewkb)
        self.srid = geom.srid
        self.geography = geography
        self._adapter = Binary(self.ewkb) 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:10,代碼來源:adapter.py

示例4: testBinary

# 需要導入模塊: import psycopg2 [as 別名]
# 或者: from psycopg2 import Binary [as 別名]
def testBinary(self):
        if sys.version_info[0] < 3:
            s = ''.join([chr(x) for x in range(256)])
            b = psycopg2.Binary(s)
            buf = self.execute("SELECT %s::bytea AS foo", (b,))
            self.assertEqual(s, str(buf))
        else:
            s = bytes(range(256))
            b = psycopg2.Binary(s)
            buf = self.execute("SELECT %s::bytea AS foo", (b,))
            self.assertEqual(s, buf.tobytes()) 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:13,代碼來源:test_types_basic.py

示例5: testBinaryNone

# 需要導入模塊: import psycopg2 [as 別名]
# 或者: from psycopg2 import Binary [as 別名]
def testBinaryNone(self):
        b = psycopg2.Binary(None)
        buf = self.execute("SELECT %s::bytea AS foo", (b,))
        self.assertEqual(buf, None) 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:6,代碼來源:test_types_basic.py

示例6: testBinaryEmptyString

# 需要導入模塊: import psycopg2 [as 別名]
# 或者: from psycopg2 import Binary [as 別名]
def testBinaryEmptyString(self):
        # test to make sure an empty Binary is converted to an empty string
        if sys.version_info[0] < 3:
            b = psycopg2.Binary('')
            self.assertEqual(str(b), "''::bytea")
        else:
            b = psycopg2.Binary(bytes([]))
            self.assertEqual(str(b), "''::bytea") 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:10,代碼來源:test_types_basic.py

示例7: testBinaryRoundTrip

# 需要導入模塊: import psycopg2 [as 別名]
# 或者: from psycopg2 import Binary [as 別名]
def testBinaryRoundTrip(self):
        # test to make sure buffers returned by psycopg2 are
        # understood by execute:
        if sys.version_info[0] < 3:
            s = ''.join([chr(x) for x in range(256)])
            buf = self.execute("SELECT %s::bytea AS foo", (psycopg2.Binary(s),))
            buf2 = self.execute("SELECT %s::bytea AS foo", (buf,))
            self.assertEqual(s, str(buf2))
        else:
            s = bytes(range(256))
            buf = self.execute("SELECT %s::bytea AS foo", (psycopg2.Binary(s),))
            buf2 = self.execute("SELECT %s::bytea AS foo", (buf,))
            self.assertEqual(s, buf2.tobytes()) 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:15,代碼來源:test_types_basic.py


注:本文中的psycopg2.Binary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。