diff --git a/src/python/libDatabase.c b/src/python/libDatabase.c index f4db103..dcd9ede 100644 --- a/src/python/libDatabase.c +++ b/src/python/libDatabase.c @@ -30,12 +30,17 @@ static char const _libdatabase_database_name[] = "libDatabase::Database"; static PyObject * _libdatabase_database_new(PyObject * self, PyObject * args); static void _libdatabase_database_delete(PyObject * self); +static PyObject * _libdatabase_database_get_last_id(PyObject * self, + PyObject * args); + /* variables */ static PyMethodDef _libdatabase_methods[] = { { "database_new", _libdatabase_database_new, METH_VARARGS, "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 } }; @@ -83,3 +88,20 @@ static void _libdatabase_database_delete(PyObject * self) return; 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); +} diff --git a/src/python/libDatabase.py b/src/python/libDatabase.py index 58bfa9d..cd8bfb4 100644 --- a/src/python/libDatabase.py +++ b/src/python/libDatabase.py @@ -23,3 +23,6 @@ import _libDatabase class Database: def __init__(self, engine, section): self.database = _libDatabase.database_new(engine, section) + + def getLastId(self): + return database.database_get_last_id(self.database)