Repository navigation
Conversation
DatabaseExporter wrote NULL values as <field name="x" value_is_null></field>. An attribute without a value is not well-formed XML, so any export of a table containing NULL could not be read back by DatabaseImporter or the import command. The attribute now has a value; the importer only checks isset(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ta and NULL - The structure attributes written by the MySQL, MySQLi and PostgreSQL exporters (types, defaults, comments, key queries) were not escaped, so a default such as a"b or x&y broke the XML. - Only mediumblob columns were base64 encoded, and the importer never decoded them, so blobs came back as base64 text. All binary column types are now encoded and marked with encoding="base64", which the importer decodes. - PgsqlExporter passed NULL to htmlspecialchars() (deprecated, exported as an empty string) and wrote bytea values as raw bytes into the XML. NULL is now marked with value_is_null, bytea is base64 encoded, and PgsqlDriver inserts bytea values with quoteBinary(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Exporting a table and importing the file again changed or lost data:
MysqlExporter,MysqliExporterandPgsqlExporterconcatenated column types, defaults, comments and key definitions into XML attributes without escaping. A default such asa"borx&yproduced a document that could not be parsed. All attributes now go through a newDatabaseExporter::escapeXml()(htmlspecialchars()withENT_QUOTES | ENT_XML1). The PostgreSQL keyQueryattribute is now double-quoted and escaped like the others (it was single-quoted and unescaped).DatabaseExporterbase64-encodedmediumblobcolumns only, andDatabaseImporter::importData()never decoded anything, so blobs were imported as base64 text. Now all binary column types (tinyblob,blob,mediumblob,longblob,binary(n),varbinary(n)) are encoded, the field is markedencoding="base64", and the importer decodes marked fields. NULL in a binary column is exported as NULL instead of an empty string.PgsqlExportercalledhtmlspecialchars($value)on NULL values (a deprecation since PHP 8.1, and NULL became'') and wrotebyteavalues withstream_get_contents()as raw bytes into the XML, which is invalid for non-text bytes. NULL is now written withvalue_is_null="1"like the base exporter, andbyteais base64 encoded and marked. On import,PgsqlDriver::sqlValue()rendersbyteavalues withquoteBinary()(decode('…', 'hex')), because a binary string cannot be inserted as a text literal.Old exports stay importable: fields without
encodingare imported as before.Depends on #379 (well-formed
value_is_null="1"), which changes a line next to the blob handling; this branch is based on it, so the diff shows that commit until #379 is merged. The trust question for imported structure (types/defaults ending up in DDL) is handled separately.Testing Instructions
MysqliExporterTest::testRoundTripWithSpecialCharactersAndBinaryDataexports a column with defaulta"b&c<dand ablobvalue containing NUL,\xFF, quotes and<&>, parses the XML, imports it withMysqliImporterinto a stub and compares the values. It fails before the change (the XML does not parse).PgsqlExporterTest::testNullAndByteaValuesexports a NULL and abyteastream; before the change the XML does not parse.Both need no database (
vendor/bin/phpunit Tests/Mysqli/MysqliExporterTest.php Tests/Pgsql/PgsqlExporterTest.php).PgsqlImporterTesthas one failure on Windows that is unrelated (it compares\r\nagainst\n) and fails on4.x-devtoo.Documentation Changes Required
None on
4.x-dev. #373'sdocs/schema-tools.md→ "Exporting"/"Importing" does not describe the XML format; nothing there becomes wrong.🤖 Generated with Claude Code