diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2018-07-24 19:17:07 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2018-07-24 21:16:36 +0100 |
commit | 97a4fb92c621416ac16738c1915efe0a1051faa7 (patch) | |
tree | 11012959469058891c027db3b5d8b0f8cd6cbb47 | |
parent | 466efe4461e5bb5f635f0121734d6c2ae520f459 (diff) | |
download | psycopg2-fix-746.tar.gz |
Fixed compile error on windowsfix-746
Because const int + 1 is not const, right???
Also fixed other occurrences of magic numbers and failed DRY around
PyOS_snprintf() calls.
-rw-r--r-- | psycopg/cursor_type.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 14647a4..5920c12 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -61,8 +61,7 @@ psyco_curs_close(cursorObject *self) } if (self->qname != NULL) { - const int bufsize = 255; - char buffer[bufsize + 1]; + char buffer[256]; PGTransactionStatusType status; if (self->conn) { @@ -91,7 +90,7 @@ psyco_curs_close(cursorObject *self) self->conn, self->name, -1, NULL, NULL))) { goto exit; } - PyOS_snprintf(buffer, bufsize, + PyOS_snprintf(buffer, sizeof(buffer), "SELECT 1 FROM pg_catalog.pg_cursors where name = %s", lname); if (pq_execute(self, buffer, 0, 0, 1) == -1) { goto exit; } @@ -103,7 +102,7 @@ psyco_curs_close(cursorObject *self) } EXC_IF_NO_MARK(self); - PyOS_snprintf(buffer, bufsize, "CLOSE %s", self->qname); + PyOS_snprintf(buffer, sizeof(buffer), "CLOSE %s", self->qname); if (pq_execute(self, buffer, 0, 0, 1) == -1) { goto exit; } } @@ -771,7 +770,7 @@ psyco_curs_fetchone(cursorObject *self) EXC_IF_NO_MARK(self); EXC_IF_ASYNC_IN_PROGRESS(self, fetchone); EXC_IF_TPC_PREPARED(self->conn, fetchone); - PyOS_snprintf(buffer, 127, "FETCH FORWARD 1 FROM %s", self->qname); + PyOS_snprintf(buffer, sizeof(buffer), "FETCH FORWARD 1 FROM %s", self->qname); if (pq_execute(self, buffer, 0, 0, self->withhold) == -1) return NULL; if (_psyco_curs_prefetch(self) < 0) return NULL; } @@ -820,7 +819,7 @@ psyco_curs_next_named(cursorObject *self) if (self->row >= self->rowcount) { char buffer[128]; - PyOS_snprintf(buffer, 127, "FETCH FORWARD %ld FROM %s", + PyOS_snprintf(buffer, sizeof(buffer), "FETCH FORWARD %ld FROM %s", self->itersize, self->qname); if (pq_execute(self, buffer, 0, 0, self->withhold) == -1) return NULL; if (_psyco_curs_prefetch(self) < 0) return NULL; @@ -889,7 +888,7 @@ psyco_curs_fetchmany(cursorObject *self, PyObject *args, PyObject *kwords) EXC_IF_NO_MARK(self); EXC_IF_ASYNC_IN_PROGRESS(self, fetchmany); EXC_IF_TPC_PREPARED(self->conn, fetchone); - PyOS_snprintf(buffer, 127, "FETCH FORWARD %d FROM %s", + PyOS_snprintf(buffer, sizeof(buffer), "FETCH FORWARD %d FROM %s", (int)size, self->qname); if (pq_execute(self, buffer, 0, 0, self->withhold) == -1) { goto exit; } if (_psyco_curs_prefetch(self) < 0) { goto exit; } @@ -965,7 +964,7 @@ psyco_curs_fetchall(cursorObject *self) EXC_IF_NO_MARK(self); EXC_IF_ASYNC_IN_PROGRESS(self, fetchall); EXC_IF_TPC_PREPARED(self->conn, fetchall); - PyOS_snprintf(buffer, 127, "FETCH FORWARD ALL FROM %s", self->qname); + PyOS_snprintf(buffer, sizeof(buffer), "FETCH FORWARD ALL FROM %s", self->qname); if (pq_execute(self, buffer, 0, 0, self->withhold) == -1) { goto exit; } if (_psyco_curs_prefetch(self) < 0) { goto exit; } } @@ -1262,11 +1261,11 @@ psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs) EXC_IF_TPC_PREPARED(self->conn, scroll); if (strcmp(mode, "absolute") == 0) { - PyOS_snprintf(buffer, 127, "MOVE ABSOLUTE %d FROM %s", + PyOS_snprintf(buffer, sizeof(buffer), "MOVE ABSOLUTE %d FROM %s", value, self->qname); } else { - PyOS_snprintf(buffer, 127, "MOVE %d FROM %s", value, self->qname); + PyOS_snprintf(buffer, sizeof(buffer), "MOVE %d FROM %s", value, self->qname); } if (pq_execute(self, buffer, 0, 0, self->withhold) == -1) return NULL; if (_psyco_curs_prefetch(self) < 0) return NULL; |