Skip to content

Commit

Permalink
Method createMultipleInsertCommandWithIgnore has been created for MyS…
Browse files Browse the repository at this point in the history
…QL and Postgres
  • Loading branch information
apphp committed Jan 29, 2024
1 parent 802bebe commit bfa9a32
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions framework/db/schema/mysql/CMysqlCommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ public function applyLimit($sql,$limit,$offset)
$limit=PHP_INT_MAX;
return parent::applyLimit($sql,$limit,$offset);
}

/**
* Creates a conflict ignorant multiple INSERT command.
* @param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
* @param array[] $data list data to be inserted, each value should be an array in format (column name=>column value).
* @return CDbCommand multiple insert command
* @throws CDbException
* @since 1.1.30
*/
public function createMultipleInsertCommandWithIgnore($table, array $data) {
return $this->composeMultipleInsertCommand($table, $data, [
"main" => "INSERT INTO {{tableName}} ({{columnInsertNames}}) VALUES {{rowInsertValues}} ON DUPLICATE KEY DO NOTHING ",
]);
}
}
14 changes: 14 additions & 0 deletions framework/db/schema/pgsql/CPgsqlCommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ protected function getIntegerPrimaryKeyDefaultValue()
{
return 'DEFAULT';
}

/**
* Creates a conflict ignorant multiple INSERT command.
* @param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
* @param array[] $data list data to be inserted, each value should be an array in format (column name=>column value).
* @return CDbCommand multiple insert command
* @throws CDbException
* @since 1.1.30
*/
public function createMultipleInsertCommandWithIgnore($table, array $data) {
return $this->composeMultipleInsertCommand($table, $data, [
"main" => "INSERT INTO {{tableName}} ({{columnInsertNames}}) VALUES {{rowInsertValues}} ON CONFLICT DO NOTHING",
]);
}
}

0 comments on commit bfa9a32

Please sign in to comment.