File tree 1 file changed +12
-8
lines changed
1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -645,6 +645,9 @@ def default(self, obj):
645
645
return str (obj )
646
646
647
647
648
+ SENTINEL = object ()
649
+
650
+
648
651
class CustomPeeweeDB (peewee .MySQLDatabase ):
649
652
"""
650
653
Override peewee.MySQLDatabase to modify `execute_sql` method
@@ -674,18 +677,19 @@ class CustomPeeweeDB(peewee.MySQLDatabase):
674
677
def __init__ (self , * args , ** kwargs ):
675
678
super ().__init__ (* args , ** kwargs )
676
679
677
- def execute_sql (self , sql ):
678
- if self .in_transaction ():
679
- commit = False
680
- elif self .commit_select :
681
- commit = True
682
- else :
683
- commit = not sql [:6 ].lower ().startswith ("select" )
680
+ def execute_sql (self , sql , params = None , commit = SENTINEL ):
681
+ if commit is SENTINEL :
682
+ if self .in_transaction ():
683
+ commit = False
684
+ elif self .commit_select :
685
+ commit = True
686
+ else :
687
+ commit = not sql [:6 ].lower ().startswith ("select" )
684
688
685
689
with self .__exception_wrapper__ :
686
690
cursor = self .cursor (commit )
687
691
try :
688
- cursor .execute (sql , None ) # params passed as none
692
+ cursor .execute (sql , params )
689
693
except Exception :
690
694
if self .autorollback and not self .in_transaction ():
691
695
self .rollback ()
You can’t perform that action at this time.
0 commit comments