andialbrecht / sqlparse

A non-validating SQL parser module for Python
BSD 3-Clause "New" or "Revised" License
3.71k stars 693 forks source link

AttributeError: 'Token' object has no attribute 'tokens' #646

Open smtcast opened 2 years ago

smtcast commented 2 years ago

SQL Query: SELECT COUNT(*) FROM {0}csub WHERE csub_id = ?

I get the following error while parsing the above query. This is a valid sql query from .NET application. Error happens to be at'{'.

AttributeError: 'Token' object has no attribute 'tokens'

Parsed tokens is

parsed.tokens is [<DML 'SELECT' at 0x5328b38>, <Whitespace ' ' at 0x5328bd8>, <Function 'COUNT(...' at 0x531f648>, <Whitespace ' ' at 0x5328d68>, <Keyword 'FROM' at 0x5328db8>, <Whitespace ' ' at 0x5328e08>, <Error '{' at 0x5328e58>, <Integer '0' at 0x5328ea8>, <Error '}' at 0x5328ef8>, <Identifier 'csub' at 0x531f848>, <Whitespace ' ' at 0x5328f98>, <Where 'WHERE ...' at 0x531f6c8>]

andialbrecht commented 2 years ago

Do you have some example code that reproduces this issue? The code I've tried was

>>> import sqlparse
>>> sqlparse.parse("SELECT COUNT(*) FROM {0}csub WHERE csub_id = ?")
(<Statement 'SELECT...' at 0x110693F50>,)
>>>