I have a method which is supposed 开发者_开发知识库to return a PatientDetails
object when I insert an unique nric
as the parameter. This doesn't work. However when I changed this method to accept int age
instead of NSString * nric
, it worked.
Is there something wrong with my syntax "WHERE ic = %s"
cause it seems wierd. I have googled 2 days on this and cannot find a solution.
Please help as I am a newbie.
- (PatientDetails *)patientDetails:(NSString *)nric {
PatientDetails *retval = nil;
NSString *query = [NSString stringWithFormat:@"SELECT ic, district, age, race, referralSource, DMRelatedAdmin, postalCode FROM patientInfo WHERE ic = %s" , nric];
sqlite3_stmt *statement;
%s
denotes the standard C string. In order to use NSString
objects as the argument, you need to use the object notation %@
.
WHERE ic = '%@'
Yes, the format specifier for Objective-C strings is %@
. So it should be,
NSString *query = [NSString stringWithFormat:@"SELECT ic, district, age, race, referralSource, DMRelatedAdmin, postalCode FROM patientInfo WHERE ic = %@" , nric];
精彩评论