I am struggling a bit with a compiler warning. Here the code:
const char *sql;
switch (fromVersion) {
case 0:
{
sql = "ALTER TABLE abiliator_options ADD COLUMN new_column00 TEXT NOT NULL DEFAULT 'migrated from version 0'";
}
case 1:
{
sql = "ALTER TABLE abiliator_options ADD COLUMN new_column01 TEXT NOT NULL DEFAULT 'migrated from version 1'";
}
case 2:
{
sql = "ALTER TABLE abiliator_options ADD COLUMN new_column02 TEXT NOT NULL DEFAULT 'migrated from version 2'";
}
case 3:
{
sql = "ALTER TABLE abiliator_options ADD COLUMN new_column03 TEXT NOT NULL DEFAULT 'migrated from version 3'";
}
case 4:
{
sql = "ALTER TABLE abiliator_options ADD COLUMN new_column04 TEXT NOT NULL DEFAULT 'migrated from version 4'";
}
case 5:
{
sql = "ALTER TABLE abiliator_options ADD COLUMN new_column05 TEXT NOT NULL DEFAULT 'migrated from version 5'";
}
}
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK)
{
if (sqlite3_step(selectstmt) == SQLITE_DONE)
{
NSLog(@"Alter statement successful");
[self setDatabaseSchemaVersion];
}
else {
NSLog(@"Failed to alter the table with message '%s'.", sqlite3_errmsg(database));
}
}
else {
NSLog(@"Failed to prepare the statement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_finalize(selectstmt);
First warning is Value stored to ‘sql’ is never read for all of the sql var assignments, except the last one in the switch (case 5). Case 5 does not result in a warning.
Second warning is Function call argument is an uninitialized value. This is for the
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK)
statement.
Thanks in advance for your hints.
break;statements between your cases.default:Compiler tells you that when your
fromVersionis, for example, 4, whatever you assign to it in thecase 4:will get immediately overwritten bycase 5:, because there is nobreak. It also tells you that whenfromVersionis negative or more than 5, yoursqlis uninitialized.