Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
admirsaheta authored Mar 25, 2024
2 parents b51507e + eac53c9 commit 6bf4351
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 15 deletions.
8 changes: 8 additions & 0 deletions lib/connection/bind_uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Logger = require('../logger');
const fs = require('fs');

const Statement = require('./statement');
const { isString } = require('util');

const STAGE_NAME = 'SYSTEM$BIND';
const CREATE_STAGE_STMT = 'CREATE OR REPLACE TEMPORARY STAGE '
Expand Down Expand Up @@ -113,6 +114,13 @@ function BindUploader(options, services, connectionConfig, requestId) {
if (data == null || data.toString() === '') {
return '""';
}
if (!isString(data)) {
if (data instanceof Date) {
data = data.toJSON();
} else {
data = JSON.stringify(data);
}
}
if (data.toString().indexOf('"') >= 0
|| data.toString().indexOf(',') >= 0
|| data.toString().indexOf('\\') >= 0
Expand Down
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ exports.getCircularReplacer = function () {
* @returns {boolean}
*/
exports.isCorrectSubdomain = function (value) {
const subdomainRegex = RegExp(/^\w[\w.-]+\w$/i);
const subdomainRegex = RegExp(/^\w([\w.-]+\w|)$/i);
return subdomainRegex.test(value);
};

Expand Down
26 changes: 15 additions & 11 deletions test/integration/testArrayBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ const Logger = require('../../lib/logger');
describe('Test Array Bind', function () {
this.timeout(300000);
let connection;
const createABTable = 'create or replace table testAB(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ)';
const insertAB = 'insert into testAB values(?, ?, ?, ?, ?, ?)';
const createABTable = 'create or replace table testAB(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ, bi binary(5), bool boolean)';
const insertAB = 'insert into testAB values(?, ?, ?, ?, ?, ?, ?, ?)';
const selectAB = 'select * from testAB where colB = 1';
const createNABTable = 'create or replace table testNAB(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ)';
const insertNAB = 'insert into testNAB values(?, ?, ?, ?, ?, ?)';
const createNABTable = 'create or replace table testNAB(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ, bi binary(5), bool boolean)';
const insertNAB = 'insert into testNAB values(?, ?, ?, ?, ?, ?, ?, ?)';
const selectNAB = 'select * from testNAB where colB = 1';
const createNullTable = 'create or replace table testNullTB(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ)';
const insertNull = 'insert into testNullTB values(?, ?, ?, ?, ?, ?)';
const createNullTable = 'create or replace table testNullTB(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ, bi binary(5), bool boolean)';
const insertNull = 'insert into testNullTB values(?, ?, ?, ?, ?, ?, ?, ?)';
const selectNull = 'select * from testNullTB where colB = 1';
const binaryData = (0xffff00).toString(16);

const usedTableNames = [
'testAB', 'testNAB', 'testNullTB',
Expand Down Expand Up @@ -61,9 +62,9 @@ describe('Test Array Bind', function () {
const arrBind = [];
const count = 100;
for (let i = 0; i < count; i++) {
arrBind.push(['string' + i, i, '2020-05-11', '12:35:41.3333333', '2022-04-01 23:59:59', '2022-07-08 12:05:30.9999999']);
arrBind.push(['string' + i, i, '2020-05-11', '12:35:41.3333333', new Date('2022-04-01 23:59:59'), new Date('2022-07-08 12:05:30.9999999'), binaryData, true]);
}

const insertABStmt = connection.execute({
sqlText: insertAB,
binds: arrBind,
Expand All @@ -89,7 +90,7 @@ describe('Test Array Bind', function () {
const arrBind = [];
const count = 2;
for (let i = 0; i < count; i++) {
arrBind.push(['string' + i, i, '2020-05-11', '12:35:41.3333333', '2022-04-01 23:59:59', '2022-07-08 12:05:30.9999999']);
arrBind.push(['string' + i, i, '2020-05-11', '12:35:41.3333333', new Date('2022-04-01 23:59:59'), new Date('2022-07-08 12:05:30.9999999'), binaryData, true]);
}
connection.execute({
sqlText: insertNAB,
Expand Down Expand Up @@ -133,6 +134,9 @@ describe('Test Array Bind', function () {
assert.equal(ABDataD.toString(), NABDataD.toString());
assert.equal(ABDataE.toString(), NABDataE.toString());
assert.equal(ABDataF.toString(), NABDataF.toString());

assert.equal(ABData['BOOL'], true);
assert.equal(Buffer.from(ABData['BI']).toString('hex'), binaryData);
callback();
}
});
Expand All @@ -158,7 +162,7 @@ describe('Test Array Bind', function () {
const arrBind = [];
const count = 100;
for (let i = 0; i < count; i++) {
arrBind.push([null, i, '2020-05-11', '12:35:41.3333333', '2022-04-01 23:59:59', '2022-07-08 12:05:30.9999999']);
arrBind.push([null, i, '2020-05-11', '12:35:41.3333333', '2022-04-01 23:59:59', '2022-07-08 12:05:30.9999999', binaryData, true]);
}

connection.execute({
Expand Down Expand Up @@ -187,7 +191,7 @@ describe('Test Array Bind', function () {
const arrBind = [];
const count = 2;
for (let i = 0; i < count; i++) {
arrBind.push(['string' + i, i, '2020-05-11', '12:35:41.3333333', '2022-04-01 23:59:59', '2022-07-08 12:05:30.9999999']);
arrBind.push(['string' + i, i, '2020-05-11', '12:35:41.3333333', '2022-04-01 23:59:59', '2022-07-08 12:05:30.9999999', binaryData, true]);
}
connection.execute({
sqlText: insertNAB,
Expand Down
75 changes: 72 additions & 3 deletions test/unit/connection/connection_config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,75 @@ describe('ConnectionConfig: basic', function () {
account: 'acc_ount',
}
},
{
name: 'only one letter account',
input:
{
account: 'a',
username: 'username',
password: 'password',
retryTimeout: 1234,
},
options:
{
accessUrl: 'https://a.snowflakecomputing.com',
username: 'username',
password: 'password',
account: 'a',
}
},
{
name: 'only one letter account and subdomain',
input:
{
account: 'a.b',
username: 'username',
password: 'password',
retryTimeout: 1234,
},
options:
{
accessUrl: 'https://a.b.snowflakecomputing.com',
username: 'username',
password: 'password',
account: 'a',
region: 'b'
}
},
{
name: 'account with [-] in the middle',
input:
{
account: 'a-b',
username: 'username',
password: 'password',
retryTimeout: 1234,
},
options:
{
accessUrl: 'https://a-b.snowflakecomputing.com',
username: 'username',
password: 'password',
account: 'a-b',
}
},
{
name: 'account with [_] in the middle',
input:
{
account: 'a_b',
username: 'username',
password: 'password',
retryTimeout: 1234,
},
options:
{
accessUrl: 'https://a_b.snowflakecomputing.com',
username: 'username',
password: 'password',
account: 'a_b',
}
},
{
name: 'account with subdomain',
input:
Expand All @@ -1145,18 +1214,18 @@ describe('ConnectionConfig: basic', function () {
name: 'account with subdomain with _ and -',
input:
{
account: 'acc_ount.sub-domain',
account: 'acc_ount.sub-domain.aws',
username: 'username',
password: 'password',
retryTimeout: 1234,
},
options:
{
accessUrl: 'https://acc_ount.sub-domain.snowflakecomputing.com',
accessUrl: 'https://acc_ount.sub-domain.aws.snowflakecomputing.com',
username: 'username',
password: 'password',
account: 'acc_ount',
region: 'sub-domain',
region: 'sub-domain.aws',
}
},
{
Expand Down

0 comments on commit 6bf4351

Please sign in to comment.