Skip to content
Merged

Gyp #274

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env-cmdrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"CONNECTION_KEY": "UAT18",
"LOCAL": "Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\\node;Database=scratch;Trusted_Connection=yes;",
"LOCAL17": "Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\\node;Database=scratch;Trusted_Connection=yes;",
"LAP": "Driver={ODBC Driver 17 for SQL Server}; Server=DESKTOP-9RLN5E4;UID=linux; PWD=linux; Database=node",
"WSL": "DSN=MSSQLTest;UID=linux; PWD=linux; Database=node",
"DEV": "Driver={ODBC Driver 17 for SQL Server}; Server=192.168.1.102;UID=linux; PWD=linux; Database=node",
Expand All @@ -11,7 +11,8 @@
"UAT18ENC": "Driver={ODBC Driver 18 for SQL Server}; Server=DESKTOP-VIUCH90; Database=node;TrustServerCertificate=yes;Trusted_Connection=yes;ColumnEncryption=Enabled;",
"UAT": "Driver={ODBC Driver 17 for SQL Server}; Server=DESKTOP-VIUCH90;UID=linux; PWD=linux; Database=node",
"SA": "Driver={ODBC Driver 17 for SQL Server}; Server=192.168.1.102;UID=sa; PWD=sqlexpress; Database=node",
"UAT11TC": "Driver={SQL Server Native Client 11.0}; Server=DESKTOP-VIUCH90; Database=node;Trusted_Connection=yes;"
"UAT11TC": "Driver={SQL Server Native Client 11.0}; Server=DESKTOP-VIUCH90; Database=node;Trusted_Connection=yes;",
"LOCAL18": "Driver={ODBC Driver 18 for SQL Server}; Server=(localdb)\\node;Database=scratch;Trusted_Connection=yes;"
},
"appv-ubuntu": {
"DEFAULT": "Driver={ODBC Driver 17 for SQL Server}; Server=localhost; Uid=SA; Pwd=Password12!"
Expand Down
48 changes: 37 additions & 11 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,51 @@
]
],
'variables': {
"openssl_fips" : "0",
'msodbcsql%': 'msodbcsql17',
'openssl_fips' : '0',
# look for include files for these versions - taking top first priority
'msodbsver%': [
'msodbcsql18',
'msodbcsql17'
],
'ext%': '.cpp',
'homebrew%': '/opt/homebrew/lib/libodbc.a',
'unixlocalodbc%': '-l/usr/local/odbc',
'linuxodbc%': '-lodbc',
'winodbc%': 'odbc32',
'linkdir%': '/usr/local/lib /opt/homebrew/lib /usr/lib .'
# pick up libodbc from somwhere - note the ms driver is loaded dynamicaly via odbc, no
# link dependency is added
'linkdir%': '/usr/local/lib /usr/local/ssl/lib64/ /opt/homebrew/lib /home/linuxbrew/.linuxbrew/lib/ /usr/lib .'
},

'targets': [
{
'target_name': 'sqlserverv8',

'variables': {
# Set the target variable only if it is not passed in by prebuild
'target%': '<!(node -e "console.log(process.versions.node)")',
# Set the target variable only if it is not passed in by prebuild

# which folders are available for include eg.
# /opt/microsoft/msodbcsql18/include/ /opt/microsoft/msodbcsql17/include/
'msodbc_include_folders%': [
"<!@(node -p \""
"'<(msodbsver)'"
".split(' ')"
".map(x => ["
"'/opt/microsoft/' + x +'/include/'"
" ,"
"'/usr/local/opt/' + x + '/include/'"
" ,"
"'/usr/local/opt/' + x + '/include/' + x + '/'"
" ,"
"'/opt/homebrew/include/' + x + '/'"
"])"
".flatMap(y => y)"
".filter(z => require('fs').existsSync(z))"
".join(' ')"
"\")"
],
# set fo
# the link folders available -L/usr/local/lib -L/usr/lib -L.
'link_path%': [
"<!@(node -p \""
"'<(linkdir)'"
Expand All @@ -51,6 +78,7 @@
"\")"
], # set for macos based on silicon

# enumerate the cpp src files rather than name them.
'fileset%': [
"<!@(node -p \""
"require('fs')"
Expand All @@ -77,7 +105,7 @@
'actions': [
{
'action_name': 'print_variables',
'action': ['echo', 'cflags_cpp <(cflags_cpp) | arch: <(arch) | link_path: <(link_path) | msodbcsql <(msodbcsql) | fileset <(fileset)'],
'action': ['echo', 'cflags_cpp <(cflags_cpp) | arch: <(arch) | link_path: <(link_path) | msodbc_include_folders <(msodbc_include_folders) | fileset <(fileset)'],
'inputs': [],
'outputs': [
"<!@(node -p \"'<(fileset)'.split(' ')[0]\")"
Expand Down Expand Up @@ -129,8 +157,8 @@
],
'cflags_cc': ['<(cflags_cpp)'],
'include_dirs': [
'/usr/include/',
'/opt/microsoft/<(msodbcsql)/include/',
"<!@(node -p \"'<(msodbc_include_folders)'.split(' ').join(' ')\")",
'/usr/include/'
],
}],
['OS=="mac"', {
Expand All @@ -149,10 +177,8 @@
'CLANG_CXX_LANGUAGE_STANDARD': '<(cflags_cpp)'
},
'include_dirs': [
'/usr/local/opt/<(msodbcsql)/include/',
'/usr/local/opt/<(msodbcsql)/include/<(msodbcsql)/',
"<!@(node -p \"'<(msodbc_include_folders)'.split(' ').join(' ')\")",
'/opt/homebrew/include',
'/opt/homebrew/include/<(msodbcsql)',
'/usr/local/include/',
],
}],
Expand Down
5 changes: 5 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,11 @@ declare module 'msnodesqlv8' {
* the proc sql taking a tvp param
*/
insertProcedureTvpSql: string

/**
* drop the insertProcedureTvpSql proc if it exists
*/
dropInsertTvpProcedure: string
}

interface TableManagerPromises {
Expand Down
5 changes: 5 additions & 0 deletions lib/table-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class TableBuilder {
return c.typed(false, true)
}

dropProc(name) {
return `IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND OBJECT_ID = OBJECT_ID('${name}')) begin drop PROCEDURE ${name} end`
}

compute () {
const tableName = this.fullTableName
const fullTypedColumns = this.columns.map(e => `[${e.name}] ${this.typed(e)}`).join(', ')
Expand Down Expand Up @@ -105,6 +109,7 @@ class TableBuilder {
this.paramsSql = paramsSql
this.insertParamsSql = `${insertSql} ${paramsSql}`
this.insertTvpProcedureName = `${this.tableSchema}.${this.tableName}_tvp_inserter`
this.dropInsertTvpProcedure = this.dropProc(this.insertTvpProcedureName)
this.insertProcedureTvpSql = this.insertTvpProcSql()
}

Expand Down
7 changes: 6 additions & 1 deletion lib/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

'use strict'

const { BasePromises } = require('./base-promises')
const tableModule = (() => {
const { BasePromises } = require('./base-promises')
const { ServerDialect } = require("./dialect")
const { TableBulkOpMgr } = require('./table-bulk-op-mgr')
const { TableMeta } = require('./table-meta')
const { TableColumn } = require('./table-column')
Expand Down Expand Up @@ -48,6 +49,10 @@ const tableModule = (() => {
this.user = connectionUser
this.bcpVersion = 0
this.promises = new TableMgrPromises(this)
this.ServerDialect = {
Sybase: ServerDialect.Sybase,
SqlServer: ServerDialect.SqlServer
}
}

setBcpVersion (v) {
Expand Down
10 changes: 8 additions & 2 deletions samples/javascript/table-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,27 @@ async function builder () {
const t = builder.toTable()
const dropTypeSql = builder.dropTypeSql
const userTypeSql = builder.userTypeTableSql
const dropTvpInsert = builder.dropInsertTvpProcedure
const tvpInserterSql = builder.insertProcedureTvpSql
const typeName = `${tableName}Type`
const selectSql = `DECLARE @test AS ${typeName};
INSERT INTO @test SELECT * FROM ?;
SELECT * FROM @test`

console.log(dropTvpInsert)
await connection.promises.query(dropTvpInsert)
const create = builder.createTableSql
const drop = builder.dropTableSql
console.log(drop)
const dropTable = builder.dropTableSql
console.log(dropTable)
await builder.drop()
console.log(create)
await builder.create()
console.log(dropTypeSql)
await connection.promises.query(dropTypeSql)
console.log(userTypeSql)
await connection.promises.query(userTypeSql)
console.log(tvpInserterSql)
await connection.promises.query(tvpInserterSql)
const table = t.asTableType()

await connection.promises.getUserTypeTable('dbo.' + typeName)
Expand Down
3 changes: 3 additions & 0 deletions samples/typescript/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ async function builder (): Promise<void> {

const vec: Row[] = Array(rows).fill(0).map((_, i) => makeOne(i))
const table: BulkTableMgr = builder.toTable()
const dropTvpProcSql = builder.dropInsertTvpProcedure
console.log(dropTvpProcSql)
await connection.promises.query(dropTvpProcSql)
const create: string = builder.createTableSql
const drop: string = builder.dropTableSql
console.log(drop)
Expand Down
1 change: 1 addition & 0 deletions src/QueryOperationParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ shared_ptr<vector<uint16_t>> _query_string;
QueryOperationParams::QueryOperationParams(const Local<Number> query_id,
const Local<Object> query_object) :
_timeout(MutateJS::getint32(query_object, "query_timeout")),
_query_tz_adjustment(0),
_id(MutateJS::getint32(query_id)),
_max_prepared_column_size(MutateJS::getint64(query_object, "max_prepared_column_size")),
_numeric_string(MutateJS::getbool(query_object, "numeric_string")),
Expand Down
7 changes: 4 additions & 3 deletions src/TimestampColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ namespace mssql {
return floor(days);
}

void TimestampColumn::milliseconds_from_timestamp(TIMESTAMP_STRUCT const & ts, const int32_t tz_offset)
void TimestampColumn::milliseconds_from_timestamp(TIMESTAMP_STRUCT const & ts, const SQLSMALLINT tz_offset)
{
const auto tzhrs = tz_offset / 60;
const auto tzmins = tz_offset % 60;
const SQLSMALLINT c = 60;
const SQLSMALLINT tzhrs = tz_offset / c;
const SQLSMALLINT tzmins = tz_offset % c;

SQL_SS_TIMESTAMPOFFSET_STRUCT time_struct;
time_struct.year = ts.year;
Expand Down
4 changes: 2 additions & 2 deletions src/TimestampColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace mssql
// return the number of days since Jan 1, 1970
double DaysSinceEpoch(SQLSMALLINT y, SQLUSMALLINT m, SQLUSMALLINT d) const;

void milliseconds_from_timestamp(TIMESTAMP_STRUCT const & ts, int tz_offset = 0);
void milliseconds_from_timestamp(TIMESTAMP_STRUCT const & ts, SQLSMALLINT tz_offset = 0);

// derived from ECMA 262 15.9
void milliseconds_from_timestamp_offset(SQL_SS_TIMESTAMPOFFSET_STRUCT const& time_struct);
Expand All @@ -121,6 +121,6 @@ namespace mssql
// since Jan 1, 1970
void DateFromMilliseconds(SQL_SS_TIMESTAMPOFFSET_STRUCT& date) const;

int32_t offset_minutes;
SQLSMALLINT offset_minutes;
};
}
2 changes: 1 addition & 1 deletion src/UnbindOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace mssql

Local<Value> UnbindOperation::CreateCompletionArg()
{
auto a = _statement->unbind_params();
const auto a = _statement->unbind_params();
const auto ret = a->Clone();
return ret;
}
Expand Down