Skip to content

Commit

Permalink
Add tests for Altibase
Browse files Browse the repository at this point in the history
  • Loading branch information
younjungpark committed Dec 23, 2024
1 parent 3694c4d commit cc142b1
Show file tree
Hide file tree
Showing 21 changed files with 1,484 additions and 29 deletions.
7 changes: 2 additions & 5 deletions src/odbc_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,8 @@ class CallProcedureAsyncWorker : public ODBCAsyncWorker {
data->parameters[i]->ParameterType = data->storedRows[i][SQLPROCEDURECOLUMNS_DATA_TYPE_INDEX].smallint_data; // DataType -> ParameterType
data->parameters[i]->ColumnSize = data->storedRows[i][SQLPROCEDURECOLUMNS_COLUMN_SIZE_INDEX].integer_data; // ParameterSize -> ColumnSize
data->parameters[i]->Nullable = data->storedRows[i][SQLPROCEDURECOLUMNS_NULLABLE_INDEX].smallint_data;
// Decimal digits are missing for IN and INOUT parameters.
data->parameters[i]->DecimalDigits = data->storedRows[i][SQLPROCEDURECOLUMNS_DECIMAL_DIGITS_INDEX].smallint_data;

// For each parameter, need to manipulate the data buffer and C type
// depending on what the InputOutputType is:
Expand Down Expand Up @@ -1736,36 +1738,31 @@ class CallProcedureAsyncWorker : public ODBCAsyncWorker {
data->parameters[i]->ValueType = SQL_C_CHAR;
data->parameters[i]->ParameterValuePtr = new SQLCHAR[bufferSize];
data->parameters[i]->BufferLength = bufferSize;
data->parameters[i]->DecimalDigits = data->storedRows[i][SQLPROCEDURECOLUMNS_DECIMAL_DIGITS_INDEX].smallint_data;
break;

case SQL_DOUBLE:
case SQL_FLOAT:
data->parameters[i]->ValueType = SQL_C_DOUBLE;
data->parameters[i]->ParameterValuePtr = new SQLDOUBLE();
data->parameters[i]->BufferLength = sizeof(SQLDOUBLE);
data->parameters[i]->DecimalDigits = data->storedRows[i][SQLPROCEDURECOLUMNS_DECIMAL_DIGITS_INDEX].smallint_data;
break;

case SQL_TINYINT:
data->parameters[i]->ValueType = SQL_C_UTINYINT;
data->parameters[i]->ParameterValuePtr = new SQLCHAR();
data->parameters[i]->BufferLength = sizeof(SQLCHAR);
data->parameters[i]->DecimalDigits = data->storedRows[i][SQLPROCEDURECOLUMNS_DECIMAL_DIGITS_INDEX].smallint_data;
break;

case SQL_SMALLINT:
data->parameters[i]->ValueType = SQL_C_SSHORT;
data->parameters[i]->ParameterValuePtr = new SQLSMALLINT();
data->parameters[i]->BufferLength = sizeof(SQLSMALLINT);
data->parameters[i]->DecimalDigits = data->storedRows[i][SQLPROCEDURECOLUMNS_DECIMAL_DIGITS_INDEX].smallint_data;
break;

case SQL_INTEGER:
data->parameters[i]->ValueType = SQL_C_SLONG;
data->parameters[i]->ParameterValuePtr = new SQLINTEGER();
data->parameters[i]->BufferLength = sizeof(SQLINTEGER);
data->parameters[i]->DecimalDigits = data->storedRows[i][SQLPROCEDURECOLUMNS_DECIMAL_DIGITS_INDEX].smallint_data;
break;

case SQL_BIGINT:
Expand Down
3 changes: 2 additions & 1 deletion test/DBMS/_test.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
ibmi: require('./ibmi/_test.test')
ibmi: require('./ibmi/_test.test'),
altibase: require('./altibase/_test.test')
}
120 changes: 120 additions & 0 deletions test/DBMS/altibase/BIGINT.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
module.exports = {
dataType: 'BIGINT',
configurations: [
{
size: null,
options: null,
tests: [
// These tests only run if the N-API version supports BigInt
...(parseInt(process.versions.napi) >= 5 ? [
{
name: 'BigInt -> BIGINT (min value)',
values: {
in: {
value: -9223372036854775807n,
expected: -9223372036854775807n,
},
inout: {
value: -9223372036854775808n,
expected: -9223372036854775807n,
},
out: {
value: null,
// expected: -9223372036854775808n,
expected: null, // In Altibase, 0x8000000000000000 is null
},
}
},
{
name: 'BigInt -> BIGINT (max value)',
values: {
in: {
value: 9223372036854775806n,
expected: 9223372036854775806n,
},
inout: {
value: 9223372036854775807n,
expected: 9223372036854775806n,
},
out: {
value: null,
expected: 9223372036854775807n,
},
},
},
] : []),
{
name: 'Number -> BIGINT [MIN_SAFE_INTEGER]',
values: {
in: {
value: Number.MIN_SAFE_INTEGER + 1,
expected: Number.MIN_SAFE_INTEGER + 1,
},
inout: {
value: Number.MIN_SAFE_INTEGER,
expected: Number.MIN_SAFE_INTEGER + 1,
},
out: {
value: null,
expected: BigInt(Number.MIN_SAFE_INTEGER),
},
},
},
{
name: 'Number -> BIGINT [MAX_SAFE_INTEGER]',
values: {
in: {
value: Number.MAX_SAFE_INTEGER - 1,
expected: Number.MAX_SAFE_INTEGER - 1,
},
inout: {
value: Number.MAX_SAFE_INTEGER,
expected: Number.MAX_SAFE_INTEGER - 1,
},
out: {
value: null,
expected: BigInt(Number.MAX_SAFE_INTEGER),
},
},
},
{
name: 'String -> BIGINT (min value)',
values: {
in: {
value: "-9223372036854775807",
expected: "-9223372036854775807",
},
inout: {
// value: "-9223372036854775808",
value: "-9223372036854775807", // In Altibase minimum bigint value is -9223372036854775807
expected: "-9223372036854775807",
},

out: {
value: null,
// binding '-9223372036854775808' makes Numeric value out of range error
expected: -9223372036854775807n,
},
},
},
{
name: 'String -> BIGINT (max value)',
values: {
in: {
value: "9223372036854775806",
expected: "9223372036854775806",
},
inout: {
value: "9223372036854775807",
expected: "9223372036854775806",
},
out: {
value: null,
expected: 9223372036854775807n,
},
},
},
],
},
],
};
62 changes: 62 additions & 0 deletions test/DBMS/altibase/BINARY.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module.exports = {
dataType: 'BINARY',
configurations: [
{
size: '(16)',
options: null,
tests: [
{
name: 'Buffer -> BINARY',
values: {
in: {
value: Buffer.from('7468697320697320612074c3a97374', 'hex'),
expected: Buffer.from('7468697320697320612074c3a97374', 'hex'),
},
inout: {
value: Buffer.from('00112233445566778899aabbccddeeff', 'hex'),
expected: Buffer.from('7468697320697320612074c3a97374', 'hex'),
},
out: {
value: null,
expected: Buffer.from('00112233445566778899aabbccddeeff', 'hex'),
},
},
},
{
name: 'Buffer -> BINARY [empty buffer]',
values: {
in: {
value: Buffer.alloc(0),
expected: Buffer.alloc(0),
},
inout: {
value: Buffer.alloc(0),
expected: null, // In Altibase, length 0 is treated as null.
},
out: {
value: null,
expected: null,
},
},
},
{
name: 'Buffer -> BINARY [null bytes]',
values: {
in: {
value: Buffer.alloc(16),
expected: Buffer.alloc(16),
},
inout: {
value: Buffer.alloc(16),
expected: Buffer.alloc(16),
},
out: {
value: null,
expected: Buffer.alloc(16),
},
},
},
],
}
],
};
62 changes: 62 additions & 0 deletions test/DBMS/altibase/CHARACTER.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module.exports = {
dataType: 'CHAR',
configurations: [
{
size: '(16)',
options: null,
tests: [
{
name: 'string -> CHARACTER [empty]',
values: {
in: {
value: '',
expected: '',
},
inout: {
value: ' ',
expected: null,
},
out: {
value: null,
expected: ' ',
},
},
},
{
name: 'string -> CHAR (partially full values)',
values: {
in: {
value: 'ABCD1234',
expected: 'ABCD1234',
},
inout: {
value: 'Z Y X W 9',
expected: 'ABCD1234 ',
},
out: {
value: null,
expected: 'Z Y X W 9 ',
},
},
},
{
name: 'string -> CHARACTER (full)',
values: {
in: {
value: 'ABCD1234EFGH5678',
expected: 'ABCD1234EFGH5678',
},
inout: {
value: 'Z Y X W 9 8 7 6 ',
expected: 'ABCD1234EFGH5678',
},
out: {
value: null,
expected: 'Z Y X W 9 8 7 6 ',
},
},
},
],
}
],
};
45 changes: 45 additions & 0 deletions test/DBMS/altibase/CLOB.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module.exports = {
dataType: 'CLOB',
configurations: [
{
size: '(16)',
options: null,
tests: [
{
name: 'string -> CLOB [full]',
values: {
in: {
value: 'ABCD1234EFGH5678',
expected: 'ABCD1234EFGH5678',
},
inout: {
value: ' A B C D E F G H',
expected: 'ABCD1234EFGH5678',
},
out: {
value: null,
expected: ' A B C D E F G H',
},
},
},
{
name: 'Buffer -> CLOB (partially full values)',
values: {
in: {
value: Buffer.from('7468697320697320612074c3a9737400', 'hex'),
expected: Buffer.from('7468697320697320612074c3a9737400', 'hex'),
},
inout: {
value: Buffer.from('c8c5d3d3d65a', 'hex'),
expected: Buffer.from('7468697320697320612074c3a9737400', 'hex'),
},
out: {
value: null,
expected: 'HELLO!',
},
},
}
],
},
],
};
Loading

0 comments on commit cc142b1

Please sign in to comment.