我有一个要插入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数组时,我得到了同样的错误。
当我将其更改为values:
重载时,我收到此错误:
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:无法调用' executeUpdate'使用类型'(String,Int64,String)'
的参数列表