1

I am doing something fundamental wrong but I am searching for better examples on the net and is coming up short :-(

in .h @interface MyDataViewController : UIViewController {

NSArray *array;
}
@property (nonatomic, retain) NSArray *array;

in m

@synthesize array;

succesful dbretrieval:

while (sqlite3_step(statement) == SQLITE_ROW) {
            //I guess this one is wrong but I cant figure it out.. (tired?)
            array = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];

//testoutput to textfield:
            //myName.text  = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
//testoutput to nslog:
            NSLog(@"Data: %@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]);

        }

Outputs the last from sqlitequeryn:

NSLog(@"%@", array);

1 Answer 1

2

What are your output and what do you expect from this? You are directly putting a NSString into a NSArray, of which might, or might not be done several times for a static NSArray.

If you are planning on putting several strings into your array, you should have a NSMutableArray and simply addObject every time you loop through your while:

NSMutableArray *array = [[NSMutableArray alloc] init];
...code....
while (sqlite3_step(statement) == SQLITE_ROW) {
    [array addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
}
Sign up to request clarification or add additional context in comments.

3 Comments

works like a charm. how do I set this question to answered...? it says "I can accept an anser within 2 min..."
great! don't forget to handle error messages in your sqlite3 queries, if you absolutely have to use it. I would rather recommend Core Data for basically any db-application for iPhone. A nice tutorial is here by Ray Wenderlich, who also has a lot of other useful tutorials :)
thx, I will remember to handle the error messages. As of now I will use a static db with controlled querys so I hope that wont be a hazzle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.