File tree 5 files changed +23
-9
lines changed
5 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ public function __toString() {
46
46
throw new Exception ('Specify a table-name ' );
47
47
}
48
48
49
- $ sqlTable = ( new AliasReplacer ( $ this ->db ()-> getAliasRegistry ()) )->replace ($ this ->table );
49
+ $ sqlTable = $ this ->aliasReplacer ( )->replace ($ this ->table );
50
50
$ queryArr = array ();
51
51
$ queryArr [] = "DELETE " ."FROM \n\t{$ sqlTable }\n" ;
52
52
Original file line number Diff line number Diff line change @@ -181,8 +181,10 @@ public function __toString() {
181
181
throw new Exception ('Specify a table-name ' );
182
182
}
183
183
184
+ $ tableName = $ this ->aliasReplacer ()->replace ($ this ->table );
185
+
184
186
$ fields = $ this ->fields ;
185
- $ tableFields = $ this ->db ()->getTableFields ($ this -> table );
187
+ $ tableFields = $ this ->db ()->getTableFields ($ tableName );
186
188
187
189
$ insertData = $ this ->buildFieldList ($ fields , $ tableFields );
188
190
$ updateData = $ this ->buildUpdate ();
@@ -191,8 +193,6 @@ public function __toString() {
191
193
throw new Exception ('No field-data found ' );
192
194
}
193
195
194
- $ tableName = (new AliasReplacer ($ this ->db ()->getAliasRegistry ()))->replace ($ this ->table );
195
-
196
196
$ queryArr = array ();
197
197
$ ignoreStr = $ this ->ignore ? ' IGNORE ' : '' ;
198
198
$ queryArr [] = "INSERT {$ ignoreStr } INTO \n\t{$ tableName }\n" ;
Original file line number Diff line number Diff line change @@ -429,7 +429,7 @@ private function buildTableName($alias, $name) {
429
429
$ name = join ("\n" , $ lines );
430
430
$ name = '( ' . trim (rtrim (trim ($ name ), '; ' )) . ') ' ;
431
431
}
432
- $ name = ( new AliasReplacer ( $ this ->db ()-> getAliasRegistry ()) )->replace ($ name );
432
+ $ name = $ this ->aliasReplacer ( )->replace ($ name );
433
433
return sprintf ("%s %s " , $ name , $ alias );
434
434
}
435
435
Original file line number Diff line number Diff line change 2
2
namespace Kir \MySQL \Builder ;
3
3
4
4
use Kir \MySQL \Database ;
5
+ use Kir \MySQL \Tools \AliasReplacer ;
5
6
6
7
abstract class Statement {
7
8
/**
8
- * @var
9
+ * @var Database
9
10
*/
10
11
private $ db ;
11
12
13
+ /**
14
+ * @var AliasReplacer
15
+ */
16
+ private $ aliasReplacer ;
17
+
12
18
/**
13
19
* @param Database $db
14
20
*/
15
21
public function __construct (Database $ db ) {
16
22
$ this ->db = $ db ;
23
+ $ this ->aliasReplacer = new AliasReplacer ($ db ->getAliasRegistry ());
17
24
}
18
25
19
26
/**
@@ -39,6 +46,13 @@ public function cloneStatement() {
39
46
return clone $ this ;
40
47
}
41
48
49
+ /**
50
+ * @return AliasReplacer
51
+ */
52
+ public function aliasReplacer () {
53
+ return $ this ->aliasReplacer ;
54
+ }
55
+
42
56
/**
43
57
* @return Database
44
58
*/
Original file line number Diff line number Diff line change @@ -94,15 +94,15 @@ public function __toString() {
94
94
throw new Exception ('Specify a table-name ' );
95
95
}
96
96
97
- $ tableFields = $ this ->db ()->getTableFields ($ this ->table );
97
+ $ tableName = $ this ->aliasReplacer ()->replace ($ this ->table );
98
+
99
+ $ tableFields = $ this ->db ()->getTableFields ($ tableName );
98
100
$ sqlFields = $ this ->buildFieldList ($ this ->fields , $ tableFields );
99
101
100
102
if (empty ($ sqlFields )) {
101
103
throw new Exception ('No field-data found ' );
102
104
}
103
105
104
- $ tableName = (new AliasReplacer ($ this ->db ()->getAliasRegistry ()))->replace ($ this ->table );
105
-
106
106
$ queryArr = array ();
107
107
$ queryArr [] = "UPDATE \n\t{$ tableName }\nSET \n{$ sqlFields }\n" ;
108
108
You can’t perform that action at this time.
0 commit comments