diff options
author | imoldman <fenghaungyuyicon@gmail.com> | 2014-01-07 10:12:08 +0400 |
---|---|---|
committer | imoldman <fenghaungyuyicon@gmail.com> | 2014-01-07 10:12:08 +0400 |
commit | 72abbca772247e05613316007e64c1e8eee1d19c (patch) | |
tree | 16ce4b506e726ef8c7f3707004a8cf039bd36451 | |
parent | 74b01bd4581d68ef6f6ffcb0833ae9f4a47cd9b5 (diff) |
improve type detect in FMDatabase.bindObject:obj when obj is a NSNumber
We should enum all possible in NSNumber, or we may get an incomprehensible result.
e.g. the result of `[@NO objCType]` is `@encode(char)` not `@encode(BOOL)` under XCode5
-rw-r--r-- | src/FMDatabase.m | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/FMDatabase.m b/src/FMDatabase.m index 6e442a5..b4cc7b9 100644 --- a/src/FMDatabase.m +++ b/src/FMDatabase.m @@ -459,12 +459,30 @@ if (strcmp([obj objCType], @encode(BOOL)) == 0) { sqlite3_bind_int(pStmt, idx, ([obj boolValue] ? 1 : 0)); } + else if (strcmp([obj objCType], @encode(char)) == 0) { + sqlite3_bind_int(pStmt, idx, [obj charValue]); + } + else if (strcmp([obj objCType], @encode(unsigned char)) == 0) { + sqlite3_bind_int(pStmt, idx, [obj unsignedCharValue]); + } + else if (strcmp([obj objCType], @encode(short)) == 0) { + sqlite3_bind_int(pStmt, idx, [obj shortValue]); + } + else if (strcmp([obj objCType], @encode(unsigned short)) == 0) { + sqlite3_bind_int(pStmt, idx, [obj unsignedShortValue]); + } else if (strcmp([obj objCType], @encode(int)) == 0) { - sqlite3_bind_int64(pStmt, idx, [obj longValue]); + sqlite3_bind_int(pStmt, idx, [obj intValue]); + } + else if (strcmp([obj objCType], @encode(unsigned int)) == 0) { + sqlite3_bind_int64(pStmt, idx, (long long)[obj unsignedIntValue]); } else if (strcmp([obj objCType], @encode(long)) == 0) { sqlite3_bind_int64(pStmt, idx, [obj longValue]); } + else if (strcmp([obj objCType], @encode(unsigned long)) == 0) { + sqlite3_bind_int64(pStmt, idx, (long long)[obj unsignedLongValue]); + } else if (strcmp([obj objCType], @encode(long long)) == 0) { sqlite3_bind_int64(pStmt, idx, [obj longLongValue]); } |