我正在使用FMDB在iPhone上创建一个SQLite数据库.我有一个形式的initial.sql
CREATE TABLE Abc ... ;
CREATE TABLE Def ... ;
Run Code Online (Sandbox Code Playgroud)
我通过将文件加载到NSString并运行它来加载它
NSString * str = // string from file initial.sql
[db executeUpdate: str];
Run Code Online (Sandbox Code Playgroud)
这成功但后来我失败了:
no such table: Def
Run Code Online (Sandbox Code Playgroud)
很明显,第二个声明没有被调用.我该怎么做才能调用所有查询?
根据SQLite文档:"例程sqlite3_prepare_v2(),sqlite3_prepare(),sqlite3_prepare16(),sqlite3_prepare16_v2(),sqlite3_exec()和sqlite3_get_table()接受一个SQL语句列表(sql-stmt-list),这是一个分号 - 分开的陈述清单."
所以,这一切都应该有效.
我-launch在NSTask 的一次撞车事件中得到了一份报告.
有问题的代码是:
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/zsh"];
if(ignore)
{
[task setArguments:@[scriptPath, recordingFolder, Argument]];
}
else
{
[task setArguments:@[scriptPath, recordingFolder]];
}
NSPipe *outPipe = [NSPipe pipe];
[task setStandardOutput:outPipe];
NSPipe *errorPipe = [NSPipe pipe];
[task setStandardError:errorPipe];
[task launch];
Run Code Online (Sandbox Code Playgroud)
scriptPath是应用程序包中包含的脚本.崩溃说:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to set posix_spawn_file_actions for fd -1 at index 0 with errno 9'
Run Code Online (Sandbox Code Playgroud)
可能是什么原因造成的?posix_spawn_file_actions引用了什么文件描述符?这是否意味着可执行脚本错误或者outPipe或errPipe格式不正确?
我相信它指的是posix_spawn函数:https: //developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/posix_spawn.2.html
并且errno 9是EBADF(错误的文件号).
当我将选择器传递给我的方法时,我应该保存它:
-(void) setCallBack:(SEL) selectorToCall
{
self->mSelectorToCall = selectorToCall;
}
Run Code Online (Sandbox Code Playgroud)
还是应该保留?
-(void) setCallBack:(SEL) selectorToCall
{
self->mSelectorToCall = [selectorToCall retain];
}
Run Code Online (Sandbox Code Playgroud)