Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Swift中使用FMDB执行准备好的语句_Swift_Fmdb - Fatal编程技术网

在Swift中使用FMDB执行准备好的语句

在Swift中使用FMDB执行准备好的语句,swift,fmdb,Swift,Fmdb,我有一个要插入SQLite数据库的对象数组。我使用FMDB作为SQLite包装器。这是我的代码: do { if !db.beginTransaction() { throw db.lastError() } for location in locations { let command = "INSERT INTO Locations ( LocationId, Name ) VALUES

我有一个要插入SQLite数据库的对象数组。我使用FMDB作为SQLite包装器。这是我的代码:

    do {
        if !db.beginTransaction() {
            throw db.lastError()
        }

        for location in locations {
            let command = "INSERT INTO Locations ( LocationId, Name ) VALUES ( ?, ? )"
            try db.executeUpdate(command, NSArray( [ location.locationId, location.name ] ) )
        }

        if !db.commit() {
            throw db.lastError()
        }
    }//do
FMDB的
executeUpdate
过载了这些Objective-C签名:

- (BOOL)executeUpdate:(NSString*)sql withErrorAndBindings:(NSError**)outErr, ...;
- (BOOL)executeUpdate:(NSString*)sql, ...;
- (BOOL)executeUpdateWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2);
- (BOOL)executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments;
- (BOOL)executeUpdate:(NSString*)sql values:(NSArray *)values error:(NSError * __autoreleasing *)error;
- (BOOL)executeUpdate:(NSString*)sql withParameterDictionary:(NSDictionary *)arguments;
- (BOOL)executeUpdate:(NSString*)sql withVAList: (va_list)args;
我的当前代码在
executeUpdate
行中给出了此编译器错误:

DatabaseService.swift:299:44:表达式类型不明确,没有更多上下文

当我传入一个普通的Swift数组时,我会得到同样的错误

当我将其更改为
值:
重载时,会出现以下错误:

try db.executeUpdate( command, values: [ location.locationId, location.name ] )
DatabaseService.swift:299:55:类型为“Int64”的值与预期的元素类型“AnyObject”不一致

当我尝试使用VAARGS版本时:

try db.executeUpdate( command, location.locationId, location.name )
DatabaseService.swift:299:12:无法使用类型为“(String,Int64,String)”的参数列表调用“executeUpdate”

db.executeUpdate(“插入…”,带ArgumentsInArray:[…])
应该可以正常工作。但是,您是否考虑使用SQLite周围的SWIFT API,比如OR?