mercredi 28 janvier 2015

SQLite.NET Check if column exists in table

I have created following method that Adds a column in an already existing SQLite table



public async void AddColumnMyNewColumn()
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(path);
await conn.ExecuteAsync("ALTER TABLE MyTable ADD COLUMN MyNewColumn bit DEFAULT 'False';");
}


It creates a new column MyNewColumn in MyTable.


Next time when AddColumnMyNewColumn method is called, then it throws an error.


How to check if this column is already created??


I've cheched this,and this, but I cant put these things together to get something like this..



public async void AddColumnMyNewColumn()
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(path);
bool columnExists;

//Check if column exists & set columnExists accordingly

if(!columnExists)
await conn.ExecuteAsync("ALTER TABLE MyTable ADD COLUMN MyNewColumn bit DEFAULT 'False';");
}

Aucun commentaire:

Enregistrer un commentaire