예제 #1
0
파일: cmd.c 프로젝트: fbessho/python-sybase
PyObject *cmd_alloc(CS_CONNECTIONObj *conn)
{
    CS_COMMANDObj *self;
    CS_RETCODE status;
    CS_COMMAND *cmd;

    self = PyObject_NEW(CS_COMMANDObj, &CS_COMMANDType);
    if (self == NULL)
	return NULL;
    SY_LEAK_REG(self);
    self->is_eed = 0;
    self->cmd = NULL;
    self->conn = NULL;
    self->strip = conn->strip;
    self->debug = conn->debug;
    self->serial = cmd_serial++;

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(conn);
    status = ct_cmd_alloc(conn->conn, &cmd);
    SY_CONN_END_THREADS(conn);

    if (self->debug)
	debug_msg("ct_cmd_alloc(conn%d, &cmd) -> %s",
		  conn->serial, value_str(VAL_STATUS, status));
    if (PyErr_Occurred()) {
	if (self->debug)
	    debug_msg("\n");
	Py_DECREF(self);
	return NULL;
    }

    if (status != CS_SUCCEED) {
	Py_DECREF(self);
	if (self->debug)
	    debug_msg(", None\n");
	return Py_BuildValue("iO", status, Py_None);
    }

    self->cmd = cmd;
    self->conn = conn;
    Py_INCREF(self->conn);
    if (self->debug)
	debug_msg(", cmd%d\n", self->serial);
    return Py_BuildValue("iN", CS_SUCCEED, self);
}
예제 #2
0
파일: datetime.c 프로젝트: sparcs-kaist/otl
PyObject *datetime_alloc(void *value, int type)
{
    DateTimeObj *self;

    self = PyObject_NEW(DateTimeObj, &DateTimeType);
    if (self == NULL)
	return NULL;

    SY_LEAK_REG(self);
    self->type = type;
    if (type == CS_DATETIME_TYPE)
	memcpy(&self->v.datetime, value, sizeof(self->v.datetime));
    else
	memcpy(&self->v.datetime4, value, sizeof(self->v.datetime4));
    memset(&self->daterec, 0, sizeof(self->daterec));
    self->cracked = 0;
    return (PyObject*)self;
}
예제 #3
0
파일: cmd.c 프로젝트: fbessho/python-sybase
PyObject *cmd_eed(CS_CONNECTIONObj *conn, CS_COMMAND *eed)
{
    CS_COMMANDObj *self;

    self = PyObject_NEW(CS_COMMANDObj, &CS_COMMANDType);
    if (self == NULL)
	return NULL;

    SY_LEAK_REG(self);
    self->is_eed = 1;
    self->cmd = eed;
    self->conn = conn;
    Py_INCREF(self->conn);

    self->strip = 0;
    self->debug = conn->debug;
    self->serial = cmd_serial++;

    return (PyObject*)self;
}
예제 #4
0
파일: databuf.c 프로젝트: sparcs-kaist/otl
PyObject *databuf_alloc(PyObject *obj)
{
    DataBufObj *self;

    self = PyObject_NEW(DataBufObj, &DataBufType);
    if (self == NULL)
	return NULL;

    SY_LEAK_REG(self);
    self->buff = NULL;
    self->copied = NULL;
    self->indicator = NULL;
    self->serial = databuf_serial++;

    if (CS_DATAFMT_Check(obj)) {
	self->strip = ((CS_DATAFMTObj*)obj)->strip;
	self->fmt = ((CS_DATAFMTObj*)obj)->fmt;
	if (self->fmt.count == 0)
	    self->fmt.count = 1;

	/* Seems like FreeTDS reports the wrong maxlength in
	 * ct_describe() - fix this when binding to a buffer.
	 */
	/* Seems like Sybase's blk_describe has the same problem - PCP */ 
	if (self->fmt.datatype == CS_NUMERIC_TYPE
	    || self->fmt.datatype == CS_DECIMAL_TYPE)
	    self->fmt.maxlength = sizeof(CS_NUMERIC);

	if (allocate_buffers(self) == NULL) {
	    Py_DECREF(self);
	    return NULL;
	}
    } else {
	if (PyInt_Check(obj) || obj == Py_None)
	    /* if (PyInt_AsLong(obj) <= INT32_MAX && PyInt_AsLong(obj) >= INT32_MIN) */
	    int_datafmt(&self->fmt);
	else if (PyLong_Check(obj))
	    numeric_datafmt(&self->fmt, CS_SRC_VALUE, 0);
	else if (PyFloat_Check(obj))
	    float_datafmt(&self->fmt);
	else if (Numeric_Check(obj))
	    numeric_datafmt(&self->fmt, CS_SRC_VALUE, CS_SRC_VALUE);
	else if (DateTime_Check(obj))
	    datetime_datafmt(&self->fmt, ((DateTimeObj*)obj)->type);
#ifdef CS_DATE_TYPE
	else if (Date_Check(obj))
	    date_datafmt(&self->fmt);
#endif
	else if (Money_Check(obj))
	    money_datafmt(&self->fmt, ((MoneyObj*)obj)->type);
	else if (PyString_Check(obj)) {
	    char_datafmt(&self->fmt);
	    self->fmt.maxlength = PyString_Size(obj) + 1;
#ifdef HAVE_DATETIME
	} else if (pydatetime_check(obj)) {
	    datetime_datafmt(&self->fmt, CS_DATETIME_TYPE);
	} else if (pydate_check(obj)) {
#ifdef CS_DATE_TYPE
	    date_datafmt(&self->fmt);
#else
	    datetime_datafmt(&self->fmt, CS_DATETIME_TYPE);
#endif
#endif
#ifdef HAVE_DECIMAL
	} else if (pydecimal_check(obj)) {
	    numeric_datafmt(&self->fmt, CS_SRC_VALUE, CS_SRC_VALUE);
#endif
	} else {
	    PyErr_SetString(PyExc_TypeError, "unsupported parameter type");
	    Py_DECREF(self);
	    return NULL;
	}
	self->fmt.status = CS_INPUTVALUE;
	self->fmt.count = 1;

	if (allocate_buffers(self) == NULL
	    || DataBuf_ass_item((PyObject*)self, 0, obj) < 0) {
	    Py_DECREF(self);
	    return NULL;
	}
    }

    return (PyObject*)self;
}