简体   繁体   中英

How to retrieve data from sqlite3?

My program is basically trying to read , write and delete data into the database . I'm currently stuck at the reading data part which i have no clue on how to proceed . Writing and deleting data into the database has been done . Please help me out by providing the relevant codes for reading data from the data base .

There is also another problem with my simulator , when i run and build the program the simulator shows nothing , however a re-run of it makes it workable , how do i solve this problems ?

Thanks in advance

You can go by these links they will help you

Reading data using SQLite3

Sqlite tutorial

sqlite3 *database;



// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    // Setup the SQL Statement and compile it for faster access
    const char *sqlStatement = "select * from yourTable";
    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
        // Loop through the results and add them to the feeds array
        while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
            // Read the data from the result row
            NSString *col1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
            NSString *col2 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
            NSString *col3 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];    
        }
    }
    // Release the compiled statement from memory
    sqlite3_finalize(compiledStatement);

}
sqlite3_close(database);

There are a number of great tutorials out there for this; such as this one below which lays out the whole process in detail from start to end >

http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

Is there anything in particular regarding reading data you're having trouble with? (or if its just a general how-to guideline you're looking for, the above link should help.

Regarding your simulator, does this ALWAYS happen? Or once in a while. Normally, old code and dara residing on the simulator could cause errors like this, so resetting the simulator, and/or cleaning and building your code could help.

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM