Browse Source

Merge pull request #6017 from VictorMinemu/develop

Fixed bug when trying to open a row with a binary encoded uuid as PK
pull/6036/head
Pranav C 1 year ago committed by GitHub
parent
commit
671f137b54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 2
      packages/nocodb/src/db/conditionV2.ts

20
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -3966,7 +3966,25 @@ function _wherePk(primaryKeys: Column[], id) {
const ids = (id + '').split('___');
const where = {};
for (let i = 0; i < primaryKeys.length; ++i) {
where[primaryKeys[i].column_name] = ids[i];
//Cast the id to string.
const idAsString = ids[i] + '';
// Check if the id is a UUID and the column is binary(16)
const isUUIDBinary16 =
primaryKeys[i].ct === 'binary(16)' &&
(idAsString.length === 36 || idAsString.length === 32);
// If the id is a UUID and the column is binary(16), convert the id to a Buffer. Otherwise, return null to indicate that the id is not a UUID.
const idAsUUID = isUUIDBinary16
? idAsString.length === 32
? idAsString.replace(
/(.{8})(.{4})(.{4})(.{4})(.{12})/,
'$1-$2-$3-$4-$5',
)
: idAsString
: null;
where[primaryKeys[i].column_name] = idAsUUID
? Buffer.from(idAsUUID.replace(/-/g, ''), 'hex')
: ids[i];
}
return where;
}

2
packages/nocodb/src/db/conditionV2.ts

@ -419,6 +419,8 @@ const parseConditionV2 = async (
].includes(column.uidt)
) {
qb = qb.where(field, val);
} else if (column.ct === 'timestamp') {
qb = qb.whereRaw('DATE(??) = DATE(?)', [field, val]);
} else {
// mysql is case-insensitive for strings, turn to case-sensitive
qb = qb.whereRaw('BINARY ?? = ?', [field, val]);

Loading…
Cancel
Save