Forgive me because I have sinned:
WITH RECURSIVE a AS ( SELECT name, lower(replace(replace(sql, char(13), ' '), char(10), ' ')) AS sql FROM sqlite_master WHERE lower(sql) LIKE '%integer% autoincrement%' ), b AS ( SELECT name, trim(substr(sql, instr(sql, '(') + 1)) AS sql FROM a ), c AS ( SELECT b.name, sql, '' AS col FROM b UNION ALL SELECT c.name, trim(substr(c.sql, ifnull(nullif(instr(c.sql, ','), 0), instr(c.sql, ')')) + 1)) AS sql, trim(substr(c.sql, 1, ifnull(nullif(instr(c.sql, ','), 0), instr(c.sql, ')')) - 1)) AS col FROM c JOIN b ON c.name = b.name WHERE c.sql != '' ), d AS ( SELECT name, substr(col, 1, instr(col, ' ') - 1) AS col FROM c WHERE col LIKE '%autoincrement%' ) SELECT name, col FROM d ORDER BY name, col;
This query is based on two assumptions:
- The
autoincrement flag autoincrement present in the column definition inside sqlite_master - The column is of type
integer (as SQLite currently requires)
Because regular expressions are not available out of the box, this query uses a recursive approach to match all columns. Please forgive me.
Sure...
You can also just process your sqlite_master.sql content with some client, for example. Java program using simple regular expressions, if thatβs easier for you.