[IMP] registry: check existence of tables with a single SQL query

This commit is contained in:
Raphael Collet
2017-07-10 12:38:25 +02:00
parent e2739d6e49
commit faacacb45f
2 changed files with 17 additions and 10 deletions
+7
View File
@@ -21,6 +21,13 @@ _CONFDELTYPES = {
'SET DEFAULT': 'd',
}
def existing_tables(cr, tablenames):
""" Return the names of existing tables among ``tablenames``. """
query = """ SELECT table_name FROM information_schema.tables
WHERE table_name IN %s AND table_schema != 'information_schema' """
cr.execute(query, [tuple(tablenames)])
return [row[0] for row in cr.fetchall()]
def table_exists(cr, tablename):
""" Return whether the given table exists. """
query = "SELECT 1 FROM information_schema.tables WHERE table_name=%s AND table_schema != 'information_schema'"