mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Refactoring insertMulti() for DboSource and drivers, updating Model test for non-transactional db's
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6707 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f91f90df71
commit
42083e0a1b
8 changed files with 31 additions and 61 deletions
|
@ -418,15 +418,5 @@ class DboAdodb extends DboSource {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Inserts multiple values into a join table
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param array $values
|
||||
*/
|
||||
function insertMulti($table, $fields, $values) {
|
||||
parent::__insertMulti($table, $fields, $values);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -502,15 +502,5 @@ class DboFirebird extends DboSource {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Inserts multiple values into a join table
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param array $values
|
||||
*/
|
||||
function insertMulti($table, $fields, $values) {
|
||||
parent::__insertMulti($table, $fields, $values);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -565,16 +565,6 @@ class DboMssql extends DboSource {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Inserts multiple values into a join table
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param array $values
|
||||
*/
|
||||
function insertMulti($table, $fields, $values) {
|
||||
parent::__insertMulti($table, $fields, $values);
|
||||
}
|
||||
/**
|
||||
* Generate a database-native column schema string
|
||||
*
|
||||
|
|
|
@ -488,6 +488,21 @@ class DboMysql extends DboSource {
|
|||
function getEncoding() {
|
||||
return mysql_client_encoding($this->connection);
|
||||
}
|
||||
/**
|
||||
* Inserts multiple values into a table
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param array $values
|
||||
*/
|
||||
function insertMulti($table, $fields, $values) {
|
||||
$table = $this->fullTableName($table);
|
||||
if (is_array($fields)) {
|
||||
$fields = join(', ', array_map(array(&$this, 'name'), $fields));
|
||||
}
|
||||
$values = implode(', ', $values);
|
||||
$this->query("INSERT INTO {$table} ({$fields}) VALUES {$values}");
|
||||
}
|
||||
/**
|
||||
* Returns an array of the indexes in given table name.
|
||||
*
|
||||
|
|
|
@ -730,17 +730,6 @@ class DboOracle extends DboSource {
|
|||
function lastAffected() {
|
||||
return $this->_statementId ? ocirowcount($this->_statementId): false;
|
||||
}
|
||||
/**
|
||||
* Inserts multiple values into a join table
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param array $values
|
||||
*/
|
||||
function insertMulti($table, $fields, $values) {
|
||||
parent::__insertMulti($table, $fields, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a final SQL statement by putting together the component parts in the correct order
|
||||
*
|
||||
|
|
|
@ -431,16 +431,6 @@ class DboSqlite extends DboSource {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Inserts multiple values into a join table
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param array $values
|
||||
*/
|
||||
function insertMulti($table, $fields, $values) {
|
||||
parent::__insertMulti($table, $fields, $values);
|
||||
}
|
||||
/**
|
||||
* Generate a database-native column schema string
|
||||
*
|
||||
|
|
|
@ -380,16 +380,6 @@ class DboSybase extends DboSource {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Inserts multiple values into a join table
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param array $values
|
||||
*/
|
||||
function insertMulti($table, $fields, $values) {
|
||||
parent::__insertMulti($table, $fields, $values);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -2149,6 +2149,7 @@ class ModelTest extends CakeTestCase {
|
|||
array('author_id' => 1, 'title' => 'New Fifth Post'),
|
||||
array('author_id' => 1, 'title' => '')
|
||||
);
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$this->assertFalse($this->model->saveAll($data));
|
||||
|
||||
$result = $this->model->find('all', array('recursive' => -1));
|
||||
|
@ -2157,6 +2158,15 @@ class ModelTest extends CakeTestCase {
|
|||
array('Post' => array('id' => '2', 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31')),
|
||||
array('Post' => array('id' => '3', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'))
|
||||
);
|
||||
if (count($result) != 3) {
|
||||
// Database doesn't support transactions
|
||||
$expected[] = array('Post' => array('id' => '4', 'author_id' => 1, 'title' => 'New Fourth Post', 'body' => null, 'published' => 'N', 'created' => $ts, 'updated' => $ts));
|
||||
$expected[] = array('Post' => array('id' => '5', 'author_id' => 1, 'title' => 'New Fifth Post', 'body' => null, 'published' => 'N', 'created' => $ts, 'updated' => $ts));
|
||||
$this->assertEqual($result, $expected);
|
||||
// Skip the rest of the transactional tests
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$data = array(
|
||||
|
@ -2164,6 +2174,7 @@ class ModelTest extends CakeTestCase {
|
|||
array('author_id' => 1, 'title' => ''),
|
||||
array('author_id' => 1, 'title' => 'New Sixth Post')
|
||||
);
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$this->assertFalse($this->model->saveAll($data));
|
||||
|
||||
$result = $this->model->find('all', array('recursive' => -1));
|
||||
|
@ -2172,6 +2183,11 @@ class ModelTest extends CakeTestCase {
|
|||
array('Post' => array('id' => '2', 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31')),
|
||||
array('Post' => array('id' => '3', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'))
|
||||
);
|
||||
if (count($result) != 3) {
|
||||
// Database doesn't support transactions
|
||||
$expected[] = array('Post' => array('id' => '4', 'author_id' => 1, 'title' => 'New Fourth Post', 'body' => 'Third Post Body', 'published' => 'N', 'created' => $ts, 'updated' => $ts));
|
||||
$expected[] = array('Post' => array('id' => '5', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'N', 'created' => $ts, 'updated' => $ts));
|
||||
}
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->model->validate = array('title' => VALID_NOT_EMPTY);
|
||||
|
|
Loading…
Add table
Reference in a new issue