#182 support for MySQL binary keys

This commit is contained in:
Jan Prochazka 2021-10-17 10:24:31 +02:00
parent 30cbcd5ce0
commit 2231bc21cd
6 changed files with 28 additions and 16 deletions

View File

@ -13,3 +13,4 @@ export * from './settingsExtractors';
export * from './filterName';
export * from './diffTools';
export * from './schemaEditorTools';
export * from './stringTools';

View File

@ -0,0 +1,3 @@
export function toHexString(byteArray) {
return byteArray.reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), '');
}

View File

@ -192,14 +192,6 @@
return `Rows: ${allRowCount.toLocaleString()}`;
}
function extractCopiedValue(row, col) {
let value = row[col];
if (value === undefined) value = _.get(row, col);
if (value === null) return '(NULL)';
if (value === undefined) return '(NoField)';
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
return value;
}
</script>
<script lang="ts">
@ -231,7 +223,7 @@
import keycodes from '../utility/keycodes';
import { selectedCellsCallback } from '../stores';
import axiosInstance from '../utility/axiosInstance';
import { copyTextToClipboard } from '../utility/clipboard';
import { copyTextToClipboard ,extractRowCopiedValue} from '../utility/clipboard';
import invalidateCommands from '../commands/invalidateCommands';
import createRef from '../utility/createRef';
import openReferenceForm, { openPrimaryKeyForm } from '../formview/openReferenceForm';
@ -370,7 +362,7 @@
if (!rowData) return '';
const line = colIndexes
.map(col => realColumnUniqueNames[col])
.map(col => extractCopiedValue(rowData, col))
.map(col => extractRowCopiedValue(rowData, col))
.join('\t');
return line;
});

View File

@ -152,7 +152,6 @@
function isDataCell(cell) {
return cell[1] % 2 == 1;
}
</script>
<script lang="ts">
@ -175,7 +174,7 @@
import FontIcon from '../icons/FontIcon.svelte';
import axiosInstance from '../utility/axiosInstance';
import { copyTextToClipboard } from '../utility/clipboard';
import { copyTextToClipboard, extractRowCopiedValue } from '../utility/clipboard';
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import createReducer from '../utility/createReducer';
@ -256,7 +255,7 @@
export function copyToClipboard() {
const column = getCellColumn(currentCell);
if (!column) return;
const text = currentCell[1] % 2 == 1 ? rowData[column.uniqueName] : column.columnName;
const text = currentCell[1] % 2 == 1 ? extractRowCopiedValue(rowData, column.uniqueName) : column.columnName;
copyTextToClipboard(text);
}
@ -475,7 +474,6 @@
function handleSetFormView(rowData, column) {
openReferenceForm(rowData, column, conid, database);
}
</script>
<div class="outer">
@ -629,5 +627,4 @@
right: 40px;
bottom: 20px;
}
</style>

View File

@ -1,3 +1,6 @@
import _ from 'lodash';
import { toHexString } from 'dbgate-tools';
export function copyTextToClipboard(text) {
const oldFocus = document.activeElement;
@ -58,3 +61,13 @@ export function copyTextToClipboard(text) {
if (oldFocus) oldFocus.focus();
}
export function extractRowCopiedValue(row, col) {
let value = row[col];
if (value === undefined) value = _.get(row, col);
if (value === null) return '(NULL)';
if (value === undefined) return '(NoField)';
if (value.type == 'Buffer' && _.isArray(value.data)) return toHexString(value.data);
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
return value;
}

View File

@ -1,4 +1,5 @@
const { SqlDumper } = global.DBGATE_TOOLS;
const { SqlDumper, toHexString } = global.DBGATE_TOOLS;
const _isArray = require('lodash/isArray');
class Dumper extends SqlDumper {
/** @param type {import('dbgate-types').TransformType} */
@ -63,6 +64,11 @@ class Dumper extends SqlDumper {
selectTableIntoNewTable(sourceName, targetName) {
this.putCmd('^create ^table %f (^select * ^from %f)', targetName, sourceName);
}
putValue(value) {
if (value.type == 'Buffer' && _isArray(value.data)) this.putRaw(`unhex('${toHexString(value.data)}')`);
else super.putValue(value);
}
}
module.exports = Dumper;