2016-10-20 4 views
-2
-(void)bindStatement:(sqlite3_stmt *)statement withArg:(NSObject *)arg atIndex:(NSUInteger)argIndex 
{ 
    if ([arg isEqual:[NSNull null]]) { 
     sqlite3_bind_null(statement, argIndex);//Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int' 
    } else if ([arg isKindOfClass:[NSNumber class]]) { 
     NSNumber *numberArg = (NSNumber *)arg; 
     const char *numberType = [numberArg objCType]; 
     if (strcmp(numberType, @encode(int)) == 0) { 
      sqlite3_bind_int(statement, argIndex, [numberArg integerValue]); 
     } else if (strcmp(numberType, @encode(long long int)) == 0) { 
      sqlite3_bind_int64(statement, argIndex, [numberArg longLongValue]); 
     } else if (strcmp(numberType, @encode(double)) == 0) { 
      sqlite3_bind_double(statement, argIndex, [numberArg doubleValue]); 
     } else { 
      sqlite3_bind_text(statement, argIndex, [[arg description] UTF8String], -1, SQLITE_TRANSIENT); 
     } 
+3

これはObjective-Cであり、Swiftではありません。 –

+1

[ 'INT' 警告にObjective Cの暗黙的な変換は、整数精度を失う 'NSUInteger'(別名 'unsigned long型')]の可能な重複(http://stackoverflow.com/questions/16918826/objective-c-implicit-conversion-loses -integer-precision-nsuinteger-aka-unsig)を使用します。 –

答えて

0

sqlite3_bind_xxx機能の全てのindexパラメータは、そのデータ型がintNSUIntegerないことを期待します。

最も簡単な解決策は、パラメータのデータ型をNSUIntegerからintに変更することです。または、sqlite3_bind_xxx関数の呼び出しで使用する場合は、argIndexintの値に変換します。

これは、与えられた変数のための適切なデータ型を使用することが常に最善です。

関連する問題