Am 09.06.2019 um 00:38 schrieb Justin Pryzby:
> I see this interface has been around since PyGreSQL 3.1 (c. 2000),
> but "source objects" are not documented.
>
> I'm referring to these:
> |pg.DB('postgres').source()
> |pg.connect('postgres').source()

This is deliberate. It's an internal object that should be considered an implementation detail of the DB-API 2 interface. We don't want to make it an official API.

> Also, I noticed this behaves strangely:
>>>> pg.DB('postgres').source()
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> pg.OperationalError: Connection has been closed

This is probably because the db object immediately gets out of scope and its connection gets closed, so the source object cannot work.

You need to keep the db object alive, e.g. like this:

with pg.DB('postgres') as db:

    source = db.source()
    source.execute("select 'source'")
    print(source.fetch(1))
    source.close()

    query = db.query("select 'query'")
    print(query.getresult())

But again, use the source() at your own risk, Luke!

-- Christoph
_______________________________________________
PyGreSQL mailing list
PyGreSQL@Vex.Net
https://mail.vex.net/mailman/listinfo/pygresql

Reply via email to