~pythoneers/ubuntu/lucid/psycopg2/ltsppa

« back to all changes in this revision

Viewing changes to psycopg/connection_type.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2009-08-27 18:05:48 UTC
  • mto: (5.1.5 squeeze)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20090827180548-tdi2cwhw4kfs38sq
Tags: upstream-2.0.12
ImportĀ upstreamĀ versionĀ 2.0.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
231
231
    return PyInt_FromLong((long)PQtransactionStatus(self->pgconn));
232
232
}
233
233
 
 
234
/* get_parameter_status method - Get server parameter status */
 
235
 
 
236
#define psyco_conn_get_parameter_status_doc \
 
237
"get_parameter_status(parameter) -- Get backend parameter status.\n\n" \
 
238
"Potential values for ``parameter``:\n" \
 
239
"  server_version, server_encoding, client_encoding, is_superuser,\n" \
 
240
"  session_authorization, DateStyle, TimeZone, integer_datetimes,\n" \
 
241
"  and standard_conforming_strings\n" \
 
242
"If server did not report requested parameter, None is returned.\n\n" \
 
243
"See libpq docs for PQparameterStatus() for further details."
 
244
 
 
245
static PyObject *
 
246
psyco_conn_get_parameter_status(connectionObject *self, PyObject *args)
 
247
{
 
248
    const char *param = NULL;
 
249
    const char *val = NULL;
 
250
 
 
251
    EXC_IF_CONN_CLOSED(self);
 
252
 
 
253
    if (!PyArg_ParseTuple(args, "s", &param)) return NULL;
 
254
 
 
255
    val = PQparameterStatus(self->pgconn, param);
 
256
    if (!val) {
 
257
        Py_INCREF(Py_None);
 
258
        return Py_None;
 
259
    }
 
260
    return PyString_FromString(val);
 
261
}
 
262
 
 
263
 
234
264
/* lobject method - allocate a new lobject */
235
265
 
236
266
#define psyco_conn_lobject_doc \
321
351
    return PyInt_FromLong((long)PQbackendPID(self->pgconn));
322
352
}
323
353
 
 
354
/* reset the currect connection */
 
355
 
 
356
#define psyco_conn_reset_doc \
 
357
"reset() -- Reset current connection to defaults."
 
358
 
 
359
static PyObject *
 
360
psyco_conn_reset(connectionObject *self)
 
361
{
 
362
    int res;
 
363
 
 
364
    EXC_IF_CONN_CLOSED(self);
 
365
 
 
366
    if (pq_reset(self) < 0)
 
367
        return NULL;
 
368
 
 
369
    pthread_mutex_lock(&self->lock);
 
370
    res = conn_setup(self, self->pgconn);
 
371
    pthread_mutex_unlock(&self->lock);
 
372
    if (res < 0)
 
373
        return NULL;
 
374
 
 
375
    Py_INCREF(Py_None);
 
376
    return Py_None;
 
377
}
 
378
 
324
379
#endif
325
380
 
326
381
static PyObject *
353
408
     METH_VARARGS, psyco_conn_set_client_encoding_doc},
354
409
    {"get_transaction_status", (PyCFunction)psyco_conn_get_transaction_status,
355
410
     METH_VARARGS, psyco_conn_get_transaction_status_doc},
 
411
    {"get_parameter_status", (PyCFunction)psyco_conn_get_parameter_status,
 
412
     METH_VARARGS, psyco_conn_get_parameter_status_doc},
356
413
    {"get_backend_pid", (PyCFunction)psyco_conn_get_backend_pid,
357
414
     METH_NOARGS, psyco_conn_get_backend_pid_doc},
358
415
    {"lobject", (PyCFunction)psyco_conn_lobject,
359
416
     METH_VARARGS|METH_KEYWORDS, psyco_conn_lobject_doc},
 
417
    {"reset", (PyCFunction)psyco_conn_reset,
 
418
     METH_NOARGS, psyco_conn_reset_doc},
360
419
#endif
361
420
    {NULL}
362
421
};
383
442
        "A set of typecasters to convert textual values."},
384
443
    {"binary_types", T_OBJECT, offsetof(connectionObject, binary_types), RO,
385
444
        "A set of typecasters to convert binary values."},
 
445
    {"protocol_version", T_INT,
 
446
        offsetof(connectionObject, protocol), RO,
 
447
        "Protocol version (2 or 3) used for this connection."},
 
448
    {"server_version", T_INT,
 
449
        offsetof(connectionObject, server_version), RO,
 
450
        "Server version."},
386
451
#endif
387
452
    {NULL}
388
453
};
430
495
    self->mark = 0;
431
496
    self->string_types = PyDict_New();
432
497
    self->binary_types = PyDict_New();
 
498
    self->notice_pending = NULL;
 
499
    self->encoding = NULL;
433
500
 
434
501
    pthread_mutex_init(&(self->lock), NULL);
435
502
 
459
526
connection_dealloc(PyObject* obj)
460
527
{
461
528
    connectionObject *self = (connectionObject *)obj;
 
529
    
 
530
    PyObject_GC_UnTrack(self);
462
531
 
463
532
    if (self->closed == 0) conn_close(self);
 
533
    
 
534
    conn_notice_clean(self);
464
535
 
465
536
    if (self->dsn) free(self->dsn);
466
537
    if (self->encoding) free(self->encoding);
467
538
    if (self->critical) free(self->critical);
468
539
 
 
540
    Py_CLEAR(self->async_cursor);
469
541
    Py_CLEAR(self->notice_list);
 
542
    Py_CLEAR(self->notice_filter);
470
543
    Py_CLEAR(self->notifies);
471
 
    Py_CLEAR(self->async_cursor);
472
544
    Py_CLEAR(self->string_types);
473
545
    Py_CLEAR(self->binary_types);
474
546