Skip to content

fix(adapter-mariadb,adapter-planetscale): return strings for text columns with binary collation in raw queries#29238

Merged
jacek-prisma merged 2 commits intoprisma:mainfrom
sakurai-ryo:fix-mysql-bin
Feb 26, 2026
Merged

fix(adapter-mariadb,adapter-planetscale): return strings for text columns with binary collation in raw queries#29238
jacek-prisma merged 2 commits intoprisma:mainfrom
sakurai-ryo:fix-mysql-bin

Conversation

@sakurai-ryo
Copy link
Copy Markdown
Contributor

@sakurai-ryo sakurai-ryo commented Feb 23, 2026

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.

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.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 23, 2026

CLA assistant check
All committers have signed the CLA.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 24, 2026

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 30 skipped benchmarks1


Comparing sakurai-ryo:fix-mysql-bin (c5b5acf) with main (4a48ecc)

Open in CodSpeed

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@jacek-prisma
Copy link
Copy Markdown
Contributor

The newly added test is failing for planetscale

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c61292b and c5b5acf.

📒 Files selected for processing (6)
  • packages/adapter-mariadb/src/conversion.ts
  • packages/adapter-planetscale/src/conversion.ts
  • packages/adapter-planetscale/src/planetscale.ts
  • packages/client/tests/functional/raw-queries/mysql-column-type/_matrix.ts
  • packages/client/tests/functional/raw-queries/mysql-column-type/prisma/_schema.ts
  • packages/client/tests/functional/raw-queries/mysql-column-type/test.ts

Walkthrough

Fixes a bug where $queryRaw returns Uint8Array instead of strings for text columns with binary collation. Updates MariaDB and PlanetScale adapters to use collation-index-based checks instead of BINARY_FLAG for type detection. Refactors PlanetScale adapter's public API. Adds MySQL functional tests to verify correct string handling.

Changes

Cohort / File(s) Summary
MariaDB Adapter
packages/adapter-mariadb/src/conversion.ts
Replaces BINARY_FLAG-based detection with collation-index check (BINARY_COLLATION_INDEX = 63) to accurately distinguish binary from text columns with binary collation.
PlanetScale Adapter
packages/adapter-planetscale/src/conversion.ts, packages/adapter-planetscale/src/planetscale.ts
Introduces collation-index-based binary detection, refactors fieldToColumnType to accept Field objects instead of PlanetScaleColumnType, removes PlanetScaleColumnType from public exports, and updates integration to pass full field objects.
MySQL Column Type Tests
packages/client/tests/functional/raw-queries/mysql-column-type/_matrix.ts, prisma/_schema.ts, test.ts
Adds functional test suite for MySQL with test matrix, schema definition, and tests verifying text columns with binary collation (utf8mb4_bin) return strings rather than Uint8Array.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: fixing binary collation handling in both adapter-mariadb and adapter-planetscale to return strings for text columns.
Linked Issues check ✅ Passed The PR implements the required change from issue #29237: replacing BINARY_FLAG checks with collation-index checks (collation.index === 63) in both adapters, and adds functional tests validating strings are returned for text columns with binary collation.
Out of Scope Changes check ✅ Passed The PR includes changes to adapter-mariadb and adapter-planetscale conversion logic as required, plus related updates to planetscale.ts to use the new function signature, and adds necessary functional tests for MySQL.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sakurai-ryo sakurai-ryo changed the title fix(adapter-mariadb): return strings for text columns with binary collation in raw queries fix(adapter-mariadb,adapter-planetscale): return strings for text columns with binary collation in raw queries Feb 26, 2026
@sakurai-ryo
Copy link
Copy Markdown
Contributor Author

I added some fixes to adapter-planetscale as well.

@jacek-prisma jacek-prisma merged commit 76bb95b into prisma:main Feb 26, 2026
244 of 253 checks passed
jacek-prisma pushed a commit that referenced this pull request Feb 27, 2026
…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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$queryRaw returns Uint8Array instead of string for string data columns with binary collation

3 participants