示例#1
0
    def test_binary(self):
        data = str2bytes("""some data with \000\013 binary
        stuff into, 'quotes' and \\ a backslash too.
        """)
        data += list2bytes(range(256))

        curs = self.conn.cursor()
        curs.execute("SELECT %s::bytea;", (psycopg2.Binary(data),))
        res = asbytes(curs.fetchone()[0])

        self.assertEqual(res, data)
        self.assert_(not self.conn.notices)
示例#2
0
 def testBinaryEmptyString(self):
     # test to make sure an empty Binary is converted to an empty string
     b = psycopg2.Binary(str2bytes(''))
     self.assertEqual(str(b), "''")