def get_used_runners(): """Return a list of the runners in use by installed games.""" with sql.db_cursor(PGA_DB) as cursor: query = "select distinct runner from games where runner is not null order by runner" rows = cursor.execute(query) results = rows.fetchall() return [result[0] for result in results if result[0]]
def create_table(name, schema): """Creates a new table in the database""" fields = ", ".join([field_to_string(**f) for f in schema]) query = "CREATE TABLE IF NOT EXISTS %s (%s)" % (name, fields) logger.debug("[PGAQuery] %s", query) with sql.db_cursor(settings.PGA_DB) as cursor: cursor.execute(query)
def get_used_platforms(): """Return a list of platforms currently in use""" with sql.db_cursor(PGA_DB) as cursor: query = ( "select distinct platform from games " "where platform is not null and platform is not '' order by platform" ) rows = cursor.execute(query) results = rows.fetchall() return [result[0] for result in results if result[0]]
def get_schema(tablename): """ Fields: - position - name - type - not null - default - indexed """ tables = [] query = "pragma table_info('%s')" % tablename with sql.db_cursor(settings.PGA_DB) as cursor: for row in cursor.execute(query).fetchall(): field = { "name": row[1], "type": row[2], "not_null": row[3], "default": row[4], "indexed": row[5], } tables.append(field) return tables
def read_sources(): with sql.db_cursor(settings.PGA_DB) as cursor: rows = cursor.execute("select uri from sources") results = rows.fetchall() return [row[0] for row in results]
def remove_category_from_game(game_id, category_id): """Remove a category from a game""" query = "DELETE FROM games_categories WHERE category_id=? AND game_id=?" with sql.db_cursor(settings.PGA_DB) as cursor: sql.cursor_execute(cursor, query, (category_id, game_id))