| 36 | |
| 37 | |
| 38 | class Sqlite3Rewriter(Rewriter): |
| 39 | def rewrite_single(self, query): |
| 40 | # Replace DB specific queries with a no-op |
| 41 | if "/*PSQL*/" in query: |
| 42 | return "UPDATE vars SET intval=1 WHERE name='doesnotexist'" # Return a no-op |
| 43 | |
| 44 | typemapping = { |
| 45 | r'BIGINT': 'INTEGER', |
| 46 | r'BIGINTEGER': 'INTEGER', |
| 47 | r'BIGSERIAL': 'INTEGER', |
| 48 | r'VARCHAR(?:\(\d+\))?': 'TEXT', |
| 49 | r'\bINT\b': 'INTEGER', |
| 50 | r'CURRENT_TIMESTAMP\(\)': "strftime('%s', 'now')", |
| 51 | r'INSERT INTO[ \t]+(.*)[ \t]+ON CONFLICT.*DO NOTHING;': 'INSERT OR IGNORE INTO \\1;', |
| 52 | # Rewrite "decode('abcd', 'hex')" to become "x'abcd'" |
| 53 | r'decode\((.*),\s*[\'\"]hex[\'\"]\)': 'x\\1', |
| 54 | # GREATEST() of multiple columns is simple MAX in sqlite3. |
| 55 | r'GREATEST\(([^)]*)\)': "MAX(\\1)", |
| 56 | # NULLS FIRST is default behavior on sqlite, make it disappear |
| 57 | r' NULLS FIRST': '', |
| 58 | } |
| 59 | return self.rewrite_types(query, typemapping) |
| 60 | |
| 61 | |
| 62 | class PostgresRewriter(Rewriter): |