1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

Merge pull request #920 from dyaskur/develop

fix: Cannot update column value with composite primary key and JSON column #916
This commit is contained in:
2025-01-15 09:12:26 +01:00
committed by GitHub
2 changed files with 23 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import customizations from '../customizations';
import { ClientCode } from '../interfaces/antares'; import { ClientCode } from '../interfaces/antares';
import { getArrayDepth } from './getArrayDepth'; import { getArrayDepth } from './getArrayDepth';
import hexToBinary, { HexChar } from './hexToBinary'; import hexToBinary, { HexChar } from './hexToBinary';
import * as antares from 'common/interfaces/antares';
/** /**
* Escapes a string fo SQL use * Escapes a string fo SQL use
@@ -209,3 +210,20 @@ export const jsonToSqlInsert = (args: {
return insertsString; return insertsString;
}; };
export const formatJsonForSqlWhere = (jsonValue: object, clientType: antares.ClientCode) => {
const formattedValue = JSON.stringify(jsonValue);
switch (clientType) {
case 'mysql':
return ` = CAST('${formattedValue}' AS JSON)`;
case 'maria':
return ` = '${formattedValue}'`;
case 'pg':
return `::text = '${formattedValue}'`;
case 'firebird':
case 'sqlite':
default:
return ` = '${formattedValue}'`;
}
};

View File

@@ -3,7 +3,7 @@ import { ARRAY, BIT, BLOB, BOOLEAN, DATE, DATETIME, FLOAT, LONG_TEXT, NUMBER, TE
import * as antares from 'common/interfaces/antares'; import * as antares from 'common/interfaces/antares';
import { InsertRowsParams } from 'common/interfaces/tableApis'; import { InsertRowsParams } from 'common/interfaces/tableApis';
import { fakerCustom } from 'common/libs/fakerCustom'; import { fakerCustom } from 'common/libs/fakerCustom';
import { sqlEscaper } from 'common/libs/sqlUtils'; import { formatJsonForSqlWhere, sqlEscaper } from 'common/libs/sqlUtils';
import { ipcMain } from 'electron'; import { ipcMain } from 'electron';
import * as fs from 'fs'; import * as fs from 'fs';
import * as moment from 'moment'; import * as moment from 'moment';
@@ -233,9 +233,10 @@ export default (connections: Record<string, antares.Client>) => {
for (const key in orgRow) { for (const key in orgRow) {
if (typeof orgRow[key] === 'string') if (typeof orgRow[key] === 'string')
orgRow[key] = `'${orgRow[key]}'`; orgRow[key] = ` = '${orgRow[key]}'`;
else if (typeof orgRow[key] === 'object' && orgRow[key] !== null)
if (orgRow[key] === null) orgRow[key] = formatJsonForSqlWhere(orgRow[key], connections[params.uid]._client);
else if (orgRow[key] === null)
orgRow[key] = `IS ${orgRow[key]}`; orgRow[key] = `IS ${orgRow[key]}`;
else else
orgRow[key] = `= ${orgRow[key]}`; orgRow[key] = `= ${orgRow[key]}`;