Question about SQLite3 and iPhone app update

Consider the following scenario.

I have an iPhone application in the application store that executes queries in a 16-column SQLite3 column table. As an update, I want to add a new column to this table.

When someone installs the update, will it mess? Will the table be replaced? How it works. How can I do it?

+4
source share
2 answers

One way to do this is to check during startup if there is a new field in the table. You can use the following SQLite command to retrieve all fields from a table

PRAGMA table_info(table-name); 

If the field you are looking for is not in the result set, do ALTER TABLE table-name ADD COLUMN column-name column-type to update the table.

You can use this method to scroll through the fields of a table.

 - (BOOL)getFields { const char *sql = "PRAGMA table_info(myTable)"; sqlite3_stmt *stmt; if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) { return NO; } while(sqlite3_step(stmt) == SQLITE_ROW) { NSString *fieldName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)]; NSLog(@"%@", fieldName); } return YES; } 

Hope this helps

+4
source

FYI, if you never copied a database to make it editable, it will be replaced. If you copied the database to a place where you can write, then you will have to process the replacement yourself.

+1
source

All Articles