<s> from . grammar import QueryGrammar <EOL> class SQLiteQueryGrammar ( QueryGrammar ) : <EOL> _operators = [ <EOL> '<STR_LIT:=>' , '<STR_LIT:<>' , '<STR_LIT:>>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:&>' , '<STR_LIT:|>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> def compile_insert ( self , query , values ) : <EOL> """<STR_LIT>""" <EOL> table = self . wrap_table ( query . from__ ) <EOL> if not isinstance ( values , list ) : <EOL> values = [ values ] <EOL> if len ( values ) == <NUM_LIT:1> : <EOL> return super ( SQLiteQueryGrammar , self ) . compile_insert ( query , values ) <EOL> names = self . columnize ( values [ <NUM_LIT:0> ] . keys ( ) ) <EOL> columns = [ ] <EOL> for column in values [ <NUM_LIT:0> ] . keys ( ) : <EOL> columns . append ( '<STR_LIT>' % ( self . get_marker ( ) , self . wrap ( column ) ) ) <EOL> columns = [ '<STR_LIT:U+002CU+0020>' . join ( columns ) ] * len ( values ) <EOL> return '<STR_LIT>' % ( table , names , '<STR_LIT>' . join ( columns ) ) <EOL> def compile_truncate ( self , query ) : <EOL> """<STR_LIT>""" <EOL> sql = { <EOL> '<STR_LIT>' % self . get_marker ( ) : [ query . from__ ] <EOL> } <EOL> sql [ '<STR_LIT>' % self . wrap_table ( query . from__ ) ] = [ ] <EOL> return sql <EOL> def _where_day ( self , query , where ) : <EOL> """<STR_LIT>""" <EOL> return self . _date_based_where ( '<STR_LIT>' , query , where ) <EOL> def _where_month ( self , query , where ) : <EOL> """<STR_LIT>""" <EOL> return self . _date_based_where ( '<STR_LIT>' , query , where ) <EOL> def _where_year ( self , query , where ) : <EOL> """<STR_LIT>""" <EOL> return self . _date_based_where ( '<STR_LIT>' , query , where ) <EOL> def _date_based_where ( self , type , query , where ) : <EOL> """<STR_LIT>""" <EOL> value = str ( where [ '<STR_LIT:value>' ] ) . zfill ( <NUM_LIT:2> ) <EOL> value = self . parameter ( value ) <EOL> return '<STR_LIT>' % ( type , self . wrap ( where [ '<STR_LIT>' ] ) , <EOL> where [ '<STR_LIT>' ] , value ) <EOL> def get_marker ( self ) : <EOL> return '<STR_LIT:?>' </s>
