Closed JetDrag closed 7 years ago
Thanks for the PR. Can you help me understand by answering my comment ?
When there're no posts in databases, if you browse blog index page, the 'index' function in 'view.py' will get the meta info below:
Line 114 in 'view.py' : meta = _get_meta(storage, count, page)
the meta's value:
{'count': 10, 'pagination': {'prev_page': None, 'next_page': None}, 'offset': -10, 'page': 1, 'max_pages': 0, 'max_posts': 0, 'max_offset': -10}
When SQLAStorage
obj invokes get_posts
method (Line 231 in 'sqlastorage.py')by using the meta info and the backend database is MySQL, an error will raise:
Traceback (most recent call last): File "/home/user00/.virtualenvs/yuqing_site/lib/python3.4/site-packages/flask_blogging/sqlastorage.py", line 272, in get_posts result = conn.execute(select_statement).fetchall()
......
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10, 10' at line 4") [SQL: 'SELECT post.id \nFROM post \nWHERE post.draft = %(draft_1)s ORDER BY post.post_date DESC \n LIMIT %(param_1)s, %(param_2)s'] [parameters: {'param_1': -10, 'param_2': 10, 'draft_1': 0}]
The reason of the error is that negative offset is not allowed in MySQL and pgSQL expression , and ignored in SQLite. So I open a pr to make sure the offset value is positive.
Ah! Thats great info. Thanks.
Fix the problem that negative offset is not allowed in pgsql and mysql.