node-firebird 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -9,7 +9,7 @@ var
9
9
  XdrWriter = serialize.XdrWriter,
10
10
  BlrWriter = serialize.BlrWriter,
11
11
  BitSet = serialize.BitSet,
12
- messages = require('./messages.js'),
12
+ MessagesError = require('./firebird.msg.json'),
13
13
  crypt = require('./unix-crypt.js'),
14
14
  path = require('path'),
15
15
  srp = require('./srp'),
@@ -22,97 +22,127 @@ if (typeof(setImmediate) === 'undefined') {
22
22
  }
23
23
 
24
24
  /**
25
- * Parse date from string
26
- * @return {Date}
25
+ * Get Error Message per gdscode
26
+ * @param {{gdscode: Number, params: Any[]}[]} status
27
+ * @returns {String} - Error message
27
28
  */
28
- if (String.prototype.parseDate === undefined) {
29
- String.prototype.parseDate = function() {
30
- var self = this.trim();
31
- var arr = self.indexOf(' ') === -1 ? self.split('T') : self.split(' ');
32
- var index = arr[0].indexOf(':');
33
- var length = arr[0].length;
34
-
35
- if (index !== -1) {
36
- var tmp = arr[1];
37
- arr[1] = arr[0];
38
- arr[0] = tmp;
29
+ const lookupMessages = (status) => {
30
+ const messages = status.map((item) => {
31
+ let text = MessagesError[item.gdscode];
32
+ if (text === undefined) {
33
+ return 'Unknow error';
34
+ }
35
+ if (item.params !== undefined) {
36
+ item.params.forEach((param, i) => {
37
+ text = text.replace('@' + (i + 1), param);
38
+ });
39
39
  }
40
+ return text;
41
+ });
42
+ return messages.join(', ');
43
+ }
40
44
 
41
- if (arr[0] === undefined)
42
- arr[0] = '';
45
+ /**
46
+ * Parse date from string
47
+ * @param {String} str
48
+ * @return {Date}
49
+ */
50
+ const parseDate = (str) => {
51
+ const self = str.trim();
52
+ const arr = self.indexOf(' ') === -1 ? self.split('T') : self.split(' ');
53
+ let index = arr[0].indexOf(':');
54
+ const length = arr[0].length;
55
+
56
+ if (index !== -1) {
57
+ const tmp = arr[1];
58
+ arr[1] = arr[0];
59
+ arr[0] = tmp;
60
+ }
43
61
 
44
- var noTime = arr[1] === undefined ? true : arr[1].length === 0;
62
+ if (arr[0] === undefined) {
63
+ arr[0] = '';
64
+ }
45
65
 
46
- for (var i = 0; i < length; i++) {
47
- var c = arr[0].charCodeAt(i);
48
- if (c > 47 && c < 58)
49
- continue;
50
- if (c === 45 || c === 46)
51
- continue;
66
+ const noTime = arr[1] === undefined || arr[1].length === 0;
52
67
 
53
- if (noTime)
54
- return new Date(self);
68
+ for (let i = 0; i < length; i++) {
69
+ const c = arr[0].charCodeAt(i);
70
+ if (c > 47 && c < 58) {
71
+ continue;
72
+ }
73
+ if (c === 45 || c === 46) {
74
+ continue;
75
+ }
76
+ if (noTime) {
77
+ return new Date(self);
55
78
  }
79
+ }
56
80
 
57
- if (arr[1] === undefined)
58
- arr[1] = '00:00:00';
81
+ if (arr[1] === undefined) {
82
+ arr[1] = '00:00:00';
83
+ }
59
84
 
60
- var firstDay = arr[0].indexOf('-') === -1;
85
+ const firstDay = arr[0].indexOf('-') === -1;
61
86
 
62
- var date = (arr[0] || '').split(firstDay ? '.' : '-');
63
- var time = (arr[1] || '').split(':');
64
- var parsed = [];
87
+ const date = (arr[0] || '').split(firstDay ? '.' : '-');
88
+ const time = (arr[1] || '').split(':');
65
89
 
66
- if (date.length < 4 && time.length < 2) {
67
- return new Date(self);
68
- }
90
+ if (date.length < 4 && time.length < 2) {
91
+ return new Date(self);
92
+ }
69
93
 
70
- index = (time[2] || '').indexOf('.');
94
+ index = (time[2] || '').indexOf('.');
71
95
 
72
- // milliseconds
73
- if (index !== -1) {
74
- time[3] = time[2].substring(index + 1);
75
- time[2] = time[2].substring(0, index);
76
- } else {
77
- time[3] = '0';
78
- }
96
+ // milliseconds
97
+ if (index !== -1) {
98
+ time[3] = time[2].substring(index + 1);
99
+ time[2] = time[2].substring(0, index);
100
+ } else {
101
+ time[3] = '0';
102
+ }
79
103
 
80
- parsed.push(parseInt(date[firstDay ? 2 : 0], 10)); // year
81
- parsed.push(parseInt(date[1], 10)); // month
82
- parsed.push(parseInt(date[firstDay ? 0 : 2], 10)); // day
83
- parsed.push(parseInt(time[0], 10)); // hours
84
- parsed.push(parseInt(time[1], 10)); // minutes
85
- parsed.push(parseInt(time[2], 10)); // seconds
86
- parsed.push(parseInt(time[3], 10)); // miliseconds
104
+ const parsed = [
105
+ parseInt(date[firstDay ? 2 : 0], 10), // year
106
+ parseInt(date[1], 10), // month
107
+ parseInt(date[firstDay ? 0 : 2], 10), // day
108
+ parseInt(time[0], 10), // hours
109
+ parseInt(time[1], 10), // minutes
110
+ parseInt(time[2], 10), // seconds
111
+ parseInt(time[3], 10) // miliseconds
112
+ ];
87
113
 
88
- var def = new Date();
114
+ const def = new Date();
89
115
 
90
- for (var i = 0, length = parsed.length; i < length; i++) {
91
- if (isNaN(parsed[i]))
92
- parsed[i] = 0;
116
+ for (let i = 0; i < parsed.length; i++) {
117
+ if (isNaN(parsed[i])) {
118
+ parsed[i] = 0;
119
+ }
93
120
 
94
- var value = parsed[i];
95
- if (value !== 0)
96
- continue;
121
+ const value = parsed[i];
122
+ if (value !== 0) {
123
+ continue;
124
+ }
97
125
 
98
- switch (i) {
99
- case 0:
100
- if (value <= 0)
101
- parsed[i] = def.getFullYear();
102
- break;
103
- case 1:
104
- if (value <= 0)
105
- parsed[i] = def.getMonth() + 1;
106
- break;
107
- case 2:
108
- if (value <= 0)
109
- parsed[i] = def.getDate();
110
- break;
111
- }
126
+ switch (i) {
127
+ case 0:
128
+ if (value <= 0) {
129
+ parsed[i] = def.getFullYear();
130
+ }
131
+ break;
132
+ case 1:
133
+ if (value <= 0) {
134
+ parsed[i] = def.getMonth() + 1;
135
+ }
136
+ break;
137
+ case 2:
138
+ if (value <= 0) {
139
+ parsed[i] = def.getDate();
140
+ }
141
+ break;
112
142
  }
143
+ }
113
144
 
114
- return new Date(parsed[0], parsed[1] - 1, parsed[2], parsed[3], parsed[4], parsed[5]);
115
- };
145
+ return new Date(parsed[0], parsed[1] - 1, parsed[2], parsed[3], parsed[4], parsed[5]);
116
146
  }
117
147
 
118
148
  function noop() {}
@@ -883,8 +913,12 @@ const
883
913
  function SQLVarText() {}
884
914
 
885
915
  SQLVarText.prototype.decode = function(data, lowerV13) {
886
- var ret;
916
+ let ret;
887
917
  if (this.subType > 1) {
918
+ // ToDo: with column charset
919
+ ret = data.readText(this.length, DEFAULT_ENCODING);
920
+ } else if (this.subType === 0) {
921
+ // without charset definition
888
922
  ret = data.readText(this.length, DEFAULT_ENCODING);
889
923
  } else {
890
924
  ret = data.readBuffer(this.length);
@@ -913,16 +947,21 @@ SQLVarNull.prototype.constructor = SQLVarNull;
913
947
  function SQLVarString() {}
914
948
 
915
949
  SQLVarString.prototype.decode = function(data, lowerV13) {
916
- var ret;
950
+ let ret;
917
951
  if (this.subType > 1) {
918
- ret = data.readString(DEFAULT_ENCODING)
952
+ // ToDo: with column charset
953
+ ret = data.readString(DEFAULT_ENCODING);
954
+ } else if (this.subType === 0) {
955
+ // without charset definition
956
+ ret = data.readString(DEFAULT_ENCODING);
919
957
  } else {
920
- ret = data.readBuffer()
958
+ ret = data.readBuffer();
921
959
  }
922
960
 
923
961
  if (!lowerV13 || !data.readInt()) {
924
962
  return ret;
925
963
  }
964
+
926
965
  return null;
927
966
  };
928
967
 
@@ -3095,11 +3134,8 @@ exports.Connection.prototype._bind_events = function(host, port, callback) {
3095
3134
  self._pending.shift();
3096
3135
 
3097
3136
  if (obj && obj.status) {
3098
- messages.lookupMessages(obj.status, self._messageFile, function (message) {
3099
- obj.message = message;
3100
- doCallback(obj, cb);
3101
- });
3102
-
3137
+ obj.message = lookupMessages(obj.status);
3138
+ doCallback(obj, cb);
3103
3139
  } else {
3104
3140
  doCallback(obj, cb);
3105
3141
  }
@@ -4297,7 +4333,7 @@ Connection.prototype.executeStatement = function(transaction, statement, params,
4297
4333
  if (value instanceof Date)
4298
4334
  ret[i] = new SQLParamDate(value);
4299
4335
  else if (typeof(value) === 'string')
4300
- ret[i] = new SQLParamDate(value.parseDate());
4336
+ ret[i] = new SQLParamDate(parseDate(value));
4301
4337
  else
4302
4338
  ret[i] = new SQLParamDate(new Date(value));
4303
4339
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-firebird",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Pure JavaScript and Asynchronous Firebird client for Node.js.",
5
5
  "keywords": [
6
6
  "firebird",