- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 FMDB 实现一个基于 SQLite 的应用程序,我需要向 SQLite 中插入大量数据,比如说 1000 行数据,但我不想一个一个地插入它们,我只想这样做使用单个查询,这会使插入进度更快,如下所示:
NSString *query = @"insert into table (c1,c2,c3,c4) values " ;
NSString *middle = @"" ;
for ( int i = 0 ; i < 1000 ; i++ ) {
NSDictionary *tmpItem = [data objectAtIndex:i] ;
if ( i == 999 ) {
middle = [NSString stringWithFormat:@"%@('%@','%@','%@','%@')", middle,[tmpItem objectForKey:@"c1"],[tmpItem objectForKey:@"c2"],[tmpItem objectForKey:@"c3"],[tmpItem objectForKey:@"c4"]] ;
}
else {
middle = [NSString stringWithFormat:@"%@('%@','%@','%@','%@') ,", middle,[tmpItem objectForKey:@"c1"],[tmpItem objectForKey:@"c2"],[tmpItem objectForKey:@"c3"],[tmpItem objectForKey:@"c4"]] ;
}
}
query = [NSString stringWithFormat:@"%@%@", query, middle] ;
[db executeUpdate:query];
上面的代码无法在“表”上插入任何数据,但是当我将for循环更改为只运行10次时,数据插入正确,这意味着没有语法错误。
我错误地尝试过,数据插入正确,for 循环设置为 i<500,而设置 i<501 时,没有插入数据。
然后我搜索http://www.sqlite.org/limits.html ,这个页面有一个Maximum Depth Of An Expression Tree,应该是我要设置的,但是在使用FMDB的时候怎么设置这个属性呢?
或者我可以插入大量数据的唯一方法就是将它们一条一条地插入?
最佳答案
您的选择并不局限于一次一个或全部。
您可以分批插入数据,这仍然会给您带来速度提升,但也更容易预测成功。更改限制仍然只是限制,仍然是限制(根据数据,您可能会遇到其他限制)。一次批处理 100 个似乎是合理的。
还要确保您没有在主 UI 线程上执行大量批处理工作。
除此之外,如果您编译自己的 sqlite 二进制文件,则您提供的 sqlite 链接具有预处理器编译设置。 FMDB 只是 sqlite 的包装器,默认情况下在 iOS 上您将获得与 iOS 打包的 sqlite。当然,您可以编译自己的并更改限制并链接到您的应用程序。
因此,您需要重新编译并链接限制为 0。请注意,运行时限制调用仅允许您降低编译限制,如果它设置为高于 0(默认为 100)
The maximum depth of an expression tree can be lowered at run-time using the sqlite3_limit(db,SQLITE_LIMIT_EXPR_DEPTH,size) interface if the SQLITE_MAX_EXPR_DEPTH is initially positive. In other words, the maximum expression depth can be lowered at run-time if there is already a compile-time limit on the expression depth. If SQLITE_MAX_EXPR_DEPTH is set to 0 at compile time (if the depth of expressions is unlimited) then the sqlite3_limit(db,SQLITE_LIMIT_EXPR_DEPTH,size) is a no-op.
关于objective-c - 如何使用FMDB SDK 更改SQLite 表达式树的最大深度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21134830/
我正在细读 http://www.khronos.org/网站,只找到了 OpenCL 的头文件(不是我不关心的 OpenGL)。如何获取 OpenCL SDK? 最佳答案 AMD 的 ATI Str
Android 项目中最低(最低 sdk)和最高(目标 sdk)级别是否有任何影响。这些东西是否会影响项目的可靠性和效率。 最佳答案 没有影响,如果您以 SDK 级别 8 为目标,那么您的应用将以 9
“min sdk version/target sdk version”和“compile sdk version”有什么区别?我知道 min 和 target sdk 是什么意思,但是 compil
我正在尝试运行 Dji Mobile-Sdk-Android:https://github.com/dji-sdk/Mobile-SDK-Android使用 dji 网站上的说明:https://de
我目前正在向我的 iPhone 应用程序添加新的 Facebook iOS sdk 3.1.1。我看到 sdk 有重大变化。例如。我的旧 sdk 创建一个 Facebook 对象并从 FBReques
我最近刚刚下载了 Xcode 4.6 with mac 10.8.4 with iOS 6.0 SDK package,我立即注意到我无法使用我的 iPhone 3Gs with iOS 4.6 进行
我尝试下载 OpenCL SDK。但是没办法。我有一个 AMD GPU,所以我在谷歌上搜索了 AMD SDK,但是来自谷歌的所有链接和一些教程都被破坏了,不可能通过 AMD 开发者网站找到 sdk。
安装 Google Cloud SDK 后,当我运行时 gcloud 授权登录 我收到一条错误消息: Your browser has been opened to visit: https://a
我一直在 nvidia 网站上搜索 GPU 计算 SDK,因为我正在尝试构建具有 cuda 支持的点云库 (PCL)。但是,在 nvidia 网站上,我只能找到工具包的链接,而不是 SDK 的单个下载
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅关注editing this post一个问题。 2
当我打开 Android SDK 管理器时,会出现一个屏幕“选择要安装的包”。它列出了一堆带有绿色复选标记(已经安装)的软件包,还有一些带有 x's 的软件包,它们没有安装。如果我选择“全部接受”,它
在开发过程中,我发布了 SDK 21 Lollipop,但我无法在我的 KitKat 设备上使用它。应用程序非常简单,我只将 SDK 用于动画和 Material 设计,但是当我尝试对 Play 商店
enter image description here friend 们好 在使用 Linux、jenkins 和 docker 探索 dotnet 核心时,我遇到了构建问题,该问题在标题“/usr
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我创建了一个flutter项目,运行flutter packages get,输出如下:【二】flutter包搞定等待另一个 flutter 命令释放启动锁...第二次运行“flutter packa
这个问题在这里已经有了答案: What are the Android SDK build-tools, platform-tools and tools? And which version sh
我使用 Corona SDK 已经快一年了,并且开发了几个简单的游戏。我现在正在寻找的是在 Corona SDK 中创建 3D 幻觉的某种方法。如果有人有 Corona 3D 方面的经验,我将不胜感激
我有一个CLDC 1.1 / MIDP 2.0项目,可以使用Java ME SDK 3.2很好地进行编译。 最近,我已将Java SE升级到8,结果Java ME SDK开始在Windows启动时显示
有没有办法以编程方式控制连接到华擎主板的 RGB 照明?我知道华硕有一个 Aura SDK,但华擎是否也有一个用于他们的硬件? 如果是,我在哪里可以找到它? 最佳答案 没有用于华擎多彩的 sdk。但是
如何使用 crm 2011 sdk 和 XrmServiceContext 创建事务? 在下一个示例中,'new_brand' 是一些自定义实体。我想创建三个品牌。第三个拥有错误的 OwnerID g
我是一名优秀的程序员,十分优秀!