开发者

how to select a string attribute from a table in objective c

开发者 https://www.devze.com 2023-03-12 08:47 出处:网络
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

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消