Skip to content

Commit

Permalink
When hex-blob was specified and virtual columns of type blob or bit e…
Browse files Browse the repository at this point in the history
…xisted, produced dump file was invalid. Fixes ifsnop#214
  • Loading branch information
ifsnop committed Feb 9, 2023
1 parent c5ef1ff commit bd1498c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,13 +1266,13 @@ public function getColumnStmt($tableName)
{
$colStmt = array();
foreach ($this->tableColumnTypes[$tableName] as $colName => $colType) {
if ($colType['type'] == 'bit' && $this->dumpSettings['hex-blob']) {
if ($colType['is_virtual']) {
$this->dumpSettings['complete-insert'] = true;
continue;
} elseif ($colType['type'] == 'bit' && $this->dumpSettings['hex-blob']) {
$colStmt[] = "LPAD(HEX(`{$colName}`),2,'0') AS `{$colName}`";
} elseif ($colType['is_blob'] && $this->dumpSettings['hex-blob']) {
$colStmt[] = "HEX(`{$colName}`) AS `{$colName}`";
} elseif ($colType['is_virtual']) {
$this->dumpSettings['complete-insert'] = true;
continue;
} else {
$colStmt[] = "`{$colName}`";
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=test011",
"travis",
"",
array('complete-insert' => false));
array('complete-insert' => false, 'hex-blob' => false));
$dump->start("mysqldump-php_test011a.sql");

print "starting mysql-php_test011b.sql" . PHP_EOL;
Expand Down
32 changes: 29 additions & 3 deletions tests/test011.src.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ DROP DATABASE IF EXISTS `test011`;
CREATE DATABASE `test011`;
USE `test011`;

-- MySQL dump 10.13 Distrib 5.7.15, for Linux (x86_64)
-- MySQL dump 10.13 Distrib 5.7.29, for Linux (x86_64)
--
-- Host: localhost Database: test
-- Host: localhost Database: test011
-- ------------------------------------------------------
-- Server version 5.7.15
-- Server version 5.7.29-0ubuntu0.18.04.1-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
Expand Down Expand Up @@ -42,6 +42,30 @@ LOCK TABLES `test011` WRITE;
INSERT INTO `test011` (`id`) VALUES (159413),(294775);
/*!40000 ALTER TABLE `test011` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `test012`
--

DROP TABLE IF EXISTS `test012`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `test012` (
`id` int(11) NOT NULL,
`hash_stored` char(32) CHARACTER SET ascii COLLATE ascii_bin GENERATED ALWAYS AS (md5(`id`)) STORED NOT NULL,
`hash_virtual` blob GENERATED ALWAYS AS (md5(`id`)) VIRTUAL NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `test012`
--

LOCK TABLES `test012` WRITE;
/*!40000 ALTER TABLE `test012` DISABLE KEYS */;
INSERT INTO `test012` (`id`) VALUES (159413),(294775);
/*!40000 ALTER TABLE `test012` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
Expand All @@ -51,3 +75,5 @@ UNLOCK TABLES;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2023-02-08 23:27:41

0 comments on commit bd1498c

Please sign in to comment.