通过从分号中分离,从单个查询中删除多个表 [英] Delete multiple tables from a single query by separating from semicolon

查看:210
本文介绍了通过从分号中分离,从单个查询中删除多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从sqlite中删除一个操作中的多个表。我尝试用分号分隔它,但它没有按预期工作。这是我当前的代码:

I am trying to delete multiple tables in a single operation from sqlite. I tried separating it by semicolon but it didn't work out as expected. Here is my current code :

NSString *query = @"DELETE from Friends;DELETE from Stream;DELETE from Version";

我需要一些关于这里可能出现问题的指导,或者我是否遗漏了什么。

I need some guidance on what could the problem be here, or if I am missing something.

推荐答案

要从多个语句中进行原子操作,请使用事务:

To make an atomic operation out of multiple statements, use a transaction:

BEGIN;
DELETE FROM Friends;
DELETE FROM Stream;
DELETE FROM Version;
COMMIT;

如果你正在使用 sqlite3_prepare_v2 ;使用 sqlite3_exec ,您可以通过一次调用执行它们(但 sqlite3_exec 不支持SQL参数。)

You have to execute these five commands one by one if you're using sqlite3_prepare_v2; with sqlite3_exec, you can execute them with one call (but sqlite3_exec would not support SQL parameters).

这篇关于通过从分号中分离,从单个查询中删除多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆