Search notes:

Python library: sqlparse

Exctract statements (separated by semicolons):
import sqlparse

stmts = '''

   select * from dual;
   select 42 + 13;
   insert into dest
   select
      x,
      y
   from
      src

'''

for i, stmt in enumerate(sqlparse.split(stmts)):
    print(str(i) + ': ' + stmt)
Parse an SQL statement:
import sqlparse

stmt = '''
  select
     clt.id                          client_id,
     clt.name                        client_name,
     sal.val *  sal.items         as total_price,
    'foo bar baz: ' || sal.txt    as conc
  from
     client clt                                  join
     sale   sal on clt.id = sal.client_id
'''


def printTokenTree(lvl, token):
   if hasattr(token, 'tokens'):
      for t in token.tokens:
          printTokenTree(lvl+1, t)
   else:
      if not token.is_whitespace:
         print( ('  ' *lvl) + token.value)

ast = sqlparse.parse(stmt)[0]

printTokenTree(0, ast)

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758203808, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/libraries/sqlparse(76): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78