我在編譯器警告中掙扎了一下。下面的代碼:存儲在'var name'中的值永遠不會被讀取
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);
首先警告值存儲到「SQL」是從來不看所有SQL VAR分配的,除了最後一個在交換機(爲5)。情況5不會導致警告。
第二個警告是函數調用參數是未初始化的值。這是爲 if(sqlite3_prepare_v2(database,sql,-1,& selectstmt,NULL)== SQLITE_OK) 聲明。
在此先感謝您的提示。
不知怎的,我從我的回答對你的編輯去了,我滾你回來, RRY。 – Joe 2012-02-08 14:02:12
謝謝大家。忘記了開關需要這些休息。認爲他們只在循環中需要。但是,if(sqlite3 ..)語句中的未初始化值警告仍然存在。 – renesteg 2012-02-08 14:36:18
第二警告可能會顯示出來,因爲你錯過了'default'(見user1186899的例子),在這種情況下'sql'可能仍處於初始化。 – 2012-02-08 14:49:57