public function testFillByObject() { $query = new InsertQuery('tbl1', (object) array('col1' => 'col1Value', 'col2' => 'col2Value', 'col3' => 1)); $this->assertSame('INSERT INTO `tbl1` (`col1`,`col2`,`col3`) VALUES (?,?,?)', $query->getQuery()); $this->assertSame('ssi', $query->getMarker()); $this->assertSame(array('col1Value', 'col2Value', 1), $query->getParameters()); }
/** * do database insert */ function doInsert() { /* refill menu from post data */ /* $this->menu->setMenuValues($_POST); */ /* now test the menu values */ if ($this->prepareForInsert()) { /* then get the data into the query */ $iq = new InsertQuery($this->dbConn, $this->relation); $iq->setKeyColumns($this->keyColumns); $cnames = $this->menu->getColumnNames(); // echo '<br> columnNames'.bvar_dump($cnames).'<br>'; $arr = $this->menu->getColumnValues($cnames); if ($this->isTransactional) { $arr['trans_id'] = $this->dbConn->createTransactionId(); } $iq->setSubmitvalueSet($arr); $iq->setUpdateSet($arr); // echo '<span style="color:red">'.bvar_dump($this->menu).'</span>'; if ($iq->areKeyColumnsSet()) { /* allow insert */ $query = $iq->getQuery(); $this->dbMessage .= 'insert query' . $query; //echo $query; $result = doUpdate($this->dbConn, $query, $this->dbMessage); if ($result < 0) { $this->dbMessage .= 'STE: Insert Failed with query ' . $query . ' db says: ' . $this->dbMessage; $this->dbConn->Execute("ROLLBACK"); } else { $this->dbMessage .= ' added ' . $result . ' record(s) '; $this->dbConn->transactionEnd(); } } else { $this->dbMessage .= 'DB ERROR: Insert failed.<br>Not all keyColumns have been set'; $this->dbConn->Execute("ROLLBACK"); } } }