当前位置: 首页>>代码示例>>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;未经允许,请勿转载。