def io_file_set(self, path, content): assert not os.path.isabs(path) assert not path.endswith("-tmp") c = self._sqlconn.cursor() q = "SELECT set_files(%s, %s, %s)" c.execute(q, (path, len(content), pg8000.Binary(content))) c.close()
def write_changelog_entry(self, serial, entry): threadlog.debug("writing changelog for serial %s", serial) data = dumps(entry) c = self._sqlconn.cursor() c.execute("INSERT INTO changelog (serial, data) VALUES (%s, %s)", (serial, pg8000.Binary(data))) c.close() self._sqlconn.commit()
def testBinaryOutputMethods(self): methods = ( ("float8send", 22.2), ("timestamp_send", datetime.datetime(2001, 2, 3, 4, 5, 6, 789)), ("byteasend", pg8000.Binary(b("\x01\x02"))), ("interval_send", pg8000.Interval(1234567, 123, 123)),) for method_out, value in methods: self.cursor.execute("SELECT %s(%%s) as f1" % method_out, (value,)) retval = self.cursor.fetchall() self.assertEqual( retval[0][0], self.db.make_params((value,))[0][2](value))
def test_binary_output_methods(con): with con.cursor() as cursor: methods = ( ("float8send", 22.2), ("timestamp_send", Datetime(2001, 2, 3, 4, 5, 6, 789)), ("byteasend", pg8000.Binary(b"\x01\x02")), ("interval_send", pg8000.Interval(1234567, 123, 123)),) for method_out, value in methods: cursor.execute("SELECT %s(%%s) as f1" % method_out, (value,)) retval = cursor.fetchall() assert retval[0][0] == con.make_params((value,))[0][2](value)
def io_file_set(self, path, content): assert not os.path.isabs(path) assert not path.endswith("-tmp") c = self._sqlconn.cursor() q = """ INSERT INTO files(path, size, data) VALUES (%s, %s, %s) ON CONFLICT (path) DO UPDATE SET size = EXCLUDED.size, data = EXCLUDED.data;""" c.execute(q, (path, len(content), pg8000.Binary(content))) c.close() self.dirty_files[path] = content
def test_bytea_roundtrip(con): retval = con.run("SELECT cast(:v as bytea)", v=pg8000.Binary(b"\x00\x01\x02\x03\x02\x01\x00")) assert retval[0][0] == b"\x00\x01\x02\x03\x02\x01\x00"
def testByteaRoundtrip(self): self.cursor.execute( "SELECT %s as f1", (pg8000.Binary(b("\x00\x01\x02\x03\x02\x01\x00")), )) retval = self.cursor.fetchall() self.assertEqual(retval[0][0], b("\x00\x01\x02\x03\x02\x01\x00"))
def test_binary(): v = pg8000.Binary(b"\x00\x01\x02\x03\x02\x01\x00") assert v == b"\x00\x01\x02\x03\x02\x01\x00" assert isinstance(v, pg8000.BINARY)
def testBinary(self): v = pg8000.Binary(b("\x00\x01\x02\x03\x02\x01\x00")) self.assertEqual(v, b("\x00\x01\x02\x03\x02\x01\x00")) self.assertTrue(isinstance(v, pg8000.BINARY))
def test_bytea_roundtrip(cursor): cursor.execute( "SELECT %s as f1", (pg8000.Binary(b"\x00\x01\x02\x03\x02\x01\x00"),)) retval = cursor.fetchall() assert retval[0][0] == b"\x00\x01\x02\x03\x02\x01\x00"
def test_bytea_roundtrip(cursor): cursor.execute("SELECT cast(%s as bytea)", (pg8000.Binary(b"\x00\x01\x02\x03\x02\x01\x00"), )) assert cursor.fetchall()[0][0] == b"\x00\x01\x02\x03\x02\x01\x00"