node-firebird 2.6.0 → 2.7.0

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.
@@ -69,6 +69,14 @@ class Statement {
69
69
  this.connection.fetchAll(this, transaction, callback);
70
70
  }
71
71
 
72
+ /**
73
+ * Execute this statement once per row via the Firebird 4 batch API
74
+ * (protocol 16+). `rows` is an array of parameter arrays.
75
+ */
76
+ executeBatch(transaction: any, rows: any[][], callback?: any, options?: any): void {
77
+ this.connection.executeBatch(transaction, this, rows, callback, options);
78
+ }
79
+
72
80
  /* Promise / async-await API — wrappers over the callback methods above. */
73
81
 
74
82
  executeAsync(transaction: any, params?: any, options?: any): Promise<any> {
@@ -76,6 +84,11 @@ class Statement {
76
84
  return fromCallback(function(cb) { self.execute(transaction, params, cb, options); });
77
85
  }
78
86
 
87
+ executeBatchAsync(transaction: any, rows: any[][], options?: any): Promise<any> {
88
+ var self = this;
89
+ return fromCallback(function(cb) { self.executeBatch(transaction, rows, cb, options); });
90
+ }
91
+
79
92
  fetchAsync(transaction: any, count: number | string): Promise<any> {
80
93
  var self = this;
81
94
  return fromCallback(function(cb) { self.fetch(transaction, count, cb); });
@@ -233,6 +233,36 @@ class Transaction {
233
233
  this.execute(query, params, callback, options);
234
234
  }
235
235
 
236
+ /**
237
+ * Execute `query` once per row in `rows` using the Firebird 4 batch API
238
+ * (protocol 16+, single network flush). The callback receives a
239
+ * completion object: { recordCount, updateCounts, errors:
240
+ * [{recordNumber, error}], errorRecordNumbers, success }. Per-record
241
+ * failures do NOT roll anything back here — inspect the completion and
242
+ * commit or roll back yourself (or use db.executeBatch for
243
+ * all-or-nothing semantics).
244
+ */
245
+ executeBatch(query: string, rows: any[][], callback?: any, options?: any): void {
246
+ var self = this;
247
+ this.newStatement(query, function(err: any, statement: any) {
248
+ if (err) {
249
+ doError(err, callback);
250
+ return;
251
+ }
252
+
253
+ statement.executeBatch(self, rows, function(err: any, result: any) {
254
+ statement.release();
255
+ if (callback)
256
+ callback(err, result);
257
+ }, options);
258
+ });
259
+ }
260
+
261
+ executeBatchAsync(query: string, rows: any[][], options?: any): Promise<any> {
262
+ var self = this;
263
+ return fromCallback(function(cb) { self.executeBatch(query, rows, cb, options); });
264
+ }
265
+
236
266
  commit(callback?: (err?: any) => void): void {
237
267
  this.connection.commit(this, callback);
238
268
  }
@@ -718,6 +718,28 @@ export class SQLParamBuffer {
718
718
 
719
719
  //------------------------------------------------------
720
720
 
721
+ /**
722
+ * Split a JS Date into the Firebird wire representation used by
723
+ * TIMESTAMP/DATE/TIME columns: `date` is the modified-Julian day number and
724
+ * `time` the count of 100-microsecond units since midnight (local time).
725
+ */
726
+ export function encodeDateTimeParts(value: Date): { date: number; time: number } {
727
+ var ms = value.getTime() - value.getTimezoneOffset() * MsPerMinute;
728
+ var time = ms % TimeCoeff;
729
+ var date = (ms - time) / TimeCoeff + DateOffset;
730
+ time *= 10;
731
+
732
+ // check overflow (dates before the epoch)
733
+ if (time < 0) {
734
+ date--;
735
+ time = TimeCoeff * 10 + time;
736
+ }
737
+
738
+ return { date: date, time: time };
739
+ }
740
+
741
+ //------------------------------------------------------
742
+
721
743
  export class SQLParamQuad {
722
744
  value: any;
723
745
 
@@ -753,20 +775,9 @@ export class SQLParamDate {
753
775
 
754
776
  encode(data: XdrWriter): void {
755
777
  if (this.value != null) {
756
-
757
- var value = this.value.getTime() - this.value.getTimezoneOffset() * MsPerMinute;
758
- var time = value % TimeCoeff;
759
- var date = (value - time) / TimeCoeff + DateOffset;
760
- time *= 10;
761
-
762
- // check overflow
763
- if (time < 0) {
764
- date--;
765
- time = TimeCoeff*10 + time;
766
- }
767
-
768
- data.addInt(date);
769
- data.addUInt(time);
778
+ var parts = encodeDateTimeParts(this.value);
779
+ data.addInt(parts.date);
780
+ data.addUInt(parts.time);
770
781
  } else {
771
782
  data.addInt(0);
772
783
  data.addUInt(0);