I have a problem with sqlite. I have a select with 2 varchars on it and save it in an object. When I'm trying to get data, only one of my varchars has the string that i want. The other one is NSBlockVariable or nil.
Debugging sqlite3, it works great, and it returns perfect what I need. This two variables are: name and store
product.name = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 3)];
product.store = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 4)];
NSLog(@"name: %@", [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 3)]);
NSLog(@"store: %@", [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 4)]);
I get:
//name: Sunglasses
//store: RayBan
I have an object created like this:
@interface ProductsCart : NSObject
@property (nonatomic, assign) NSInteger idtrans;
@property (nonatomic, assign) NSInteger idproduct;
@property (nonatomic, assign) NSInteger idstore;
@property (nonatomic, assign) NSString *name;
@property (nonatomic, assign) NSString *store;
And this is how i save it in my DAO class:
NSMutableArray *productList = [[NSMutableArray alloc] init];
while(sqlite3_step(sqlStatement) == SQLITE_ROW)
{
ProductsCart *product = [[ProductsCart alloc] init];
product.idtrans = sqlite3_column_int(sqlStatement, 0);
product.idproduct = sqlite3_column_int(sqlStatement, 1);
product.idstore = sqlite3_column_int(sqlStatement, 2);
product.name = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 3)];
product.store = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 4)];
[productList addObject:product];
}
In my Cart class I have a table and this is how I get the info on each row:
In viewdidload
self.products= [dao getProductList];
In cellForRowAtIndexPath
ProductsCart * productCart=[self.products objectAtIndex:[indexPath row]];
int idtrans=[[[self.products objectAtIndex:[indexPath row]] valueForKey:@"idtrans"] intValue];
NSString* name=[[self.products objectAtIndex:[indexPath row]] valueForKey:@"name"];
NSString* store=[[self.products objectAtIndex:[indexPath row]] valueForKey:@"store"];
At this point:
- name is a NSMutableString and it contains "Sunglasses"
- store is a NSObject and it must be a string
I checked the stored database on simulator and the rows are perfect so the problem is not on it.
If I change the order saving the data (store in product.name and name in product.store):
product.name = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 4)];
product.store = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 3)];
This is what I get:
- name is a NSMutableString and it contains "RayBan"
- store is a NSObject and it must be a string
in store, sometimes I get
store __NSCFString * @"star.count.singular" 0x00007fae62068e40
How can I solve this problem??
Thanks a lot!!
Aucun commentaire:
Enregistrer un commentaire