/* libdatabase_database_query */ static PyObject * _libdatabase_database_query(PyObject * self, PyObject * args) { Database * database; char const * query; int ret; if(!PyArg_ParseTuple(args, "Os", &self, &query)) return NULL; if((database = PyCapsule_GetPointer(self, _libdatabase_database_name)) == NULL) return NULL; /* FIXME implement the callbacks one way or another */ ret = database_query(database, query, NULL, NULL); return Py_BuildValue("i", ret); }
int groups_load_list() { sqlite3_stmt *groups = database_query("SELECT * FROM groups ORDER BY group_id DESC LIMIT 3"); int count = 0; while(sqlite3_step(groups)==SQLITE_ROW) { if(groups_list == NULL) { groups_list = malloc(sizeof(struct groups_node)); groups_list->caption = malloc(500); groups_list->name = malloc(16); memset(groups_list->caption,'\0',500); memset(groups_list->name,'\0',16); groups_list->id = sqlite3_column_int(groups,0); strcpy(groups_list->name, (char*)sqlite3_column_text(groups,1)); strcpy(groups_list->caption, (char*)sqlite3_column_text(groups,2)); groups_list->next = NULL; } else { struct groups_node *temp = malloc(sizeof(struct groups_node)); temp->caption = malloc(500); temp->name = malloc(16); memset(temp->name,'\0',16); memset(temp->caption,'\0',500); temp->id = sqlite3_column_int(groups,0); strcpy(temp->name, (char*)sqlite3_column_text(groups,1)); strcpy(temp->caption, (char*)sqlite3_column_text(groups,2)); temp->next = groups_list; groups_list = temp; } count++; } groups_count = count; return count; }