### Running the node-sqlserver-v8 Demo (Command Line) Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md This example shows how to execute the main demo script for the node-sqlserver-v8 library from the command line. It assumes the module is installed and provides the basic command to start the demonstration. ```bash admin@DESKTOP MINGW64 ~/dev/js/test/node_modules/node-sqlserver-v8 (master) $ node mssql-demo.js ``` -------------------------------- ### Running the node-sqlserver-v8 Demo (Command Line) Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home This example shows how to execute the main demo script for the node-sqlserver-v8 library from the command line. It assumes the module is installed and provides the basic command to start the demonstration. ```bash admin@DESKTOP MINGW64 ~/dev/js/test/node_modules/node-sqlserver-v8 (master) $ node mssql-demo.js ``` -------------------------------- ### node-sqlserver-v8 Driver Build and Setup Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Instructions for cloning the node-sqlserver-v8 repository, navigating into the directory, and rebuilding the driver using node-gyp. Also includes installing dependencies via npm. ```bash git clone https://github.com/TimelordUK/node-sqlserver-v8.git msnodesqlv8 ``` ```bash cd msnodesqlv8/ ``` ```bash node-gyp rebuild ``` ```bash npm install ``` ```bash cd samples/javascript ``` -------------------------------- ### node-sqlserver-v8 Driver Build and Setup Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Instructions for cloning the node-sqlserver-v8 repository, navigating into the directory, and rebuilding the driver using node-gyp. Also includes installing dependencies via npm. ```bash git clone https://github.com/TimelordUK/node-sqlserver-v8.git msnodesqlv8 ``` ```bash cd msnodesqlv8/ ``` ```bash node-gyp rebuild ``` ```bash npm install ``` ```bash cd samples/javascript ``` -------------------------------- ### Electron React Boilerplate Setup with msnodesqlv8 Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md This command-line sequence details the setup for the electron-react-boilerplate project, integrating the msnodesqlv8 module. It covers cloning the repository, installing dependencies, adding the msnodesqlv8 package, and performing the necessary electron-rebuild step. ```cmd git clone --depth 1 --single-branch https://github.com/electron-react-boilerplate/electron-react-boilerplate.git erb-msnodesqlv8 cd .\erb-msnodesqlv8\ yarn cd .\app\ yarn yarn add --dev electron-rebuild yarn add msnodesqlv8 .\node_modules\.bin\electron-rebuild.cmd cd .. yarn dev ``` -------------------------------- ### Electron React Boilerplate Setup with msnodesqlv8 Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home This command-line sequence details the setup for the electron-react-boilerplate project, integrating the msnodesqlv8 module. It covers cloning the repository, installing dependencies, adding the msnodesqlv8 package, and performing the necessary electron-rebuild step. ```cmd git clone --depth 1 --single-branch https://github.com/electron-react-boilerplate/electron-react-boilerplate.git erb-msnodesqlv8 cd .\erb-msnodesqlv8\ yarn cd .\app\ yarn yarn add --dev electron-rebuild yarn add msnodesqlv8 .\node_modules\.bin\electron-rebuild.cmd cd .. yarn dev ``` -------------------------------- ### ODBC Configuration Example Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home An example of the content found in `/etc/odbcinst.ini`, specifying the driver name, description, and the path to the shared library for Microsoft's ODBC Driver 18 for SQL Server. ```txt [ODBC Driver 18 for SQL Server] Description=Microsoft ODBC Driver 18 for SQL Server Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 UsageCount=1 ``` -------------------------------- ### ODBC Configuration Example Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md An example of the content found in `/etc/odbcinst.ini`, specifying the driver name, description, and the path to the shared library for Microsoft's ODBC Driver 18 for SQL Server. ```txt [ODBC Driver 18 for SQL Server] Description=Microsoft ODBC Driver 18 for SQL Server Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 UsageCount=1 ``` -------------------------------- ### Stored Procedure Definition Example Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Provides an example SQL script for creating a stored procedure. This includes defining input parameters, output parameters, and the procedure's logic. ```sql USE [scratch] CREATE PROCEDURE [dbo].[test_sp_get_int_int]( @num1 INT, @num2 INT, @num3 INT OUTPUT )AS BEGIN SET @num3 = @num1 + @num2 RETURN 99; END GO ``` -------------------------------- ### Stored Procedure Definition Example Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Provides an example SQL script for creating a stored procedure. This includes defining input parameters, output parameters, and the procedure's logic. ```sql USE [scratch] CREATE PROCEDURE [dbo].[test_sp_get_int_int]( @num1 INT, @num2 INT, @num3 INT OUTPUT )AS BEGIN SET @num3 = @num1 + @num2 RETURN 99; END GO ``` -------------------------------- ### Sybase Adaptive Server Query Examples Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Illustrates querying Sybase Adaptive Server using the msnodesqlv8 library. It shows examples using both the legacy callback-based API (`sql.open`, `con.query`) and the modern promise-based API (`sql.promises.open`, `connection.promises.query`). ```js const sql = require('msnodesqlv8') const { GetConnection } = require('./get-connection') const connectionString = new GetConnection().connectionString const query = 'SELECT top 5 * FROM syscomments' // "Driver={Adaptive Server Enterprise}; app=myAppName; server=localhost port=5000; db=pubs3; uid=sa; pwd=ooooo;" function legacyQuery () { return new Promise((resolve, reject) => { sql.open(connectionString, (err, con) => { if (err) { reject(err) } con.query(query, (err, rows) => { if (err) { reject(err) } con.close(() => { resolve(rows) }) }) }) }) } async function promised () { const connection = await sql.promises.open(connectionString) const res = await connection.promises.query(query) console.log(`promised ${JSON.stringify(res, null, 4)}`) await connection.promises.close() return res } async function q1 () { const d = new Date() try { const rows = await legacyQuery() const elapsed = new Date() - d console.log(`legacyQuery rows.length ${rows.length} elapsed ${elapsed}`) console.log(`legacyQuery ${JSON.stringify(rows, null, 4)}`) } catch (err) { console.error(err) } } ``` -------------------------------- ### Batch Script Examples for Driver Testing Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Provides examples of batch scripts used for testing driver behavior, specifically related to connection recovery and error handling with different RAISERROR severity levels. ```cmd tool\t-busy14.bat node test\edge-case.js -t busy --delay=500 --severity=14 ``` ```cmd tool\t-busy9.bat node test\edge-case.js -t busy --delay=500 --severity=9 ``` -------------------------------- ### Sybase Adaptive Server Query Examples Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Illustrates querying Sybase Adaptive Server using the msnodesqlv8 library. It shows examples using both the legacy callback-based API (`sql.open`, `con.query`) and the modern promise-based API (`sql.promises.open`, `connection.promises.query`). ```js const sql = require('msnodesqlv8') const { GetConnection } = require('./get-connection') const connectionString = new GetConnection().connectionString const query = 'SELECT top 5 * FROM syscomments' // "Driver={Adaptive Server Enterprise}; app=myAppName; server=localhost port=5000; db=pubs3; uid=sa; pwd=ooooo;" function legacyQuery () { return new Promise((resolve, reject) => { sql.open(connectionString, (err, con) => { if (err) { reject(err) } con.query(query, (err, rows) => { if (err) { reject(err) } con.close(() => { resolve(rows) }) }) }) }) } async function promised () { const connection = await sql.promises.open(connectionString) const res = await connection.promises.query(query) console.log(`promised ${JSON.stringify(res, null, 4)}`) await connection.promises.close() return res } async function q1 () { const d = new Date() try { const rows = await legacyQuery() const elapsed = new Date() - d console.log(`legacyQuery rows.length ${rows.length} elapsed ${elapsed}`) console.log(`legacyQuery ${JSON.stringify(rows, null, 4)}`) } catch (err) { console.error(err) } } ``` -------------------------------- ### Batch Script Examples for Driver Testing Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Provides examples of batch scripts used for testing driver behavior, specifically related to connection recovery and error handling with different RAISERROR severity levels. ```cmd tool\t-busy14.bat node test\edge-case.js -t busy --delay=500 --severity=14 ``` ```cmd tool\t-busy9.bat node test\edge-case.js -t busy --delay=500 --severity=9 ``` -------------------------------- ### Setting up SQL Server LocalDB (Command Line) Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home These commands demonstrate how to create, start, and check the status of a SQL Server LocalDB instance named 'node'. This is recommended for testing the library when a full SQL Server instance is not available. ```bash sqllocaldb create node sqllocaldb start node sqllocaldb info node ``` -------------------------------- ### Debian SSL Debugging and Environment Setup Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Steps to address segmentation faults on Debian by preloading a specific OpenSSL library version. Includes commands to check loaded libraries and system information. ```bash brew install openssl ``` ```bash cd /usr/lib ``` ```bash sudo ln -s /home/linuxbrew/.linuxbrew/opt/openssl@3/lib/libssl.so libssl.so.1.1 ``` ```bash export LD_PRELOAD=/usr/lib/libssl.so.1.1 ``` ```bash ps -ef | grep node ``` ```bash pldd 6350 ``` ```bash uname -a ``` ```javascript node simple-demo.js ``` -------------------------------- ### Docker Image Management Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Commands to list Docker images, filter them by name, start containers, and connect to running containers. ```bash docker images ``` ```bash docker images msnodesql* ``` ```bash docker run -it msnodesqlv8-debian bash ``` ```bash docker container ls ``` ```bash docker start abc6f443950c ``` ```bash docker exec -it upbeat_easley bash ``` ```bash docker ps -a ``` -------------------------------- ### Docker Image Management Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Commands to list Docker images, filter them by name, start containers, and connect to running containers. ```bash docker images ``` ```bash docker images msnodesql* ``` ```bash docker run -it msnodesqlv8-debian bash ``` ```bash docker container ls ``` ```bash docker start abc6f443950c ``` ```bash docker exec -it upbeat_easley bash ``` ```bash docker ps -a ``` -------------------------------- ### Debian SSL Debugging and Environment Setup Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Steps to address segmentation faults on Debian by preloading a specific OpenSSL library version. Includes commands to check loaded libraries and system information. ```bash brew install openssl ``` ```bash cd /usr/lib ``` ```bash sudo ln -s /home/linuxbrew/.linuxbrew/opt/openssl@3/lib/libssl.so libssl.so.1.1 ``` ```bash export LD_PRELOAD=/usr/lib/libssl.so.1.1 ``` ```bash ps -ef | grep node ``` ```bash pldd 6350 ``` ```bash uname -a ``` ```javascript node simple-demo.js ``` -------------------------------- ### Setting up SQL Server LocalDB (Command Line) Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md These commands demonstrate how to create, start, and check the status of a SQL Server LocalDB instance named 'node'. This is recommended for testing the library when a full SQL Server instance is not available. ```bash sqllocaldb create node sqllocaldb start node sqllocaldb info node ``` -------------------------------- ### Connection Pool Example with Promises Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Demonstrates how to use the promise-based API to manage a connection pool. It opens the pool, executes multiple queries concurrently using Promise.all, and then closes the pool. ```ts async function pool() { try { const connStr: string = getConnection() const size = 4 const options: PoolOptions = { connectionString: connStr, ceiling: size } const pool: Pool = new sql.Pool(options) await pool.promises.open() const all = Array(size * 2).fill(0).map((_, i) => pool.promises.query(`select ${i} as i, @@SPID as spid`)) const promised: QueryAggregatorResults[] = await Promise.all(all) const res = promised.map(r => r.first[0].spid) await pool.promises.close() console.log(`pool spids ${res.join(', ')}`) } catch (e) { console.log(e) } } ``` -------------------------------- ### Execute Node.js SQL Server Sample Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Runs a sample JavaScript file that utilizes the msnodesqlv8 package to connect to a SQL Server database. It shows an example of how to execute a query and retrieve metadata. ```javascript node samples/javascript/streaming.js ``` -------------------------------- ### Ad-hoc Stored Procedure Call with Promises Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Demonstrates calling a stored procedure using the promise-based `sql.promises.callProc` method. It includes setup and teardown for a sample procedure. ```ts async function adhocProc() { try { const connStr: string = getConnection() const proc = new ProcTest(connStr, sampleProc) await proc.create() const msg = 'hello world' const res: QueryAggregatorResults = await sql.promises.callProc(connStr, sampleProc.name, { param: msg }) await proc.drop() console.log(`adhocProc returns ${res.returns} from param '${msg}''`) } catch (e) { console.log(e) } } ``` -------------------------------- ### Connection Pool Example with Promises Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Demonstrates how to use the promise-based API to manage a connection pool. It opens the pool, executes multiple queries concurrently using Promise.all, and then closes the pool. ```ts async function pool() { try { const connStr: string = getConnection() const size = 4 const options: PoolOptions = { connectionString: connStr, ceiling: size } const pool: Pool = new sql.Pool(options) await pool.promises.open() const all = Array(size * 2).fill(0).map((_, i) => pool.promises.query(`select ${i} as i, @@SPID as spid`)) const promised: QueryAggregatorResults[] = await Promise.all(all) const res = promised.map(r => r.first[0].spid) await pool.promises.close() console.log(`pool spids ${res.join(', ')}`) } catch (e) { console.log(e) } } ``` -------------------------------- ### Execute Node.js SQL Server Sample Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Runs a sample JavaScript file that utilizes the msnodesqlv8 package to connect to a SQL Server database. It shows an example of how to execute a query and retrieve metadata. ```javascript node samples/javascript/streaming.js ``` -------------------------------- ### Access Prepared Statement Metadata Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Provides examples of helper functions to retrieve metadata, the SQL signature, and the unique ID associated with a prepared statement object. ```javascript var meta = ps.getMeta(); // column meta data reserved in driver var sql = ps.getSignature(); // the sql used to create prepared statement. var id = ps.getId(); // unique integer reprenting statement ``` -------------------------------- ### JavaScript Async Pattern with Generators and Promises Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Illustrates an advanced asynchronous pattern using generators and the `asynquence` library to manage a sequence of database operations. This example shows preparing, executing, and freeing a SQL command. ```JavaScript let ASQ = require('asynquence-contrib'); testPrepare: string = `select len(convert(varchar, ?)) as len`; private prepare(): Promise { let inst = this; return new Promise((resolve, reject) => { ASQ().runner(function *() { let connection = yield inst.sqlWrapper.open(); let command = connection.getCommand().sql(inst.testPrepare); command = yield command.prepare(); let res = yield command.params([1000]).execute(); assert.deepEqual(res.asObjects, inst.expectedPrepared, "results didn't match"); yield command.freePrepared(); yield connection.close(); resolve(); }).or((e: any) => { reject(e); } ) }) } ``` -------------------------------- ### Ad-hoc Stored Procedure Call with Promises Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Demonstrates calling a stored procedure using the promise-based `sql.promises.callProc` method. It includes setup and teardown for a sample procedure. ```ts async function adhocProc() { try { const connStr: string = getConnection() const proc = new ProcTest(connStr, sampleProc) await proc.create() const msg = 'hello world' const res: QueryAggregatorResults = await sql.promises.callProc(connStr, sampleProc.name, { param: msg }) await proc.drop() console.log(`adhocProc returns ${res.returns} from param '${msg}''`) } catch (e) { console.log(e) } } ``` -------------------------------- ### TypeScript Table Management Example Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Demonstrates using the node-sqlserver-v8 library in TypeScript to manage database tables. It shows fetching a table, inserting rows, querying data, and dropping the table using a promise-based API. ```TypeScript async function table() { try { const connStr: string = getConnection() const connection = await sql.promises.open(connStr) const tm: BulkTableTest = new BulkTableTest(connection, sampleTableDef) const table: BulkTableMgr = await tm.create() const vec: SampleRecord[] = getInsertVec(10) console.log(`table = ${tm.createTableSql}`) await table.promises.insert(vec) const read = await connection.promises.query(tm.selectSql) console.log(`table ${read.first.length} rows from ${tm.tableName}`) console.log(JSON.stringify(read.first, null, 4)) await tm.drop() await connection.promises.close() } catch (e) { console.log(e) } } ``` -------------------------------- ### JavaScript Async Pattern with Generators and Promises Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Illustrates an advanced asynchronous pattern using generators and the `asynquence` library to manage a sequence of database operations. This example shows preparing, executing, and freeing a SQL command. ```JavaScript let ASQ = require('asynquence-contrib'); testPrepare: string = `select len(convert(varchar, ?)) as len`; private prepare(): Promise { let inst = this; return new Promise((resolve, reject) => { ASQ().runner(function *() { let connection = yield inst.sqlWrapper.open(); let command = connection.getCommand().sql(inst.testPrepare); command = yield command.prepare(); let res = yield command.params([1000]).execute(); assert.deepEqual(res.asObjects, inst.expectedPrepared, "results didn't match"); yield command.freePrepared(); yield connection.close(); resolve(); }).or((e: any) => { reject(e); } ) }) } ``` -------------------------------- ### TypeScript Table Management Example Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Demonstrates using the node-sqlserver-v8 library in TypeScript to manage database tables. It shows fetching a table, inserting rows, querying data, and dropping the table using a promise-based API. ```TypeScript async function table() { try { const connStr: string = getConnection() const connection = await sql.promises.open(connStr) const tm: BulkTableTest = new BulkTableTest(connection, sampleTableDef) const table: BulkTableMgr = await tm.create() const vec: SampleRecord[] = getInsertVec(10) console.log(`table = ${tm.createTableSql}`) await table.promises.insert(vec) const read = await connection.promises.query(tm.selectSql) console.log(`table ${read.first.length} rows from ${tm.tableName}`) console.log(JSON.stringify(read.first, null, 4)) await tm.drop() await connection.promises.close() } catch (e) { console.log(e) } } ``` -------------------------------- ### Executing a Stored Procedure via Connection Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Shows a practical example of executing a stored procedure (`test_sp_get_int_int`) directly using the `callproc` method on a connection object, demonstrating parameter passing and output verification. ```javascript function exec_proc(conn) { var pm = conn.procedureMgr(); pm.callproc('test_sp_get_int_int', [10, 5], function(err, results, output) { // var expected = [99, 15]; // assert.deepEqual(output, expected, "results didn't match"); }); } ``` -------------------------------- ### Executing a Stored Procedure via Connection Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Shows a practical example of executing a stored procedure (`test_sp_get_int_int`) directly using the `callproc` method on a connection object, demonstrating parameter passing and output verification. ```javascript function exec_proc(conn) { var pm = conn.procedureMgr(); pm.callproc('test_sp_get_int_int', [10, 5], function(err, results, output) { // var expected = [99, 15]; // assert.deepEqual(output, expected, "results didn't match"); }); } ``` -------------------------------- ### Start SQL Server in Docker Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/docker/sqlserver-always-encrypted/docker-always-encrypted-setup.md Pulls the latest SQL Server 2022 image and runs it in a Docker container, mapping port 1433 and setting a SA password. This is the initial step to get a SQL Server instance running for testing. ```bash # Pull the latest SQL Server 2022 image docker pull mcr.microsoft.com/mssql/server:2022-latest # Run SQL Server with a strong password docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrong@Passw0rd" \ -p 1433:1433 --name sql_always_encrypted \ -d mcr.microsoft.com/mssql/server:2022-latest ``` -------------------------------- ### Start SQL Server Docker Setup Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/docker/sqlserver-always-encrypted/README.md Executes the main PowerShell script to initialize the SQL Server 2022 Docker container with Always Encrypted. This script handles directory creation, container pulling/starting, certificate setup, and test data population. ```PowerShell .\start.ps1 ``` -------------------------------- ### Connection Pool Initialization Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Illustrates how to create and configure a connection pool using the `sql.Pool` constructor with various options. ```javascript const sql = require('msnodesqlv8'); export interface PoolOptions { floor?: number ceiling?: number heartbeatSecs?: number heartbeatSql?: string inactivityTimeoutSecs?: number useUTC?:boolean connectionString: string } const pool = new sql.Pool(options) // options is an object conforming to PoolOptions ``` -------------------------------- ### GDB Stack Trace Example Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md A sample stack trace from a segmentation fault, showing the sequence of function calls leading to the crash. This example indicates the fault occurred within OpenSSL functions and the msodbcsql18 library. ```txt Thread 8 "node" received signal SIGSEGV, Segmentation fault. [Switching to LWP 31950] 0x000000000179eaf0 in EC_GROUP_order_bits () (gdb) bt #0 0x000000000179eaf0 in EC_GROUP_order_bits () #1 0x00007fffd631f60d in engine_unlocked_init () from /usr/local/ssl/lib64/libcrypto.so.3 #2 0x00007fffd631f796 in ENGINE_init () from /usr/local/ssl/lib64/libcrypto.so.3 #3 0x00007fffd636b7e7 in EVP_PKEY_CTX_new_from_pkey () from /usr/local/ssl/lib64/libcrypto.so.3 #4 0x00007fffd66f325b in ssl_setup_sigalgs () from /usr/local/ssl/lib64/libssl.so.3 #5 0x00007fffd66e858f in SSL_CTX_new_ex () from /usr/local/ssl/lib64/libssl.so.3 #6 0x00007ffff44aa4f7 in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #7 0x00007ffff44a50d2 in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #8 0x00007ffff44a599b in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #9 0x00007ffff446f5cf in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #10 0x00007ffff446c8cc in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #11 0x00007ffff446d675 in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #12 0x00007ffff446dcd4 in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #13 0x00007ffff43db23c in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #14 0x00007ffff440ff8e in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #15 0x00007ffff43d9dfa in SQLDriverConnectW () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 ``` -------------------------------- ### GDB Stack Trace Example Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home A sample stack trace from a segmentation fault, showing the sequence of function calls leading to the crash. This example indicates the fault occurred within OpenSSL functions and the msodbcsql18 library. ```txt Thread 8 "node" received signal SIGSEGV, Segmentation fault. [Switching to LWP 31950] 0x000000000179eaf0 in EC_GROUP_order_bits () (gdb) bt #0 0x000000000179eaf0 in EC_GROUP_order_bits () #1 0x00007fffd631f60d in engine_unlocked_init () from /usr/local/ssl/lib64/libcrypto.so.3 #2 0x00007fffd631f796 in ENGINE_init () from /usr/local/ssl/lib64/libcrypto.so.3 #3 0x00007fffd636b7e7 in EVP_PKEY_CTX_new_from_pkey () from /usr/local/ssl/lib64/libcrypto.so.3 #4 0x00007fffd66f325b in ssl_setup_sigalgs () from /usr/local/ssl/lib64/libssl.so.3 #5 0x00007fffd66e858f in SSL_CTX_new_ex () from /usr/local/ssl/lib64/libssl.so.3 #6 0x00007ffff44aa4f7 in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #7 0x00007ffff44a50d2 in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #8 0x00007ffff44a599b in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #9 0x00007ffff446f5cf in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #10 0x00007ffff446c8cc in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #11 0x00007ffff446d675 in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #12 0x00007ffff446dcd4 in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #13 0x00007ffff43db23c in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #14 0x00007ffff440ff8e in ?? () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 #15 0x00007ffff43d9dfa in SQLDriverConnectW () from /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1 ``` -------------------------------- ### Prepare and Execute SQL Statement Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Illustrates the use of prepared statements for efficient execution of SQL queries. It involves preparing a query, executing it with parameters, retrieving metadata, and freeing resources. ```typescript function employeePrepare(done) { var query = `SELECT [ModifiedDate] ,[BusinessEntityID] ,[OrganizationNode] ,[ModifiedDate] FROM [scratch].[dbo].[Employee] WHERE BusinessEntityID = ?`; sql.open(connStr, (err, conn) => { assert.ifError(err); conn.prepare(query, (e, ps) => { assert.ifError(err); ps.preparedQuery([1], (err, fetched) => { console.log(ps.getMeta()); console.log(fetched); ps.free(() => { done(); }) }); }); }); } ``` -------------------------------- ### Prepare and Execute SQL Statement Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Illustrates the use of prepared statements for efficient execution of SQL queries. It involves preparing a query, executing it with parameters, retrieving metadata, and freeing resources. ```typescript function employeePrepare(done) { var query = `SELECT [ModifiedDate] ,[BusinessEntityID] ,[OrganizationNode] ,[ModifiedDate] FROM [scratch].[dbo].[Employee] WHERE BusinessEntityID = ?`; sql.open(connStr, (err, conn) => { assert.ifError(err); conn.prepare(query, (e, ps) => { assert.ifError(err); ps.preparedQuery([1], (err, fetched) => { console.log(ps.getMeta()); console.log(fetched); ps.free(() => { done(); }) }); }); }); } ``` -------------------------------- ### SQL Server Docker Setup - Troubleshooting Container Issues Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/docker/sqlserver-always-encrypted/README.md Provides steps to diagnose and resolve problems with the Docker container not starting or running correctly. Includes checking Docker status, resource usage, and detailed container logs. ```Bash # Check Docker is running docker version # Check available resources docker system df # View detailed container logs docker logs sqlserver-always-encrypted --details ``` -------------------------------- ### GDB Debugging - Start Node Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Initiates the Node.js process within the GNU Debugger (gdb) to analyze runtime behavior and crashes. ```sh gdb node (gdb) run samples/javascript/streaming ``` -------------------------------- ### GDB Debugging - Start Node Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Initiates the Node.js process within the GNU Debugger (gdb) to analyze runtime behavior and crashes. ```sh gdb node (gdb) run samples/javascript/streaming ``` -------------------------------- ### Connection Pool Initialization Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Illustrates how to create and configure a connection pool using the `sql.Pool` constructor with various options. ```javascript const sql = require('msnodesqlv8'); export interface PoolOptions { floor?: number ceiling?: number heartbeatSecs?: number heartbeatSql?: string inactivityTimeoutSecs?: number useUTC?:boolean connectionString: string } const pool = new sql.Pool(options) // options is an object conforming to PoolOptions ``` -------------------------------- ### Obtain Procedure Manager Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Shows how to get an instance of the procedure manager from the connection object. This manager is used to interact with stored procedures. ```typescript var pm = conn.procedureMgr(); ``` -------------------------------- ### Obtain Procedure Manager Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Shows how to get an instance of the procedure manager from the connection object. This manager is used to interact with stored procedures. ```typescript var pm = conn.procedureMgr(); ``` -------------------------------- ### SQL Server Docker Setup - Troubleshooting Connection Issues Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/docker/sqlserver-always-encrypted/README.md Guides users through diagnosing SQL Server connection problems. It suggests checking the container's health via sqlcmd and verifying network accessibility to the SQL Server port. ```Bash # Test container health docker exec sqlserver-always-encrypted /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "Password_123#" -Q "SELECT @@VERSION" # Check if port is accessible telnet 127.0.0.1 1433 ``` -------------------------------- ### Basic Usage of MockIOdbcStatement Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/test/cpp/MOCK_STATEMENT_USAGE.md Demonstrates the fundamental steps to instantiate and configure a MockIOdbcStatement for basic testing. It shows how to set expectations for method calls using a mocking framework. ```cpp // Create a mock statement auto mockStatement = std::make_shared(); // Set up basic expectations EXPECT_CALL(*mockStatement, GetType()) .WillOnce(Return(StatementType::Prepared)); // Use the mock ASSERT_EQ(StatementType::Prepared, mockStatement->GetType()); ``` -------------------------------- ### Establishing a Database Connection Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Shows how to open a connection to a SQL Server database using a connection string, supporting trusted connections or SQL Server authentication. ```javascript var sql = require('msnodesqlv8'); function connect() { var connStr = "Driver={SQL Server Native Client 11.0};Server=;Database={scratch};Trusted_Connection=Yes;"; sql.open(connStr, function (err, conn) { assert.ifError(err); // connection is now ready to use. }); } ``` -------------------------------- ### Access Prepared Statement Metadata Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Provides examples of helper functions to retrieve metadata, the SQL signature, and the unique ID associated with a prepared statement object. ```javascript var meta = ps.getMeta(); // column meta data reserved in driver var sql = ps.getSignature(); // the sql used to create prepared statement. var id = ps.getId(); // unique integer reprenting statement ``` -------------------------------- ### User Binding Example Source: https://github.com/timelorduk/node-sqlserver-v8/blob/master/wiki.md Demonstrates how to explicitly bind a value to a specific SQL Server data type using the driver's type casting methods. ```typescript conn.query("declare @v tinyint = ?; select @v as v", [sql.TinyInt(255)], (err, res) => {}); ``` -------------------------------- ### User Binding Example Source: https://github.com/timelorduk/node-sqlserver-v8/wiki/Home Demonstrates how to explicitly bind a value to a specific SQL Server data type using the driver's type casting methods. ```typescript conn.query("declare @v tinyint = ?; select @v as v", [sql.TinyInt(255)], (err, res) => {}); ```