I am recently working with SQLite database and I was stuck with a very simple task: writing a function to create a table, existing table should be dropped. In other database engines this can be achieved using a simple CREATE OR REPLACE TABLE statement but this is not supported in current version of SQLite. Therefore I need to check the existence of a table before running the CREATE TABLE statement, but how?
Having a simple Google search, I got the clue at here: using the DbConnection.GetSchema() method.
Here is the complete code:
public static bool IsTableExists(SQLiteConnection conn, string table_name)
return conn.GetSchema("Tables").Select("Table_Name = '" + table_name + "'").Length > 0;
Since this is a method defined in ADO standard, so probably it will work for those ADO implementations of other database engine. (Not tested)