Added Database::getLastId()
This commit is contained in:
parent
7d823fc736
commit
c37190350a
|
@ -30,12 +30,17 @@ static char const _libdatabase_database_name[] = "libDatabase::Database";
|
||||||
static PyObject * _libdatabase_database_new(PyObject * self, PyObject * args);
|
static PyObject * _libdatabase_database_new(PyObject * self, PyObject * args);
|
||||||
static void _libdatabase_database_delete(PyObject * self);
|
static void _libdatabase_database_delete(PyObject * self);
|
||||||
|
|
||||||
|
static PyObject * _libdatabase_database_get_last_id(PyObject * self,
|
||||||
|
PyObject * args);
|
||||||
|
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
static PyMethodDef _libdatabase_methods[] =
|
static PyMethodDef _libdatabase_methods[] =
|
||||||
{
|
{
|
||||||
{ "database_new", _libdatabase_database_new, METH_VARARGS,
|
{ "database_new", _libdatabase_database_new, METH_VARARGS,
|
||||||
"Instantiates a Database object." },
|
"Instantiates a Database object." },
|
||||||
|
{ "database_get_last_id", _libdatabase_database_get_last_id,
|
||||||
|
METH_VARARGS, "Obtain the ID of the latest row inserted." },
|
||||||
{ NULL, NULL, 0, NULL }
|
{ NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,3 +88,20 @@ static void _libdatabase_database_delete(PyObject * self)
|
||||||
return;
|
return;
|
||||||
database_delete(database);
|
database_delete(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* libdatabase_database_get_last_id */
|
||||||
|
static PyObject * _libdatabase_database_get_last_id(PyObject * self,
|
||||||
|
PyObject * args)
|
||||||
|
{
|
||||||
|
Database * database;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if((database = PyCapsule_GetPointer(self, _libdatabase_database_name))
|
||||||
|
== NULL)
|
||||||
|
return NULL;
|
||||||
|
if(!PyArg_ParseTuple(args, ""))
|
||||||
|
return NULL;
|
||||||
|
ret = database_get_last_id(database);
|
||||||
|
return Py_BuildValue("i", ret);
|
||||||
|
}
|
||||||
|
|
|
@ -23,3 +23,6 @@ import _libDatabase
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, engine, section):
|
def __init__(self, engine, section):
|
||||||
self.database = _libDatabase.database_new(engine, section)
|
self.database = _libDatabase.database_new(engine, section)
|
||||||
|
|
||||||
|
def getLastId(self):
|
||||||
|
return database.database_get_last_id(self.database)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user