Skip to content

Commit

Permalink
fix: unable to export BLOB values from table content o query result
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Apr 8, 2023
1 parent 8be9f93 commit afa61a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/common/libs/sqlUtils.ts
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/components/WorkspaceTabQueryTable.vue
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/libs/exportRows.ts
Expand Up @@ -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;
Expand Down

0 comments on commit afa61a9

Please sign in to comment.