Skip to content

Commit

Permalink
feat(PostgreSQL): insert and edit blob fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Mar 18, 2021
1 parent fc65114 commit 1f80a64
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 21 deletions.
94 changes: 76 additions & 18 deletions src/main/ipc-handlers/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default (connections) => {
});

ipcMain.handle('update-table-cell', async (event, params) => {
try {
try { // TODO: move to client classes
let escapedParam;
let reload = false;
const id = typeof params.id === 'number' ? params.id : `"${params.id}"`;
Expand All @@ -74,12 +74,32 @@ export default (connections) => {
escapedParam = `'${params.content.replaceAll('\'', '\'\'')}'`;
else if (BLOB.includes(params.type)) {
if (params.content) {
const fileBlob = fs.readFileSync(params.content);
escapedParam = `0x${fileBlob.toString('hex')}`;
let fileBlob;

switch (connections[params.uid]._client) {
case 'mysql':
case 'maria':
fileBlob = fs.readFileSync(params.content);
escapedParam = `0x${fileBlob.toString('hex')}`;
break;
case 'pg':
fileBlob = fs.readFileSync(params.content);
escapedParam = `decode('${fileBlob.toString('hex')}', 'hex')`;
break;
}
reload = true;
}
else
escapedParam = '""';
else {
switch (connections[params.uid]._client) {
case 'mysql':
case 'maria':
escapedParam = '""';
break;
case 'pg':
escapedParam = 'decode(\'\', \'hex\')';
break;
}
}
}
else if ([...BIT].includes(params.type)) {
escapedParam = `b'${sqlEscaper(params.content)}'`;
Expand Down Expand Up @@ -171,7 +191,7 @@ export default (connections) => {
});

ipcMain.handle('insert-table-rows', async (event, params) => {
try {
try { // TODO: move to client classes
const insertObj = {};
for (const key in params.row) {
const type = params.fields[key];
Expand All @@ -184,15 +204,33 @@ export default (connections) => {
else if ([...TEXT, ...LONG_TEXT].includes(type))
escapedParam = `'${sqlEscaper(params.row[key])}'`;
else if (BLOB.includes(type)) {
if (params.row[key]) {
const fileBlob = fs.readFileSync(params.row[key]);
escapedParam = `0x${fileBlob.toString('hex')}`;
if (params.row[key].value) {
let fileBlob;

switch (connections[params.uid]._client) {
case 'mysql':
case 'maria':
fileBlob = fs.readFileSync(params.row[key].value);
escapedParam = `0x${fileBlob.toString('hex')}`;
break;
case 'pg':
fileBlob = fs.readFileSync(params.row[key].value);
escapedParam = `decode('${fileBlob.toString('hex')}', 'hex')`;
break;
}
}
else {
switch (connections[params.uid]._client) {
case 'mysql':
case 'maria':
escapedParam = '""';
break;
case 'pg':
escapedParam = 'decode(\'\', \'hex\')';
break;
}
}
else
escapedParam = '\'\'';
}
else
escapedParam = `'${sqlEscaper(params.row[key])}'`;

insertObj[key] = escapedParam;
}
Expand All @@ -213,7 +251,7 @@ export default (connections) => {
});

ipcMain.handle('insert-table-fake-rows', async (event, params) => {
try {
try { // TODO: move to client classes
const rows = [];

for (let i = 0; i < +params.repeat; i++) {
Expand All @@ -232,11 +270,31 @@ export default (connections) => {
escapedParam = `'${sqlEscaper(params.row[key].value)}'`;
else if (BLOB.includes(type)) {
if (params.row[key].value) {
const fileBlob = fs.readFileSync(params.row[key].value);
escapedParam = `0x${fileBlob.toString('hex')}`;
let fileBlob;

switch (connections[params.uid]._client) {
case 'mysql':
case 'maria':
fileBlob = fs.readFileSync(params.row[key].value);
escapedParam = `0x${fileBlob.toString('hex')}`;
break;
case 'pg':
fileBlob = fs.readFileSync(params.row[key].value);
escapedParam = `decode('${fileBlob.toString('hex')}', 'hex')`;
break;
}
}
else {
switch (connections[params.uid]._client) {
case 'mysql':
case 'maria':
escapedParam = '""';
break;
case 'pg':
escapedParam = 'decode(\'\', \'hex\')';
break;
}
}
else
escapedParam = '\'\'';
}
else if (BIT.includes(type))
escapedParam = `b'${sqlEscaper(params.row[key].value)}'`;
Expand Down
14 changes: 11 additions & 3 deletions src/renderer/components/Workspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@
<i class="mdi mdi-24px mdi-tools" />
</a>
<ul class="menu text-left text-uppercase">
<li class="menu-item">
<li v-if="workspace.customizations.processesList" class="menu-item">
<a class="c-hand p-vcentered" @click="showProcessesModal">
<i class="mdi mdi-memory mr-1 tool-icon" />
<span>{{ $t('message.processesList') }}</span>
</a>
</li>
<li class="menu-item" title="Coming...">
<li
v-if="workspace.customizations.variables"
class="menu-item"
title="Coming..."
>
<a class="c-hand p-vcentered disabled">
<i class="mdi mdi-shape mr-1 tool-icon" />
<span>{{ $t('word.variables') }}</span>
</a>
</li>
<li class="menu-item" title="Coming...">
<li
v-if="workspace.customizations.usersManagement"
class="menu-item"
title="Coming..."
>
<a class="c-hand p-vcentered disabled">
<i class="mdi mdi-account-group mr-1 tool-icon" />
<span>{{ $t('message.manageUsers') }}</span>
Expand Down

0 comments on commit 1f80a64

Please sign in to comment.