File tree 2 files changed +9
-0
lines changed
2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ function figureOutType(){
35
35
$ this ->type = self ::INSERT ;
36
36
elseif (preg_match ('/^(.*)\s+UNION\s+(.*)$/ ' , $ this ->sql ))
37
37
$ this ->type = self ::UNION ;
38
+ elseif (preg_match ('/^UPDATE\s/ ' , $ this ->sql ))
39
+ $ this ->type = self ::UPDATE ;
38
40
else
39
41
$ this ->type = self ::UNKNOWN ;
40
42
}
@@ -48,6 +50,9 @@ function toSelect() {
48
50
return preg_replace ('/^DELETE\s+FROM\s/ ' , 'SELECT 0 FROM ' , $ this ->sql );
49
51
case self ::DELETEMULTI :
50
52
return preg_replace ('/^DELETE\s+ ' .self ::TABLEREF .'\s+FROM\s/ ' , 'SELECT 0 FROM ' , $ this ->sql );
53
+ case self ::UPDATE :
54
+ preg_match ('/^UPDATE\s+(.*)\s+SET\s+(.*)\s+WHERE\s+(.*)$/ ' , $ this ->sql , $ subpatterns );
55
+ return "SELECT {$ subpatterns [2 ]} FROM {$ subpatterns [1 ]} WHERE {$ subpatterns [3 ]}" ;
51
56
}
52
57
return null ;
53
58
}
@@ -60,6 +65,7 @@ function asExplain() {
60
65
break ;
61
66
case self ::DELETE :
62
67
case self ::DELETEMULTI :
68
+ case self ::UPDATE :
63
69
$ sql = $ this ->toSelect ();
64
70
break ;
65
71
default :
Original file line number Diff line number Diff line change 15
15
$ Query = new QueryRewrite ($ query );
16
16
$ sample = $ Query ->asExtendedExplain ();
17
17
18
+ $ return ['oQuery ' ] = $ query ;
19
+ $ return ['eQuery ' ] = $ sample ;
20
+
18
21
if (is_null ($ sample )) {
19
22
$ return ['Warnings ' ][] = array ('Code ' => '0 ' , 'Level ' => 'Error ' , 'Message ' => "I can't explain this type of query yet " );
20
23
}
You can’t perform that action at this time.
0 commit comments