Exemple #1
0
 def testBinaryRoundTrip(self):
     # test to make sure buffers returned by psycopg2 are
     # understood by execute:
     s = list2bytes(range(256))
     buf = self.execute("SELECT %s::bytea AS foo", (psycopg2.Binary(s),))
     buf2 = self.execute("SELECT %s::bytea AS foo", (buf,))
     self.failUnless(asbytes(buf2) == s, "wrong binary quoting")
Exemple #2
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)
Exemple #3
0
 def testBinary(self):
     s = list2bytes(range(256))
     b = psycopg2.Binary(s)
     buf = self.execute("SELECT %s::bytea AS foo", (b,))
     self.failUnless(asbytes(buf) == s, "wrong binary quoting")