For FMDatabase used in the query which encountered a little problem, like a long time did not come up with what they hope will give you much point tips! Questions are as follows:
I wrote a select function,
- (NSMutableArray *) select: (NSString *) column {
NSMutableArray * result = [[[NSMutableArray alloc] initWithCapacity: 0] autorelease];
/ / FMDatabase * db; db declared in the header file is a FMDatabase object that can be identified in the coupon_table my database where data is
FMResultSet * rs = [db executeQuery: @ "select% @ from coupon_table", column];
NSLog (@ "rs =% @", rs);
/ / Print the results here rs = (null), resulting in not enter while loop, so the result is an array variable result = ();
while ([rs next]) {
[Result addObject: [rs stringForColumn: column]];
/ / The reason to use addObject to the values in the table related fields taken out, writes the array to use when operating the array directly on the line
}
[Rs close];
NSLog (@ "result =% @", result);
/ / Print the results here result = ()
return result;
}
This function is invoked in another folder:
[CouSql select: @ "id"];
/ / Here's couSql object that contains the class select the file where the function object.
Before version is - (NSMutableArray *) select, no additional parameters. In this case, result values are able to get to my list data. But that case was written dead, this is not good. So add a parameter change, the result is a sad reminder.
I also tried FMResultSet * rs = [db executeQuery: @ "select from coupon_table?", Column]; this form, in this case, rs able to point to the correct memory location, but the implementation of the [result addObject: [rs stringForColumn: column]]; would crash out. I do not know if you encountered such a situation, seek help ah!
Reply:
FMResultSet * rs = [db executeQuery: @ "select% @ from coupon_table", column];
Personal feeling this sentence in question, can be:
NSString * sql = [NSString stringWithFormat: @ "select% @ from coupon_table", column];
Then
FMResultSet * rs = [db executeQuery: sql];
Not used fmdatabase, so I do not know executeQuery support does not support this method you write fomart form, only ideas! I wish the landlord as soon as possible to solve the problem!
Reply:
Thank you, as if I did not so used, and now I can only write it dead. Although this is not good, but no way, can only make do with it!
Reply:
The dead do not write it,
NSString * sql = [NSString stringWithFormat: @ "select% @ from coupon_table", column];
FMResultSet * rs = [db executeQuery: sql];
Like this can be the right
Reply:
Try a little fmdatabase,
Here you FMResultSet * rs = [db executeQuery: @ "? Select from coupon_table", column]; This form should be changed:
FMResultSet * rs = [db executeQuery: @ "? Select from coupon_table", column , nil ];
This can be a
Reply:
Thank you!
Reply:
Brother, why are many methods with parameters back to add nil ah?
Reply:
Because this interface when multiple parameters, you need to add nil as at the end
No comments:
Post a Comment