fix: unable to export BLOB values from table content o query result

This commit is contained in:
Fabio Di Stasio 2023-04-08 09:39:28 +02:00
parent 8be9f932e7
commit afa61a9bc2
3 changed files with 18 additions and 7 deletions

View File

@ -107,10 +107,16 @@ export const valueToSqlString = (args: {
else if (BIT.includes(field.type))
parsedValue = `b'${hexToBinary(Buffer.from(val).toString('hex') as undefined as HexChar[])}'`;
else if (BLOB.includes(field.type)) {
let buffer: Buffer;
if (val instanceof Uint8Array)
buffer = Buffer.from(val);
else
buffer = val;
if (['mysql', 'maria'].includes(client))
parsedValue = `X'${val.toString('hex').toUpperCase()}'`;
parsedValue = `X'${buffer.toString('hex').toUpperCase()}'`;
else if (client === 'pg')
parsedValue = `decode('${val.toString('hex').toUpperCase()}', 'hex')`;
parsedValue = `decode('${buffer.toString('hex').toUpperCase()}', 'hex')`;
}
else if (NUMBER.includes(field.type))
parsedValue = val;

View File

@ -668,15 +668,14 @@ const selectResultset = (index: number) => {
const downloadTable = (format: 'csv' | 'json' | 'sql', table: string) => {
if (!sortedResults.value) return;
const rows = JSON.parse(JSON.stringify(sortedResults.value)).map((row: any) => {
const rows = sortedResults.value.map((row: any) => {
delete row._antares_id;
return row;
});
exportRows({
type: format,
content: rows,
fields: fieldsObj.value as {
fields: JSON.parse(JSON.stringify(fieldsObj.value)) as {
[key: string]: {type: string; datePrecision: number};
},
client: workspaceClient.value,

View File

@ -21,8 +21,14 @@ export const exportRows = (args: {
if (args.content.length)
csv.push(Object.keys(args.content[0]).join(';'));
for (const row of args.content)
csv.push(Object.values(row).map(col => typeof col === 'string' ? `"${col}"` : col).join(';'));
for (const row of args.content) {
csv.push(Object.values(row).map(col => {
if (typeof col === 'string') return `"${col}"`;
if (col instanceof Buffer) return col.toString('base64');
if (col instanceof Uint8Array) return Buffer.from(col).toString('base64');
return col;
}).join(';'));
}
content = csv.join('\n');
break;