mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-29 12:23:42 +03:00
.connect() port parameter as string or int (closes: #120).
This commit is contained in:
parent
f88b973bd1
commit
ec865ae932
|
@ -1,5 +1,9 @@
|
|||
2006-09-01 Federico Di Gregorio <fog@initd.org>
|
||||
|
||||
* psycopg/psycopgmodule.c: applied patch from jdahlin (#120)
|
||||
to have .connect() accept either a string or int as the port
|
||||
parameter.
|
||||
|
||||
* psycopg/adapter_binary.c: applied patch from jdahlin (#119)
|
||||
to fix the segfault on empty binary buffers.
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ static PyObject *
|
|||
psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
PyObject *conn, *factory = NULL;
|
||||
PyObject *pyport = NULL;
|
||||
|
||||
int idsn=-1, iport=-1;
|
||||
char *dsn=NULL, *database=NULL, *user=NULL, *password=NULL;
|
||||
|
@ -134,12 +135,25 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
|
|||
"user", "password", "sslmode",
|
||||
"connection_factory", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sssisssO", kwlist,
|
||||
&dsn, &database, &host, &iport,
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sssOsssO", kwlist,
|
||||
&dsn, &database, &host, &pyport,
|
||||
&user, &password, &sslmode, &factory)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pyport && PyString_Check(pyport)) {
|
||||
PyObject *pyint = PyInt_FromString(PyString_AsString(pyport), NULL, 10);
|
||||
if (!pyint) return NULL;
|
||||
iport = PyInt_AsLong(pyint);
|
||||
}
|
||||
else if (pyport && PyInt_Check(pyport)) {
|
||||
iport = PyInt_AsLong(pyport);
|
||||
}
|
||||
else if (pyport != NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "port must be a string or int");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (iport > 0)
|
||||
PyOS_snprintf(port, 16, "%d", iport);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user