@@ -315,38 +315,6 @@ def insert_before(self, where, token):
315315 """Inserts *token* before *where*."""
316316 self .tokens .insert (self .token_index (where ), token )
317317
318-
319- class Statement (TokenList ):
320- """Represents a SQL statement."""
321-
322- __slots__ = ('value' , 'ttype' , 'tokens' )
323-
324- def get_type (self ):
325- """Returns the type of a statement.
326-
327- The returned value is a string holding an upper-cased reprint of
328- the first DML or DDL keyword. If the first token in this group
329- isn't a DML or DDL keyword "UNKNOWN" is returned.
330- """
331- first_token = self .token_first ()
332- if first_token is None :
333- # An "empty" statement that either has not tokens at all
334- # or only whitespace tokens.
335- return 'UNKNOWN'
336- elif first_token .ttype in (T .Keyword .DML , T .Keyword .DDL ):
337- return first_token .value .upper ()
338- else :
339- return 'UNKNOWN'
340-
341-
342- class Identifier (TokenList ):
343- """Represents an identifier.
344-
345- Identifiers may have aliases or typecasts.
346- """
347-
348- __slots__ = ('value' , 'ttype' , 'tokens' )
349-
350318 def has_alias (self ):
351319 """Returns ``True`` if an alias is present."""
352320 return self .get_alias () is not None
@@ -359,8 +327,8 @@ def get_alias(self):
359327 if alias is None :
360328 return None
361329 else :
362- next_ = self .token_next ( 0 )
363- if next_ is None or not isinstance ( next_ , Identifier ) :
330+ next_ = self .token_next_by_instance ( 0 , Identifier )
331+ if next_ is None :
364332 return None
365333 alias = next_
366334 if isinstance (alias , Identifier ):
@@ -393,6 +361,39 @@ def get_real_name(self):
393361 return None
394362 return next_ .value
395363
364+
365+
366+ class Statement (TokenList ):
367+ """Represents a SQL statement."""
368+
369+ __slots__ = ('value' , 'ttype' , 'tokens' )
370+
371+ def get_type (self ):
372+ """Returns the type of a statement.
373+
374+ The returned value is a string holding an upper-cased reprint of
375+ the first DML or DDL keyword. If the first token in this group
376+ isn't a DML or DDL keyword "UNKNOWN" is returned.
377+ """
378+ first_token = self .token_first ()
379+ if first_token is None :
380+ # An "empty" statement that either has not tokens at all
381+ # or only whitespace tokens.
382+ return 'UNKNOWN'
383+ elif first_token .ttype in (T .Keyword .DML , T .Keyword .DDL ):
384+ return first_token .value .upper ()
385+ else :
386+ return 'UNKNOWN'
387+
388+
389+ class Identifier (TokenList ):
390+ """Represents an identifier.
391+
392+ Identifiers may have aliases or typecasts.
393+ """
394+
395+ __slots__ = ('value' , 'ttype' , 'tokens' )
396+
396397 def get_parent_name (self ):
397398 """Return name of the parent object if any.
398399
0 commit comments