diff --git a/integration-tests/docker-compose.yaml b/integration-tests/docker-compose.yaml index 24f0e8144..5c0d846da 100644 --- a/integration-tests/docker-compose.yaml +++ b/integration-tests/docker-compose.yaml @@ -1,21 +1,21 @@ version: '3' services: - postgres: - image: postgres - restart: always - environment: - POSTGRES_PASSWORD: Pwd2020Db - ports: - - 15000:5432 + # postgres: + # image: postgres + # restart: always + # environment: + # POSTGRES_PASSWORD: Pwd2020Db + # ports: + # - 15000:5432 - mariadb: - image: mariadb - command: --default-authentication-plugin=mysql_native_password - restart: always - ports: - - 15004:3306 - environment: - - MYSQL_ROOT_PASSWORD=Pwd2020Db + # mariadb: + # image: mariadb + # command: --default-authentication-plugin=mysql_native_password + # restart: always + # ports: + # - 15004:3306 + # environment: + # - MYSQL_ROOT_PASSWORD=Pwd2020Db # mysql: # image: mysql:8.0.18 @@ -26,15 +26,15 @@ services: # environment: # - MYSQL_ROOT_PASSWORD=Pwd2020Db - # mssql: - # image: mcr.microsoft.com/mssql/server - # restart: always - # ports: - # - 15002:1433 - # environment: - # - ACCEPT_EULA=Y - # - SA_PASSWORD=Pwd2020Db - # - MSSQL_PID=Express + mssql: + image: mcr.microsoft.com/mssql/server + restart: always + ports: + - 15002:1433 + environment: + - ACCEPT_EULA=Y + - SA_PASSWORD=Pwd2020Db + - MSSQL_PID=Express # cockroachdb: # image: cockroachdb/cockroach diff --git a/integration-tests/engines.js b/integration-tests/engines.js index fee75b88f..5e8b57c00 100644 --- a/integration-tests/engines.js +++ b/integration-tests/engines.js @@ -135,8 +135,8 @@ const filterLocal = [ // filter local testing '-MySQL', '-MariaDB', - 'PostgreSQL', - '-SQL Server', + '-PostgreSQL', + 'SQL Server', '-SQLite', '-CockroachDB', ]; diff --git a/plugins/dbgate-plugin-mssql/src/backend/createTediousBulkInsertStream.js b/plugins/dbgate-plugin-mssql/src/backend/createTediousBulkInsertStream.js index 6457f7d15..6c2967378 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/createTediousBulkInsertStream.js +++ b/plugins/dbgate-plugin-mssql/src/backend/createTediousBulkInsertStream.js @@ -1,6 +1,7 @@ const { createBulkInsertStreamBase } = require('dbgate-tools'); const tedious = require('tedious'); const getConcreteType = require('./getConcreteType'); +const _ = require('lodash'); function runBulkInsertBatch(pool, tableName, writable, rows) { return new Promise((resolve, reject) => { @@ -12,24 +13,34 @@ function runBulkInsertBatch(pool, tableName, writable, rows) { else resolve(); }); - for (const column of writable.columnNames) { - const tcol = writable.templateColumns.find((x) => x.columnName == column); + const stringColumns = new Set(); - bulkLoad.addColumn( - column, - tcol - ? getConcreteType(tcol.driverNativeColumn.type, tcol.driverNativeColumn.dataLength) - : tedious.TYPES.NVarChar, - { - nullable: tcol ? !tcol.notNull : true, - length: tcol ? tcol.driverNativeColumn.dataLength : undefined, - precision: tcol ? tcol.driverNativeColumn.precision : undefined, - scale: tcol ? tcol.driverNativeColumn.scale : undefined, - } - ); + for (const column of writable.columnNames) { + const tcol = writable.templateColumns.find(x => x.columnName == column); + + const type = tcol + ? getConcreteType(tcol.driverNativeColumn.type, tcol.driverNativeColumn.dataLength) + : tedious.TYPES.NVarChar; + + if (type.type.toLowerCase().includes('char')) stringColumns.add(column); + + bulkLoad.addColumn(column, type, { + nullable: tcol ? !tcol.notNull : true, + length: tcol ? tcol.driverNativeColumn.dataLength : undefined, + precision: tcol ? tcol.driverNativeColumn.precision : undefined, + scale: tcol ? tcol.driverNativeColumn.scale : undefined, + }); } - pool.execBulkLoad(bulkLoad, rows); + const rowsMapped = rows.map(row => + _.mapValues(row, (v, k) => { + if (stringColumns.has(k)) return v ? v.toString() : null; + return v; + }) + ); + // console.log('IMPORT ROWS', rowsMapped); + + pool.execBulkLoad(bulkLoad, rowsMapped); }); }