Skip to content

Commit

Permalink
added complete-insert. Closes ifsnop#93.
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsnop committed Oct 25, 2015
1 parent 905646b commit de89359
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ MySQLDump-PHP is the only library that supports:
* resolves view dependencies (using Stand-In tables).
* output compared against original mysqldump. Linked to travis-ci testing system.
* dumps stored procedures.
* does extended-insert and/or complete-insert.

## Important

Expand Down Expand Up @@ -120,6 +121,7 @@ Refer to the [wiki](https://github.com/ifsnop/mysqldump-php/wiki/full-example) f
'lock-tables' => false,
'add-locks' => true,
'extended-insert' => true,
'complete-insert' => false,
'disable-keys' => true,
'where' => '',
'no-create-info' => false,
Expand Down Expand Up @@ -167,6 +169,8 @@ Refer to the [wiki](https://github.com/ifsnop/mysqldump-php/wiki/full-example) f
- http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_add-locks
- **extended-insert**
- http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_extended-insert
- **complete-insert**
- http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_complete-insert
- **disable-keys**
- http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_disable-keys
- **where**
Expand Down
16 changes: 13 additions & 3 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function __construct(
'lock-tables' => true,
'add-locks' => true,
'extended-insert' => true,
'complete-insert' => false,
'disable-keys' => true,
'where' => '',
'no-create-info' => false,
Expand Down Expand Up @@ -799,9 +800,18 @@ private function listValues($tableName)
foreach ($resultSet as $row) {
$vals = $this->escape($tableName, $row);
if ($onlyOnce || !$this->dumpSettings['extended-insert']) {
$lineSize += $this->compressManager->write(
"INSERT INTO `$tableName` VALUES (" . implode(",", $vals) . ")"
);

if ($this->dumpSettings['complete-insert']) {
$lineSize += $this->compressManager->write(
"INSERT INTO `$tableName` (`" .
implode("`, `", array_keys($this->tableColumnTypes[$tableName])) .
"`) VALUES (" . implode(",", $vals) . ")"
);
} else {
$lineSize += $this->compressManager->write(
"INSERT INTO `$tableName` VALUES (" . implode(",", $vals) . ")"
);
}
$onlyOnce = false;
} else {
$lineSize += $this->compressManager->write(",(" . implode(",", $vals) . ")");
Expand Down
3 changes: 3 additions & 0 deletions tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
$dump->start("mysqldump-php_test001.sql");

$dumpSettings['default-character-set'] = IMysqldump\Mysqldump::UTF8MB4;
$dumpSettings['complete-insert'] = true;

$dump = new IMysqldump\Mysqldump(
"mysql:host=localhost;dbname=test002",
Expand All @@ -49,6 +50,8 @@

$dump->start("mysqldump-php_test002.sql");

$dumpSettings['complete-insert'] = false;

$dump = new IMysqldump\Mysqldump(
"mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=test005",
"travis",
Expand Down
1 change: 1 addition & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ret[((index++))]=$?
mysqldump -uroot test002 \
--no-autocommit \
--extended-insert=false \
--complete-insert=true \
--hex-blob=true \
--default-character-set=utf8mb4 \
> mysqldump_test002.sql
Expand Down
10 changes: 5 additions & 5 deletions tests/test002.src.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ CREATE TABLE `test201` (
`col` text COLLATE utf8mb4_unicode_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `test201` VALUES ('áéíóú');
INSERT INTO `test201` VALUES ('🎲');
INSERT INTO `test201` VALUES ('🎭');
INSERT INTO `test201` VALUES ('💩');
INSERT INTO `test201` VALUES ('🐈');
INSERT INTO `test201` (`col`) VALUES ('áéíóú');
INSERT INTO `test201` (`col`) VALUES ('🎲');
INSERT INTO `test201` (`col`) VALUES ('🎭');
INSERT INTO `test201` (`col`) VALUES ('💩');
INSERT INTO `test201` (`col`) VALUES ('🐈');

0 comments on commit de89359

Please sign in to comment.