fix: unable to copy as sql inserts with BIT fileds, fixes #613

This commit is contained in:
Fabio Di Stasio 2023-07-06 12:06:32 +02:00
parent 38bfea279c
commit 6e01f0f2e7
2 changed files with 5 additions and 5 deletions

View File

@ -72,7 +72,7 @@ export const escapeAndQuote = (val: string, client: ClientCode) => {
export const valueToSqlString = (args: {
val: any;
client: ClientCode;
field: {type: string; datePrecision: number; isArray?: boolean};
field: {type: string; datePrecision?: number; precision?: number | false; isArray?: boolean};
}): string => {
let parsedValue;
const { val, client, field } = args;
@ -105,7 +105,7 @@ export const valueToSqlString = (args: {
else if (TEXT_SEARCH.includes(field.type))
parsedValue = `'${val.replaceAll('\'', '\'\'')}'`;
else if (BIT.includes(field.type))
parsedValue = `b'${hexToBinary(Buffer.from(val).toString('hex') as undefined as HexChar[])}'`;
parsedValue = `b'${hexToBinary(Buffer.from(new Uint8Array(Object.values(val))).toString('hex') as undefined as HexChar[])}'`;
else if (BLOB.includes(field.type)) {
let buffer: Buffer;
if (val instanceof Uint8Array)

View File

@ -293,7 +293,7 @@ const inputProps = computed(() => {
let timeMask = '##:##:##';
const precision = props.fields[editingField.value].length;
for (let i = 0; i < precision; i++)
for (let i = 0; i < Number(precision); i++)
timeMask += i === 0 ? '.#' : '#';
if (HAS_TIMEZONE.includes(editingType.value))
@ -309,7 +309,7 @@ const inputProps = computed(() => {
let datetimeMask = '####-##-## ##:##:##';
const precision = props.fields[editingField.value].length;
for (let i = 0; i < precision; i++)
for (let i = 0; i < Number(precision); i++)
datetimeMask += i === 0 ? '.#' : '#';
if (HAS_TIMEZONE.includes(editingType.value))
@ -582,7 +582,7 @@ const typeFormat = (val: string | number | Date | number[], type: string, precis
return val;
let datePrecision = '';
for (let i = 0; i < precision; i++)
for (let i = 0; i < Number(precision); i++)
datePrecision += i === 0 ? '.S' : 'S';
return moment(val).isValid() ? moment(val).format(`YYYY-MM-DD HH:mm:ss${datePrecision}`) : val;