fix(adapter-mariadb,adapter-planetscale): return strings for text columns with binary collation in raw queries#29238
Conversation
…lation in raw queries
Merging this PR will not alter performance
Comparing Footnotes
|
|
The newly added test is failing for |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (6)
WalkthroughFixes a bug where Changes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I added some fixes to adapter-planetscale as well. |
…umns with binary collation in raw queries (#29238) Fixes #29237 ## Summary ### adapter-mariadb Replace the `BINARY_FLAG` check with a collation index check (`collation.index === 63`), matching the approach used by `mariadb-connector-nodejs`. https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/3.5.1/lib/cmd/decoder/text-decoder.js#L44 ### adapter-planetscale Add a charset-based collation check (`field.charset !== 63`) in `fieldToColumnType` to distinguish text columns from true binary columns. Vitess converts CHAR/VARCHAR/TEXT columns with a binary collation to BINARY/VARBINARY/BLOB respectively, so the charset value is used to detect this conversion. https://github.com/planetscale/database-js/blob/de78eebfaec8cd88c670b8c644fc5a3fd69e664c/src/cast.ts#L92 ## Root cause Because the `mapColumnType` function in `adapter-mariadb` returns `ColumnTypeEnum.Bytes` when a column has a Binary Collation, https://github.com/prisma/prisma/blob/7.4.1/packages/adapter-mariadb/src/conversion.ts#L86 and the `fieldToColumnType` function in `adapter-planetscale` does not inspect the charset at all for BLOB/BINARY/VARBINARY types, https://github.com/prisma/prisma/blob/7.4.1/packages/adapter-planetscale/src/conversion.ts#L85 the `deserializeValue` function unintentionally converts even string data into a `Uint8Array`, treating it as a base64 string. https://github.com/prisma/prisma/blob/7.4.1/packages/client/src/runtime/utils/deserializeRawResults.ts#L20 Since a Binary Collation can also apply to string data types like `CHAR`, the type determination logic in both `adapter-mariadb` and `adapter-planetscale` needs to be updated. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved binary collation detection in MariaDB and PlanetScale database adapters. Columns with binary collation now correctly return as text data. * **Tests** * Added MySQL column type tests to validate binary collation handling in query results. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Fixes #29237
Summary
adapter-mariadb
Replace the
BINARY_FLAGcheck with a collation index check (collation.index === 63), matching the approach used bymariadb-connector-nodejs.https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/3.5.1/lib/cmd/decoder/text-decoder.js#L44
adapter-planetscale
Add a charset-based collation check (
field.charset !== 63) infieldToColumnTypeto distinguish text columns from true binary columns. Vitess converts CHAR/VARCHAR/TEXT columns with a binary collation to BINARY/VARBINARY/BLOB respectively, so the charset value is used to detect this conversion.https://github.com/planetscale/database-js/blob/de78eebfaec8cd88c670b8c644fc5a3fd69e664c/src/cast.ts#L92
Root cause
Because the
mapColumnTypefunction inadapter-mariadbreturnsColumnTypeEnum.Byteswhen a column has a Binary Collation,https://github.com/prisma/prisma/blob/7.4.1/packages/adapter-mariadb/src/conversion.ts#L86
and the
fieldToColumnTypefunction inadapter-planetscaledoes not inspect the charset at all for BLOB/BINARY/VARBINARY types,https://github.com/prisma/prisma/blob/7.4.1/packages/adapter-planetscale/src/conversion.ts#L85
the
deserializeValuefunction unintentionally converts even string data into aUint8Array, treating it as a base64 string.https://github.com/prisma/prisma/blob/7.4.1/packages/client/src/runtime/utils/deserializeRawResults.ts#L20
Since a Binary Collation can also apply to string data types like
CHAR, the type determination logic in bothadapter-mariadbandadapter-planetscaleneeds to be updated.Summary by CodeRabbit
Bug Fixes
Tests