have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':remark OR :remark IS NULL)\n AND (s.ftype_id = :ftype_id OR :ftype_' at line 8") def fetch_data_api_mode(platforms, remark, user_id=None, ftype_id=None, inviter_id=None, page=None, page_size=None): table_name_strategy_mapping = { 'okx': 'strategy_okxapimode', 'binance': 'strategy_bnapimode', # 添加其他平台的映射关系 } table_names_strategy = [table_name_strategy_mapping[p] for p in platforms] union_queries = [] for strategy in table_names_strategy: union_query = f""" SELECT s.id, s.create_time, s.update_time, s.ftype_id, s.active, s.user_id, s.platform, s.remark, s.inviter_id, s.user_id, u.username AS username, s.inviter_id, u_inviter.username AS inviter_name FROM {strategy} AS s LEFT JOIN system_user AS u ON s.user_id = u.id LEFT JOIN system_user AS u_inviter ON s.inviter_id = u_inviter.id WHERE (s.remark = :remark OR :remark IS NULL) AND (s.ftype_id = :ftype_id OR :ftype_id IS NULL) AND (s.user_id = :user_id OR :user_id IS NULL) AND (s.inviter_id = :inviter_id OR :inviter_id IS NULL) """ union_queries.append(union_query) query = f""" SELECT id, create_time, update_time, ftype_id, active, user_id, platform, remark, inviter_id, inviter_name,user_id,username FROM ({' UNION ALL '.join(union_queries)}) AS combined_tables ORDER BY create_time DESC LIMIT :page_size OFFSET :offset """ count_query = f""" SELECT COUNT(*) AS total_count FROM ({' UNION ALL '.join(union_queries)}) AS combined_tables """ query_parms = { 'remark': remark, 'ftype_id': ftype_id, 'user_id': user_id, 'inviter_id': inviter_id, 'page_size': page_size, 'offset': (page - 1) * page_size if page is not None and page_size is not None else None } result = execute_raw_sql_query(query, query_parms) count_result = execute_raw_sql_query(count_query, query_parms) return result, count_result[0]['total_count']
时间: 2024-04-12 22:30:50 浏览: 221
根据您提供的代码,错误可能是由于SQL语法问题引起的。根据错误消息,看起来是与第8行的语法有关。
在您的代码中,您使用了参数占位符(:remark,:ftype_id,:user_id,:inviter_id)。但是,根据错误消息,似乎您正在使用MySQL数据库,而MySQL使用的参数占位符不同。在MySQL中,通常使用问号占位符(?)而不是冒号(:)作为参数占位符。
要解决这个问题,您可以尝试将查询中的参数占位符更改为问号占位符,如下所示:
```python
union_query = """
SELECT s.id, s.create_time, s.update_time, s.ftype_id, s.active, s.user_id, s.platform, s.remark, s.inviter_id,
s.user_id, u.username AS username, s.inviter_id, u_inviter.username AS inviter_name
FROM {strategy} AS s
LEFT JOIN system_user AS u ON s.user_id = u.id
LEFT JOIN system_user AS u_inviter ON s.inviter_id = u_inviter.id
WHERE (s.remark = ? OR ? IS NULL)
AND (s.ftype_id = ? OR ? IS NULL)
AND (s.user_id = ? OR ? IS NULL)
AND (s.inviter_id = ? OR ? IS NULL)
"""
```
然后在执行查询时,将参数值作为一个元组传递给execute_raw_sql_query()函数:
```python
result = execute_raw_sql_query(query, (remark, ftype_id, user_id, inviter_id, page_size, (page - 1) * page_size if page is not None and page_size is not None else None))
count_result = execute_raw_sql_query(count_query, (remark, ftype_id, user_id, inviter_id))
```
请注意,我仅在这段代码中提供了更改参数占位符的示例。您还需要根据您的代码适配其他部分,以确保所有参数占位符都正确地使用了问号占位符。
希望这可以帮助您解决问题。如果问题仍然存在,请提供更多的信息,以便我可以更好地帮助您。
阅读全文