diff options
| author | Jan UrbaĆski <wulczer@wulczer.org> | 2010-03-29 00:42:56 +0200 |
|---|---|---|
| committer | Federico Di Gregorio <fog@initd.org> | 2010-03-29 09:19:35 +0200 |
| commit | e0d789466a818762c929ec30aa1c2aee684bb742 (patch) | |
| tree | f06f1ce02e537aaa5842cee6da498b6af8cc7cb4 /psycopg/lobject_int.c | |
| parent | 0edd52059300228b6df8813c9c55191e69f1412d (diff) | |
| download | psycopg2-e0d789466a818762c929ec30aa1c2aee684bb742.tar.gz | |
Support large objects truncating.
The lobject.truncate(len=0) method will be available if psycopg2 has
been built against libpq from 8.3 or later (which is when the lobject
truncating support has been introduced).
Diffstat (limited to 'psycopg/lobject_int.c')
| -rw-r--r-- | psycopg/lobject_int.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/psycopg/lobject_int.c b/psycopg/lobject_int.c index a66c72b..0b38325 100644 --- a/psycopg/lobject_int.c +++ b/psycopg/lobject_int.c @@ -333,6 +333,36 @@ lobject_export(lobjectObject *self, const char *filename) return retvalue; } +#if PG_VERSION_HEX >= 0x080300 + +int +lobject_truncate(lobjectObject *self, size_t len) +{ + int retvalue; + PGresult *pgres = NULL; + char *error = NULL; + + Dprintf("lobject_truncate: fd = %d, len = %d", + self->fd, len); + + Py_BEGIN_ALLOW_THREADS; + pthread_mutex_lock(&(self->conn->lock)); + + retvalue = lo_truncate(self->conn->pgconn, self->fd, len); + Dprintf("lobject_truncate: result = %d", retvalue); + if (retvalue < 0) + collect_error(self->conn, &error); + + pthread_mutex_unlock(&(self->conn->lock)); + Py_END_ALLOW_THREADS; + + if (retvalue < 0) + pq_complete_error(self->conn, &pgres, &error); + return retvalue; + +} + +#endif /* PG_VERSION_HEX >= 0x080300 */ #endif |
