├── .gitignore ├── .jshintrc ├── .npmignore ├── .reuse └── dep5 ├── .travis.yml ├── LICENSE ├── LICENSES └── Apache-2.0.txt ├── Makefile ├── README.md ├── bin └── coveralls.js ├── chrome └── sockets │ └── tcp.js ├── examples ├── app1.js ├── app10.js ├── app2.js ├── app3.js ├── app4.js ├── app5.js ├── app6.js ├── app7.js ├── app8.js ├── app9.js ├── call1.js ├── call2.js ├── call3.js ├── client.js ├── csv.js ├── pool.js ├── server.js └── tx1.js ├── index.js ├── lib ├── Client.js ├── index.js ├── protocol │ ├── ClientInfo.js │ ├── Connection.js │ ├── ConnectionManager.js │ ├── ExecuteTask.js │ ├── Lob.js │ ├── MessageBuffer.js │ ├── Parser.js │ ├── Reader.js │ ├── Result.js │ ├── ResultSet.js │ ├── ResultSetTransform.js │ ├── Statement.js │ ├── Stringifier.js │ ├── Transaction.js │ ├── Writer.js │ ├── auth │ │ ├── JWT.js │ │ ├── LDAP.js │ │ ├── Manager.js │ │ ├── SAML.js │ │ ├── SCRAMSHA256.js │ │ ├── SessionCookie.js │ │ └── index.js │ ├── common │ │ ├── ClientContextOption.js │ │ ├── ClientDistributionMode.js │ │ ├── CommandOption.js │ │ ├── CommitOption.js │ │ ├── ConnectOption.js │ │ ├── ConnectOptionType.js │ │ ├── Constants.js │ │ ├── DataFormatVersion.js │ │ ├── DbConnectInfoOption.js │ │ ├── DistributionProtocolVersion.js │ │ ├── ErrorLevel.js │ │ ├── FunctionCode.js │ │ ├── IoType.js │ │ ├── LobOptions.js │ │ ├── LobSourceType.js │ │ ├── MessageType.js │ │ ├── NormalizedTypeCode.js │ │ ├── ParameterMode.js │ │ ├── PartKind.js │ │ ├── ReadFunction.js │ │ ├── RedirectType.js │ │ ├── ResultSetAttributes.js │ │ ├── SegmentKind.js │ │ ├── SessionContext.js │ │ ├── StatementContext.js │ │ ├── StatementContextType.js │ │ ├── TopologyInformation.js │ │ ├── TransactionFlag.js │ │ ├── TransactionFlagType.js │ │ ├── TypeCode.js │ │ └── index.js │ ├── data │ │ ├── Binary.js │ │ ├── Default.js │ │ ├── Fields.js │ │ ├── Int32.js │ │ ├── MultilineOptions.js │ │ ├── Options.js │ │ ├── ParameterMetadata.js │ │ ├── Parameters.js │ │ ├── ReadLobReply.js │ │ ├── ReadLobRequest.js │ │ ├── ResultSetMetadata.js │ │ ├── SqlError.js │ │ ├── Text.js │ │ ├── Text20.js │ │ ├── TextList.js │ │ ├── TransactionFlags.js │ │ ├── WriteLobReply.js │ │ └── index.js │ ├── index.js │ ├── part │ │ ├── AbstractOptions.js │ │ ├── ClientContextOptions.js │ │ ├── ConnectOptions.js │ │ ├── DbConnectInfoOptions.js │ │ ├── StatementContext.js │ │ └── index.js │ ├── reply │ │ ├── Part.js │ │ ├── Segment.js │ │ └── index.js │ ├── request │ │ ├── Part.js │ │ ├── Segment.js │ │ └── index.js │ └── tcp.js └── util │ ├── Queue.js │ ├── bignum.js │ ├── calendar.js │ ├── convert.js │ ├── index.js │ └── zeropad.js ├── package.json └── test ├── acceptance ├── db.DataType.js ├── db.Dummy.js ├── db.Events.js ├── db.Lob.js ├── db.Prepare.js └── db.Query.js ├── auth.Manager.js ├── common.TopologyInformation.js ├── data.Binary.js ├── data.Default.js ├── data.Fields.js ├── data.Int32.js ├── data.Options.js ├── data.ParameterMetadata.js ├── data.Parameters.js ├── data.ReadLob.js ├── data.ResultSet.js ├── data.ResultSetMetadata.js ├── data.SqlError.js ├── data.Text.js ├── data.TopogolyInformation.js ├── data.WriteLob.js ├── db ├── LocalDB.js ├── RemoteDB.js ├── TestDB.js ├── config.tpl.json └── index.js ├── fixtures ├── images.js ├── img │ ├── lobby.jpg │ ├── locked.png │ ├── logo.png │ └── sap.jpg ├── lorem.js ├── numbers.js ├── parametersData.js ├── resultSetData.js ├── resultSetMetadata.js ├── topogolyInformation.js └── txt │ ├── long.txt │ └── short.txt ├── hdb.Client.js ├── lib.ClientInfo.js ├── lib.Connection.js ├── lib.ExecuteTask.js ├── lib.Lob.js ├── lib.MessageBuffer.js ├── lib.Parser.js ├── lib.Reader.js ├── lib.Result.js ├── lib.ResultSet.js ├── lib.ResultSetTransform.js ├── lib.Statement.js ├── lib.Stringifier.js ├── lib.Transaction.js ├── lib.Writer.js ├── lib.index.js ├── lib.tcp.js ├── mocha.opts ├── mock ├── MockAuthenticationManager.js ├── MockConnection.js ├── MockResult.js ├── MockSocket.js ├── data │ ├── dbConnectInfo.js │ ├── execute.js │ ├── executeDirect.js │ ├── fetch.js │ ├── prepare.js │ ├── readLob.js │ ├── replies.js │ └── writeLob.js ├── index.js └── server.js ├── normalize.js ├── part.DbConnectInfoOptions.js ├── part.StatementContext.js ├── rep.part.js ├── rep.segment.js ├── req.Authenticate.js ├── req.index.js ├── req.segment.js ├── util.Queue.js ├── util.bignum.js ├── util.calendar.js ├── util.convert.js ├── util.index.js └── util.zeropad.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .vscode 3 | node_modules 4 | coverage 5 | config.json 6 | hdb.js 7 | examples/test*.js 8 | npm-debug.log 9 | tmp 10 | /test/db/config.json* 11 | package-lock.json 12 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "asi": false, 4 | "boss": false, 5 | "eqnull": false, 6 | "evil": false, 7 | "expr": false, 8 | "funcscope": false, 9 | "smarttabs": true, 10 | "shadow": false, 11 | "sub": false, 12 | "supernew": false, 13 | "bitwise": true, 14 | "camelcase": true, 15 | "curly": true, 16 | "eqeqeq": true, 17 | "forin": true, 18 | "immed": true, 19 | "indent": 2, 20 | "latedef": false, 21 | "loopfunc": false, 22 | "maxerr": 7, 23 | "newcap": true, 24 | "noarg": true, 25 | "nonew": true, 26 | "plusplus": false, 27 | "quotmark": "single", 28 | "regexdash": false, 29 | "undef": true, 30 | "unused": true, 31 | "strict": true, 32 | "trailing": true, 33 | "white": true, 34 | "predef": [ 35 | "describe", 36 | "it", 37 | "before", 38 | "after" 39 | ] 40 | } 41 | 42 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | examples/ 3 | test/ 4 | coverage/ 5 | bin/ -------------------------------------------------------------------------------- /.reuse/dep5: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: node-hdb 3 | Source: https://github.com/SAP/node-hdb 4 | Disclaimer: The code in this project may include calls to APIs (“API Calls”) of 5 | SAP or third-party products or services developed outside of this project 6 | (“External Products”). 7 | “APIs” means application programming interfaces, as well as their respective 8 | specifications and implementing code that allows software to communicate with 9 | other software. 10 | API Calls to External Products are not licensed under the open source license 11 | that governs this project. The use of such API Calls and related External 12 | Products are subject to applicable additional agreements with the relevant 13 | provider of the External Products. In no event shall the open source license 14 | that governs this project grant any rights in or to any External Products,or 15 | alter, expand or supersede any terms of the applicable additional agreements. 16 | If you have a valid license agreement with SAP for the use of a particular SAP 17 | External Product, then you may make use of any API Calls included in this 18 | project’s code for that SAP External Product, subject to the terms of such 19 | license agreement. If you do not have a valid license agreement for the use of 20 | a particular SAP External Product, then you may only make use of any API Calls 21 | in this project for that SAP External Product for your internal, non-productive 22 | and non-commercial test and evaluation of such API Calls. Nothing herein grants 23 | you any rights to use or access any SAP External Product, or provide any third 24 | parties the right to use of access any SAP External Product, through API Calls. 25 | 26 | Files: * 27 | Copyright: 2013-2021 SAP SE or an SAP affiliate company and node-hdb contributors 28 | License: Apache-2.0 -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | cache: 4 | directories: 5 | - node_modules 6 | node_js: 7 | - "0.12" 8 | - "4" 9 | - "6" 10 | - "8" 11 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | REPORTER = spec 2 | 3 | test: 4 | @NODE_ENV=test ./node_modules/.bin/mocha \ 5 | -R $(REPORTER) -b --recursive 6 | 7 | test-unit: 8 | @NODE_ENV=test ./node_modules/.bin/mocha \ 9 | -R $(REPORTER) -b 10 | 11 | test-acceptance: 12 | @NODE_ENV=test ./node_modules/.bin/mocha \ 13 | -R $(REPORTER) -b test/acceptance/*.js 14 | 15 | test-mock: 16 | @HDB_MOCK=1 $(MAKE) -s test 17 | 18 | test-lcov: 19 | @NODE_ENV=test ./node_modules/.bin/istanbul cover \ 20 | --report lcov \ 21 | ./node_modules/mocha/bin/_mocha -- \ 22 | -R spec -b --recursive 23 | 24 | test-coveralls: 25 | @NODE_ENV=test ./node_modules/.bin/istanbul cover \ 26 | --report lcovonly \ 27 | ./node_modules/mocha/bin/_mocha -- \ 28 | -R spec -b --recursive \ 29 | && cat ./coverage/lcov.info | node ./bin/coveralls.js \ 30 | && rm -rf ./coverage 31 | 32 | clean: 33 | @rm -rf ./coverage \ 34 | @rm -f hdb.js 35 | 36 | chromify: 37 | @browserify -r buffer -r ./lib:hdb -o ./hdb.js 38 | 39 | .PHONY: test clean -------------------------------------------------------------------------------- /bin/coveralls.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | var util = require('util'); 6 | var coveralls = require('coveralls'); 7 | 8 | if (process.env.TRAVIS_JOB_ID) { 9 | process.env.TRAVIS = '1'; 10 | } 11 | if (process.env.SEND_TO_STDOUT) { 12 | coveralls.sendToCoveralls = function (obj, cb) { 13 | console.log(util.inspect(obj, { 14 | colors: true, 15 | depth: 8 16 | })); 17 | setImmediate(function () { 18 | cb(null, { 19 | statusCode: 200 20 | }, 'OK'); 21 | }); 22 | }; 23 | } 24 | 25 | var input = ''; 26 | process.stdin 27 | .on('readable', function () { 28 | var chunk; 29 | while (null !== (chunk = this.read())) { 30 | input += chunk; 31 | } 32 | }) 33 | .on('end', function () { 34 | coveralls.handleInput(input, function (err) { 35 | if (err) { 36 | throw err; 37 | } 38 | }); 39 | }) 40 | .setEncoding('utf8'); -------------------------------------------------------------------------------- /chrome/sockets/tcp.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var chromeNet = require('chrome-net'); 17 | 18 | exports.connect = function connect(options, cb) { 19 | function connectionListener() { 20 | /* jshint validthis:true */ 21 | this.setNoDelay(true); 22 | if (typeof cb === 'function') { 23 | cb.apply(this, arguments); 24 | } 25 | } 26 | return chromeNet.connect(options, connectionListener); 27 | }; 28 | exports._connect = chromeNet.connect; -------------------------------------------------------------------------------- /examples/app1.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | var async = require('async'); 18 | var client = require('./client'); 19 | 20 | var fields = ['SCHEMA_NAME || \'.\' || TABLE_NAME as TABLE']; 21 | var sql = util.format('select top 50 %s from TABLES', fields.join(',')); 22 | 23 | async.waterfall([connect, executeAndfetchRows, disconnect], done); 24 | 25 | function connect(cb) { 26 | client.connect(cb); 27 | } 28 | 29 | function disconnect(rows, cb) { 30 | function done(err) { 31 | cb(err, rows); 32 | } 33 | client.disconnect(done); 34 | } 35 | 36 | function executeAndfetchRows(cb) { 37 | client.exec(sql, cb); 38 | } 39 | 40 | function done(err, rows) { 41 | client.end(); 42 | if (err) { 43 | return console.error(err); 44 | } 45 | console.log(util.inspect(rows, { 46 | colors: true 47 | })); 48 | } -------------------------------------------------------------------------------- /examples/app10.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Copyright 2013 SAP AG. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http: //www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | // either express or implied. See the License for the specific 15 | // language governing permissions and limitations under the License. 16 | 'use strict'; 17 | 18 | var util = require('../lib/util'); 19 | var async = require('async'); 20 | var client = require('./client'); 21 | 22 | async.series([connect, init, insert, select], done); 23 | 24 | function connect(cb) { 25 | client.connect(cb); 26 | } 27 | 28 | 29 | function init(cb) { 30 | async.series([ 31 | function (done) { 32 | client.exec([ 33 | 'create local temporary column table #x (', 34 | 'id int not null,', 35 | 'name nvarchar(256) not null)', 36 | ].join('\n'), done); 37 | }, 38 | function (done) { 39 | client.exec([ 40 | 'create local temporary column table #y (', 41 | 'id int not null,', 42 | 'name nvarchar(256) not null)', 43 | ].join('\n'), done); 44 | } 45 | ], cb); 46 | } 47 | 48 | function insert(cb) { 49 | var statement; 50 | async.series([ 51 | function (done) { 52 | client.prepare('insert into #x values (?,?)', function (err, stmnt) { 53 | statement = stmnt; 54 | done(err); 55 | }); 56 | }, 57 | function (done) { 58 | statement.exec([ 59 | [1, 'A'], 60 | [2, 'B'], 61 | [3, 'C'] 62 | ], done); 63 | }, 64 | function (done) { 65 | statement.drop(function (err) { 66 | statement = undefined; 67 | done(err); 68 | }); 69 | }, 70 | function (done) { 71 | client.prepare('insert into #y values (?,?)', function (err, stmnt) { 72 | statement = stmnt; 73 | done(err); 74 | }); 75 | }, 76 | function (done) { 77 | statement.exec([ 78 | [1, 'a'], 79 | [2, 'b'], 80 | [3, 'c'] 81 | ], done); 82 | }, 83 | function (done) { 84 | statement.drop(function (err) { 85 | statement = undefined; 86 | done(err); 87 | }); 88 | }, 89 | ], cb); 90 | } 91 | 92 | function select(cb) { 93 | var sql = 'select * from #x join #y on #x.id = #y.id'; 94 | client.exec(sql, { 95 | rowsAsArray: true 96 | }, function (err, rows) { 97 | if (err) { 98 | return cb(err); 99 | } 100 | console.log(util.inspect(rows, { 101 | colors: true, 102 | depth: 9 103 | })); 104 | cb(); 105 | }); 106 | } 107 | 108 | function done() { 109 | client.end(); 110 | } -------------------------------------------------------------------------------- /examples/app2.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | var async = require('async'); 18 | var client = require('./client'); 19 | 20 | var fields = ['SCHEMA_NAME || \'.\' || TABLE_NAME as TABLE']; 21 | var sql = util.format('select top 50 %s from TABLES', fields.join(',')); 22 | 23 | async.waterfall([connect, execute, fetchRows], done); 24 | 25 | function connect(cb) { 26 | client.connect(cb); 27 | } 28 | 29 | function execute(cb) { 30 | client.execute(sql, cb); 31 | } 32 | 33 | function fetchRows(rs, cb) { 34 | rs.fetch(cb); 35 | } 36 | 37 | function done(err, rows) { 38 | client.end(); 39 | if (err) { 40 | return console.error(err); 41 | } 42 | console.log(util.inspect(rows, { 43 | colors: true 44 | })); 45 | } -------------------------------------------------------------------------------- /examples/app3.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | var async = require('async'); 18 | var client = require('./client'); 19 | 20 | var fields = ['SCHEMA_NAME || \'.\' || TABLE_NAME as TABLE']; 21 | var sql = util.format('select top 50 %s from TABLES', fields.join(',')); 22 | 23 | async.waterfall([connect, execute, fetchRows], done); 24 | 25 | function connect(cb) { 26 | client.connect(cb); 27 | } 28 | 29 | function execute(cb) { 30 | client.execute(sql, cb); 31 | } 32 | 33 | function fetchRows(rs, cb) { 34 | var stream = rs.createObjectStream(); 35 | var rows = []; 36 | 37 | function finish(err) { 38 | stream.removeListener('error', finish); 39 | stream.removeListener('end', onend); 40 | stream.removeListener('readable', onreadable); 41 | cb(err, rows); 42 | } 43 | stream.on('error', finish); 44 | 45 | function onend() { 46 | if (!rs.closed) { 47 | rs.close(); 48 | } 49 | finish(null); 50 | } 51 | stream.on('end', onend); 52 | 53 | function onreadable() { 54 | /* jshint validthis:true */ 55 | var chunk = this.read(); 56 | if (chunk) { 57 | rows.push(chunk); 58 | } 59 | } 60 | stream.on('readable', onreadable); 61 | } 62 | 63 | function done(err, rows) { 64 | client.end(); 65 | if (err) { 66 | return console.error(err); 67 | } 68 | console.log(util.inspect(rows, { 69 | colors: true 70 | })); 71 | } -------------------------------------------------------------------------------- /examples/app4.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | var async = require('async'); 18 | var client = require('./client'); 19 | var hdb = require('../index'); 20 | 21 | var fields = ['SCHEMA_NAME || \'.\' || TABLE_NAME as TABLE']; 22 | var sql = util.format('select top 50 %s from TABLES', fields.join(',')); 23 | 24 | async.waterfall([connect, execute, pipeRows], done); 25 | 26 | function connect(cb) { 27 | client.connect(cb); 28 | } 29 | 30 | function execute(cb) { 31 | client.execute(sql, cb); 32 | } 33 | 34 | function pipeRows(rs, cb) { 35 | var stream = rs.createArrayStream(); 36 | var stringifier = hdb.createJSONStringifier(); 37 | 38 | function finish(err) { 39 | stream.removeListener('error', finish); 40 | stream.removeListener('end', onend); 41 | stringifier.removeListener('finish', finish); 42 | cb(err); 43 | } 44 | stream.on('error', finish); 45 | stringifier.on('finish', finish); 46 | 47 | function onend() { 48 | if (!rs.closed) { 49 | rs.close(); 50 | } 51 | } 52 | stream.on('end', onend); 53 | 54 | stream.pipe(stringifier).pipe(process.stdout); 55 | } 56 | 57 | function done(err) { 58 | client.end(); 59 | if (err) { 60 | return console.error(err); 61 | } 62 | console.log(); 63 | console.log('Piped rows as JSON-Stream to STDOUT'); 64 | } -------------------------------------------------------------------------------- /examples/app8.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var async = require('async'); 17 | var client = require('./client'); 18 | 19 | async.series([connect, execute, reconnect, execute, disconnect], done); 20 | 21 | function connect(cb) { 22 | client.connect(cb); 23 | } 24 | 25 | function disconnect(cb) { 26 | client.disconnect(cb); 27 | } 28 | 29 | function execute(cb) { 30 | client.exec('select * from dummy', cb); 31 | } 32 | 33 | function reconnect(cb) { 34 | // reconnect on close 35 | client.on('close', function onclose(hadError) { 36 | if (hadError) { 37 | this.connect(); 38 | } 39 | }); 40 | // simulate a network error 41 | client._connection._socket.end(); 42 | client.once('connect', function reconnected() { 43 | cb(); 44 | }); 45 | } 46 | 47 | function done(err, results) { 48 | client.end(); 49 | if (err) { 50 | return console.error('Error', err); 51 | } 52 | console.log(results); 53 | } -------------------------------------------------------------------------------- /examples/call1.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | var async = require('async'); 18 | var client = require('./client'); 19 | 20 | async.waterfall([connect, setSchema, init, prepare, callProc], done); 21 | 22 | function connect(cb) { 23 | client.connect(cb); 24 | } 25 | 26 | function setSchema(cb) { 27 | var schema = client.get('user'); 28 | var sql = util.format('set schema %s', schema); 29 | client.exec(sql, cb); 30 | } 31 | 32 | function init(cb) { 33 | var sql = 'drop procedure PROC_DUMMY'; 34 | client.exec(sql, function onexec() { 35 | // ignore error 36 | var sql = [ 37 | 'create procedure PROC_DUMMY (in a int, in b int, out c int, out d DUMMY)', 38 | 'language sqlscript', 39 | 'reads sql data as', 40 | 'begin', 41 | ' c := :a + :b;', 42 | ' d = select * from DUMMY;', 43 | 'end;' 44 | ].join('\n'); 45 | client.exec(sql, cb); 46 | }); 47 | } 48 | 49 | function prepare(cb) { 50 | var sql = 'call PROC_DUMMY (?, ?, ?, ?)'; 51 | client.prepare(sql, cb); 52 | } 53 | 54 | function callProc(statement, cb) { 55 | var values = { 56 | A: 3, 57 | B: 4 58 | }; 59 | statement.exec(values, function onexec(err, parameters, rows) { 60 | statement.drop(); 61 | cb(err, parameters, rows); 62 | }); 63 | } 64 | 65 | function done(err, parameters, rows) { 66 | client.end(); 67 | if (err) { 68 | return console.error('error', err); 69 | } 70 | console.log('Parameters:', util.inspect(parameters, { 71 | depth: 4, 72 | colors: true 73 | })); 74 | console.log('Rows:', util.inspect(rows, { 75 | depth: 4, 76 | colors: true 77 | })); 78 | } -------------------------------------------------------------------------------- /examples/call2.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var async = require('async'); 17 | var client = require('./client'); 18 | 19 | async.waterfall([connect, init, prepare, callProc], done); 20 | 21 | function connect(cb) { 22 | client.connect(cb); 23 | } 24 | 25 | function init(cb) { 26 | var sql = 'drop procedure PROC_READ_OBJECT'; 27 | client.exec(sql, function onexec() { 28 | // ignore error 29 | var sql = [ 30 | 'CREATE PROCEDURE PROC_READ_OBJECT (', 31 | ' in name nvarchar(255),', 32 | ' out data blob)', 33 | 'LANGUAGE SQLSCRIPT AS', 34 | 'CURSOR c_cursor (name nvarchar(255)) FOR', 35 | ' SELECT DATA FROM TEST_LOBS WHERE name = :name;', 36 | 'BEGIN', 37 | ' OPEN c_cursor(:name);', 38 | ' FETCH c_cursor INTO data;', 39 | ' CLOSE c_cursor;', 40 | 'END;' 41 | ].join('\n'); 42 | client.exec(sql, cb); 43 | }); 44 | } 45 | 46 | function prepare(cb) { 47 | var sql = 'call PROC_READ_OBJECT(?, ?)'; 48 | client.prepare(sql, cb); 49 | } 50 | 51 | function callProc(statement, cb) { 52 | var values = { 53 | NAME: 'hello.txt' 54 | }; 55 | statement.exec(values, function onexec(err, parameters) { 56 | statement.drop(); 57 | cb(err, parameters); 58 | }); 59 | } 60 | 61 | function done(err, parameters) { 62 | client.end(); 63 | if (err) { 64 | return console.error('error', err); 65 | } 66 | console.log(parameters.DATA); 67 | } -------------------------------------------------------------------------------- /examples/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var fs = require('fs'); 17 | var path = require('path'); 18 | var hdb = require('../index'); 19 | var filename = path.join(__dirname, '..', 'test', 'db', 'config.json'); 20 | var options = JSON.parse(fs.readFileSync(filename)); 21 | 22 | var client = hdb.createClient({ 23 | host: options.host, 24 | port: options.port, 25 | user: options.user, 26 | password: options.password 27 | }); 28 | 29 | function onerror(err) { 30 | console.error('Network connection error', err); 31 | } 32 | client.on('error', onerror); 33 | 34 | function onclose() { 35 | console.log('Client closed'); 36 | } 37 | client.on('close', onclose); 38 | 39 | function onconnect() { 40 | console.log('Client connected'); 41 | } 42 | client.on('connect', onconnect); 43 | 44 | function ondisconnect() { 45 | console.log('Client disconnected'); 46 | } 47 | client.on('disconnect', ondisconnect); 48 | 49 | module.exports = client; -------------------------------------------------------------------------------- /examples/pool.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var fs = require('fs'); 17 | var path = require('path'); 18 | var gp = require('generic-pool'); 19 | var hdb = require('../index'); 20 | var filename = path.join(__dirname, '..', 'test', 'db', 'config.json'); 21 | var options = JSON.parse(fs.readFileSync(filename)); 22 | 23 | var pool = gp.Pool({ 24 | name: 'hdb', 25 | // create a new client object 26 | create: function create(callback) { 27 | var client = hdb.createClient(options); 28 | client.hadError = false; 29 | client.once('error', function onerror(err) { 30 | console.error('Client error:', err); 31 | client.hadError = true; 32 | }); 33 | client.connect(function onconnect(err) { 34 | if (err) { 35 | return callback(err); 36 | } 37 | callback(null, client); 38 | }); 39 | }, 40 | // If a client is removed from the pool 41 | // and the client is not already closed 42 | // gently close the client connection. 43 | destroy: function destroy(client) { 44 | if (!client.hadError && client.readyState !== 'closed') { 45 | client.end(); 46 | } 47 | }, 48 | // validate is called before a client is acquired from pool. 49 | // If the client is not connected it should be removed from pool. 50 | validate: function validate(client) { 51 | return (!client.hadError && client.readyState === 'connected'); 52 | }, 53 | max: 3, 54 | min: 1, 55 | idleTimeoutMillis: 30000, 56 | // don't destroy and recreat idle resources every idleTimeoutMillis 57 | refreshIdle: false, 58 | log: false 59 | }); 60 | 61 | exports = module.exports = pool; -------------------------------------------------------------------------------- /examples/tx1.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | var async = require('async'); 18 | var client = require('./client'); 19 | 20 | async.waterfall([connect, init, prepare, insert, update, select], done); 21 | 22 | function connect(cb) { 23 | client.setAutoCommit(false); 24 | client.connect(cb); 25 | } 26 | 27 | function dropTable(cb) { 28 | var sql = 'drop table PERSONS cascade'; 29 | client.exec(sql, cb); 30 | } 31 | 32 | function init(cb) { 33 | dropTable(function droped(err) { 34 | /* jshint unused:false */ 35 | // ignore error 36 | createTable(cb); 37 | }); 38 | } 39 | 40 | function createTable(cb) { 41 | var sql = [ 42 | 'create column table PERSONS (', 43 | '"ID" INTEGER NOT NULL,', 44 | '"LAST_NAME" NVARCHAR(256),', 45 | '"FIRST_NAME" NVARCHAR(256),', 46 | 'PRIMARY KEY ("ID"))' 47 | ].join('\n'); 48 | client.exec(sql, cb); 49 | } 50 | 51 | function prepare(cb) { 52 | var sql = 'insert into PERSONS values(?, ?, ?)'; 53 | client.prepare(sql, cb); 54 | } 55 | 56 | function insert(statement, cb) { 57 | var rows = [ 58 | [1, 'Ferdinand', 'Fuchs'], 59 | [2, 'Waldemar', 'Wild'], 60 | [3, 'Maximilian', 'Maier'] 61 | ]; 62 | 63 | function createTask(params) { 64 | return statement.exec.bind(statement, params); 65 | } 66 | var tasks = rows.map(createTask); 67 | 68 | function done(err) { 69 | if (err) { 70 | client.rollback(cb); 71 | } else { 72 | client.commit(cb); 73 | } 74 | } 75 | async.series(tasks, done); 76 | } 77 | 78 | function select(cb) { 79 | var sql = 'select * from PERSONS'; 80 | client.exec(sql, cb); 81 | } 82 | 83 | function update(cb) { 84 | function done(err) { 85 | /* jshint unused:false */ 86 | // force rollback 87 | client.rollback(cb); 88 | } 89 | var sql = 'update PERSONS set first_name = "Max" where id = 3'; 90 | client.exec(sql, done); 91 | } 92 | 93 | function done(err, rows) { 94 | client.end(); 95 | if (err) { 96 | return console.error(err); 97 | } 98 | console.log(util.inspect(rows, { 99 | colors: true 100 | })); 101 | } 102 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('./lib'); 17 | exports.Client = lib.Client; 18 | exports.createClient = lib.createClient; 19 | exports.Stringifier = lib.Stringifier; 20 | exports.createJSONStringifier = lib.createJSONStringifier; 21 | exports.iconv = require('iconv-lite'); 22 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | exports.util = require('./util'); 17 | exports.util.extend(exports, require('./protocol')); 18 | exports.Client = require('./Client'); 19 | 20 | exports.createClient = function createClient(options) { 21 | return new exports.Client(options); 22 | }; 23 | 24 | exports.connect = function connect(options, cb) { 25 | var client = exports.createClient(options); 26 | client.connect(cb); 27 | return client; 28 | }; 29 | 30 | exports.createJSONStringifier = function createJSONStringifier() { 31 | return new exports.Stringifier({ 32 | header: '[', 33 | footer: ']', 34 | seperator: ',', 35 | stringify: JSON.stringify 36 | }); 37 | }; -------------------------------------------------------------------------------- /lib/protocol/ClientInfo.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var common = require('./common'); 17 | var util = require('../util'); 18 | var MessageType = common.MessageType; 19 | 20 | module.exports = ClientInfo; 21 | 22 | function ClientInfo() { 23 | this._properties = {}; 24 | this._updatedProperties = {}; 25 | // this._user_default and this._application_default are overwritten 26 | // by the APPLICATIONUSER and APPLICATION properties respectively 27 | this._user_default = util.os_user; 28 | this._application_default = "node"; 29 | } 30 | 31 | ClientInfo.prototype.setProperty = function setProperty(key, value) { 32 | this._updatedProperties[key] = true; 33 | this._properties[key] = value; 34 | }; 35 | 36 | ClientInfo.prototype.getProperty = function getProperty(key) { 37 | return this._properties[key]; 38 | }; 39 | 40 | ClientInfo.prototype.getUser = function getUser() { 41 | for(var key in this._properties) { 42 | if(key === "APPLICATIONUSER") return this._properties[key]; 43 | } 44 | return this._user_default; 45 | }; 46 | 47 | ClientInfo.prototype.getApplication = function getApplication() { 48 | for(var key in this._properties) { 49 | if(key === "APPLICATION") return this._properties[key]; 50 | } 51 | return this._application_default; 52 | } 53 | 54 | ClientInfo.prototype.shouldSend = function shouldSend(messageType) { 55 | switch (messageType) { 56 | case MessageType.EXECUTE: 57 | case MessageType.EXECUTE_DIRECT: 58 | case MessageType.PREPARE: 59 | case MessageType.FETCH_NEXT: 60 | { 61 | return Object.keys(this._updatedProperties).length > 0; 62 | } 63 | default: 64 | return false; 65 | } 66 | }; 67 | 68 | ClientInfo.prototype.getUpdatedProperties = function getUpdatedProperties() { 69 | var self = this; 70 | var res = Object.keys(this._updatedProperties).reduce(function (p, c) { 71 | p.push(c, self._properties[c]); 72 | return p; 73 | }, []); 74 | this._updatedProperties = {}; 75 | return res; 76 | }; 77 | 78 | -------------------------------------------------------------------------------- /lib/protocol/MessageBuffer.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../util'); 17 | var common = require('./common'); 18 | var bignum = util.bignum; 19 | var PACKET_HEADER_LENGTH = common.PACKET_HEADER_LENGTH; 20 | 21 | module.exports = MessageBuffer; 22 | 23 | function MessageBuffer() { 24 | this.length = 0; 25 | this.header = undefined; 26 | this.data = undefined; 27 | } 28 | 29 | MessageBuffer.prototype.isReady = function () { 30 | return this.header && this.length >= this.header.length; 31 | }; 32 | 33 | MessageBuffer.prototype.push = function push(chunk) { 34 | if (!chunk || !chunk.length) { 35 | return; 36 | } 37 | this.length += chunk.length; 38 | if (!this.data) { 39 | this.data = chunk; 40 | } else if (Buffer.isBuffer(this.data)) { 41 | this.data = [this.data, chunk]; 42 | } else { 43 | this.data.push(chunk); 44 | } 45 | if (!this.header && this.length >= PACKET_HEADER_LENGTH) { 46 | this.readHeader(); 47 | } 48 | }; 49 | 50 | MessageBuffer.prototype.getData = function getData() { 51 | if (Array.isArray(this.data)) { 52 | return Buffer.concat(this.data, this.length); 53 | } 54 | return this.data; 55 | }; 56 | 57 | MessageBuffer.prototype.readHeader = function readHeader() { 58 | var buffer = this.getData(); 59 | this.header = { 60 | sessionId: bignum.readUInt64LE(buffer, 0), 61 | packetCount: buffer.readUInt32LE(8), 62 | length: buffer.readUInt32LE(12) 63 | }; 64 | this.data = buffer.slice(PACKET_HEADER_LENGTH); 65 | this.length -= PACKET_HEADER_LENGTH; 66 | }; 67 | 68 | MessageBuffer.prototype.clear = function clear() { 69 | this.length = 0; 70 | this.header = undefined; 71 | this.data = undefined; 72 | }; -------------------------------------------------------------------------------- /lib/protocol/Stringifier.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../util'); 17 | var Transform = util.stream.Transform; 18 | 19 | module.exports = Stringifier; 20 | 21 | util.inherits(Stringifier, Transform); 22 | 23 | function Stringifier(options) { 24 | options = options || {}; 25 | 26 | Transform.call(this, options); 27 | 28 | this._writableState.objectMode = true; 29 | this._header = options.header !== undefined ? options.header : '['; 30 | this._footer = options.footer !== undefined ? options.footer : ']'; 31 | this._seperator = options.seperator !== undefined ? options.seperator : ','; 32 | this._stringify = options.stringify || JSON.stringify; 33 | this._map = undefined; 34 | if (util.isFunction(options.map)) { 35 | this._map = options.map; 36 | } 37 | this._first = true; 38 | } 39 | 40 | Stringifier.prototype._transform = function _transform(thing, encoding, done) { 41 | if (Array.isArray(thing) && thing.length) { 42 | this.push(this.transformRows(thing)); 43 | } else { 44 | this.push(this.transformRow(thing)); 45 | } 46 | done(); 47 | }; 48 | 49 | Stringifier.prototype._flush = function _flush(done) { 50 | if (this._first) { 51 | this.push(this._header + this._footer); 52 | } else { 53 | this.push(this._footer); 54 | } 55 | done(null); 56 | }; 57 | 58 | Stringifier.prototype.transformRows = function transformRows(rows) { 59 | if (this._map) { 60 | rows = rows.map(this._map); 61 | } 62 | var str = this._first ? this._header : this._seperator; 63 | this._first = false; 64 | for (var i = 0; i < rows.length; i++) { 65 | if (i > 0) { 66 | str += this._seperator; 67 | } 68 | str += this._stringify(rows[i]); 69 | } 70 | return str; 71 | }; 72 | 73 | Stringifier.prototype.transformRow = function transformRow(row) { 74 | if (this._map) { 75 | row = this._map(row); 76 | } 77 | if (this._first) { 78 | this._first = false; 79 | return this._header + this._stringify(row); 80 | } 81 | return this._seperator + this._stringify(row); 82 | }; -------------------------------------------------------------------------------- /lib/protocol/Transaction.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../util'); 17 | var EventEmitter = require('events').EventEmitter; 18 | var ErrorLevel = require('./common/ErrorLevel'); 19 | var debug = util.debuglog('hdbtx'); 20 | 21 | module.exports = Transaction; 22 | 23 | util.inherits(Transaction, EventEmitter); 24 | 25 | function Transaction() { 26 | EventEmitter.call(this); 27 | 28 | this.autoCommit = true; 29 | this.kind = 'none'; 30 | this.error = undefined; 31 | } 32 | 33 | Transaction.prototype.setAutoCommit = function setAutoCommit(autoCommit) { 34 | this.autoCommit = autoCommit; 35 | }; 36 | 37 | Transaction.prototype.setFlags = function setFlags(flags) { 38 | debug(flags); 39 | if (flags.committed) { 40 | this.emit('end', true, this.kind); 41 | this.kind = 'none'; 42 | } 43 | if (flags.rolledBack) { 44 | this.emit('end', false, this.kind); 45 | this.kind = 'none'; 46 | } 47 | if (flags.writeTransactionStarted) { 48 | this.kind = 'write'; 49 | this.emit('new', this.kind); 50 | } 51 | if (flags.noWriteTransactionStarted) { 52 | this.kind = 'read'; 53 | this.emit('new', this.kind); 54 | } 55 | if (flags.sessionClosingTransactionErrror) { 56 | this.error = new Error( 57 | 'A transaction error occured that implies the session must be terminated.' 58 | ); 59 | this.error.code = 'EHDBTX'; 60 | this.error.level = ErrorLevel.FATAL; 61 | this.error.fatal = true; 62 | this.emit('error', this.error); 63 | } 64 | }; -------------------------------------------------------------------------------- /lib/protocol/auth/JWT.js: -------------------------------------------------------------------------------- 1 | // Copyright 2022 SAP SE. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = JWT; 17 | 18 | function JWT(options) { 19 | this.name = 'JWT'; 20 | this.token = options.token || options.password; 21 | this.user = undefined; 22 | this.sessionCookie = undefined; 23 | } 24 | 25 | JWT.prototype.initialData = function initialData() { 26 | return this.token; 27 | }; 28 | 29 | JWT.prototype.initialize = function initialize(buffer, cb) { 30 | this.user = buffer.toString('utf8'); 31 | cb(); 32 | }; 33 | 34 | JWT.prototype.finalData = function finalData() { 35 | return new Buffer(0); 36 | }; 37 | 38 | JWT.prototype.finalize = function finalize(buffer) { 39 | this.sessionCookie = buffer; 40 | }; 41 | -------------------------------------------------------------------------------- /lib/protocol/auth/SAML.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = SAML; 17 | 18 | function SAML(options) { 19 | this.name = 'SAML'; 20 | this.assertion = options.assertion || options.password; 21 | this.user = undefined; 22 | this.sessionCookie = undefined; 23 | } 24 | 25 | SAML.prototype.initialData = function initialData() { 26 | return this.assertion; 27 | }; 28 | 29 | SAML.prototype.initialize = function initialize(buffer, cb) { 30 | this.user = buffer.toString('utf8'); 31 | cb(); 32 | }; 33 | 34 | SAML.prototype.finalData = function finalData() { 35 | return new Buffer(0); 36 | }; 37 | 38 | SAML.prototype.finalize = function finalize(buffer) { 39 | this.sessionCookie = buffer; 40 | }; 41 | -------------------------------------------------------------------------------- /lib/protocol/auth/SessionCookie.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | 18 | module.exports = SessionCookie; 19 | 20 | function SessionCookie(options) { 21 | this.name = 'SessionCookie'; 22 | var termId = new Buffer(util.cid, 'utf8'); 23 | var rawSessionCookie = options.sessionCookie; 24 | var length = rawSessionCookie.length + termId.length; 25 | this.sessionCookie = new Buffer.concat([rawSessionCookie, termId], length); 26 | } 27 | 28 | SessionCookie.prototype.initialData = function initialData() { 29 | return this.sessionCookie; 30 | }; 31 | 32 | SessionCookie.prototype.initialize = function initialize(buffer, cb) { 33 | /* jshint unused:false */ 34 | cb(); 35 | }; 36 | 37 | SessionCookie.prototype.finalData = function finalData() { 38 | return new Buffer(0); 39 | }; 40 | 41 | SessionCookie.prototype.finalize = function finalize(buffer) { 42 | /* jshint unused:false */ 43 | }; 44 | -------------------------------------------------------------------------------- /lib/protocol/auth/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var Manager = require('./Manager'); 17 | 18 | exports.createManager = function createManager(options) { 19 | return new Manager(options); 20 | }; -------------------------------------------------------------------------------- /lib/protocol/common/ClientContextOption.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | CLIENT_VERSION : 1, 18 | CLIENT_TYPE : 2, 19 | CLIENT_APPLICATION_PROGRAM : 3 20 | }; 21 | -------------------------------------------------------------------------------- /lib/protocol/common/ClientDistributionMode.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | OFF: 0, 18 | CONNECTION: 1, 19 | STATEMENT_ONLY: 2, 20 | STATEMENT_CONNECTION: 3 21 | }; -------------------------------------------------------------------------------- /lib/protocol/common/CommandOption.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | SELFETCH_OFF: 1, 18 | SCROLLABLE_CURSOR_ON: 2, 19 | NO_RESULT_SET_CLOSE_NEEDED: 4, 20 | HOLD_CURSORS_OVER_COMMIT: 8, 21 | EXECUTE_LOCALLY: 16 22 | }; -------------------------------------------------------------------------------- /lib/protocol/common/CommitOption.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | HOLD_CURSORS_OVER_COMMIT: 1 18 | }; -------------------------------------------------------------------------------- /lib/protocol/common/ConnectOption.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | CONNECTION_ID: 1, 18 | COMPLETE_ARRAY_EXECUTION: 2, 19 | CLIENT_LOCALE: 3, 20 | SUPPORTS_LARGE_BULK_OPERATIONS: 4, 21 | LARGE_NUMBER_OF_PARAMETERS_SUPPORT: 10, 22 | SYSTEM_ID: 11, 23 | DATA_FORMAT_VERSION: 12, 24 | SELECT_FOR_UPDATE_SUPPORTED: 14, 25 | CLIENT_DISTRIBUTION_MODE: 15, 26 | ENGINE_DATA_FORMAT_VERSION: 16, 27 | DISTRIBUTION_PROTOCOL_VERSION: 17, 28 | SPLIT_BATCH_COMMANDS: 18, 29 | USE_TRANSACTION_FLAGS_ONLY: 19, 30 | ROW_AND_COLUMN_OPTIMIZED_FORMAT: 20, 31 | IGNORE_UNKNOWN_PARTS: 21, 32 | DATA_FORMAT_VERSION2: 23, 33 | OS_USER: 32, 34 | FULL_VERSION_STRING: 44, 35 | REDIRECTION_TYPE: 57, 36 | REDIRECTED_HOST: 58, 37 | REDIRECTED_PORT: 59, 38 | ENDPOINT_HOST: 60, 39 | ENDPOINT_PORT: 61, 40 | ENDPOINT_LIST: 62, 41 | CLOUD_VERSION_STRING: 65, 42 | }; 43 | -------------------------------------------------------------------------------- /lib/protocol/common/ConnectOptionType.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var ConnectOption = require('./ConnectOption'); 17 | var TypeCode = require('./TypeCode'); 18 | 19 | var ConnectOptionType = module.exports = {}; 20 | ConnectOptionType[ConnectOption.CONNECTION_ID] = TypeCode.INT; 21 | ConnectOptionType[ConnectOption.COMPLETE_ARRAY_EXECUTION] = TypeCode.BOOLEAN; 22 | ConnectOptionType[ConnectOption.CLIENT_LOCALE] = TypeCode.STRING; 23 | ConnectOptionType[ConnectOption.SUPPORTS_LARGE_BULK_OPERATIONS] = TypeCode.BOOLEAN; 24 | ConnectOptionType[ConnectOption.LARGE_NUMBER_OF_PARAMETERS_SUPPORT] = TypeCode.BOOLEAN; 25 | ConnectOptionType[ConnectOption.SYSTEM_ID] = TypeCode.STRING; 26 | ConnectOptionType[ConnectOption.DATA_FORMAT_VERSION] = TypeCode.INT; 27 | ConnectOptionType[ConnectOption.SELECT_FOR_UPDATE_SUPPORTED] = TypeCode.BOOLEAN; 28 | ConnectOptionType[ConnectOption.CLIENT_DISTRIBUTION_MODE] = TypeCode.INT; 29 | ConnectOptionType[ConnectOption.ENGINE_DATA_FORMAT_VERSION] = TypeCode.INT; 30 | ConnectOptionType[ConnectOption.DISTRIBUTION_PROTOCOL_VERSION] = TypeCode.BOOLEAN; 31 | ConnectOptionType[ConnectOption.SPLIT_BATCH_COMMANDS] = TypeCode.BOOLEAN; 32 | ConnectOptionType[ConnectOption.USE_TRANSACTION_FLAGS_ONLY] = TypeCode.BOOLEAN; 33 | ConnectOptionType[ConnectOption.ROW_AND_COLUMN_OPTIMIZED_FORMAT] = TypeCode.BOOLEAN; 34 | ConnectOptionType[ConnectOption.IGNORE_UNKNOWN_PARTS] = TypeCode.BOOLEAN; 35 | ConnectOptionType[ConnectOption.DATA_FORMAT_VERSION2] = TypeCode.INT; 36 | ConnectOptionType[ConnectOption.OS_USER] = TypeCode.STRING; 37 | ConnectOptionType[ConnectOption.FULL_VERSION_STRING] = TypeCode.STRING; 38 | ConnectOptionType[ConnectOption.REDIRECTION_TYPE] = TypeCode.INT; 39 | ConnectOptionType[ConnectOption.REDIRECTED_HOST] = TypeCode.STRING; 40 | ConnectOptionType[ConnectOption.REDIRECTED_PORT] = TypeCode.INT; 41 | ConnectOptionType[ConnectOption.ENDPOINT_HOST] = TypeCode.STRING; 42 | ConnectOptionType[ConnectOption.ENDPOINT_PORT] = TypeCode.INT; 43 | ConnectOptionType[ConnectOption.ENDPOINT_LIST] = TypeCode.STRING; 44 | ConnectOptionType[ConnectOption.CLOUD_VERSION_STRING] = TypeCode.STRING; 45 | -------------------------------------------------------------------------------- /lib/protocol/common/Constants.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var ConnectOption = require('./ConnectOption'); 17 | var TypeCode = require('./TypeCode'); 18 | var ClientDistributionMode = require('./ClientDistributionMode'); 19 | var DataFormatVersion = require('./DataFormatVersion'); 20 | var DistributionProtocolVersion = require('./DistributionProtocolVersion'); 21 | 22 | module.exports = { 23 | PACKET_HEADER_LENGTH: 32, 24 | SEGMENT_HEADER_LENGTH: 24, 25 | PART_HEADER_LENGTH: 16, 26 | DEFAULT_PACKET_SIZE: Math.pow(2, 17), 27 | MAXIMUM_PACKET_SIZE: Math.pow(2, 30) - 1, 28 | MINIMUM_PACKET_SIZE: Math.pow(2, 16), 29 | MAX_RESULT_SET_SIZE: Math.pow(2, 20), 30 | EMPTY_BUFFER: new Buffer(0), 31 | DATA_LENGTH_MAX1BYTE_LENGTH: 245, 32 | DATA_LENGTH_MAX2BYTE_LENGTH: 32767, 33 | DATA_LENGTH_2BYTE_LENGTH_INDICATOR: 246, 34 | DATA_LENGTH_4BYTE_LENGTH_INDICATOR: 247, 35 | DEFAULT_SPATIAL_TYPES: 0, 36 | DEFAULT_CONNECT_OPTIONS: [{ 37 | name: ConnectOption.CLIENT_LOCALE, 38 | value: 'en_US', 39 | type: TypeCode.STRING 40 | }, { 41 | name: ConnectOption.COMPLETE_ARRAY_EXECUTION, 42 | value: true, 43 | type: TypeCode.BOOLEAN 44 | }, { 45 | name: ConnectOption.DATA_FORMAT_VERSION2, 46 | value: DataFormatVersion.COMPLETE_DATATYPE_SUPPORT, 47 | type: TypeCode.INT 48 | }, { 49 | name: ConnectOption.DATA_FORMAT_VERSION, 50 | value: DataFormatVersion.COMPLETE_DATATYPE_SUPPORT, 51 | type: TypeCode.INT 52 | }, { 53 | name: ConnectOption.DISTRIBUTION_ENABLED, 54 | value: false, 55 | type: TypeCode.BOOLEAN 56 | }, { 57 | name: ConnectOption.DISTRIBUTION_MODE, 58 | value: ClientDistributionMode.OFF, 59 | type: TypeCode.INT 60 | }, { 61 | name: ConnectOption.DISTRIBUTION_PROTOCOL_VERSION, 62 | value: DistributionProtocolVersion.BASE, 63 | type: TypeCode.INT 64 | }, { 65 | name: ConnectOption.SELECT_FOR_UPDATE_SUPPORTED, 66 | value: false, 67 | type: TypeCode.BOOLEAN 68 | }, { 69 | name: ConnectOption.ROW_AND_COLUMN_OPTIMIZED_FORMAT, 70 | value: true, 71 | type: TypeCode.BOOLEAN 72 | }] 73 | }; -------------------------------------------------------------------------------- /lib/protocol/common/DataFormatVersion.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | BASE_FORMAT: 0, 18 | COMPLETE_DATATYPE_SUPPORT: 1, 19 | // deprecated 20 | EXTENDED_DATE_TIME_SUPPORT: 3, 21 | LEVEL4: 4, 22 | LEVEL5: 5, 23 | LEVEL6: 6, 24 | LEVEL7: 7, 25 | LEVEL8: 8, 26 | LEVEL9: 9, 27 | // Maximum data format version supported by this driver 28 | MAX_VERSION: 9, 29 | }; 30 | -------------------------------------------------------------------------------- /lib/protocol/common/DbConnectInfoOption.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | DATABASE_NAME: 1, 18 | HOST: 2, 19 | PORT: 3, 20 | IS_CONNECTED: 4 21 | }; -------------------------------------------------------------------------------- /lib/protocol/common/DistributionProtocolVersion.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | BASE: 0, 18 | STATEMENT_SEQUENCE_NUMBER_SUPPORTED: 1 19 | }; -------------------------------------------------------------------------------- /lib/protocol/common/ErrorLevel.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | WARNING: 0, 18 | ERROR: 1, 19 | FATAL: 2 20 | }; -------------------------------------------------------------------------------- /lib/protocol/common/FunctionCode.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | NIL: 0, 18 | DDL: 1, 19 | INSERT: 2, 20 | UPDATE: 3, 21 | DELETE: 4, 22 | SELECT: 5, 23 | SELECT_FOR_UPDATE: 6, 24 | EXPLAIN: 7, 25 | DB_PROCEDURE_CALL: 8, 26 | DB_PROCEDURE_CALL_WITH_RESULT: 9, 27 | FETCH: 10, 28 | COMMIT: 11, 29 | ROLLBACK: 12, 30 | SAVEPOINT: 13, 31 | CONNECT: 14, 32 | WRITE_LOB: 15, 33 | READ_LOB: 16, 34 | PING: 17, 35 | DISCONNECT: 18, 36 | CLOSE_CURSOR: 19, 37 | FIND_LOB: 20, 38 | ABAP_STREAM: 21, 39 | XA_START: 22, 40 | XA_JOIN: 23 41 | }; -------------------------------------------------------------------------------- /lib/protocol/common/IoType.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | INPUT: 1, 18 | IN_OUT: 2, 19 | OUTPUT: 4 20 | }; -------------------------------------------------------------------------------- /lib/protocol/common/LobOptions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | NULL_INDICATOR: 1, 18 | DATA_INCLUDED: 2, 19 | LAST_DATA: 4 20 | }; -------------------------------------------------------------------------------- /lib/protocol/common/LobSourceType.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | UNKNOWN: 0, 18 | BLOB: 1, 19 | CLOB: 2, 20 | NCLOB: 3 21 | }; -------------------------------------------------------------------------------- /lib/protocol/common/MessageType.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | NIL: 0, 18 | EXECUTE_DIRECT: 2, 19 | PREPARE: 3, 20 | ABAP_STREAM: 4, 21 | XA_START: 5, 22 | XA_JOIN: 6, 23 | EXECUTE: 13, 24 | READ_LOB: 16, 25 | WRITE_LOB: 17, 26 | FIND_LOB: 18, 27 | PING: 25, 28 | AUTHENTICATE: 65, 29 | CONNECT: 66, 30 | COMMIT: 67, 31 | ROLLBACK: 68, 32 | CLOSE_RESULT_SET: 69, 33 | DROP_STATEMENT_ID: 70, 34 | FETCH_NEXT: 71, 35 | DISCONNECT: 77, 36 | EXECUTE_ITAB: 78, 37 | FETCH_NEXT_ITAB: 79, 38 | INSERT_NEXT_ITAB: 80, 39 | BATCH_PREPARE: 81, 40 | DB_CONNECT_INFO: 82 41 | }; -------------------------------------------------------------------------------- /lib/protocol/common/ParameterMode.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | MANDATORY: 1, 18 | OPTIONAL: 2, 19 | DEFAULT: 4, 20 | ESCAPE_CHAR: 8, 21 | READONLY: 16, 22 | AUTO_INCREMENT: 32 23 | }; -------------------------------------------------------------------------------- /lib/protocol/common/PartKind.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | NIL: 0, 18 | COMMAND: 3, 19 | RESULT_SET: 5, 20 | ERROR: 6, 21 | STATEMENT_ID: 10, 22 | TRANSACTION_ID: 11, 23 | ROWS_AFFECTED: 12, 24 | RESULT_SET_ID: 13, 25 | TOPOLOGY_INFORMATION: 15, 26 | TABLE_LOCATION: 16, 27 | READ_LOB_REQUEST: 17, 28 | READ_LOB_REPLY: 18, 29 | TABLE_NAME: 19, 30 | /* 31 | ABAP_ISTREAM: 25, 32 | ABAP_OSTREAM: 26, 33 | */ 34 | COMMAND_INFO: 27, 35 | WRITE_LOB_REQUEST: 28, 36 | CLIENT_CONTEXT: 29, 37 | WRITE_LOB_REPLY: 30, 38 | PARAMETERS: 32, 39 | AUTHENTICATION: 33, 40 | SESSION_CONTEXT: 34, 41 | CLIENT_ID: 35, 42 | STATEMENT_CONTEXT: 39, 43 | PARTITION_INFORMATION: 40, 44 | OUTPUT_PARAMETERS: 41, 45 | CONNECT_OPTIONS: 42, 46 | COMMIT_OPTIONS: 43, 47 | FETCH_OPTIONS: 44, 48 | FETCH_SIZE: 45, 49 | PARAMETER_METADATA: 47, 50 | RESULT_SET_METADATA: 48, 51 | FIND_LOB_REQUEST: 49, 52 | FIND_LOB_REPLY: 50, 53 | /* 54 | ITAB_SHM: 51, 55 | ITAB_CHUNK_METADATA: 53, 56 | ITAB_METADATA: 55, 57 | ITAB_RESULT_CHUNK: 56, 58 | */ 59 | CLIENT_INFO: 57, 60 | /* 61 | STREAM_DATA: 58, 62 | OSTREAM_RESULT: 59, 63 | FDA_REQUEST_METADATA: 60, 64 | FDA_REPLY_METADATA: 61, 65 | BATCH_PREPARE: 62, 66 | BATCH_EXECUTE: 63, 67 | */ 68 | TRANSACTION_FLAGS: 64, 69 | DB_CONNECT_INFO: 67 70 | }; 71 | -------------------------------------------------------------------------------- /lib/protocol/common/RedirectType.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | REDIRECTION_NONE: 0, 18 | REDIRECTION_DISABLED: 1, 19 | REDIRECTION_DBNAMEBASED: 2, 20 | REDIRECTION_TENANTWITHAZAWARE: 3 21 | }; 22 | -------------------------------------------------------------------------------- /lib/protocol/common/ResultSetAttributes.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | LAST: 1, 18 | NEXT: 2, 19 | FIRST: 4, 20 | ROW_NOT_FOUND: 8, 21 | CLOSED: 16 22 | }; -------------------------------------------------------------------------------- /lib/protocol/common/SegmentKind.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | INVALID: 0, 18 | REQUEST: 1, 19 | REPLY: 2, 20 | ERROR: 5 21 | }; -------------------------------------------------------------------------------- /lib/protocol/common/SessionContext.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | PRIMARY_CONNECTION_ID: 1, 18 | PRIMARY_HOST: 2, 19 | PRIMARY_PORT: 3, 20 | MASTER_CONNECTION_ID: 4, 21 | MASTER_HOST: 5, 22 | MASTER_PORT: 6 23 | }; -------------------------------------------------------------------------------- /lib/protocol/common/StatementContext.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | STATEMENT_SEQUENCE_INFO: 1, 18 | SERVER_EXECUTION_TIME: 2 19 | }; -------------------------------------------------------------------------------- /lib/protocol/common/StatementContextType.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var StatementContext = require('./StatementContext'); 17 | var TypeCode = require('./TypeCode'); 18 | 19 | var StatementContextType = module.exports = {}; 20 | StatementContextType[StatementContext.STATEMENT_SEQUENCE_INFO] = TypeCode.BSTRING; 21 | StatementContextType[StatementContext.SERVER_EXECUTION_TIME] = TypeCode.INT; -------------------------------------------------------------------------------- /lib/protocol/common/TopologyInformation.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | HOST_NAME: 1, 18 | HOST_PORT_NUMBER: 2, 19 | TENAT_NAME: 3, 20 | LOAD_FACTOR: 4, 21 | VOLUME_ID: 5, 22 | IS_MASTER: 6, 23 | IS_CURRENT_SESSION: 7, 24 | SERVICE_TYPE: 8, 25 | NETWORK_DOMAIN: 9, 26 | IS_STANDBY: 10, 27 | ALL_IP_ADDRESSES: 11, 28 | ALL_HOST_NAMES: 12 29 | }; 30 | 31 | Object.defineProperty(module.exports, 'ALL_IP_ADRESSES', { 32 | get: function () { 33 | return this.ALL_IP_ADDRESSES; 34 | } 35 | }); -------------------------------------------------------------------------------- /lib/protocol/common/TransactionFlag.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | ROLLED_BACK: 0, 18 | COMMITTED: 1, 19 | NEW_ISOLATION_LEVEL: 2, 20 | DDL_COMMIT_MODE_CHANGED: 3, 21 | WRITE_TRANSACTION_STARTED: 4, 22 | NO_WRITE_TRANSACTION_STARTED: 5, 23 | SESSION_CLOSING_TRANSACTION_ERRROR: 6 24 | }; -------------------------------------------------------------------------------- /lib/protocol/common/TransactionFlagType.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var TransactionFlag = require('./TransactionFlag'); 17 | var TypeCode = require('./TypeCode'); 18 | 19 | var TransactionFlagType = module.exports = {}; 20 | TransactionFlagType[TransactionFlag.ROLLED_BACK] = TypeCode.BOOLEAN; 21 | TransactionFlagType[TransactionFlag.COMMITTED] = TypeCode.BOOLEAN; 22 | TransactionFlagType[TransactionFlag.NEW_ISOLATION_LEVEL] = TypeCode.INT; 23 | TransactionFlagType[TransactionFlag.DDL_COMMIT_MODE_CHANGED] = TypeCode.BOOLEAN; 24 | TransactionFlagType[TransactionFlag.WRITE_TRANSACTION_STARTED] = TypeCode.BOOLEAN; 25 | TransactionFlagType[TransactionFlag.NO_WRITE_TRANSACTION_STARTED] = TypeCode.BOOLEAN; 26 | TransactionFlagType[TransactionFlag.SESSION_CLOSING_TRANSACTION_ERRROR] = 27 | TypeCode.BOOLEAN; -------------------------------------------------------------------------------- /lib/protocol/common/TypeCode.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = { 17 | NULL: 0, 18 | TINYINT: 1, 19 | SMALLINT: 2, 20 | INT: 3, 21 | BIGINT: 4, 22 | DECIMAL: 5, 23 | REAL: 6, 24 | DOUBLE: 7, 25 | CHAR: 8, 26 | VARCHAR1: 9, 27 | NCHAR: 10, 28 | NVARCHAR: 11, 29 | BINARY: 12, 30 | VARBINARY: 13, 31 | DATE: 14, 32 | TIME: 15, 33 | TIMESTAMP: 16, 34 | TIME_TZ: 17, 35 | TIME_LTZ: 18, 36 | TIMESTAMP_TZ: 19, 37 | TIMESTAMP_LTZ: 20, 38 | INTERVAL_YM: 21, 39 | INTERVAL_DS: 22, 40 | ROWID: 23, 41 | UROWID: 24, 42 | CLOB: 25, 43 | NCLOB: 26, 44 | BLOB: 27, 45 | BOOLEAN: 28, 46 | STRING: 29, 47 | NSTRING: 30, 48 | LOCATOR: 31, 49 | NLOCATOR: 32, 50 | BSTRING: 33, 51 | DECIMAL_DIGIT_ARRAY: 34, 52 | VARCHAR2: 35, 53 | UNUSED1: 36, 54 | UNUSED2: 37, 55 | UNUSED3: 38, 56 | UNUSED4: 39, 57 | UNUSED5: 40, 58 | UNUSED6: 41, 59 | UNUSED7: 42, 60 | UNUSED8: 43, 61 | UNUSED9: 44, 62 | TABLE: 45, 63 | UNUSED11: 46, 64 | UNUSED1F: 47, 65 | ABAPSTREAM: 48, 66 | ABAPSTRUCT: 49, 67 | UNUSED12: 50, 68 | TEXT: 51, 69 | SHORTTEXT: 52, 70 | BINTEXT: 53, 71 | UNUSED16: 54, 72 | ALPHANUM: 55, 73 | UNUSED18: 56, 74 | UNUSED19: 57, 75 | UNUSED20: 58, 76 | UNUSED21: 59, 77 | UNUSED22: 60, 78 | LONGDATE: 61, 79 | SECONDDATE: 62, 80 | DAYDATE: 63, 81 | SECONDTIME: 64, 82 | CSDATE: 65, 83 | CSTIME: 66, 84 | BLOB_DISK: 71, 85 | CLOB_DISK: 72, 86 | NCLOB_DISK: 73, 87 | ST_GEOMETRY: 74, 88 | ST_POINT: 75, 89 | FIXED16: 76, 90 | FIXED8: 81, 91 | FIXED12: 82, 92 | REAL_VECTOR: 96 93 | }; -------------------------------------------------------------------------------- /lib/protocol/common/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | 18 | exports.ClientDistributionMode = require('./ClientDistributionMode'); 19 | exports.CommandOption = require('./CommandOption'); 20 | exports.CommitOption = require('./CommitOption'); 21 | exports.DbConnectInfoOption = require('./DbConnectInfoOption'); 22 | exports.ConnectOption = require('./ConnectOption'); 23 | exports.ConnectOptionType = require('./ConnectOptionType'); 24 | exports.ClientContextOption = require('./ClientContextOption'); 25 | exports.DataFormatVersion = require('./DataFormatVersion'); 26 | exports.DistributionProtocolVersion = require('./DistributionProtocolVersion'); 27 | exports.ErrorLevel = require('./ErrorLevel'); 28 | exports.FunctionCode = require('./FunctionCode'); 29 | exports.IoType = require('./IoType'); 30 | exports.LobOptions = require('./LobOptions'); 31 | exports.LobSourceType = require('./LobSourceType'); 32 | exports.MessageType = require('./MessageType'); 33 | exports.ParameterMode = require('./ParameterMode'); 34 | exports.PartKind = require('./PartKind'); 35 | exports.ResultSetAttributes = require('./ResultSetAttributes'); 36 | exports.SegmentKind = require('./SegmentKind'); 37 | exports.SessionContext = require('./SessionContext'); 38 | exports.StatementContext = require('./StatementContext'); 39 | exports.StatementContextType = require('./StatementContextType'); 40 | exports.TransactionFlag = require('./TransactionFlag'); 41 | exports.TopologyInformation = require('./TopologyInformation'); 42 | exports.TypeCode = require('./TypeCode'); 43 | exports.NormalizedTypeCode = require('./NormalizedTypeCode'); 44 | exports.ReadFunction = require('./ReadFunction'); 45 | exports.RedirectType = require('./RedirectType'); 46 | 47 | invert('DbConnectInfoOption'); 48 | invert('ConnectOption'); 49 | invert('ClientContextOption'); 50 | invert('TransactionFlag'); 51 | invert('TopologyInformation'); 52 | invert('MessageType'); 53 | invert('StatementContext'); 54 | invert('SessionContext'); 55 | invert('TypeCode'); 56 | invert('FunctionCode'); 57 | invert('PartKind'); 58 | invert('SegmentKind'); 59 | 60 | function invert(name) { 61 | /* jshint forin: false */ 62 | var source = exports[name]; 63 | var target = {}; 64 | for (var key in source) { 65 | target[source[key]] = key; 66 | } 67 | exports[name + 'Name'] = target; 68 | } 69 | 70 | util.extend(exports, require('./Constants')); 71 | -------------------------------------------------------------------------------- /lib/protocol/data/Binary.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | exports.read = read; 17 | exports.write = write; 18 | exports.getByteLength = getByteLength; 19 | exports.getArgumentCount = getArgumentCount; 20 | 21 | function read(part) { 22 | return part.buffer; 23 | } 24 | 25 | function write(part, value) { 26 | /* jshint validthis:true */ 27 | 28 | value = value || this; 29 | part = part || {}; 30 | part.argumentCount = getArgumentCount(value); 31 | part.buffer = value; 32 | return part; 33 | } 34 | 35 | function getByteLength(value) { 36 | return value.length; 37 | } 38 | 39 | function getArgumentCount(value) { 40 | /* jshint unused:false */ 41 | return 1; 42 | } -------------------------------------------------------------------------------- /lib/protocol/data/Default.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | 18 | exports.read = read; 19 | exports.write = write; 20 | exports.getByteLength = getByteLength; 21 | exports.getArgumentCount = getArgumentCount; 22 | 23 | function read(part) { 24 | return part; 25 | } 26 | 27 | function write(part, sourcePart) { 28 | /* jshint validthis:true */ 29 | 30 | sourcePart = sourcePart || this; 31 | part = part || {}; 32 | return util.extend(part, sourcePart); 33 | } 34 | 35 | function getByteLength(part) { 36 | return part.length; 37 | } 38 | 39 | function getArgumentCount(part) { 40 | /* jshint unused:false */ 41 | return part.argumentCount; 42 | } -------------------------------------------------------------------------------- /lib/protocol/data/Int32.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | exports.read = read; 17 | exports.write = write; 18 | exports.getByteLength = getByteLength; 19 | exports.getArgumentCount = getArgumentCount; 20 | 21 | function read(part) { 22 | if (part.argumentCount === 1) { 23 | return part.buffer.readInt32LE(0); 24 | } 25 | var offset = 0; 26 | var buffer = part.buffer; 27 | var args = []; 28 | for (var i = 0; i < part.argumentCount; i++) { 29 | args.push(buffer.readInt32LE(offset)); 30 | offset += 4; 31 | } 32 | return args; 33 | } 34 | 35 | function write(part, value) { 36 | /* jshint validthis:true */ 37 | if (typeof value === 'undefined') { 38 | value = this; 39 | } 40 | part = part || {}; 41 | part.argumentCount = getArgumentCount(value); 42 | part.buffer = new Buffer(4); 43 | part.buffer.writeInt32LE(value, 0); 44 | return part; 45 | } 46 | 47 | function getByteLength(value) { 48 | /* jshint unused:false */ 49 | return 4; 50 | } 51 | 52 | function getArgumentCount(value) { 53 | /* jshint unused:false */ 54 | return 1; 55 | } -------------------------------------------------------------------------------- /lib/protocol/data/MultilineOptions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var opts = require('./Options'); 17 | var getByteLengthOfOptions = opts.getByteLength; 18 | var writeOptions = opts.write; 19 | var readOptions = opts._read; 20 | 21 | exports.read = read; 22 | exports.write = write; 23 | exports.getByteLength = getByteLength; 24 | exports.getArgumentCount = getArgumentCount; 25 | 26 | function read(part) { 27 | var offset = 0; 28 | var buffer = part.buffer; 29 | var lines = []; 30 | var numberOfOptions, options; 31 | for (var i = 0; i < part.argumentCount; i++) { 32 | numberOfOptions = buffer.readInt16LE(offset); 33 | offset += 2; 34 | options = new Array(numberOfOptions); 35 | offset = readOptions.call(options, buffer, offset); 36 | lines.push(options); 37 | } 38 | return lines; 39 | } 40 | 41 | function write(part, lines) { 42 | /* jshint validthis:true */ 43 | 44 | var offset = 0; 45 | lines = lines || this; 46 | part = part || {}; 47 | var byteLength = getByteLength(lines); 48 | var buffer = new Buffer(byteLength); 49 | var options; 50 | for (var i = 0; i < lines.length; i++) { 51 | options = writeOptions({}, lines[i]); 52 | buffer.writeInt16LE(options.argumentCount, offset); 53 | offset += 2; 54 | options.buffer.copy(buffer, offset); 55 | offset += options.buffer.length; 56 | } 57 | part.argumentCount = getArgumentCount(lines); 58 | part.buffer = buffer; 59 | return part; 60 | } 61 | 62 | function getByteLength(lines) { 63 | var byteLength = 0; 64 | 65 | for (var i = 0; i < lines.length; i++) { 66 | byteLength += 2 + getByteLengthOfOptions(lines[i]); 67 | } 68 | return byteLength; 69 | } 70 | 71 | function getArgumentCount(lines) { 72 | /* jshint unused:false */ 73 | return lines.length; 74 | } -------------------------------------------------------------------------------- /lib/protocol/data/ParameterMetadata.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var common = require('../common'); 17 | var ParameterMode = common.ParameterMode; 18 | 19 | exports.read = read; 20 | exports.getArgumentCount = getArgumentCount; 21 | 22 | function read(part) { 23 | var params = new Array(part.argumentCount); 24 | _read.call(params, part.buffer, 0); 25 | return params; 26 | } 27 | 28 | function _read(buffer, offset) { 29 | /* jshint validthis:true */ 30 | 31 | offset = offset || 0; 32 | var params = this; 33 | var textOffset = offset + params.length * 16; 34 | for (var i = 0; i < params.length; i++) { 35 | params[i] = new Parameter(buffer, offset, textOffset); 36 | offset += 16; 37 | } 38 | return offset; 39 | } 40 | 41 | function getArgumentCount(params) { 42 | /* jshint unused:false */ 43 | return params.length; 44 | } 45 | 46 | function Parameter(buffer, offset, textOffset) { 47 | this.mode = buffer[offset]; 48 | this.dataType = buffer[offset + 1]; 49 | this.ioType = buffer[offset + 2]; 50 | var nameOffset = buffer.readInt32LE(offset + 4); 51 | if (nameOffset < 0) { 52 | this.name = undefined; 53 | } else { 54 | var start = textOffset + nameOffset; 55 | var length = buffer[start]; 56 | start += 1; 57 | this.name = buffer.toString('utf-8', start, start + length); 58 | } 59 | this.length = buffer.readInt16LE(offset + 8); 60 | this.fraction = buffer.readInt16LE(offset + 10); 61 | } 62 | 63 | Parameter.prototype.isReadOnly = function isReadOnly() { 64 | /* jshint bitwise:false */ 65 | return !!(this.mode & ParameterMode.READONLY); 66 | }; 67 | 68 | Parameter.prototype.isMandatory = function isMandatory() { 69 | /* jshint bitwise:false */ 70 | return !!(this.mode & ParameterMode.MANDATORY); 71 | }; 72 | 73 | Parameter.prototype.isAutoIncrement = function isAutoIncrement() { 74 | /* jshint bitwise:false */ 75 | return !!(this.mode & ParameterMode.AUTO_INCREMENT); 76 | }; -------------------------------------------------------------------------------- /lib/protocol/data/Parameters.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | exports.write = write; 17 | exports.getByteLength = getByteLength; 18 | exports.getArgumentCount = getArgumentCount; 19 | 20 | function write(part, value) { 21 | /* jshint validthis:true */ 22 | 23 | value = value || this; 24 | part = part || {}; 25 | if (Array.isArray(value)) { 26 | part.argumentCount = value.length; 27 | part.buffer = Buffer.concat(value); 28 | return part; 29 | } 30 | part.argumentCount = 1; 31 | part.buffer = value; 32 | return part; 33 | } 34 | 35 | function getByteLength(value) { 36 | if (Array.isArray(value)) { 37 | var byteLength = 0; 38 | for (var i = 0; i < value.length; i++) { 39 | byteLength += value[i].length; 40 | } 41 | return byteLength; 42 | } 43 | return value.length; 44 | } 45 | 46 | function getArgumentCount(value) { 47 | /* jshint unused:false */ 48 | if (Array.isArray(value)) { 49 | return value.length; 50 | } 51 | return 1; 52 | } -------------------------------------------------------------------------------- /lib/protocol/data/ReadLobReply.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var common = require('../common'); 17 | var LobOptions = common.LobOptions; 18 | 19 | exports.read = read; 20 | exports.getByteLength = getByteLength; 21 | exports.getArgumentCount = getArgumentCount; 22 | 23 | function read(part) { 24 | var offset = 0; 25 | var buffer = part.buffer; 26 | 27 | var locatorId = buffer.slice(offset, offset + 8); 28 | offset += 8; 29 | var options = buffer[offset]; 30 | offset += 1; 31 | var length = buffer.readInt32LE(offset); 32 | offset = 16; 33 | var chunk = buffer.slice(offset, offset + length); 34 | offset += length; 35 | return new ReadLobReply(locatorId, options, chunk); 36 | } 37 | 38 | function getByteLength(chunk) { 39 | return 16 + chunk.length; 40 | } 41 | 42 | function getArgumentCount(value) { 43 | /* jshint unused:false */ 44 | return 1; 45 | } 46 | 47 | function ReadLobReply(locatorId, options, chunk) { 48 | this.locatorId = locatorId; 49 | this.options = options; 50 | this.chunk = chunk; 51 | } 52 | 53 | Object.defineProperties(ReadLobReply.prototype, { 54 | isNull: { 55 | get: function isNull() { 56 | /* jshint bitwise:false */ 57 | return !!(this.options & LobOptions.NULL_INDICATOR); 58 | } 59 | }, 60 | isDataIncluded: { 61 | get: function isDataIncluded() { 62 | /* jshint bitwise:false */ 63 | return !!(this.options & LobOptions.DATA_INCLUDED); 64 | } 65 | }, 66 | isLast: { 67 | get: function isLast() { 68 | /* jshint bitwise:false */ 69 | return !!(this.options & LobOptions.LAST_DATA); 70 | } 71 | } 72 | }); -------------------------------------------------------------------------------- /lib/protocol/data/ReadLobRequest.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | var bignum = util.bignum; 18 | 19 | var READ_LOB_REQUEST_LENGTH = 24; 20 | 21 | exports.write = write; 22 | exports.read = read; 23 | exports.getByteLength = getByteLength; 24 | exports.getArgumentCount = getArgumentCount; 25 | 26 | function write(part, req) { 27 | /* jshint validthis:true */ 28 | 29 | var offset = 0; 30 | part = part || {}; 31 | req = req || this; 32 | 33 | var buffer = new Buffer(READ_LOB_REQUEST_LENGTH); 34 | if (Buffer.isBuffer(req.locatorId)) { 35 | req.locatorId.copy(buffer, offset, 0, 8); 36 | } else { 37 | bignum.writeInt64LE(buffer, req.locatorId, offset); 38 | } 39 | offset += 8; 40 | bignum.writeInt64LE(buffer, req.offset, offset); 41 | offset += 8; 42 | buffer.writeInt32LE(req.length, offset); 43 | offset += 4; 44 | buffer.fill(0x00, offset); 45 | part.argumentCount = getArgumentCount(req); 46 | part.buffer = buffer; 47 | return part; 48 | } 49 | 50 | function read(part) { 51 | var buffer = part.buffer; 52 | var locatorId = new Buffer(8); 53 | buffer.copy(locatorId, 0); 54 | return { 55 | locatorId: locatorId, 56 | offset: bignum.readInt64LE(buffer, 8), 57 | length: buffer.readInt32LE(16) 58 | }; 59 | } 60 | 61 | function getByteLength(req) { 62 | /* jshint unused:false */ 63 | return READ_LOB_REQUEST_LENGTH; 64 | } 65 | 66 | function getArgumentCount(req) { 67 | /* jshint unused:false */ 68 | return 1; 69 | } -------------------------------------------------------------------------------- /lib/protocol/data/ResultSetMetadata.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var common = require('../common'); 17 | var ParameterMode = common.ParameterMode; 18 | var READONLY = ParameterMode.READONLY; 19 | var AUTO_INCREMENT = ParameterMode.AUTO_INCREMENT; 20 | var MANDATORY = ParameterMode.MANDATORY; 21 | var OPTIONAL = ParameterMode.OPTIONAL; 22 | 23 | exports.read = read; 24 | exports.getArgumentCount = getArgumentCount; 25 | exports.Column = Column; 26 | 27 | function read(part) { 28 | var columns = new Array(part.argumentCount); 29 | var offset = 0; 30 | var textOffset = columns.length * 24; 31 | for (var i = 0; i < columns.length; i++) { 32 | columns[i] = readColumn(part.buffer, offset, textOffset); 33 | offset += 24; 34 | } 35 | return columns; 36 | } 37 | 38 | function getArgumentCount(columns) { 39 | /* jshint unused:false */ 40 | return columns.length; 41 | } 42 | 43 | var COLUMN_NAME_PROPERTIES = [ 44 | 'tableName', 'schemaName', 'columnName', 'columnDisplayName' 45 | ]; 46 | 47 | function readColumn(buffer, offset, textOffset) { 48 | var column = new Column( 49 | buffer.readInt8(offset), 50 | buffer.readInt8(offset + 1), 51 | buffer.readInt16LE(offset + 2), 52 | buffer.readInt16LE(offset + 4) 53 | ); 54 | offset += 8; 55 | 56 | function readName(name) { 57 | var start = buffer.readInt32LE(offset); 58 | offset += 4; 59 | if (start < 0) { 60 | column[name] = undefined; 61 | } else { 62 | start += textOffset; 63 | var length = buffer.readUInt8(start); 64 | start += 1; 65 | column[name] = buffer.toString('utf-8', start, start + length); 66 | } 67 | } 68 | COLUMN_NAME_PROPERTIES.forEach(readName); 69 | return column; 70 | } 71 | 72 | function Column(mode, dataType, fraction, length) { 73 | this.mode = mode; 74 | this.dataType = dataType; 75 | this.fraction = fraction; 76 | this.length = length; 77 | this.tableName = undefined; 78 | this.schemaName = undefined; 79 | this.columnName = undefined; 80 | this.columnDisplayName = undefined; 81 | } 82 | 83 | Column.prototype.isReadOnly = function isReadOnly() { 84 | /* jshint bitwise:false */ 85 | return !!(this.mode & READONLY); 86 | }; 87 | 88 | Column.prototype.isMandatory = function isMandatory() { 89 | /* jshint bitwise:false */ 90 | return !!(this.mode & MANDATORY); 91 | }; 92 | 93 | Column.prototype.isOptional = function isOptional() { 94 | /* jshint bitwise:false */ 95 | return !!(this.mode & OPTIONAL); 96 | }; 97 | 98 | Column.prototype.isAutoIncrement = function isAutoIncrement() { 99 | /* jshint bitwise:false */ 100 | return !!(this.mode & AUTO_INCREMENT); 101 | }; -------------------------------------------------------------------------------- /lib/protocol/data/SqlError.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | var ErrorLevel = require('../common/ErrorLevel'); 18 | 19 | exports.read = read; 20 | exports.getByteLength = getByteLength; 21 | exports.getArgumentCount = getArgumentCount; 22 | 23 | function read(part) { 24 | var err = new SqlError(); 25 | _read.call(err, part.buffer, 0); 26 | return err; 27 | } 28 | 29 | function _read(buffer, offset) { 30 | /* jshint validthis:true */ 31 | 32 | offset = offset || 0; 33 | this.code = buffer.readInt32LE(offset); 34 | offset += 4; 35 | this.position = buffer.readInt32LE(offset); 36 | offset += 4; 37 | var length = buffer.readInt32LE(offset); 38 | offset += 4; 39 | this.level = buffer.readInt8(offset); 40 | if (this.level === ErrorLevel.FATAL) { 41 | this.fatal = true; 42 | } 43 | offset += 1; 44 | this.sqlState = buffer.toString('ascii', offset, offset + 5); 45 | offset += 5; 46 | this.message = buffer.toString('utf-8', offset, offset + length); 47 | offset += util.alignLength(length, 8); 48 | return offset; 49 | } 50 | 51 | function getByteLength(err) { 52 | return 18 + Buffer.byteLength(err.message); 53 | } 54 | 55 | function getArgumentCount(err) { 56 | /* jshint unused:false */ 57 | return 1; 58 | } 59 | 60 | util.inherits(SqlError, Error); 61 | 62 | function SqlError() { 63 | Error.call(this); 64 | 65 | this.message = undefined; 66 | this.code = undefined; 67 | this.sqlState = undefined; 68 | this.level = undefined; 69 | this.position = undefined; 70 | } -------------------------------------------------------------------------------- /lib/protocol/data/Text.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | 18 | exports.read = read; 19 | exports.write = write; 20 | exports.getByteLength = getByteLength; 21 | exports.getArgumentCount = getArgumentCount; 22 | 23 | function read(part) { 24 | return util.convert.decode(part.buffer, part.useCesu8); 25 | } 26 | 27 | function write(part, value) { 28 | /* jshint validthis:true */ 29 | 30 | value = value || this; 31 | part = part || {}; 32 | part.argumentCount = getArgumentCount(value); 33 | part.buffer = util.convert.encode(value, part.useCesu8); 34 | return part; 35 | } 36 | 37 | function getByteLength(value) { 38 | return Buffer.byteLength(value); 39 | } 40 | 41 | function getArgumentCount(value) { 42 | /* jshint unused:false */ 43 | return 1; 44 | } -------------------------------------------------------------------------------- /lib/protocol/data/Text20.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | 18 | exports.read = read; 19 | exports.write = write; 20 | exports.getByteLength = getByteLength; 21 | exports.getArgumentCount = getArgumentCount; 22 | 23 | function read(part) { 24 | return util.convert.decode(part.buffer.slice(1), part.useCesu8); 25 | } 26 | 27 | function write(part, value) { 28 | /* jshint validthis:true */ 29 | 30 | value = value || this; 31 | part = part || {}; 32 | part.argumentCount = getArgumentCount(value); 33 | part.buffer = util.convert.encode(' ' + value, part.useCesu8); 34 | return part; 35 | } 36 | 37 | function getByteLength(value) { 38 | return Buffer.byteLength(value) + 1; 39 | } 40 | 41 | function getArgumentCount(value) { 42 | /* jshint unused:false */ 43 | return 1; 44 | } -------------------------------------------------------------------------------- /lib/protocol/data/TextList.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | var common = require('../common'); 18 | 19 | exports.write = write; 20 | exports.getByteLength = getByteLength; 21 | exports.getArgumentCount = getArgumentCount; 22 | 23 | function write(part, fields) { 24 | /* jshint validthis:true */ 25 | var offset = 0; 26 | part = part || {}; 27 | fields = fields || this; 28 | 29 | var byteLength = getByteLength(fields, part.useCesu8); 30 | var buffer = new Buffer(byteLength); 31 | 32 | var field, fieldLength, data; 33 | for (var i = 0; i < fields.length; i++) { 34 | field = fields[i]; 35 | data = util.convert.encode(field, part.useCesu8); 36 | 37 | fieldLength = data.length; 38 | if (fieldLength <= common.DATA_LENGTH_MAX1BYTE_LENGTH) { 39 | buffer[offset] = fieldLength; 40 | offset += 1; 41 | } else { 42 | buffer[offset] = common.DATA_LENGTH_2BYTE_LENGTH_INDICATOR; 43 | offset += 1; 44 | buffer.writeUInt16LE(fieldLength, offset); 45 | offset += 2; 46 | } 47 | 48 | data.copy(buffer, offset); 49 | offset += fieldLength; 50 | } 51 | part.argumentCount = getArgumentCount(fields); 52 | part.buffer = buffer; 53 | return part; 54 | } 55 | 56 | function getByteLength(fields, useCesu8) { 57 | var byteLength = 0; 58 | var fieldLength; 59 | for (var i = 0; i < fields.length; i++) { 60 | fieldLength = getByteLengthOfField(fields[i], useCesu8); 61 | if (fieldLength <= common.DATA_LENGTH_MAX1BYTE_LENGTH) { 62 | byteLength += fieldLength + 1; 63 | } else { 64 | byteLength += fieldLength + 3; 65 | } 66 | } 67 | return byteLength; 68 | } 69 | 70 | function getArgumentCount(fields) { 71 | /* jshint unused:false */ 72 | return fields.length; 73 | } 74 | 75 | function getByteLengthOfField(field, useCesu8) { 76 | if (useCesu8) { 77 | return util.convert.encode(field, useCesu8).length; 78 | } 79 | return Buffer.byteLength(field); 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /lib/protocol/data/TransactionFlags.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | 17 | var Options = require('./Options'); 18 | var common = require('../common'); 19 | 20 | exports.read = read; 21 | exports.getByteLength = Options.getByteLength; 22 | exports.getArgumentCount = Options.getArgumentCount; 23 | 24 | function read(part) { 25 | return Options.read(part, common.TransactionFlagName); 26 | } -------------------------------------------------------------------------------- /lib/protocol/data/WriteLobReply.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | exports.read = read; 17 | exports.getArgumentCount = getArgumentCount; 18 | 19 | function read(part) { 20 | var offset = 0; 21 | var buffer = part.buffer; 22 | var args = []; 23 | for (var i = 0; i < part.argumentCount; i++) { 24 | args.push(buffer.slice(offset, offset + 8)); 25 | offset += 8; 26 | } 27 | return args; 28 | } 29 | 30 | function getArgumentCount(args) { 31 | return args.length; 32 | } -------------------------------------------------------------------------------- /lib/protocol/data/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var common = require('../common'); 17 | var PartKind = common.PartKind; 18 | 19 | var Binary = require('./Binary'); 20 | var Default = require('./Default'); 21 | var Fields = require('./Fields'); 22 | var TextList = require('./TextList'); 23 | 24 | var Int32 = require('./Int32'); 25 | var MultilineOptions = require('./MultilineOptions'); 26 | var Options = require('./Options'); 27 | var ParameterMetadata = require('./ParameterMetadata'); 28 | var Parameters = require('./Parameters'); 29 | var ReadLobReply = require('./ReadLobReply'); 30 | var ReadLobRequest = require('./ReadLobRequest'); 31 | var ResultSetMetadata = require('./ResultSetMetadata'); 32 | var SqlError = require('./SqlError'); 33 | var Text = require('./Text'); 34 | var Text20 = require('./Text20'); 35 | var TransactionFlags = require('./TransactionFlags'); 36 | var WriteLobReply = require('./WriteLobReply'); 37 | 38 | var rw = module.exports = {}; 39 | rw[PartKind.COMMAND] = Text; 40 | rw[PartKind.RESULT_SET] = Default; 41 | rw[PartKind.ERROR] = SqlError; 42 | rw[PartKind.STATEMENT_ID] = Binary; 43 | rw[PartKind.TRANSACTION_ID] = Binary; 44 | rw[PartKind.ROWS_AFFECTED] = Int32; 45 | rw[PartKind.RESULT_SET_ID] = Binary; 46 | rw[PartKind.TOPOLOGY_INFORMATION] = MultilineOptions; 47 | rw[PartKind.READ_LOB_REQUEST] = ReadLobRequest; 48 | rw[PartKind.READ_LOB_REPLY] = ReadLobReply; 49 | rw[PartKind.TABLE_NAME] = Text; 50 | rw[PartKind.WRITE_LOB_REQUEST] = Default; 51 | rw[PartKind.CLIENT_CONTEXT] = Options; 52 | rw[PartKind.WRITE_LOB_REPLY] = WriteLobReply; 53 | rw[PartKind.PARAMETERS] = Parameters; 54 | rw[PartKind.AUTHENTICATION] = Fields; 55 | rw[PartKind.SESSION_CONTEXT] = Options; 56 | rw[PartKind.CLIENT_ID] = Text20; 57 | rw[PartKind.STATEMENT_CONTEXT] = Options; 58 | rw[PartKind.PARTITION_INFORMATION] = Default; 59 | rw[PartKind.OUTPUT_PARAMETERS] = Default; 60 | rw[PartKind.CONNECT_OPTIONS] = Options; 61 | rw[PartKind.COMMIT_OPTIONS] = Options; 62 | rw[PartKind.FETCH_OPTIONS] = Options; 63 | rw[PartKind.FETCH_SIZE] = Int32; 64 | rw[PartKind.PARAMETER_METADATA] = ParameterMetadata; 65 | rw[PartKind.RESULT_SET_METADATA] = ResultSetMetadata; 66 | rw[PartKind.CLIENT_INFO] = TextList; 67 | rw[PartKind.TRANSACTION_FLAGS] = TransactionFlags; 68 | rw[PartKind.DB_CONNECT_INFO] = Options; 69 | 70 | for (var name in PartKind) { 71 | /* jshint forin: false */ 72 | var kind = PartKind[name]; 73 | if (!rw[kind]) { 74 | rw[kind] = Default; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /lib/protocol/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | exports.Connection = require('./Connection'); 17 | exports.ConnectionManager = require('./ConnectionManager'); 18 | exports.ClientInfo = require('./ClientInfo'); 19 | exports.Parser = require('./Parser'); 20 | exports.Result = require('./Result'); 21 | exports.ResultSet = require('./ResultSet'); 22 | exports.ResultSetTransform = require('./ResultSetTransform'); 23 | exports.Statement = require('./Statement'); 24 | exports.Stringifier = require('./Stringifier'); 25 | exports.Transaction = require('./Transaction'); 26 | exports.Reader = require('./Reader'); 27 | exports.Writer = require('./Writer'); 28 | exports.ExecuteTask = require('./ExecuteTask'); 29 | exports.MessageBuffer = require('./MessageBuffer'); 30 | exports.Lob = require('./Lob'); 31 | exports.auth = require('./auth'); 32 | exports.common = require('./common'); 33 | exports.data = require('./data'); 34 | exports.part = require('./part'); 35 | exports.reply = require('./reply'); 36 | exports.request = require('./request'); 37 | exports.tcp = require('./tcp'); 38 | -------------------------------------------------------------------------------- /lib/protocol/part/AbstractOptions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | 18 | module.exports = AbstractOptions; 19 | 20 | function AbstractOptions() {} 21 | 22 | AbstractOptions.prototype.getOptions = function getOptions() { 23 | var self = this; 24 | 25 | function getOption(name) { 26 | var propertyName = util._2cc(self.PROPERTY_NAMES[name]); 27 | var value = self[propertyName]; 28 | var type = self.TYPES[name]; 29 | return { 30 | name: name, 31 | value: value, 32 | type: type 33 | }; 34 | } 35 | return this.KEYS.map(getOption).filter(function(option) { 36 | return (typeof option.value !== 'undefined'); 37 | }); 38 | }; 39 | 40 | AbstractOptions.prototype.setOptions = function setOptions(options) { 41 | var self = this; 42 | 43 | if (!Array.isArray(options)) { 44 | return; 45 | } 46 | 47 | function hasProperty(option) { 48 | return Object.prototype.hasOwnProperty.call(self.PROPERTY_NAMES, option.name); 49 | } 50 | 51 | function setOption(option) { 52 | self[util._2cc(self.PROPERTY_NAMES[option.name])] = option.value; 53 | } 54 | options.filter(hasProperty).forEach(setOption); 55 | }; 56 | -------------------------------------------------------------------------------- /lib/protocol/part/ClientContextOptions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | var AbstractOptions = require('./AbstractOptions'); 18 | var common = require('../common'); 19 | var ClientContext = require('../common/ClientContextOption'); 20 | var TypeCode = require('../common/TypeCode'); 21 | var pjson = require('../../../package.json'); 22 | 23 | module.exports = ClientContextOptions; 24 | 25 | util.inherits(ClientContextOptions, AbstractOptions); 26 | 27 | function ClientContextOptions() { 28 | AbstractOptions.call(this); 29 | 30 | this.clientVersion = pjson.version, 31 | 32 | this.clientType = 'node-hdb'; 33 | 34 | this.clientApplicationProgram = 'node'; 35 | } 36 | 37 | ClientContextOptions.prototype.PROPERTY_NAMES = common.ClientContextOptionName; 38 | var types = ClientContextOptions.prototype.TYPES = {}; 39 | types[ClientContext.CLIENT_VERSION] = TypeCode.STRING; 40 | types[ClientContext.CLIENT_TYPE] = TypeCode.STRING; 41 | types[ClientContext.CLIENT_APPLICATION_PROGRAM] = TypeCode.STRING; 42 | ClientContextOptions.prototype.KEYS = [ 43 | ClientContext.CLIENT_VERSION, 44 | ClientContext.CLIENT_TYPE, 45 | ClientContext.CLIENT_APPLICATION_PROGRAM 46 | ]; 47 | -------------------------------------------------------------------------------- /lib/protocol/part/DbConnectInfoOptions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | var AbstractOptions = require('./AbstractOptions'); 18 | var common = require('../common'); 19 | var DbConnectInfo = require('../common/DbConnectInfoOption'); 20 | var TypeCode = require('../common/TypeCode'); 21 | 22 | module.exports = DbConnectInfoOptions; 23 | 24 | util.inherits(DbConnectInfoOptions, AbstractOptions); 25 | 26 | function DbConnectInfoOptions() { 27 | AbstractOptions.call(this); 28 | } 29 | 30 | DbConnectInfoOptions.prototype.PROPERTY_NAMES = common.DbConnectInfoOptionName; 31 | var types = DbConnectInfoOptions.prototype.TYPES = {}; 32 | types[DbConnectInfo.DATABASE_NAME] = TypeCode.STRING; 33 | types[DbConnectInfo.HOST] = TypeCode.STRING; 34 | types[DbConnectInfo.PORT] = TypeCode.INT; 35 | types[DbConnectInfo.IS_CONNECTED] = TypeCode.BOOLEAN; 36 | DbConnectInfoOptions.prototype.KEYS = [ 37 | DbConnectInfo.DATABASE_NAME, 38 | DbConnectInfo.HOST, 39 | DbConnectInfo.PORT, 40 | DbConnectInfo.IS_CONNECTED 41 | ]; -------------------------------------------------------------------------------- /lib/protocol/part/StatementContext.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | var AbstractOptions = require('./AbstractOptions'); 18 | var common = require('../common'); 19 | var PART_HEADER_LENGTH = common.PART_HEADER_LENGTH; 20 | module.exports = StatementContext; 21 | 22 | util.inherits(StatementContext, AbstractOptions); 23 | 24 | function StatementContext() { 25 | AbstractOptions.call(this); 26 | 27 | // Information on the statement sequence within the transaction 28 | this.statementSequenceInfo = undefined; 29 | // Time for statement execution on the server in nano seconds 30 | this.serverExecutionTime = 0; 31 | } 32 | 33 | Object.defineProperties(StatementContext.prototype, { 34 | size: { 35 | get: function getSize() { 36 | var statementSequenceInfoLength; 37 | if (this.statementSequenceInfo) { 38 | statementSequenceInfoLength = this.statementSequenceInfo.length; 39 | } else { 40 | statementSequenceInfoLength = 10; 41 | } 42 | return PART_HEADER_LENGTH + util.alignLength(4 + 43 | statementSequenceInfoLength, 8); 44 | } 45 | } 46 | }); 47 | 48 | StatementContext.prototype.PROPERTY_NAMES = common.StatementContextName; 49 | StatementContext.prototype.TYPES = common.StatementContextType; 50 | StatementContext.prototype.KEYS = [ 51 | common.StatementContext.STATEMENT_SEQUENCE_INFO 52 | ]; -------------------------------------------------------------------------------- /lib/protocol/part/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | exports.ConnectOptions = require('./ConnectOptions'); 17 | exports.ClientContextOptions = require('./ClientContextOptions'); 18 | exports.StatementContext = require('./StatementContext'); 19 | exports.DbConnectInfoOptions = require('./DbConnectInfoOptions'); -------------------------------------------------------------------------------- /lib/protocol/reply/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | exports.Part = require('./Part'); 17 | exports.Segment = require('./Segment'); -------------------------------------------------------------------------------- /lib/protocol/request/Part.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('../../util'); 17 | var PartKind = require('../common/PartKind'); 18 | 19 | var PART_HEADER_LENGTH = 16; 20 | 21 | module.exports = Part; 22 | 23 | function Part(options) { 24 | this.kind = options.kind || PartKind.NIL; 25 | this.attributes = options.attributes || 0; 26 | this.argumentCount = options.argumentCount || 0; 27 | this.useCesu8 = options.useCesu8; 28 | this.buffer = undefined; 29 | } 30 | 31 | 32 | Part.prototype.toBuffer = function toBuffer(size) { 33 | var byteLength = util.alignLength(this.buffer.length, 8); 34 | var buffer = new Buffer(PART_HEADER_LENGTH + byteLength); 35 | // Part kind, specifies nature of part data 36 | buffer.writeInt8(this.kind, 0); 37 | // Further attributes of part 38 | buffer.writeInt8(this.attributes, 1); 39 | // Argument count, number of elements in part data. 40 | buffer.writeInt16LE(this.argumentCount, 2); 41 | // Argument count, number of elements in part data (only for some part kinds). 42 | buffer.writeInt32LE(0, 4); 43 | // Length of part buffer in bytes 44 | buffer.writeInt32LE(this.buffer.length, 8); 45 | // Length in packet remaining without this part. 46 | buffer.writeInt32LE(size, 12); 47 | this.buffer.copy(buffer, PART_HEADER_LENGTH); 48 | if (this.buffer.length < byteLength) { 49 | buffer.fill(0x00, PART_HEADER_LENGTH + this.buffer.length); 50 | } 51 | return buffer; 52 | }; -------------------------------------------------------------------------------- /lib/util/Queue.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | var EventEmitter = require('events').EventEmitter; 18 | 19 | module.exports = Queue; 20 | 21 | util.inherits(Queue, EventEmitter); 22 | 23 | function Queue(immediate) { 24 | EventEmitter.call(this); 25 | 26 | this.queue = []; 27 | this.busy = false; 28 | this.running = !!immediate; 29 | } 30 | 31 | Object.defineProperty(Queue.prototype, 'empty', { 32 | get: function isEmpty() { 33 | return this.queue.length === 0; 34 | } 35 | }); 36 | 37 | Queue.prototype.unshift = function unshift(task) { 38 | this.queue.unshift(task); 39 | if (this.running) { 40 | this.dequeue(); 41 | } 42 | return this; 43 | }; 44 | 45 | Queue.prototype.push = function push(task) { 46 | this.queue.push(task); 47 | if (this.running) { 48 | this.dequeue(); 49 | } 50 | return this; 51 | }; 52 | 53 | Queue.prototype.resume = function resume() { 54 | this.running = true; 55 | if (this.queue.length) { 56 | this.dequeue(); 57 | } 58 | return this; 59 | }; 60 | 61 | Queue.prototype.pause = function pause() { 62 | this.running = false; 63 | return this; 64 | }; 65 | 66 | Queue.prototype.abort = function abort(err) { 67 | this.queue.forEach(t => t.receive(err)) 68 | this.queue = []; 69 | this.busy = false; 70 | this.running = false; 71 | this.removeAllListeners(); 72 | return this; 73 | }; 74 | 75 | Queue.prototype.createTask = function createTask(send, receive, name) { 76 | return new Task(send, receive, name); 77 | }; 78 | 79 | Queue.prototype.dequeue = function dequeue() { 80 | var self = this; 81 | 82 | function next(err, name) { 83 | /* jshint unused:false */ 84 | self.busy = false; 85 | if (self.queue.length) { 86 | run(); 87 | } else { 88 | self.emit('drain'); 89 | } 90 | } 91 | 92 | function run() { 93 | if (self.running && !self.busy) { 94 | // Queue is running and not busy 95 | self.busy = true; 96 | var task = self.queue.shift(); 97 | task.run(next); 98 | } 99 | } 100 | run(); 101 | }; 102 | 103 | function Task(send, receive, name) { 104 | this.send = send; 105 | this.receive = receive; 106 | this.name = name; 107 | } 108 | 109 | Task.prototype.run = function run(next) { 110 | var self = this; 111 | 112 | function receive() { 113 | /* jshint validthis:true */ 114 | self.receive.apply(null, arguments); 115 | next(null, self.name); 116 | } 117 | try { 118 | this.send(receive); 119 | } catch (err) { 120 | process.nextTick(function () { 121 | receive(err); 122 | }); 123 | } 124 | }; 125 | -------------------------------------------------------------------------------- /lib/util/convert.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var iconv = require('iconv-lite'); 4 | 5 | exports.encode = encode; 6 | exports.decode = decode; 7 | exports.lengthInCesu8 = lengthInCesu8; 8 | 9 | function encode(text, useCesu8) { 10 | return (useCesu8) ? 11 | iconv.encode(text, 'cesu8') : 12 | new Buffer(text, 'utf-8'); 13 | } 14 | 15 | function decode(buffer, useCesu8) { 16 | return (useCesu8) ? 17 | iconv.decode(buffer, 'cesu8') : 18 | buffer.toString('utf-8'); 19 | } 20 | 21 | function lengthInCesu8(buffer, combineSurrogates = true) { 22 | var text = iconv.decode(buffer, 'cesu8'); 23 | var len = 0; 24 | if (combineSurrogates) { 25 | // count surrogate pairs as a single char (String.length counts it as 2) 26 | var code = 0; 27 | for (var i = 0; i < text.length; i++) { 28 | code = text.charCodeAt(i); 29 | if (0xD800 <= code && code <= 0xDBFF) { i++; } 30 | len++; 31 | } 32 | } else { 33 | len = text.length; 34 | } 35 | return len; 36 | } 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Koser, Holger ", 3 | "contributors": [ 4 | "Vachkov, Georgi ", 5 | "Penev, Alexander " 6 | ], 7 | "name": "hdb", 8 | "description": "SAP HANA Database Client for Node", 9 | "version": "0.19.12", 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/SAP/node-hdb.git" 13 | }, 14 | "license": "Apache-2.0", 15 | "keywords": [ 16 | "sap", 17 | "hana", 18 | "database", 19 | "in-memory" 20 | ], 21 | "main": "./index.js", 22 | "scripts": { 23 | "test": "make test-coveralls" 24 | }, 25 | "browser": { 26 | "./lib/protocol/tcp.js": "./chrome/sockets/tcp.js" 27 | }, 28 | "engines": { 29 | "node": ">= 18" 30 | }, 31 | "dependencies": { 32 | "iconv-lite": "^0.4.18" 33 | }, 34 | "devDependencies": { 35 | "async": "^2.4.1", 36 | "chrome-net": "^3.3.0", 37 | "concat-stream": "^1.5.1", 38 | "coveralls": "^2.13.1", 39 | "fstream": "^1.0.11", 40 | "generic-pool": "^2.4.2", 41 | "istanbul": "^0.4.4", 42 | "mocha": "^3.4.2", 43 | "should": "^10.0.0" 44 | }, 45 | "optionalDependencies": {} 46 | } 47 | -------------------------------------------------------------------------------- /test/acceptance/db.Dummy.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint undef:false, expr:true */ 16 | 17 | var db = require('../db')(); 18 | 19 | describe('db', function () { 20 | before(db.init.bind(db)); 21 | after(db.end.bind(db)); 22 | describe('DUMMY ', function () { 23 | 24 | describe('direct execute of Query', function () { 25 | 26 | it('should return a single row', function (done) { 27 | var sql = 'select * from DUMMY'; 28 | db.client.exec(sql, function (err, rows) { 29 | (!!err).should.be.not.ok; 30 | rows.should.eql([{ 31 | DUMMY: 'X' 32 | }]); 33 | done(); 34 | }); 35 | }); 36 | 37 | it('should return a single row as array', function (done) { 38 | var sql = 'select * from DUMMY'; 39 | db.client.exec({ 40 | sql: sql, 41 | rowsAsArray: true 42 | }, function (err, rows) { 43 | (!!err).should.be.not.ok; 44 | rows.should.eql([ 45 | ['X'] 46 | ]); 47 | done(); 48 | }); 49 | }); 50 | 51 | it('should return a single row with name nest tables', function (done) { 52 | var sql = 'select * from DUMMY'; 53 | db.client.exec(sql, { 54 | nestTables: true 55 | }, function (err, rows) { 56 | (!!err).should.be.not.ok; 57 | rows.should.eql([{ 58 | DUMMY: { 59 | DUMMY: 'X' 60 | } 61 | }]); 62 | done(); 63 | }); 64 | }); 65 | 66 | }); 67 | 68 | describe('prepared execute of a Query', function () { 69 | 70 | it('should return a single row with name nest tables', function (done) { 71 | var sql = 'select * from dummy where dummy = ?'; 72 | db.client.prepare({ 73 | sql: sql, 74 | nestTables: true 75 | }, function (err, statement) { 76 | (!!err).should.be.not.ok; 77 | statement.exec({ 78 | parameters: ['X'] 79 | }, function (err, rows) { 80 | (!!err).should.be.not.ok; 81 | rows.should.eql([{ 82 | DUMMY: { 83 | DUMMY: 'X' 84 | } 85 | }]); 86 | statement.drop(done); 87 | }); 88 | 89 | }); 90 | }); 91 | 92 | }); 93 | 94 | }); 95 | }); -------------------------------------------------------------------------------- /test/acceptance/db.Events.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var db = require('../db')(); 17 | 18 | describe('db', function () { 19 | 20 | describe('events', function () { 21 | var client; 22 | 23 | beforeEach(function (done) { 24 | db.init(function (err) { 25 | if (err) { 26 | return done(err); 27 | } 28 | 29 | client = db.client; 30 | done(); 31 | }); 32 | }); 33 | 34 | after(function () { 35 | if (client && client.readyState !== 'closed') { 36 | client.close(); 37 | } 38 | }); 39 | 40 | it('should invoke pending callback', function (done) { 41 | client.close(); 42 | 43 | client.exec('SELECT * FROM DUMMY', function (err) { 44 | err.should.be.an.instanceOf(Error); 45 | done(); 46 | }); 47 | }); 48 | 49 | it('should fail to execute prepared statement after client closed', function (done) { 50 | client.prepare('select * from dummy where dummy = ?', function(err, stmt) { 51 | client.close(); 52 | setTimeout(function () { 53 | stmt.execute(["test"], function(err, res) { 54 | err.message.should.equal("Connection closed"); 55 | done(); 56 | }); 57 | }, 0); 58 | }); 59 | }); 60 | }); 61 | 62 | }); 63 | -------------------------------------------------------------------------------- /test/common.TopologyInformation.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var TopologyInformation = lib.common.TopologyInformation; 18 | var TopologyInformationName = lib.common.TopologyInformationName; 19 | 20 | describe('Common', function () { 21 | 22 | describe('#TopologyInformation', function () { 23 | 24 | it('should read the value for ALL_IP_ADRESSES', function () { 25 | TopologyInformation.ALL_IP_ADRESSES.should.equal(TopologyInformation.ALL_IP_ADDRESSES); 26 | TopologyInformation.ALL_IP_ADRESSES.should.equal(TopologyInformation.ALL_IP_ADDRESSES); 27 | }); 28 | 29 | it('should read the name for ALL_IP_ADRESSES', function () { 30 | TopologyInformationName[TopologyInformation.ALL_IP_ADRESSES].should.equal('ALL_IP_ADDRESSES'); 31 | }); 32 | 33 | }); 34 | 35 | }); -------------------------------------------------------------------------------- /test/data.Binary.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var PartKind = lib.common.PartKind; 18 | var Binary = lib.data[PartKind.RESULT_SET_ID]; 19 | 20 | describe('Data', function () { 21 | 22 | describe('#Binary', function () { 23 | 24 | it('should deserialize a Binary Part from buffer', function () { 25 | var buffer = new Buffer([1, 2, 3, 4]); 26 | var part = { 27 | argumentCount: 1, 28 | buffer: buffer 29 | }; 30 | var value = Binary.read(part); 31 | value.should.eql(buffer); 32 | Binary.getArgumentCount(value).should.equal(1); 33 | Binary.getByteLength(value).should.equal(buffer.length); 34 | }); 35 | 36 | it('should serialize a Binary Part', function () { 37 | var buffer = new Buffer(0); 38 | Binary.write.call(buffer).should.eql({ 39 | argumentCount: 1, 40 | buffer: buffer 41 | }); 42 | }); 43 | 44 | }); 45 | 46 | }); -------------------------------------------------------------------------------- /test/data.Default.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var PartKind = lib.common.PartKind; 18 | var Default = lib.data[PartKind.RESULT_SET]; 19 | 20 | describe('Data', function () { 21 | 22 | describe('#Default', function () { 23 | 24 | it('should deserialize an Default Part from buffer', function () { 25 | var buffer = new Buffer([1, 2, 3, 4]); 26 | var part = { 27 | argumentCount: 1, 28 | buffer: buffer, 29 | length: 16 + buffer.length 30 | }; 31 | var value = Default.read(part); 32 | value.should.eql(part); 33 | Default.getArgumentCount(value).should.equal(part.argumentCount); 34 | Default.getByteLength(value).should.equal(part.length); 35 | }); 36 | 37 | it('should serialize a Default Part', function () { 38 | var part = { 39 | argumentCount: 1, 40 | buffer: new Buffer(0), 41 | length: 16 42 | }; 43 | Default.write.call(part).should.eql(part); 44 | }); 45 | 46 | }); 47 | 48 | }); -------------------------------------------------------------------------------- /test/data.Int32.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var PartKind = lib.common.PartKind; 18 | var Int32 = lib.data[PartKind.ROWS_AFFECTED]; 19 | 20 | describe('Data', function () { 21 | 22 | describe('#Int32', function () { 23 | 24 | it('should deserialize an Int32 Part from buffer', function () { 25 | var part = { 26 | argumentCount: 1, 27 | buffer: new Buffer([1, 0, 0, 0]) 28 | }; 29 | var value = Int32.read(part); 30 | value.should.equal(1); 31 | Int32.getArgumentCount(value).should.equal(1); 32 | Int32.getByteLength(value).should.equal(4); 33 | }); 34 | 35 | it('should serialize an Int32 Part', function () { 36 | Int32.write.call(1).should.eql({ 37 | argumentCount: 1, 38 | buffer: new Buffer([1, 0, 0, 0]) 39 | }); 40 | }); 41 | }); 42 | 43 | }); -------------------------------------------------------------------------------- /test/data.Options.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var PartKind = lib.common.PartKind; 18 | var Options = lib.data[PartKind.CONNECT_OPTIONS]; 19 | 20 | describe('Data', function () { 21 | 22 | var optsPart = { 23 | argumentCount: 10, 24 | buffer: new Buffer([ 25 | 0x01, 0x03, 0x67, 0x15, 0x03, 0x00, 26 | 0x0b, 0x1d, 0x03, 0x00, 0x58, 0x53, 0x45, 27 | 0x0c, 0x03, 0x01, 0x00, 0x00, 0x00, 28 | 0x17, 0x03, 0x01, 0x00, 0x00, 0x00, 29 | 0x10, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x02, 0x1c, 0x01, 31 | 0x0f, 0x03, 0x02, 0x00, 0x00, 0x00, 32 | 0x13, 0x1c, 0x01, 33 | 0x14, 0x1c, 0x01, 34 | 0x15, 0x03, 0x01, 0x00, 0x00, 0x00 35 | ]) 36 | }; 37 | 38 | var opts = [{ 39 | name: 1, 40 | type: 3, 41 | value: 202087 42 | }, { 43 | name: 11, 44 | type: 29, 45 | value: 'XSE' 46 | }, { 47 | name: 12, 48 | type: 3, 49 | value: 1 50 | }, { 51 | name: 23, 52 | type: 3, 53 | value: 1 54 | }, { 55 | name: 16, 56 | type: 4, 57 | value: 3 58 | }, { 59 | name: 2, 60 | type: 28, 61 | value: true 62 | }, { 63 | name: 15, 64 | type: 3, 65 | value: 2 66 | }, { 67 | name: 19, 68 | type: 28, 69 | value: true 70 | }, { 71 | name: 20, 72 | type: 28, 73 | value: true 74 | }, { 75 | name: 21, 76 | type: 3, 77 | value: 1 78 | }]; 79 | 80 | describe('#Options', function () { 81 | 82 | it('should write an Options part', function () { 83 | Options.write({}, opts).should.eql(optsPart); 84 | Options.write.call(opts).should.eql(optsPart); 85 | }); 86 | 87 | it('should read an Options part', function () { 88 | Options.read(optsPart).should.eql(opts); 89 | }); 90 | 91 | }); 92 | 93 | }); -------------------------------------------------------------------------------- /test/data.ParameterMetadata.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr: true */ 16 | 17 | var lib = require('../lib'); 18 | var normalize = require('./normalize'); 19 | var PartKind = lib.common.PartKind; 20 | var ParameterMetadata = lib.data[PartKind.PARAMETER_METADATA]; 21 | 22 | describe('Data', function () { 23 | 24 | var paramsPart = { 25 | argumentCount: 4, 26 | buffer: new Buffer( 27 | '020b01000000000000010000500a0000' + 28 | '020b01000b0000000001000000000000' + 29 | '020b01001b0000000001000000000000' + 30 | '02030400240000000a00000000004d7f' + 31 | '0a504152454e5455554944' + 32 | '0f5345415243485f4352495445524941' + 33 | '085355425f54595045' + 34 | '0a4552524f525f434f4445', 'hex') 35 | }; 36 | var paramsMetadata = [{ 37 | mode: 2, 38 | dataType: 11, 39 | ioType: 1, 40 | length: 256, 41 | fraction: 0, 42 | name: 'PARENTUUID' 43 | }, { 44 | mode: 2, 45 | dataType: 11, 46 | ioType: 1, 47 | length: 256, 48 | fraction: 0, 49 | name: 'SEARCH_CRITERIA' 50 | }, { 51 | mode: 2, 52 | dataType: 11, 53 | ioType: 1, 54 | length: 256, 55 | fraction: 0, 56 | name: 'SUB_TYPE' 57 | }, { 58 | mode: 2, 59 | dataType: 3, 60 | ioType: 4, 61 | length: 10, 62 | fraction: 0, 63 | name: 'ERROR_CODE' 64 | }]; 65 | 66 | describe('#ParameterMetadata', function () { 67 | 68 | it('should read parameter metadata', function () { 69 | var parameterMetadata = ParameterMetadata.read(paramsPart); 70 | var argumentCount = ParameterMetadata.getArgumentCount( 71 | parameterMetadata); 72 | argumentCount.should.equal(paramsMetadata.length); 73 | parameterMetadata.forEach(function (param) { 74 | param.isReadOnly().should.be.false; 75 | param.isMandatory().should.be.false; 76 | param.isAutoIncrement().should.be.false; 77 | }); 78 | normalize(parameterMetadata).should.eql(paramsMetadata); 79 | }); 80 | 81 | }); 82 | 83 | }); -------------------------------------------------------------------------------- /test/data.Parameters.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var PartKind = lib.common.PartKind; 18 | var Parameters = lib.data[PartKind.PARAMETERS]; 19 | 20 | describe('Data', function () { 21 | 22 | describe('#Parameters', function () { 23 | 24 | it('should write multiple parameters values', function () { 25 | var value = [new Buffer([1]), new Buffer([2])]; 26 | var part = Parameters.write({}, value); 27 | part.argumentCount.should.equal(2); 28 | Parameters.getArgumentCount(value).should.equal(2); 29 | part.buffer.should.eql(new Buffer([1, 2])); 30 | Parameters.getByteLength(value).should.equal(2); 31 | }); 32 | 33 | it('should write one parameters value', function () { 34 | var value = new Buffer([1]); 35 | Parameters.getArgumentCount(value).should.equal(1); 36 | Parameters.getByteLength(value).should.equal(1); 37 | Parameters.write({}, value).should.eql({ 38 | argumentCount: 1, 39 | buffer: value 40 | }); 41 | Parameters.write.call(value).should.eql({ 42 | argumentCount: 1, 43 | buffer: value 44 | }); 45 | }); 46 | 47 | }); 48 | 49 | }); -------------------------------------------------------------------------------- /test/data.ReadLob.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var normalize = require('./normalize'); 18 | var bignum = lib.util.bignum; 19 | var PartKind = lib.common.PartKind; 20 | var ReadLobReply = lib.data[PartKind.READ_LOB_REPLY]; 21 | var ReadLobRequest = lib.data[PartKind.READ_LOB_REQUEST]; 22 | 23 | describe('Data', function () { 24 | 25 | var reqPart = { 26 | argumentCount: 1, 27 | buffer: new Buffer([ 28 | 0x00, 0x00, 0x00, 0x00, 0xf0, 0x18, 0x03, 0x00, 29 | 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x40, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 31 | ]) 32 | }; 33 | 34 | var reqOptions = { 35 | locatorId: 871844001349632, 36 | offset: 1025, 37 | length: 200000 38 | }; 39 | 40 | var replyPart = { 41 | argumentCount: 1, 42 | buffer: new Buffer([ 43 | 0x00, 0x00, 0x00, 0x00, 0xf0, 0x18, 0x03, 0x00, 44 | 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x60, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x00 46 | ]) 47 | }; 48 | 49 | var replyOptions = { 50 | locatorId: new Buffer([0x00, 0x00, 0x00, 0x00, 0xf0, 0x18, 0x03, 51 | 0x00 52 | ]), 53 | options: 6, 54 | chunk: new Buffer([0x60, 0x61, 0x62, 0x63]) 55 | }; 56 | 57 | describe('#ReadLob', function () { 58 | 59 | it('should write a ReadLob request', function () { 60 | ReadLobRequest.write({}, reqOptions).should.eql(reqPart); 61 | ReadLobRequest.write.call(reqOptions).should.eql(reqPart); 62 | ReadLobRequest.getByteLength(reqOptions).should.equal(24); 63 | ReadLobRequest.getArgumentCount(reqOptions).should.equal(1); 64 | }); 65 | 66 | it('should read a ReadLob request', function () { 67 | var options = ReadLobRequest.read(reqPart); 68 | options.locatorId = bignum.readInt64LE(options.locatorId, 0); 69 | options.should.eql(reqOptions); 70 | }); 71 | 72 | it('should read a ReadLob reply', function () { 73 | /* jshint expr: true */ 74 | var readLobReply = ReadLobReply.read(replyPart); 75 | readLobReply.isNull.should.be.false; 76 | readLobReply.isDataIncluded.should.be.true; 77 | readLobReply.isLast.should.be.true; 78 | var options = normalize(readLobReply); 79 | options.should.eql(replyOptions); 80 | ReadLobReply.getArgumentCount(options.chunk).should.equal(1); 81 | ReadLobReply.getByteLength(options.chunk).should.equal(20); 82 | }); 83 | 84 | }); 85 | 86 | }); -------------------------------------------------------------------------------- /test/data.ResultSet.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var Parser = lib.Parser; 18 | 19 | var metadata = require('./fixtures/resultSetMetadata').TABLES; 20 | var data = require('./fixtures/resultSetData').TABLES; 21 | 22 | describe('Data', function () { 23 | 24 | describe('#ResultSet', function () { 25 | 26 | var count = data.part.argumentCount; 27 | var first = 0; 28 | var last = count - 1; 29 | 30 | it('deserialize from part buffer', function (done) { 31 | var parser = new Parser(metadata.columns); 32 | var rows = parser.parse(data.part.buffer); 33 | rows.should.have.length(count); 34 | rows[first].should.eql(data.rows[first]); 35 | rows[last].should.eql(data.rows[last]); 36 | done(); 37 | }); 38 | 39 | }); 40 | 41 | }); -------------------------------------------------------------------------------- /test/data.ResultSetMetadata.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var normalize = require('./normalize'); 18 | var PartKind = lib.common.PartKind; 19 | var ParameterMode = lib.common.ParameterMode; 20 | var READONLY = ParameterMode.READONLY; 21 | var AUTO_INCREMENT = ParameterMode.AUTO_INCREMENT; 22 | var MANDATORY = ParameterMode.MANDATORY; 23 | var OPTIONAL = ParameterMode.OPTIONAL; 24 | var ResultSetMetadata = lib.data[PartKind.RESULT_SET_METADATA]; 25 | 26 | var data = require('./fixtures/resultSetMetadata').VERSION_AND_CURRENT_USER; 27 | 28 | describe('Data', function () { 29 | 30 | describe('#ResultSetMetadata', function () { 31 | 32 | it('should read resultSet metadata', function () { 33 | /* jshint bitwise: false */ 34 | var resultSetMetadata = ResultSetMetadata.read(data.part); 35 | var columns = normalize(resultSetMetadata); 36 | columns.should.eql(data.columns); 37 | var argumentCount = ResultSetMetadata.getArgumentCount(columns); 38 | argumentCount.should.equal(data.columns.length); 39 | 40 | resultSetMetadata.forEach(function (column, index) { 41 | var mode = data.columns[index].mode; 42 | column.isReadOnly().should.equal(!!(mode & READONLY)); 43 | column.isAutoIncrement().should.equal(!!(mode & AUTO_INCREMENT)); 44 | column.isMandatory().should.equal(!!(mode & MANDATORY)); 45 | column.isOptional().should.equal(!!(mode & OPTIONAL)); 46 | }); 47 | }); 48 | 49 | }); 50 | 51 | }); -------------------------------------------------------------------------------- /test/data.SqlError.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var normalize = require('./normalize'); 18 | var PartKind = lib.common.PartKind; 19 | var ErrorLevel = lib.common.ErrorLevel; 20 | var SqlError = lib.data[PartKind.ERROR]; 21 | 22 | function serializeError(error) { 23 | var length = Buffer.byteLength(error.message); 24 | var buffer = new Buffer(18 + length); 25 | buffer.writeInt32LE(error.code, 0); 26 | buffer.writeInt32LE(error.position, 4); 27 | buffer.writeInt32LE(length, 8); 28 | buffer.writeInt8(error.level, 12); 29 | buffer.write(error.sqlState, 13, 5); 30 | buffer.write(error.message, 18, length); 31 | return buffer; 32 | } 33 | describe('Data', function () { 34 | 35 | describe('#SqlError', function () { 36 | 37 | it('should deserialize warning from buffer', function () { 38 | var warning = { 39 | message: 'foo', 40 | code: 1, 41 | position: 2, 42 | level: ErrorLevel.WARNING, 43 | sqlState: 'HY001' 44 | }; 45 | var sqlError = SqlError.read({ 46 | buffer: serializeError(warning), 47 | argumentCount: 1 48 | }); 49 | normalize(sqlError).should.eql(warning); 50 | SqlError.getArgumentCount(sqlError).should.equal(1); 51 | SqlError.getByteLength(sqlError).should.equal(21); 52 | }); 53 | 54 | it('should deserialize fatal error from buffer', function () { 55 | var fatal = { 56 | message: 'bar', 57 | code: 1, 58 | position: 2, 59 | level: ErrorLevel.FATAL, 60 | fatal: true, 61 | sqlState: 'HY001' 62 | }; 63 | var sqlError = SqlError.read({ 64 | buffer: serializeError(fatal), 65 | argumentCount: 1 66 | }); 67 | normalize(sqlError).should.eql(fatal); 68 | }); 69 | 70 | }); 71 | 72 | }); -------------------------------------------------------------------------------- /test/data.TopogolyInformation.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var PartKind = lib.common.PartKind; 18 | var MultilineOptions = lib.data[PartKind.TOPOLOGY_INFORMATION]; 19 | 20 | var data = require('./fixtures/topogolyInformation').DEFAULT; 21 | 22 | describe('Data', function () { 23 | 24 | describe('#TopologyInformation', function () { 25 | 26 | it('should write topology information', function () { 27 | MultilineOptions.write({}, data.options).should.eql(data.part); 28 | MultilineOptions.write.call(data.options).should.eql(data.part); 29 | }); 30 | 31 | it('should deserialize options from buffer', function () { 32 | MultilineOptions.read(data.part).should.eql(data.options); 33 | }); 34 | 35 | }); 36 | 37 | }); -------------------------------------------------------------------------------- /test/data.WriteLob.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var PartKind = lib.common.PartKind; 18 | var WriteLobReply = lib.data[PartKind.WRITE_LOB_REPLY]; 19 | 20 | describe('Data', function () { 21 | 22 | var replyPart = { 23 | argumentCount: 3, 24 | buffer: new Buffer([ 25 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 26 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 27 | 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | ]) 29 | }; 30 | 31 | describe('#WriteLob', function () { 32 | 33 | it('should read a WriteLob reply', function () { 34 | /* jshint expr: true */ 35 | var writeLobReply = WriteLobReply.read(replyPart); 36 | writeLobReply[0].readUInt8(0).should.equal(1); 37 | writeLobReply[1].readUInt8(0).should.equal(2); 38 | writeLobReply[2].readUInt8(0).should.equal(3); 39 | var argumentCount = WriteLobReply.getArgumentCount(writeLobReply); 40 | argumentCount.should.equal(replyPart.argumentCount); 41 | }); 42 | 43 | }); 44 | 45 | }); -------------------------------------------------------------------------------- /test/db/LocalDB.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | var TestDB = require('./TestDB'); 18 | var mock = require('../mock'); 19 | 20 | module.exports = LocalDB; 21 | 22 | util.inherits(LocalDB, TestDB); 23 | 24 | function LocalDB(options) { 25 | TestDB.call(this, options); 26 | this.server = mock.createServer(); 27 | } 28 | 29 | LocalDB.prototype.init = function init(cb) { 30 | var self = this; 31 | 32 | function done(err) { 33 | self.server.removeListener('listening', done); 34 | self.server.removeListener('error', done); 35 | if (err) { 36 | return cb(err); 37 | } 38 | TestDB.prototype.init.call(self, cb); 39 | } 40 | this.server.listen(30015); 41 | this.server.on('error', done).on('listening', done); 42 | }; -------------------------------------------------------------------------------- /test/db/TestDB.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var hdb = require('../../lib'); 17 | 18 | module.exports = TestDB; 19 | 20 | function TestDB(options) { 21 | this.client = hdb.createClient(options); 22 | this.numbers = undefined; 23 | } 24 | 25 | TestDB.NUMBERS = require('../fixtures/numbers'); 26 | TestDB.IMAGES = require('../fixtures/images'); 27 | 28 | TestDB.prototype.init = function init(cb) { 29 | this.client.connect(cb); 30 | }; 31 | 32 | TestDB.prototype.disconnect = function disconnect(cb) { 33 | this.client.disconnect(cb); 34 | }; 35 | 36 | TestDB.prototype.end = function end(cb) { 37 | var self = this; 38 | 39 | function done(err) { 40 | self.client.end(); 41 | setTimeout(cb.bind(null, err), 1); 42 | } 43 | this.client.disconnect(done); 44 | }; 45 | 46 | TestDB.prototype.createNumbers = function createNumbers(cb) { 47 | this.numbers = TestDB.NUMBERS.slice(0); 48 | doNothing(cb); 49 | }; 50 | 51 | TestDB.prototype.dropNumbers = function dropNumbers(cb) { 52 | this.numbers = undefined; 53 | doNothing(cb); 54 | }; 55 | 56 | TestDB.prototype.createImages = function createImages(cb) { 57 | this.images = TestDB.IMAGES.slice(0); 58 | doNothing(cb); 59 | }; 60 | 61 | TestDB.prototype.dropImages = function dropImages(cb) { 62 | this.images = undefined; 63 | doNothing(cb); 64 | }; 65 | 66 | TestDB.prototype.createReadNumbersProc = function createReadNumbersProc(cb) { 67 | doNothing(cb); 68 | }; 69 | 70 | TestDB.prototype.dropReadNumbersProc = function dropReadNumbersProc(cb) { 71 | doNothing(cb); 72 | }; 73 | 74 | TestDB.prototype.createConcatStringsProc = function createConcatStringsProc(cb) { 75 | doNothing(cb); 76 | }; 77 | 78 | TestDB.prototype.dropConcatStringsProc = function dropConcatStringsProc(cb) { 79 | doNothing(cb); 80 | }; 81 | 82 | TestDB.prototype.createHashBlobProc = function createHashBlobProc(cb) { 83 | doNothing(cb); 84 | }; 85 | 86 | TestDB.prototype.dropHashBlobProc = function dropHashBlobProc(cb) { 87 | doNothing(cb); 88 | }; 89 | 90 | 91 | function doNothing(done) { 92 | process.nextTick(done); 93 | } -------------------------------------------------------------------------------- /test/db/config.tpl.json: -------------------------------------------------------------------------------- 1 | { 2 | "host": "localhost", 3 | "port": 30015, 4 | "user": "USER", 5 | "password": "PASSWORD" 6 | } -------------------------------------------------------------------------------- /test/db/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var fs = require('fs'); 17 | var path = require('path'); 18 | var LocalDB = require('./LocalDB'); 19 | var RemoteDB = require('./RemoteDB'); 20 | var libUtil = require('../../lib/util'); 21 | 22 | var localOptions = { 23 | host: 'localhost', 24 | port: 30015, 25 | user: 'TEST_USER', 26 | password: 'abcd1234', 27 | ignoreDefaultLobType: process.env.IGNORE_DEFAULT_LOB_TYPE === 'true' 28 | }; 29 | 30 | var options; 31 | try { 32 | options = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))); 33 | } catch (err) { 34 | options = null; 35 | } 36 | 37 | function getOptions(testOptions) { 38 | return libUtil.extend(options || localOptions, testOptions); 39 | } 40 | 41 | module.exports = function create(testOptions) { 42 | if (!options || process.env.HDB_MOCK) { 43 | return new LocalDB(getOptions(testOptions)); 44 | } 45 | return new RemoteDB(getOptions(testOptions)); 46 | }; -------------------------------------------------------------------------------- /test/fixtures/images.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var fs = require('fs'); 17 | var path = require('path'); 18 | 19 | module.exports = [{ 20 | NAME: 'lobby.jpg', 21 | BDATA: fs.readFileSync(path.join(__dirname, 'img', 'lobby.jpg')) 22 | }, { 23 | NAME: 'locked.png', 24 | BDATA: fs.readFileSync(path.join(__dirname, 'img', 'locked.png')) 25 | }, { 26 | NAME: 'logo.png', 27 | BDATA: fs.readFileSync(path.join(__dirname, 'img', 'logo.png')) 28 | }, { 29 | NAME: 'sap.jpg', 30 | BDATA: fs.readFileSync(path.join(__dirname, 'img', 'sap.jpg')) 31 | }]; -------------------------------------------------------------------------------- /test/fixtures/img/lobby.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP/node-hdb/723e937dd4c2dd8be234b3ba85dd855305dcb1e7/test/fixtures/img/lobby.jpg -------------------------------------------------------------------------------- /test/fixtures/img/locked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP/node-hdb/723e937dd4c2dd8be234b3ba85dd855305dcb1e7/test/fixtures/img/locked.png -------------------------------------------------------------------------------- /test/fixtures/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP/node-hdb/723e937dd4c2dd8be234b3ba85dd855305dcb1e7/test/fixtures/img/logo.png -------------------------------------------------------------------------------- /test/fixtures/img/sap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP/node-hdb/723e937dd4c2dd8be234b3ba85dd855305dcb1e7/test/fixtures/img/sap.jpg -------------------------------------------------------------------------------- /test/fixtures/lorem.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var fs = require('fs'); 17 | var path = require('path'); 18 | 19 | exports.SHORT = fs.readFileSync(path.join(__dirname, 'txt', 'short.txt')); 20 | exports.LONG = fs.readFileSync(path.join(__dirname, 'txt', 'long.txt')); -------------------------------------------------------------------------------- /test/fixtures/numbers.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = [ 17 | 'zero', 18 | 'one', 19 | 'two', 20 | 'three', 21 | 'four', 22 | 'five', 23 | 'six', 24 | 'seven', 25 | 'eight', 26 | 'nine', 27 | 'ten', 28 | 'eleven', 29 | 'twelve', 30 | 'thirteen', 31 | 'fourteen', 32 | 'fifteen', 33 | 'sixteen', 34 | 'seventeen', 35 | 'eighteen', 36 | 'nineteen', 37 | 'twenty', 38 | 'twenty-one', 39 | 'twenty-two', 40 | 'twenty-three', 41 | 'twenty-four', 42 | 'twenty-five', 43 | 'twenty-six', 44 | 'twenty-seven', 45 | 'twenty-eight', 46 | 'twenty-nine', 47 | 'thirty', 48 | 'thirty-one', 49 | 'thirty-two', 50 | 'thirty-three', 51 | 'thirty-four', 52 | 'thirty-five', 53 | 'thirty-six', 54 | 'thirty-seven', 55 | 'thirty-eight', 56 | 'thirty-nine', 57 | 'fourty', 58 | 'fourty-one', 59 | 'fourty-two', 60 | 'fourty-three', 61 | 'fourty-four', 62 | 'fourty-five', 63 | 'fourty-six', 64 | 'fourty-seven', 65 | 'fourty-eight', 66 | 'fourty-nine', 67 | 'fifty', 68 | 'fifty-one', 69 | 'fifty-two', 70 | 'fifty-three', 71 | 'fifty-four', 72 | 'fifty-five', 73 | 'fifty-six', 74 | 'fifty-seven', 75 | 'fifty-eight', 76 | 'fifty-nine', 77 | 'sixty', 78 | 'sixty-one', 79 | 'sixty-two', 80 | 'sixty-three', 81 | 'sixty-four', 82 | 'sixty-five', 83 | 'sixty-six', 84 | 'sixty-seven', 85 | 'sixty-eight', 86 | 'sixty-nine', 87 | 'seventy', 88 | 'seventy-one', 89 | 'seventy-two', 90 | 'seventy-three', 91 | 'seventy-four', 92 | 'seventy-five', 93 | 'seventy-six', 94 | 'seventy-seven', 95 | 'seventy-eight', 96 | 'seventy-nine', 97 | 'eighty', 98 | 'eighty-one', 99 | 'eighty-two', 100 | 'eighty-three', 101 | 'eighty-four', 102 | 'eighty-five', 103 | 'eighty-six', 104 | 'eighty-seven', 105 | 'eighty-eight', 106 | 'eighty-nine', 107 | 'ninety', 108 | 'ninety-one', 109 | 'ninety-two', 110 | 'ninety-three', 111 | 'ninety-four', 112 | 'ninety-five', 113 | 'ninety-six', 114 | 'ninety-seven', 115 | 'ninety-eight', 116 | 'ninety-nine', 117 | 'one-hundred' 118 | ].map(indexAndDescription); 119 | 120 | function indexAndDescription(n, i) { 121 | return { 122 | A: i, 123 | B: n 124 | }; 125 | } -------------------------------------------------------------------------------- /test/fixtures/txt/short.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. -------------------------------------------------------------------------------- /test/lib.ClientInfo.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr:true */ 16 | 17 | var lib = require('../lib'); 18 | var ClientInfo = lib.ClientInfo; 19 | var MessageType = lib.common.MessageType; 20 | var os = require('os'); 21 | 22 | describe('Lib', function () { 23 | 24 | describe('#ClientInfo', function () { 25 | it('should fetch newly modified properties', function() { 26 | var ci = new ClientInfo(); 27 | ci.setProperty('LOCALE', 'en'); 28 | 29 | ci.shouldSend(MessageType.CONNECT).should.eql(false); 30 | ci.shouldSend(MessageType.EXECUTE_DIRECT).should.eql(true); 31 | ci.getUpdatedProperties().should.eql(['LOCALE', 'en']); 32 | 33 | ci.setProperty('APPLICATIONUSER', 'hanaUser'); 34 | ci.shouldSend(MessageType.PREPARE).should.eql(true); 35 | ci.getUpdatedProperties().should.eql(['APPLICATIONUSER', 'hanaUser']); 36 | 37 | ci.shouldSend(MessageType.PREPARE).should.eql(false); 38 | ci.getUpdatedProperties().should.eql([]); 39 | }); 40 | 41 | it('should provide default application and application user values', function() { 42 | var ci = new ClientInfo(); 43 | ci.getUser().should.eql(os.userInfo().username); 44 | ci.getApplication().should.eql('node'); 45 | }); 46 | 47 | it('should override default application and application user values', function() { 48 | var ci = new ClientInfo(); 49 | ci.setProperty('APPLICATIONUSER', 'TestUser'); 50 | ci.getUser().should.eql('TestUser'); 51 | 52 | ci.setProperty('APPLICATION', 'lib.ClientInfo.js'); 53 | ci.getApplication().should.eql('lib.ClientInfo.js'); 54 | }); 55 | }); 56 | }); 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /test/lib.MessageBuffer.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr:true */ 16 | 17 | var lib = require('../lib'); 18 | var MessageBuffer = lib.MessageBuffer; 19 | 20 | describe('Lib', function () { 21 | 22 | describe('#MessageBuffer', function () { 23 | 24 | it('should create a message buffer', function () { 25 | var messageBuffer = new MessageBuffer(); 26 | messageBuffer.push(null); 27 | messageBuffer.should.have.length(0); 28 | }); 29 | 30 | }); 31 | 32 | }); -------------------------------------------------------------------------------- /test/lib.Stringifier.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | 18 | describe('Lib', function () { 19 | 20 | describe('#Stringifier', function () { 21 | 22 | it('should create a JSON Stringifier', function () { 23 | var stringifier = lib.createJSONStringifier(); 24 | stringifier.should.be.instanceof(lib.Stringifier); 25 | stringifier._stringify.should.equal(JSON.stringify); 26 | stringifier._header.should.equal('['); 27 | stringifier._footer.should.equal(']'); 28 | stringifier._seperator.should.equal(','); 29 | }); 30 | 31 | it('should write an array with 3 elements', function (done) { 32 | testStringifier([0, 1, 2], [0, 1, 2], done); 33 | }); 34 | 35 | it('should write an array with 5 elements', function (done) { 36 | testStringifier([ 37 | [0, 1], 38 | [2, 3], 39 | 4 40 | ], [0, 1, 2, 3, 4], done); 41 | }); 42 | 43 | it('should write an empty array', function (done) { 44 | testStringifier([], [], done); 45 | }); 46 | 47 | it('should write an array with powers of 2', function (done) { 48 | var stringifier = new lib.Stringifier({ 49 | map: Math.pow.bind(null, 2) 50 | }); 51 | testStringifier.call(stringifier, [0, 1, 2, 3], [1, 2, 4, 8], done); 52 | }); 53 | 54 | it('should write an array with powers of 3', function (done) { 55 | var stringifier = new lib.Stringifier({ 56 | map: Math.pow.bind(null, 3) 57 | }); 58 | testStringifier.call(stringifier, [ 59 | [0, 1], 60 | [2, 3], 61 | 4 62 | ], [1, 3, 9, 27, 81], done); 63 | }); 64 | 65 | }); 66 | 67 | }); 68 | 69 | function testStringifier(chunks, rows, done) { 70 | /* jshint validthis:true */ 71 | var data = ''; 72 | var stringifier = this || lib.createJSONStringifier(); 73 | stringifier.on('error', function (err) { 74 | done(err); 75 | }).on('readable', function () { 76 | var chunk = this.read(); 77 | if (chunk) { 78 | data += chunk; 79 | } 80 | }).on('finish', function () { 81 | JSON.parse(data).should.eql(rows); 82 | done(); 83 | }); 84 | chunks.forEach(function (chunk) { 85 | stringifier.write(chunk); 86 | }); 87 | stringifier.end(); 88 | } 89 | -------------------------------------------------------------------------------- /test/lib.Transaction.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr:true */ 16 | 17 | var lib = require('../lib'); 18 | 19 | describe('Lib', function () { 20 | 21 | describe('#Transaction', function () { 22 | 23 | it('should create a transaction', function () { 24 | var transaction = new lib.Transaction(); 25 | transaction.autoCommit.should.be.true; 26 | transaction.setAutoCommit(false); 27 | transaction.autoCommit.should.be.false; 28 | }); 29 | 30 | it('should emit a transaction errror', function (done) { 31 | var transaction = new lib.Transaction(); 32 | transaction.on('error', function (err) { 33 | err.should.be.an.Error; 34 | err.level.should.equal(lib.common.ErrorLevel.FATAL); 35 | done(); 36 | }); 37 | transaction.setFlags({ 38 | sessionClosingTransactionErrror: true 39 | }); 40 | }); 41 | 42 | it('should start a new read transaction', function (done) { 43 | var transaction = new lib.Transaction(); 44 | transaction.on('new', function (kind) { 45 | kind.should.equal('read'); 46 | transaction.setFlags({ 47 | committed: true 48 | }); 49 | }); 50 | transaction.on('end', function (success) { 51 | success.should.equal(true); 52 | done(); 53 | }); 54 | transaction.setFlags({ 55 | noWriteTransactionStarted: true 56 | }); 57 | }); 58 | 59 | it('should start a new write transaction', function (done) { 60 | var transaction = new lib.Transaction(); 61 | transaction.on('new', function (kind) { 62 | kind.should.equal('write'); 63 | transaction.setFlags({ 64 | rolledBack: true 65 | }); 66 | }); 67 | transaction.on('end', function (success) { 68 | success.should.equal(false); 69 | done(); 70 | }); 71 | transaction.setFlags({ 72 | writeTransactionStarted: true 73 | }); 74 | }); 75 | 76 | }); 77 | 78 | }); -------------------------------------------------------------------------------- /test/lib.index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr: true */ 16 | 17 | var lib = require('../lib'); 18 | var Client = lib.Client; 19 | 20 | function TestClient() {} 21 | TestClient.prototype.connect = function connect(cb) { 22 | process.nextTick(cb); 23 | }; 24 | 25 | describe('Lib', function () { 26 | 27 | describe('#index', function () { 28 | before(function () { 29 | lib.Client = TestClient; 30 | }); 31 | after(function () { 32 | lib.Client = Client; 33 | }); 34 | 35 | it('should connect', function (done) { 36 | var client = lib.connect({}, function (err) { 37 | (!err).should.be.ok; 38 | done(); 39 | }); 40 | client.should.be.instanceof(TestClient); 41 | }); 42 | 43 | }); 44 | }); -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require should 2 | --growl -------------------------------------------------------------------------------- /test/mock/MockAuthenticationManager.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = MockAuthenticationManager; 17 | 18 | function MockAuthenticationManager(options) { 19 | this.options = options; 20 | } 21 | 22 | MockAuthenticationManager.create = function createManager(options) { 23 | return new MockAuthenticationManager(options); 24 | }; 25 | 26 | MockAuthenticationManager.prototype.initialData = function initialData() { 27 | if (this.options.initialDataError) { 28 | return this.options.initialDataError; 29 | } 30 | return 'INITIAL'; 31 | }; 32 | 33 | MockAuthenticationManager.prototype.initialize = function initialize(data, cb) { 34 | if (this.options.initializeError) { 35 | return cb(this.options.initializeError); 36 | } 37 | data.should.equal('INITIAL'); 38 | cb(); 39 | }; 40 | 41 | MockAuthenticationManager.prototype.finalData = function initialData() { 42 | if (this.options.finalDataError) { 43 | return this.options.finalDataError; 44 | } 45 | return 'FINAL'; 46 | }; 47 | 48 | MockAuthenticationManager.prototype.finalize = function finalize(data) { 49 | if (this.options.finalizeError) { 50 | throw this.options.finalizeError; 51 | } 52 | data.should.equal('FINAL'); 53 | }; 54 | -------------------------------------------------------------------------------- /test/mock/MockResult.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = MockResult; 17 | 18 | function MockResult(connection, options) { 19 | this.connection = connection; 20 | this.options = options; 21 | } 22 | 23 | MockResult.create = function createResult(connection, options) { 24 | return new MockResult(connection, options); 25 | }; 26 | 27 | MockResult.prototype.handle = function handle(err, reply, cb) { 28 | cb(err, reply); 29 | }; 30 | 31 | MockResult.prototype.setResultSetMetadata = function setResultSetMetadata(metadata) { 32 | this.resultSetMetadata = metadata; 33 | }; 34 | MockResult.prototype.setParameterMetadata = function setParameterMetadata(metadata) { 35 | this.parameterMetadata = metadata; 36 | }; -------------------------------------------------------------------------------- /test/mock/MockSocket.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = MockSocket; 17 | 18 | var lib = require('../../lib'); 19 | var EventEmitter = require('events').EventEmitter; 20 | var util = lib.util; 21 | 22 | function MockSocket(options) { 23 | EventEmitter.call(this); 24 | this.initialized = false; 25 | this.writable = true; 26 | this.readable = true; 27 | this.delay = options.delay || 1; 28 | this.keepAlive = false; 29 | this.keepAliveIdle = 0; 30 | this.invalidInitializationReply = !!options.invalidInitializationReply; 31 | this.initializationErrorCode = options.initializationErrorCode; 32 | var chunk; 33 | if (this.invalidInitializationReply) { 34 | chunk = new Buffer(5); 35 | } else if (this.initializationErrorCode) { 36 | chunk = this.initializationErrorCode; 37 | } else { 38 | chunk = new Buffer([4, 20, 0, 4, 1, 0, 0, 0]); 39 | } 40 | this.chunks = [chunk]; 41 | } 42 | 43 | MockSocket.create = function createSocket(options) { 44 | return new MockSocket(options); 45 | }; 46 | 47 | util.inherits(MockSocket, EventEmitter); 48 | 49 | MockSocket.prototype.write = function write() { 50 | var chunk = this.chunks.shift(); 51 | var event, data; 52 | if (Buffer.isBuffer(chunk)) { 53 | event = 'data'; 54 | data = chunk; 55 | } else if (util.isString(chunk)) { 56 | event = 'error'; 57 | data = new Error('Initialization Error'); 58 | data.code = chunk; 59 | } else { 60 | event = 'end'; 61 | data = undefined; 62 | } 63 | var self = this; 64 | setTimeout(function () { 65 | if (!self.invalidInitializationReply && 66 | !self.initializationErrorCode && 67 | !self.initialized) { 68 | self.initialized = true; 69 | } 70 | self.emit(event, data); 71 | }, this.delay); 72 | }; 73 | 74 | MockSocket.prototype.setKeepAlive = function setKeepAlive(enable, time) { 75 | if (enable) { 76 | this.keepAlive = true; 77 | this.keepAliveIdle = time; 78 | } else { 79 | this.keepAlive = false; 80 | } 81 | }; 82 | 83 | Object.defineProperty(MockSocket.prototype, 'readyState', { 84 | get: function () { 85 | if (this.readable && this.writable) { 86 | return 'open'; 87 | } else if (this.readable && !this.writable) { 88 | return 'readOnly'; 89 | } else if (!this.readable && this.writable) { 90 | return 'writeOnly'; 91 | } else { 92 | return 'closed'; 93 | } 94 | } 95 | }); 96 | 97 | MockSocket.prototype.end = function end() { 98 | this.writable = false; 99 | }; 100 | 101 | MockSocket.prototype.destroy = function destroy(err) { 102 | this.readable = false; 103 | this.writable = false; 104 | this.emit('close', !!err); 105 | }; -------------------------------------------------------------------------------- /test/mock/data/dbConnectInfo.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../../../lib'); 17 | var SegmentKind = lib.common.SegmentKind; 18 | var FunctionCode = lib.common.FunctionCode; 19 | var PartKind = lib.common.PartKind; 20 | 21 | exports.NOT_CONNECTED = { 22 | kind: SegmentKind.REPLY, 23 | functionCode: FunctionCode.NIL, 24 | parts: [ 25 | { 26 | kind: PartKind.DB_CONNECT_INFO, 27 | argumentCount: 3, 28 | attributes: 0, 29 | buffer: new Buffer('041c00021d0c0031322e33342e35362e3132330303a8790000', 'hex') 30 | } 31 | ] 32 | }; 33 | 34 | exports.CONNECTED = { 35 | kind: SegmentKind.REPLY, 36 | functionCode: FunctionCode.NIL, 37 | parts: [ 38 | { 39 | kind: PartKind.DB_CONNECT_INFO, 40 | argumentCount: 1, 41 | attributes: 0, 42 | buffer: new Buffer('041c01', 'hex') 43 | } 44 | ] 45 | }; -------------------------------------------------------------------------------- /test/mock/data/readLob.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | 17 | var lib = require('../../../lib'); 18 | var IMAGES = require('../../fixtures/images'); 19 | var bignum = lib.util.bignum; 20 | var SegmentKind = lib.common.SegmentKind; 21 | var FunctionCode = lib.common.FunctionCode; 22 | var PartKind = lib.common.PartKind; 23 | var LobOptions = lib.common.LobOptions; 24 | 25 | exports.read = function read(req) { 26 | var id = bignum.readUInt64LE(req.locatorId, 0); 27 | return { 28 | kind: SegmentKind.REPLY, 29 | functionCode: FunctionCode.READ_LOB, 30 | parts: [{ 31 | kind: PartKind.READ_LOB_REPLY, 32 | argumentCount: 1, 33 | attributes: 0, 34 | buffer: getBuffer(id, req.offset, req.length) 35 | }] 36 | }; 37 | }; 38 | 39 | function getBuffer(id, offset, length) { 40 | /* jshint bitwise:false, unused:false */ 41 | offset = offset || 1025; 42 | var bdata = IMAGES[id].BDATA; 43 | var buffer = new Buffer(16); 44 | bignum.writeUInt64LE(buffer, id, 0); 45 | var start = offset - 1; 46 | var end = start + length; 47 | if (end < bdata.length) { 48 | buffer[8] = LobOptions.DATA_INCLUDED; 49 | } else { 50 | buffer[8] = LobOptions.DATA_INCLUDED | LobOptions.LAST_DATA; 51 | end = bdata.length; 52 | } 53 | var chunk = bdata.slice(start, end); 54 | buffer.writeUInt32LE(chunk.length, 9); 55 | buffer.fill(0x00, 13); 56 | return Buffer.concat([buffer, chunk], buffer.length + chunk.length); 57 | } -------------------------------------------------------------------------------- /test/mock/data/replies.js: -------------------------------------------------------------------------------- 1 | var mock_auth_reply= { 2 | kind: 2, 3 | functionCode: 0, 4 | resultSets: [], 5 | authentication: 'INITIAL' 6 | }; 7 | 8 | var mock_conn_reply = { 9 | kind: 2, 10 | functionCode: 0, 11 | resultSets: [], 12 | authentication: 'FINAL', 13 | connectOptions: { fullVersionString: "2.00.083.00.1737144279" }, 14 | }; 15 | 16 | module.exports = { 17 | mock_auth_reply, 18 | mock_conn_reply 19 | }; 20 | -------------------------------------------------------------------------------- /test/mock/data/writeLob.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../../../lib'); 17 | var SegmentKind = lib.common.SegmentKind; 18 | var FunctionCode = lib.common.FunctionCode; 19 | var PartKind = lib.common.PartKind; 20 | 21 | exports['0300000000000000'] = { 22 | 2: { 23 | kind: SegmentKind.REPLY, 24 | functionCode: FunctionCode.WRITE_LOB, 25 | parts: [{ 26 | kind: PartKind.WRITE_LOB_REPLY, 27 | argumentCount: 1, 28 | attributes: 0, 29 | buffer: new Buffer('0300000000000000', 'hex') 30 | }] 31 | }, 32 | 6: { 33 | kind: SegmentKind.REPLY, 34 | functionCode: FunctionCode.WRITE_LOB, 35 | parts: [{ 36 | kind: PartKind.WRITE_LOB_REPLY, 37 | argumentCount: 0, 38 | attributes: 0, 39 | buffer: new Buffer(0) 40 | }] 41 | } 42 | }; -------------------------------------------------------------------------------- /test/mock/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var server = require('./server'); 17 | var MockConnection = require('./MockConnection'); 18 | var MockResult = require('./MockResult'); 19 | var MockSocket = require('./MockSocket'); 20 | var MockAuthenticationManager = require('./MockAuthenticationManager'); 21 | 22 | exports.createServer = server.create; 23 | exports.createConnection = MockConnection.create; 24 | exports.createResult = MockResult.create; 25 | exports.createSocket = MockSocket.create; 26 | exports.createManager = MockAuthenticationManager.create; -------------------------------------------------------------------------------- /test/normalize.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | module.exports = normalize; 17 | 18 | function normalize(source) { 19 | if (Array.isArray(source)) { 20 | return normalizeArray(source); 21 | } 22 | return normalizeObject(source); 23 | } 24 | 25 | function normalizeObject(source) { 26 | var obj = {}; 27 | Object.keys(source).forEach(function (key) { 28 | obj[key] = source[key]; 29 | }); 30 | return obj; 31 | } 32 | 33 | function normalizeArray(source) { 34 | return source.map(normalizeObject); 35 | } -------------------------------------------------------------------------------- /test/part.DbConnectInfoOptions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr: true */ 16 | 17 | var lib = require('../lib'); 18 | var DbConnectInfoOption = lib.common.DbConnectInfoOption; 19 | 20 | function createDbConnectInfoOptions() { 21 | return new lib.part.DbConnectInfoOptions(); 22 | } 23 | 24 | describe('Part', function () { 25 | 26 | describe('#DbConnectInfoOptions', function () { 27 | 28 | it('create a valid DbConnectInfoOptions', function () { 29 | var dbConnectInfo = createDbConnectInfoOptions(); 30 | 31 | var databaseName = 'DB0'; 32 | var host = '127.0.0.1'; 33 | var port = 30041; 34 | var isConnected = false; 35 | 36 | var options = [ 37 | { name: DbConnectInfoOption.DATABASE_NAME, value: databaseName }, 38 | { name: DbConnectInfoOption.HOST, value: host }, 39 | { name: DbConnectInfoOption.PORT, value: port }, 40 | { name: DbConnectInfoOption.IS_CONNECTED, value: isConnected } 41 | ]; 42 | 43 | dbConnectInfo.setOptions(options); 44 | 45 | dbConnectInfo.databaseName.should.equal(databaseName); 46 | dbConnectInfo.host.should.equal(host); 47 | dbConnectInfo.port.should.equal(port); 48 | dbConnectInfo.isConnected.should.equal(isConnected); 49 | }); 50 | 51 | }); 52 | 53 | }); -------------------------------------------------------------------------------- /test/part.StatementContext.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr: true */ 16 | 17 | var lib = require('../lib'); 18 | var StatementContext = lib.common.StatementContext; 19 | 20 | function createStatementContext() { 21 | var statementContext = new lib.part.StatementContext(); 22 | return statementContext; 23 | } 24 | 25 | describe('Part', function () { 26 | 27 | describe('#StatementContext', function () { 28 | 29 | it('create a valid statement context', function (done) { 30 | var statementContext = createStatementContext(); 31 | var statementSequenceInfo = new Buffer([0, 1, 2, 3, 4, 5, 6, 32 | 7, , 8, 9 33 | ]); 34 | var serverExecutionTime = 1234; 35 | var options = [{ 36 | name: StatementContext.STATEMENT_SEQUENCE_INFO, 37 | value: statementSequenceInfo 38 | }, { 39 | name: StatementContext.SERVER_EXECUTION_TIME, 40 | value: serverExecutionTime 41 | }]; 42 | statementContext.setOptions(options); 43 | statementContext.statementSequenceInfo.should.equal( 44 | statementSequenceInfo); 45 | statementContext.serverExecutionTime.should.equal( 46 | serverExecutionTime); 47 | statementContext.size.should.equal(32); 48 | done(); 49 | }); 50 | 51 | it('create an initial statement context', function (done) { 52 | var statementContext = createStatementContext(); 53 | statementContext.setOptions(false); 54 | (!statementContext.statementSequenceInfo).should.be.ok; 55 | statementContext.serverExecutionTime.should.equal(0); 56 | statementContext.size.should.equal(32); 57 | done(); 58 | }); 59 | 60 | }); 61 | 62 | }); -------------------------------------------------------------------------------- /test/req.Authenticate.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var request = lib.request; 18 | var common = lib.common; 19 | var MAX_SEGMENT_SIZE = common.MAX_PACKET_SIZE - common.PACKET_HEADER_LENGTH; 20 | var auth = lib.auth; 21 | 22 | describe('Req', function () { 23 | 24 | var segmentHeader = new Buffer([ 25 | 0x70, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x00, 0x00, 27 | 0x01, 0x00, 28 | 0x01, 0x00, 29 | 0x01, 30 | 0x41, 31 | 0x00, 32 | 0x00, 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 34 | ]); 35 | 36 | var partHeader = new Buffer([ 37 | 0x21, 38 | 0x00, 39 | 0x01, 0x00, 40 | 0x00, 0x00, 0x00, 0x00, 41 | 0x47, 0x00, 0x00, 0x00, 42 | 0xc8, 0xff, 0x01, 0x00 43 | ]); 44 | 45 | 46 | var partBuffer = new Buffer([ 47 | 0x07, 0x00, 48 | 0x06, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 49 | 0x04, 0x4c, 0x44, 0x41, 0x50, 50 | 0x10, 0x02, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04, 0x08, 0x01, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52 | 0x11, 0x53, 0x43, 0x52, 0x41, 0x4d, 0x50, 0x42, 0x4b, 0x44, 0x46, 53 | 0x32, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36, 54 | 0x04, 0x01, 0x02, 0x03, 0x04, 55 | 0x0b, 0x53, 0x43, 0x52, 0x41, 0x4d, 0x53, 0x48, 0x41, 0x32, 0x35, 56 | 0x36, 57 | 0x04, 0x01, 0x02, 0x03, 0x04, 58 | 0x00 // filler 59 | ]); 60 | 61 | var buffer = Buffer.concat([segmentHeader, partHeader, partBuffer]); 62 | 63 | var options = { 64 | user: 'SYSTEM', 65 | password: 'secret', 66 | clientChallenge: new Buffer([0x01, 0x02, 0x03, 0x04]) 67 | }; 68 | 69 | describe('#authenticate', function () { 70 | 71 | it('should create an authenticate request', 72 | function () { 73 | var manager = auth.createManager(options); 74 | var req = request.authenticate({ 75 | authentication: manager.initialData() 76 | }); 77 | req.parts.should.have.length(1); 78 | req.parts[0].kind.should.equal(lib.common.PartKind.AUTHENTICATION); 79 | var LDAPdata = Buffer.concat([new Uint8Array([0x02, 0x00, 0x04]), 80 | options.clientChallenge, 81 | new Uint8Array([0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])]); 82 | var fields = [options.user, 83 | 'LDAP', 84 | LDAPdata, 85 | 'SCRAMPBKDF2SHA256', 86 | options.clientChallenge, 87 | 'SCRAMSHA256', 88 | options.clientChallenge]; 89 | req.parts[0].args.should.eql(fields); 90 | req.toBuffer(MAX_SEGMENT_SIZE).should.eql(buffer); 91 | }); 92 | 93 | }); 94 | 95 | }); 96 | -------------------------------------------------------------------------------- /test/req.index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | 18 | describe('Req', function () { 19 | 20 | describe('#index', function () { 21 | 22 | it('should create an execute direct request', function () { 23 | var request = lib.request.executeDirect({ 24 | commitImmediateley: true 25 | }); 26 | request.commitImmediateley.should.equal(1); 27 | }); 28 | 29 | }); 30 | 31 | }); -------------------------------------------------------------------------------- /test/req.segment.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var MessageType = lib.common.MessageType; 18 | var Segment = lib.request.Segment; 19 | 20 | describe('Req', function () { 21 | 22 | describe('#Segment', function () { 23 | 24 | it('should create a new Segment', function () { 25 | var segment = new Segment(); 26 | segment.type.should.equal(MessageType.NIL); 27 | segment.commitImmediateley.should.equal(0); 28 | segment.commandOptions.should.equal(0); 29 | segment.parts.should.have.length(0); 30 | segment.addPart({ 31 | kind: 1, 32 | args: true 33 | }); 34 | segment.parts.should.have.length(1); 35 | segment.push(2, true); 36 | segment.parts.should.have.length(2); 37 | segment.add(3); 38 | segment.parts.should.have.length(2); 39 | segment.add({ 40 | kind: 3, 41 | module: 'module' 42 | }, true); 43 | segment.parts.should.have.length(3); 44 | }); 45 | 46 | it('should create a new Segment with set useCesu8', function () { 47 | var segment = new Segment(MessageType.NIL, 0, 0, true); 48 | segment.useCesu8.should.be.true; 49 | }); 50 | 51 | }); 52 | 53 | }); -------------------------------------------------------------------------------- /test/util.Queue.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr: true */ 16 | 17 | var lib = require('../lib'); 18 | var Queue = lib.util.Queue; 19 | 20 | function createTask(reply, cb) { 21 | function send(cb) { 22 | setTimeout(function () { 23 | cb(null, reply); 24 | }, 1); 25 | } 26 | return Queue.prototype.createTask(send, cb, 'standard'); 27 | } 28 | 29 | function createErrorTask(message, cb) { 30 | function send(cb) { 31 | setTimeout(function () { 32 | cb(new Error(message)); 33 | }, 1); 34 | } 35 | return Queue.prototype.createTask(send, cb, 'error'); 36 | } 37 | 38 | function createThrowTask(message, cb) { 39 | function send() { 40 | throw new Error(message); 41 | } 42 | return Queue.prototype.createTask(send, cb, 'throw'); 43 | } 44 | 45 | describe('Util', function () { 46 | 47 | describe('#Queue', function () { 48 | 49 | it('should create a standard queue', function (done) { 50 | var replies = []; 51 | var q = new Queue(); 52 | q.empty.should.be.true; 53 | q.busy.should.be.false; 54 | q.running.should.be.false; 55 | q.push(createTask('foo', function (err, reply) { 56 | replies.push(reply); 57 | })); 58 | q.push(createErrorTask('abc', function (err) { 59 | replies.push(err.message); 60 | })); 61 | q.unshift(createThrowTask('def', function (err) { 62 | replies.push(err.message); 63 | })); 64 | q.push(createTask('bar', function (err, reply) { 65 | replies.push(reply); 66 | })); 67 | q.on('drain', function () { 68 | replies.should.eql(['def', 'foo', 'abc', 'bar']); 69 | done(); 70 | }); 71 | q.resume(); 72 | }); 73 | 74 | it('should create a running queue', function (done) { 75 | var replies = []; 76 | var q = new Queue(true); 77 | q.empty.should.be.true; 78 | q.busy.should.be.false; 79 | q.running.should.be.true; 80 | q.push(createTask('foo', function (err, reply) { 81 | replies.push(reply); 82 | })); 83 | q.unshift(createTask('bar', function (err, reply) { 84 | replies.push(reply); 85 | })); 86 | q.on('drain', function () { 87 | replies.should.eql(['foo', 'bar']); 88 | done(); 89 | }); 90 | }); 91 | 92 | }); 93 | 94 | }); -------------------------------------------------------------------------------- /test/util.calendar.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var calendar = lib.util.calendar; 18 | 19 | describe('Util', function () { 20 | 21 | describe('#DATE', function () { 22 | 23 | it('should convert daydate to date', function () { 24 | calendar.DATE(735284).should.deepEqual({y: 2014, m: 2, d: 18}); 25 | calendar.DATE(577738).should.deepEqual({y: 1582, m: 10, d: 15}); 26 | calendar.DATE(577737).should.deepEqual({y: 1582, m: 10, d: 4}); 27 | calendar.DATE(1).should.deepEqual({y: 1, m: 1, d: 1}); 28 | }); 29 | 30 | }); 31 | 32 | describe('#DAYDATE', function () { 33 | 34 | it('should convert date string to daydate', function () { 35 | calendar.DAYDATE('2014-02-18').should.equal(735284); 36 | calendar.DAYDATE('1582-10-15').should.equal(577738); 37 | calendar.DAYDATE('1582-10-04').should.equal(577737); 38 | calendar.DAYDATE('0001-01-01').should.equal(1); 39 | }); 40 | 41 | it('should convert date object to daydate', function () { 42 | calendar.DAYDATE(new Date('1582-10-14')).should.equal(577747); 43 | }); 44 | 45 | it('should convert year, month and day values to daydate', function () { 46 | calendar.DAYDATE(1582, 10, 5).should.equal(577738); 47 | }); 48 | 49 | }); 50 | 51 | describe('#DATETIMEVALIDITY', function () { 52 | 53 | it('should identify invalid days', function() { 54 | calendar.isValidDay(20, 11, 1995).should.equal(true); 55 | calendar.isValidDay(31, 11, 1995).should.equal(false); 56 | calendar.isValidDay(20, 13, 1995).should.equal(false); 57 | calendar.isValidDay(20, 11, 10000).should.equal(false); 58 | }); 59 | 60 | it('should identify invalid times', function() { 61 | calendar.isValidTime(59, 59, 23).should.equal(true); 62 | calendar.isValidTime(60, 59, 23).should.equal(false); 63 | calendar.isValidTime(59, 60, 23).should.equal(false); 64 | calendar.isValidTime(59, 59, 24).should.equal(false); 65 | }); 66 | 67 | it('should identify leap years', function() { 68 | calendar.isValidDay(29, 2, 2023).should.equal(false); 69 | calendar.isValidDay(29, 2, 2024).should.equal(true); 70 | calendar.isValidDay(29, 2, 2100).should.equal(false); 71 | calendar.isValidDay(29, 2, 2000).should.equal(true); 72 | }); 73 | }); 74 | 75 | }); 76 | -------------------------------------------------------------------------------- /test/util.convert.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | /* jshint expr: true */ 16 | 17 | var lib = require('../lib'); 18 | var util = lib.util; 19 | 20 | describe('Util', function () { 21 | 22 | describe('#convert', function () { 23 | var outOfBom = '🍩'; 24 | var outOfBomCesuBuffer = new Buffer([0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa9]); 25 | var outOfBomUtf8Buffer = new Buffer([0xf0, 0x9f, 0x8d, 0xa9]); 26 | 27 | it('should encode in cesu8 if useCesu8 is true', function () { 28 | util.convert.encode(outOfBom, true).should.eql(outOfBomCesuBuffer); 29 | }); 30 | 31 | it('should encode in utf-8 if useCesu8 is false', function () { 32 | util.convert.encode(outOfBom, false).should.eql(outOfBomUtf8Buffer); 33 | }); 34 | 35 | it('should decode from utf-8 if useCesu8 is false', function () { 36 | util.convert.decode(outOfBomUtf8Buffer, false).should.eql(outOfBom); 37 | }); 38 | 39 | it('should decode from cesu-8 if useCesu8 is true', function () { 40 | util.convert.decode(outOfBomCesuBuffer, true).should.eql(outOfBom); 41 | }); 42 | 43 | it('should count cesu8 characters in cesu8 encoded buffer', function () { 44 | util.convert.lengthInCesu8(outOfBomCesuBuffer).should.equal(1); 45 | }); 46 | 47 | it('should count cesu8 surrogates in cesu8 encoded buffer', function () { 48 | util.convert.lengthInCesu8(outOfBomCesuBuffer, false).should.equal(2); 49 | }); 50 | 51 | }); 52 | 53 | }); 54 | -------------------------------------------------------------------------------- /test/util.zeropad.js: -------------------------------------------------------------------------------- 1 | // Copyright 2013 SAP AG. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http: //www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, 10 | // software distributed under the License is distributed on an 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 12 | // either express or implied. See the License for the specific 13 | // language governing permissions and limitations under the License. 14 | 'use strict'; 15 | 16 | var lib = require('../lib'); 17 | var util = lib.util; 18 | 19 | describe('Util', function () { 20 | 21 | describe('#zeropad', function () { 22 | 23 | it('should add left variable left padding', function () { 24 | util.lpad(2, 1).should.equal('01'); 25 | util.lpad(2, 10).should.equal('10'); 26 | util.lpad(7, 10000).should.equal('0010000'); 27 | util.lpad(14, 1).should.equal('00000000000001'); 28 | util.lpad(28, 1).should.equal('0000000000000000000000000001'); 29 | }); 30 | 31 | it('should validate ZEROS', function () { 32 | util.ZEROS.should.have.length(39); 33 | }); 34 | 35 | it('should add left padding up to length 2', function () { 36 | util.lpad2(1).should.equal('01'); 37 | util.lpad2(10).should.equal('10'); 38 | }); 39 | 40 | it('should add left padding up to length 4', function () { 41 | util.lpad4(1).should.equal('0001'); 42 | util.lpad4(10).should.equal('0010'); 43 | util.lpad4(100).should.equal('0100'); 44 | util.lpad4(1000).should.equal('1000'); 45 | }); 46 | 47 | it('should add left padding up to length 7', function () { 48 | util.lpad7(1).should.equal('0000001'); 49 | util.lpad7(10).should.equal('0000010'); 50 | util.lpad7(100).should.equal('0000100'); 51 | util.lpad7(1000).should.equal('0001000'); 52 | util.lpad7(10000).should.equal('0010000'); 53 | util.lpad7(100000).should.equal('0100000'); 54 | util.lpad7(1000000).should.equal('1000000'); 55 | }); 56 | 57 | it('should add left padding up to length 14', function () { 58 | util.lpad14(1).should.equal('00000000000001'); 59 | util.lpad14(10).should.equal('00000000000010'); 60 | util.lpad14(100).should.equal('00000000000100'); 61 | util.lpad14(1000).should.equal('00000000001000'); 62 | util.lpad14(10000).should.equal('00000000010000'); 63 | util.lpad14(100000).should.equal('00000000100000'); 64 | util.lpad14(1000000).should.equal('00000001000000'); 65 | util.lpad14(10000000).should.equal('00000010000000'); 66 | util.lpad14(100000000).should.equal('00000100000000'); 67 | util.lpad14(1000000000).should.equal('00001000000000'); 68 | util.lpad14(10000000000).should.equal('00010000000000'); 69 | util.lpad14(100000000000).should.equal('00100000000000'); 70 | util.lpad14(1000000000000).should.equal('01000000000000'); 71 | util.lpad14(10000000000000).should.equal('10000000000000'); 72 | }); 73 | 74 | }); 75 | 76 | }); --------------------------------------------------------------------------------