I need to check to see if a column exists and if it doesn\'t exist add it. From my research it looks like sqlite doesn\'t support IF statements and case statement should be
A weird way to check for existing column
public static bool SqliteColumnExists(this SQLiteCommand cmd, string table, string column)
{
lock (cmd.Connection)
{
// make sure table exists
cmd.CommandText = string.Format("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = '{0}'", table);
var reader = cmd.ExecuteReader();
if (reader.Read())
{
//does column exists?
bool hascol = reader.GetString(0).Contains(String.Format("\"{0}\"", column));
reader.Close();
return hascol;
}
reader.Close();
return false;
}
}