我试图在CKAN(ckan.org)中使用datastore_api并想要删除ID高于X的所有记录 - 我的目标是简单地删除所有记录删除表格。删除CKAN中ID高于X的所有记录
运行API与
'filters': {'_id': '0'}
的工作,但设置
{'_id': '>0'}
或
{'_id': '*'} fails.
如何在不删除表的情况下清空数据存储中的表?
在CKAN生成的SQL是:
...9b89-7ab1c36c8e00" WHERE ("_id" = '*') ...
所以很有意义失败的原因,但我不知道如何使用通配符两种或API调用“高于”。
这似乎是代码:
def delete_data(context, data_dict):
validate(context, data_dict)
fields_types = _get_fields_types(context, data_dict)
query_dict = {
'where': []
}
for plugin in p.PluginImplementations(interfaces.IDatastore):
query_dict = plugin.datastore_delete(context, data_dict,
fields_types, query_dict)
where_clause, where_values = _where(query_dict['where'])
sql_string = u'DELETE FROM "{0}" {1}'.format(
data_dict['resource_id'],
where_clause
)
_execute_single_statement(context, sql_string, where_values)
...
def _where(where_clauses_and_values):
'''Return a SQL WHERE clause from list with clauses and values
:param where_clauses_and_values: list of tuples with format
(where_clause, param1, ...)
:type where_clauses_and_values: list of tuples
:returns: SQL WHERE string with placeholders for the parameters, and list
of parameters
:rtype: string
'''
where_clauses = []
values = []
for clause_and_values in where_clauses_and_values:
where_clauses.append('(' + clause_and_values[0] + ')')
values += clause_and_values[1:]
where_clause = u' AND '.join(where_clauses)
if where_clause:
where_clause = u'WHERE ' + where_clause
return where_clause, values
您是否阅读过相关的代码? –
添加评论有问题... –