From: Charles D. <cd...@sp...> - 2006-04-11 21:05:17
|
Using the SQLObject included in TurboGears 0.9a4 (presently against the SQLite backend), I'm trying to do the following query: model.LessonPage.select(model.LessonPage.q.pageNumber == Select(func.MIN(model.LessonPage.q.pageNumber), where=model.LessonPage.q.pageNumber > page.pageNumber)) ...for which the following SQL is generated: SELECT lesson_page.id, lesson_page.child_name, lesson_page.title, lesson_page.page_number, lesson_page.lesson_id FROM lesson_page WHERE (lesson_page.page_number = SELECT MIN(lesson_page.page_number) FROM lesson_page WHERE (lesson_page.page_number > 1)) This is invalid, however, and leads to a syntax error on account of the subselect not having parenthesis around it. If I paste the query into SQLite and add an extra set of parenthesis (from just before the nested SELECT to the end of the statement), all is well. Is there a mechanism by which I can ask SQLObject to add these parens? Alternately, is the SQLite binding for SQLObject broken? If the latter is the case, is there a way to fix it? Also, is there a better way to write this query? (I'm trying to find the next page number, but there's no guarantee that pages are contiguous). |