@@ -9,26 +9,26 @@ class Insert extends InsertUpdateStatement {
99 * @var array
1010 */
1111 private $ fields = array ();
12+
1213 /**
1314 * @var array
1415 */
1516 private $ update = array ();
17+
1618 /**
1719 * @var string
1820 */
1921 private $ table = null ;
22+
2023 /**
2124 * @var string
2225 */
2326 private $ keyField = null ;
27+
2428 /**
2529 * @var bool
2630 */
2731 private $ ignore = false ;
28- /**
29- * @var Select
30- */
31- private $ from = null ;
3232
3333 /**
3434 * @param string $table
@@ -172,15 +172,6 @@ public function addOrUpdateAll(array $data) {
172172 return $ this ;
173173 }
174174
175- /**
176- * @param Select $select
177- * @return $this
178- */
179- public function from (Select $ select ) {
180- $ this ->from = $ select ;
181- return $ this ;
182- }
183-
184175 /**
185176 * @throws Exception
186177 * @return string
@@ -190,6 +181,16 @@ public function __toString() {
190181 throw new Exception ('Specify a table-name ' );
191182 }
192183
184+ $ fields = $ this ->fields ;
185+ $ tableFields = $ this ->db ()->getTableFields ($ this ->table );
186+
187+ $ insertData = $ this ->buildFieldList ($ fields , $ tableFields );
188+ $ updateData = $ this ->buildUpdate ();
189+
190+ if (empty ($ insertData )) {
191+ throw new Exception ('No field-data found ' );
192+ }
193+
193194 $ tableName = (new AliasReplacer ($ this ->db ()->getAliasRegistry ()))->replace ($ this ->table );
194195
195196 $ queryArr = array ();
@@ -231,7 +232,8 @@ public function __toString() {
231232 */
232233 private function buildUpdate () {
233234 $ queryArr = array ();
234- $ tableFields = $ this ->db ()->getTableFields ($ this ->table );
235+ $ tableName = $ this ->aliasReplacer ()->replace ($ this ->table );
236+ $ tableFields = $ this ->db ()->getTableFields ($ tableName );
235237 if (!empty ($ this ->update )) {
236238 $ queryArr [] = "ON DUPLICATE KEY UPDATE \n" ;
237239 $ updateArr = array ();
0 commit comments