我試圖在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
您是否閱讀過相關的代碼? –
添加評論有問題... –