oracledb 3.0.0 → 3.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.
Files changed (112) hide show
  1. package/CHANGELOG.md +135 -8
  2. package/README.md +6 -4
  3. package/build/Release/oracledb-abi48-darwin-x64.node +0 -0
  4. package/build/Release/oracledb-abi48-darwin-x64.node-buildinfo.txt +1 -0
  5. package/build/Release/oracledb-abi48-linux-x64.node +0 -0
  6. package/build/Release/oracledb-abi48-linux-x64.node-buildinfo.txt +1 -0
  7. package/build/Release/oracledb-abi48-win32-x64.node +0 -0
  8. package/build/Release/oracledb-abi48-win32-x64.node-buildinfo.txt +1 -0
  9. package/build/Release/oracledb-abi57-darwin-x64.node +0 -0
  10. package/build/Release/oracledb-abi57-darwin-x64.node-buildinfo.txt +1 -0
  11. package/build/Release/oracledb-abi57-linux-x64.node +0 -0
  12. package/build/Release/oracledb-abi57-linux-x64.node-buildinfo.txt +1 -0
  13. package/build/Release/oracledb-abi57-win32-x64.node +0 -0
  14. package/build/Release/oracledb-abi57-win32-x64.node-buildinfo.txt +1 -0
  15. package/build/Release/oracledb-abi64-darwin-x64.node +0 -0
  16. package/build/Release/oracledb-abi64-darwin-x64.node-buildinfo.txt +1 -0
  17. package/build/Release/oracledb-abi64-linux-x64.node +0 -0
  18. package/build/Release/oracledb-abi64-linux-x64.node-buildinfo.txt +1 -0
  19. package/build/Release/oracledb-abi64-win32-x64.node +0 -0
  20. package/build/Release/oracledb-abi64-win32-x64.node-buildinfo.txt +1 -0
  21. package/build/Release/oracledb-abi67-darwin-x64.node +0 -0
  22. package/build/Release/oracledb-abi67-darwin-x64.node-buildinfo.txt +1 -0
  23. package/build/Release/oracledb-abi67-linux-x64.node +0 -0
  24. package/build/Release/oracledb-abi67-linux-x64.node-buildinfo.txt +1 -0
  25. package/build/Release/oracledb-abi67-win32-x64.node +0 -0
  26. package/build/Release/oracledb-abi67-win32-x64.node-buildinfo.txt +1 -0
  27. package/lib/connection.js +18 -4
  28. package/lib/oracledb.js +44 -92
  29. package/lib/pool.js +36 -2
  30. package/lib/sodaCollection.js +1 -1
  31. package/lib/sodaDatabase.js +1 -1
  32. package/lib/util.js +82 -5
  33. package/package/README.md +32 -101
  34. package/package/install.js +139 -0
  35. package/package/prunebinaries.js +51 -0
  36. package/package.json +4 -11
  37. package/binding.gyp +0 -162
  38. package/lib/rel.txt +0 -1
  39. package/odpi/.npmignore +0 -4
  40. package/odpi/LICENSE.md +0 -218
  41. package/odpi/README.md +0 -61
  42. package/odpi/embed/README.md +0 -4
  43. package/odpi/embed/dpi.c +0 -50
  44. package/odpi/include/dpi.h +0 -1748
  45. package/odpi/src/dpiConn.c +0 -2089
  46. package/odpi/src/dpiContext.c +0 -296
  47. package/odpi/src/dpiData.c +0 -797
  48. package/odpi/src/dpiDebug.c +0 -184
  49. package/odpi/src/dpiDeqOptions.c +0 -370
  50. package/odpi/src/dpiEnqOptions.c +0 -174
  51. package/odpi/src/dpiEnv.c +0 -189
  52. package/odpi/src/dpiError.c +0 -204
  53. package/odpi/src/dpiErrorMessages.h +0 -86
  54. package/odpi/src/dpiGen.c +0 -303
  55. package/odpi/src/dpiGlobal.c +0 -292
  56. package/odpi/src/dpiHandleList.c +0 -117
  57. package/odpi/src/dpiHandlePool.c +0 -118
  58. package/odpi/src/dpiImpl.h +0 -1707
  59. package/odpi/src/dpiLob.c +0 -506
  60. package/odpi/src/dpiMsgProps.c +0 -386
  61. package/odpi/src/dpiObject.c +0 -897
  62. package/odpi/src/dpiObjectAttr.c +0 -115
  63. package/odpi/src/dpiObjectType.c +0 -326
  64. package/odpi/src/dpiOci.c +0 -3527
  65. package/odpi/src/dpiOracleType.c +0 -492
  66. package/odpi/src/dpiPool.c +0 -549
  67. package/odpi/src/dpiRowid.c +0 -136
  68. package/odpi/src/dpiSodaColl.c +0 -685
  69. package/odpi/src/dpiSodaCollCursor.c +0 -143
  70. package/odpi/src/dpiSodaDb.c +0 -432
  71. package/odpi/src/dpiSodaDoc.c +0 -230
  72. package/odpi/src/dpiSodaDocCursor.c +0 -143
  73. package/odpi/src/dpiStmt.c +0 -1797
  74. package/odpi/src/dpiSubscr.c +0 -674
  75. package/odpi/src/dpiUtils.c +0 -410
  76. package/odpi/src/dpiVar.c +0 -1794
  77. package/package/MAKEPKG.BAT +0 -156
  78. package/package/Makefile +0 -85
  79. package/package/createpackage.js +0 -186
  80. package/package/extractpackage.js +0 -76
  81. package/package/getversion.js +0 -37
  82. package/package/oracledbinstall.js +0 -497
  83. package/package/package.json +0 -54
  84. package/package/util.js +0 -286
  85. package/src/njsCommon.cpp +0 -1055
  86. package/src/njsCommon.h +0 -484
  87. package/src/njsConnection.cpp +0 -2926
  88. package/src/njsConnection.h +0 -227
  89. package/src/njsIntLob.cpp +0 -618
  90. package/src/njsIntLob.h +0 -179
  91. package/src/njsMessages.cpp +0 -122
  92. package/src/njsMessages.h +0 -118
  93. package/src/njsOracle.cpp +0 -1274
  94. package/src/njsOracle.h +0 -237
  95. package/src/njsPool.cpp +0 -482
  96. package/src/njsPool.h +0 -132
  97. package/src/njsResultSet.cpp +0 -478
  98. package/src/njsResultSet.h +0 -120
  99. package/src/njsSodaCollection.cpp +0 -507
  100. package/src/njsSodaCollection.h +0 -128
  101. package/src/njsSodaDatabase.cpp +0 -335
  102. package/src/njsSodaDatabase.h +0 -108
  103. package/src/njsSodaDocCursor.cpp +0 -203
  104. package/src/njsSodaDocCursor.h +0 -94
  105. package/src/njsSodaDocument.cpp +0 -412
  106. package/src/njsSodaDocument.h +0 -105
  107. package/src/njsSodaOperation.cpp +0 -557
  108. package/src/njsSodaOperation.h +0 -123
  109. package/src/njsSubscription.cpp +0 -388
  110. package/src/njsSubscription.h +0 -111
  111. package/src/njsUtils.cpp +0 -158
  112. package/src/njsUtils.h +0 -68
@@ -1,797 +0,0 @@
1
- //-----------------------------------------------------------------------------
2
- // Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
3
- // This program is free software: you can modify it and/or redistribute it
4
- // under the terms of:
5
- //
6
- // (i) the Universal Permissive License v 1.0 or at your option, any
7
- // later version (http://oss.oracle.com/licenses/upl); and/or
8
- //
9
- // (ii) the Apache License v 2.0. (http://www.apache.org/licenses/LICENSE-2.0)
10
- //-----------------------------------------------------------------------------
11
-
12
- //-----------------------------------------------------------------------------
13
- // dpiData.c
14
- // Implementation of transformation routines.
15
- //-----------------------------------------------------------------------------
16
-
17
- #include "dpiImpl.h"
18
-
19
- // constants used for converting timestamps to/from an interval
20
- #define DPI_MS_DAY 86400000 // 24 * 60 * 60 * 1000
21
- #define DPI_MS_HOUR 3600000 // 60 * 60 * 1000
22
- #define DPI_MS_MINUTE 60000 // 60 * 1000
23
- #define DPI_MS_SECOND 1000 // ms per sec
24
- #define DPI_MS_FSECOND 1000000 // 1000 * 1000
25
-
26
-
27
- //-----------------------------------------------------------------------------
28
- // dpiDataBuffer__fromOracleDate() [INTERNAL]
29
- // Populate the data from an dpiOciDate structure.
30
- //-----------------------------------------------------------------------------
31
- int dpiDataBuffer__fromOracleDate(dpiDataBuffer *data,
32
- dpiOciDate *oracleValue)
33
- {
34
- dpiTimestamp *timestamp = &data->asTimestamp;
35
-
36
- timestamp->year = oracleValue->year;
37
- timestamp->month = oracleValue->month;
38
- timestamp->day = oracleValue->day;
39
- timestamp->hour = oracleValue->hour;
40
- timestamp->minute = oracleValue->minute;
41
- timestamp->second = oracleValue->second;
42
- timestamp->fsecond = 0;
43
- timestamp->tzHourOffset = 0;
44
- timestamp->tzMinuteOffset = 0;
45
- return DPI_SUCCESS;
46
- }
47
-
48
-
49
- //-----------------------------------------------------------------------------
50
- // dpiDataBuffer__fromOracleIntervalDS() [INTERNAL]
51
- // Populate the data from an OCIInterval structure (days/seconds).
52
- //-----------------------------------------------------------------------------
53
- int dpiDataBuffer__fromOracleIntervalDS(dpiDataBuffer *data, dpiEnv *env,
54
- dpiError *error, void *oracleValue)
55
- {
56
- dpiIntervalDS *interval = &data->asIntervalDS;
57
-
58
- return dpiOci__intervalGetDaySecond(env->handle, &interval->days,
59
- &interval->hours, &interval->minutes, &interval->seconds,
60
- &interval->fseconds, oracleValue, error);
61
- }
62
-
63
-
64
- //-----------------------------------------------------------------------------
65
- // dpiDataBuffer__fromOracleIntervalYM() [INTERNAL]
66
- // Populate the data from an OCIInterval structure (years/months).
67
- //-----------------------------------------------------------------------------
68
- int dpiDataBuffer__fromOracleIntervalYM(dpiDataBuffer *data, dpiEnv *env,
69
- dpiError *error, void *oracleValue)
70
- {
71
- dpiIntervalYM *interval = &data->asIntervalYM;
72
-
73
- return dpiOci__intervalGetYearMonth(env->handle, &interval->years,
74
- &interval->months, oracleValue, error);
75
- }
76
-
77
-
78
- //-----------------------------------------------------------------------------
79
- // dpiDataBuffer__fromOracleNumberAsDouble() [INTERNAL]
80
- // Populate the data from an OCINumber structure as a double.
81
- //-----------------------------------------------------------------------------
82
- int dpiDataBuffer__fromOracleNumberAsDouble(dpiDataBuffer *data,
83
- dpiError *error, void *oracleValue)
84
- {
85
- return dpiOci__numberToReal(&data->asDouble, oracleValue, error);
86
- }
87
-
88
-
89
- //-----------------------------------------------------------------------------
90
- // dpiDataBuffer__fromOracleNumberAsInteger() [INTERNAL]
91
- // Populate the data from an OCINumber structure as an integer.
92
- //-----------------------------------------------------------------------------
93
- int dpiDataBuffer__fromOracleNumberAsInteger(dpiDataBuffer *data,
94
- dpiError *error, void *oracleValue)
95
- {
96
- return dpiOci__numberToInt(oracleValue, &data->asInt64, sizeof(int64_t),
97
- DPI_OCI_NUMBER_SIGNED, error);
98
- }
99
-
100
-
101
- //-----------------------------------------------------------------------------
102
- // dpiDataBuffer__fromOracleNumberAsUnsignedInteger() [INTERNAL]
103
- // Populate the data from an OCINumber structure as an unsigned integer.
104
- //-----------------------------------------------------------------------------
105
- int dpiDataBuffer__fromOracleNumberAsUnsignedInteger(dpiDataBuffer *data,
106
- dpiError *error, void *oracleValue)
107
- {
108
- return dpiOci__numberToInt(oracleValue, &data->asUint64, sizeof(uint64_t),
109
- DPI_OCI_NUMBER_UNSIGNED, error);
110
- }
111
-
112
-
113
- //-----------------------------------------------------------------------------
114
- // dpiDataBuffer__fromOracleNumberAsText() [INTERNAL]
115
- // Populate the data from an OCINumber structure as text.
116
- //-----------------------------------------------------------------------------
117
- int dpiDataBuffer__fromOracleNumberAsText(dpiDataBuffer *data, dpiEnv *env,
118
- dpiError *error, void *oracleValue)
119
- {
120
- uint8_t *target, numDigits, digits[DPI_NUMBER_MAX_DIGITS];
121
- int16_t decimalPointIndex, i;
122
- uint16_t *targetUtf16;
123
- uint32_t numBytes;
124
- dpiBytes *bytes;
125
- int isNegative;
126
-
127
- // parse the OCINumber structure
128
- if (dpiUtils__parseOracleNumber(oracleValue, &isNegative,
129
- &decimalPointIndex, &numDigits, digits, error) < 0)
130
- return DPI_FAILURE;
131
-
132
- // calculate the number of bytes that will be required for the string
133
- numBytes = numDigits;
134
- if (isNegative)
135
- numBytes++;
136
- if (decimalPointIndex <= 0)
137
- numBytes += -decimalPointIndex + 2;
138
- else if (decimalPointIndex < numDigits)
139
- numBytes++;
140
- else if (decimalPointIndex > numDigits)
141
- numBytes += decimalPointIndex - numDigits;
142
- if (env->charsetId == DPI_CHARSET_ID_UTF16)
143
- numBytes *= 2;
144
-
145
- // verify that the provided buffer is large enough
146
- bytes = &data->asBytes;
147
- if (numBytes > bytes->length)
148
- return dpiError__set(error, "check number to text size",
149
- DPI_ERR_BUFFER_SIZE_TOO_SMALL, bytes->length);
150
- bytes->length = numBytes;
151
-
152
- // UTF-16 must be handled differently; the platform endianness is used in
153
- // order to be compatible with OCI which has this restriction
154
- if (env->charsetId == DPI_CHARSET_ID_UTF16) {
155
- targetUtf16 = (uint16_t*) bytes->ptr;
156
-
157
- // if negative, include the sign
158
- if (isNegative)
159
- *targetUtf16++ = '-';
160
-
161
- // if the decimal point index is 0 or less, add the decimal point and
162
- // any leading zeroes that are needed
163
- if (decimalPointIndex <= 0) {
164
- *targetUtf16++ = '0';
165
- *targetUtf16++ = '.';
166
- for (; decimalPointIndex < 0; decimalPointIndex++)
167
- *targetUtf16++ = '0';
168
- }
169
-
170
- // add each of the digits
171
- for (i = 0; i < numDigits; i++) {
172
- if (i > 0 && i == decimalPointIndex)
173
- *targetUtf16++ = '.';
174
- *targetUtf16++ = '0' + digits[i];
175
- }
176
-
177
- // if the decimal point index exceeds the number of digits, add any
178
- // trailing zeroes that are needed
179
- if (decimalPointIndex > numDigits) {
180
- for (i = numDigits; i < decimalPointIndex; i++)
181
- *targetUtf16++ = '0';
182
- }
183
-
184
- // the following should be the same logic as the section above for UTF-16,
185
- // simply with single byte encodings instead
186
- } else {
187
- target = (uint8_t*) bytes->ptr;
188
-
189
- // if negative, include the sign
190
- if (isNegative)
191
- *target++ = '-';
192
-
193
- // if the decimal point index is 0 or less, add the decimal point and
194
- // any leading zeroes that are needed
195
- if (decimalPointIndex <= 0) {
196
- *target++ = '0';
197
- *target++ = '.';
198
- for (; decimalPointIndex < 0; decimalPointIndex++)
199
- *target++ = '0';
200
- }
201
-
202
- // add each of the digits
203
- for (i = 0; i < numDigits; i++) {
204
- if (i > 0 && i == decimalPointIndex)
205
- *target++ = '.';
206
- *target++ = '0' + digits[i];
207
- }
208
-
209
- // if the decimal point index exceeds the number of digits, add any
210
- // trailing zeroes that are needed
211
- if (decimalPointIndex > numDigits) {
212
- for (i = numDigits; i < decimalPointIndex; i++)
213
- *target++ = '0';
214
- }
215
-
216
- }
217
-
218
- return DPI_SUCCESS;
219
- }
220
-
221
-
222
- //-----------------------------------------------------------------------------
223
- // dpiDataBuffer__fromOracleTimestamp() [INTERNAL]
224
- // Populate the data from an OCIDateTime structure.
225
- //-----------------------------------------------------------------------------
226
- int dpiDataBuffer__fromOracleTimestamp(dpiDataBuffer *data, dpiEnv *env,
227
- dpiError *error, void *oracleValue, int withTZ)
228
- {
229
- dpiTimestamp *timestamp = &data->asTimestamp;
230
-
231
- if (dpiOci__dateTimeGetDate(env->handle, oracleValue, &timestamp->year,
232
- &timestamp->month, &timestamp->day, error) < 0)
233
- return DPI_FAILURE;
234
- if (dpiOci__dateTimeGetTime(env->handle, oracleValue, &timestamp->hour,
235
- &timestamp->minute, &timestamp->second, &timestamp->fsecond,
236
- error) < 0)
237
- return DPI_FAILURE;
238
- if (withTZ) {
239
- if (dpiOci__dateTimeGetTimeZoneOffset(env->handle, oracleValue,
240
- &timestamp->tzHourOffset, &timestamp->tzMinuteOffset,
241
- error) < 0)
242
- return DPI_FAILURE;
243
- } else {
244
- timestamp->tzHourOffset = 0;
245
- timestamp->tzMinuteOffset = 0;
246
- }
247
- return DPI_SUCCESS;
248
- }
249
-
250
-
251
- //-----------------------------------------------------------------------------
252
- // dpiDataBuffer__fromOracleTimestampAsDouble() [INTERNAL]
253
- // Populate the data from an OCIDateTime structure as a double value (number
254
- // of milliseconds since January 1, 1970).
255
- //-----------------------------------------------------------------------------
256
- int dpiDataBuffer__fromOracleTimestampAsDouble(dpiDataBuffer *data,
257
- dpiEnv *env, dpiError *error, void *oracleValue)
258
- {
259
- int32_t day, hour, minute, second, fsecond;
260
- void *interval;
261
- int status;
262
-
263
- // allocate interval to use in calculation
264
- if (dpiOci__descriptorAlloc(env->handle, &interval,
265
- DPI_OCI_DTYPE_INTERVAL_DS, "alloc interval", error) < 0)
266
- return DPI_FAILURE;
267
-
268
- // subtract dates to determine interval between date and base date
269
- if (dpiOci__dateTimeSubtract(env->handle, oracleValue, env->baseDate,
270
- interval, error) < 0) {
271
- dpiOci__descriptorFree(interval, DPI_OCI_DTYPE_INTERVAL_DS);
272
- return DPI_FAILURE;
273
- }
274
-
275
- // get the days, hours, minutes and seconds from the interval
276
- status = dpiOci__intervalGetDaySecond(env->handle, &day, &hour, &minute,
277
- &second, &fsecond, interval, error);
278
- dpiOci__descriptorFree(interval, DPI_OCI_DTYPE_INTERVAL_DS);
279
- if (status < 0)
280
- return DPI_FAILURE;
281
-
282
- // calculate milliseconds since January 1, 1970
283
- data->asDouble = ((double) day) * DPI_MS_DAY + hour * DPI_MS_HOUR +
284
- minute * DPI_MS_MINUTE + second * DPI_MS_SECOND +
285
- fsecond / DPI_MS_FSECOND;
286
- return DPI_SUCCESS;
287
- }
288
-
289
-
290
- //-----------------------------------------------------------------------------
291
- // dpiDataBuffer__toOracleDate() [INTERNAL]
292
- // Populate the data in an dpiOciDate structure.
293
- //-----------------------------------------------------------------------------
294
- int dpiDataBuffer__toOracleDate(dpiDataBuffer *data, dpiOciDate *oracleValue)
295
- {
296
- dpiTimestamp *timestamp = &data->asTimestamp;
297
-
298
- oracleValue->year = timestamp->year;
299
- oracleValue->month = timestamp->month;
300
- oracleValue->day = timestamp->day;
301
- oracleValue->hour = timestamp->hour;
302
- oracleValue->minute = timestamp->minute;
303
- oracleValue->second = timestamp->second;
304
- return DPI_SUCCESS;
305
- }
306
-
307
-
308
- //-----------------------------------------------------------------------------
309
- // dpiDataBuffer__toOracleIntervalDS() [INTERNAL]
310
- // Populate the data in an OCIInterval structure (days/seconds).
311
- //-----------------------------------------------------------------------------
312
- int dpiDataBuffer__toOracleIntervalDS(dpiDataBuffer *data, dpiEnv *env,
313
- dpiError *error, void *oracleValue)
314
- {
315
- dpiIntervalDS *interval = &data->asIntervalDS;
316
-
317
- return dpiOci__intervalSetDaySecond(env->handle, interval->days,
318
- interval->hours, interval->minutes, interval->seconds,
319
- interval->fseconds, oracleValue, error);
320
- }
321
-
322
-
323
- //-----------------------------------------------------------------------------
324
- // dpiDataBuffer__toOracleIntervalYM() [INTERNAL]
325
- // Populate the data in an OCIInterval structure (years/months).
326
- //-----------------------------------------------------------------------------
327
- int dpiDataBuffer__toOracleIntervalYM(dpiDataBuffer *data, dpiEnv *env,
328
- dpiError *error, void *oracleValue)
329
- {
330
- dpiIntervalYM *interval = &data->asIntervalYM;
331
-
332
- return dpiOci__intervalSetYearMonth(env->handle, interval->years,
333
- interval->months, oracleValue, error);
334
- }
335
-
336
-
337
- //-----------------------------------------------------------------------------
338
- // dpiDataBuffer__toOracleNumberFromDouble() [INTERNAL]
339
- // Populate the data in an OCINumber structure from a double.
340
- //-----------------------------------------------------------------------------
341
- int dpiDataBuffer__toOracleNumberFromDouble(dpiDataBuffer *data,
342
- dpiError *error, void *oracleValue)
343
- {
344
- if (isnan(data->asDouble))
345
- return dpiError__set(error, "convert double to Oracle number",
346
- DPI_ERR_NAN);
347
- return dpiOci__numberFromReal(data->asDouble, oracleValue, error);
348
- }
349
-
350
-
351
- //-----------------------------------------------------------------------------
352
- // dpiDataBuffer__toOracleNumberFromInteger() [INTERNAL]
353
- // Populate the data in an OCINumber structure from an integer.
354
- //-----------------------------------------------------------------------------
355
- int dpiDataBuffer__toOracleNumberFromInteger(dpiDataBuffer *data,
356
- dpiError *error, void *oracleValue)
357
- {
358
- return dpiOci__numberFromInt(&data->asInt64, sizeof(int64_t),
359
- DPI_OCI_NUMBER_SIGNED, oracleValue, error);
360
- }
361
-
362
-
363
- //-----------------------------------------------------------------------------
364
- // dpiDataBuffer__toOracleNumberFromText() [INTERNAL]
365
- // Populate the data in an OCINumber structure from text.
366
- //-----------------------------------------------------------------------------
367
- int dpiDataBuffer__toOracleNumberFromText(dpiDataBuffer *data, dpiEnv *env,
368
- dpiError *error, void *oracleValue)
369
- {
370
- uint8_t numDigits, digits[DPI_NUMBER_AS_TEXT_CHARS], *source, *target, i;
371
- int isNegative, prependZero, appendSentinel;
372
- dpiBytes *value = &data->asBytes;
373
- int16_t decimalPointIndex;
374
- uint8_t byte, numPairs;
375
- int8_t ociExponent;
376
-
377
- // parse the string into its constituent components
378
- if (dpiUtils__parseNumberString(value->ptr, value->length, env->charsetId,
379
- &isNegative, &decimalPointIndex, &numDigits, digits, error) < 0)
380
- return DPI_FAILURE;
381
-
382
- // if the exponent is odd, prepend a zero
383
- prependZero = (decimalPointIndex > 0 && decimalPointIndex % 2 == 1) ||
384
- (decimalPointIndex < 0 && decimalPointIndex % 2 == -1);
385
- if (prependZero && numDigits != 0) {
386
- digits[numDigits++] = 0;
387
- decimalPointIndex++;
388
- }
389
-
390
- // determine the number of digit pairs; if the number of digits is odd,
391
- // append a zero to make the number of digits even
392
- if (numDigits % 2 == 1)
393
- digits[numDigits++] = 0;
394
- numPairs = numDigits / 2;
395
-
396
- // append a sentinel 102 byte for negative numbers if there is room
397
- appendSentinel = (isNegative && numDigits < DPI_NUMBER_MAX_DIGITS);
398
-
399
- // initialize the OCINumber value
400
- // the length is the number of pairs, plus one for the exponent
401
- // include an extra byte for the sentinel if applicable
402
- target = (uint8_t*) oracleValue;
403
- *target++ = (uint8_t) (numPairs + 1 + appendSentinel);
404
-
405
- // if the number of digits is zero, the value is itself zero since all
406
- // leading and trailing zeroes are removed from the digits string; the OCI
407
- // value for zero is a special case
408
- if (numDigits == 0) {
409
- *target = 128;
410
- return DPI_SUCCESS;
411
- }
412
-
413
- // calculate the exponent
414
- ociExponent = (int8_t) ((decimalPointIndex - 2) / 2 + 193);
415
- if (isNegative)
416
- ociExponent = ~ociExponent;
417
- *target++ = (uint8_t) ociExponent;
418
-
419
- // calculate the mantissa bytes
420
- source = digits;
421
- for (i = 0; i < numPairs; i++) {
422
- if (i == 0 && prependZero)
423
- byte = *source++;
424
- else {
425
- byte = *source++ * 10;
426
- byte += *source++;
427
- }
428
- if (isNegative)
429
- byte = 101 - byte;
430
- else byte++;
431
- *target++ = byte;
432
- }
433
-
434
- // append 102 byte for negative numbers if the number of digits is less
435
- // than the maximum allowable
436
- if (appendSentinel)
437
- *target = 102;
438
-
439
- return DPI_SUCCESS;
440
- }
441
-
442
-
443
- //-----------------------------------------------------------------------------
444
- // dpiDataBuffer__toOracleNumberFromUnsignedInteger() [INTERNAL]
445
- // Populate the data in an OCINumber structure from an integer.
446
- //-----------------------------------------------------------------------------
447
- int dpiDataBuffer__toOracleNumberFromUnsignedInteger(dpiDataBuffer *data,
448
- dpiError *error, void *oracleValue)
449
- {
450
- return dpiOci__numberFromInt(&data->asUint64, sizeof(uint64_t),
451
- DPI_OCI_NUMBER_UNSIGNED, oracleValue, error);
452
- }
453
-
454
-
455
- //-----------------------------------------------------------------------------
456
- // dpiDataBuffer__toOracleTimestamp() [INTERNAL]
457
- // Populate the data in an OCIDateTime structure.
458
- //-----------------------------------------------------------------------------
459
- int dpiDataBuffer__toOracleTimestamp(dpiDataBuffer *data, dpiEnv *env,
460
- dpiError *error, void *oracleValue, int withTZ)
461
- {
462
- dpiTimestamp *timestamp = &data->asTimestamp;
463
- char tzOffsetBuffer[10], *tzOffset = NULL;
464
- size_t tzOffsetLength = 0;
465
- char sign;
466
-
467
- if (withTZ) {
468
- sign = (timestamp->tzHourOffset < 0 || timestamp->tzMinuteOffset < 0) ?
469
- '-' : '+';
470
- tzOffsetLength = (size_t) sprintf(tzOffsetBuffer, "%c%.2d:%.2d", sign,
471
- abs(timestamp->tzHourOffset), abs(timestamp->tzMinuteOffset));
472
- tzOffset = tzOffsetBuffer;
473
- }
474
- return dpiOci__dateTimeConstruct(env->handle, oracleValue, timestamp->year,
475
- timestamp->month, timestamp->day, timestamp->hour,
476
- timestamp->minute, timestamp->second, timestamp->fsecond, tzOffset,
477
- tzOffsetLength, error);
478
- }
479
-
480
-
481
- //-----------------------------------------------------------------------------
482
- // dpiDataBuffer__toOracleTimestampFromDouble() [INTERNAL]
483
- // Populate the data in an OCIDateTime structure, given the number of
484
- // milliseconds since January 1, 1970.
485
- //-----------------------------------------------------------------------------
486
- int dpiDataBuffer__toOracleTimestampFromDouble(dpiDataBuffer *data,
487
- dpiEnv *env, dpiError *error, void *oracleValue)
488
- {
489
- int32_t day, hour, minute, second, fsecond;
490
- void *interval;
491
- int status;
492
- double ms;
493
-
494
- // allocate interval to use in calculation
495
- if (dpiOci__descriptorAlloc(env->handle, &interval,
496
- DPI_OCI_DTYPE_INTERVAL_DS, "alloc interval", error) < 0)
497
- return DPI_FAILURE;
498
-
499
- // determine the interval
500
- ms = data->asDouble;
501
- day = (int32_t) (ms / DPI_MS_DAY);
502
- ms = ms - ((double) day) * DPI_MS_DAY;
503
- hour = (int32_t) (ms / DPI_MS_HOUR);
504
- ms = ms - (hour * DPI_MS_HOUR);
505
- minute = (int32_t) (ms / DPI_MS_MINUTE);
506
- ms = ms - (minute * DPI_MS_MINUTE);
507
- second = (int32_t) (ms / DPI_MS_SECOND);
508
- ms = ms - (second * DPI_MS_SECOND);
509
- fsecond = (int32_t)(ms * DPI_MS_FSECOND);
510
- if (dpiOci__intervalSetDaySecond(env->handle, day, hour, minute, second,
511
- fsecond, interval, error) < 0) {
512
- dpiOci__descriptorFree(interval, DPI_OCI_DTYPE_INTERVAL_DS);
513
- return DPI_FAILURE;
514
- }
515
-
516
- // add the interval to the base date
517
- status = dpiOci__dateTimeIntervalAdd(env->handle, env->baseDate, interval,
518
- oracleValue, error);
519
- dpiOci__descriptorFree(interval, DPI_OCI_DTYPE_INTERVAL_DS);
520
- return dpiError__check(error, status, NULL, "add date");
521
- }
522
-
523
-
524
- //-----------------------------------------------------------------------------
525
- // dpiData_getBool() [PUBLIC]
526
- // Return the boolean portion of the data.
527
- //-----------------------------------------------------------------------------
528
- int dpiData_getBool(dpiData *data)
529
- {
530
- return data->value.asBoolean;
531
- }
532
-
533
-
534
- //-----------------------------------------------------------------------------
535
- // dpiData_getBytes() [PUBLIC]
536
- // Return the bytes portion of the data.
537
- //-----------------------------------------------------------------------------
538
- dpiBytes *dpiData_getBytes(dpiData *data)
539
- {
540
- return &data->value.asBytes;
541
- }
542
-
543
-
544
- //-----------------------------------------------------------------------------
545
- // dpiData_getDouble() [PUBLIC]
546
- // Return the double portion of the data.
547
- //-----------------------------------------------------------------------------
548
- double dpiData_getDouble(dpiData *data)
549
- {
550
- return data->value.asDouble;
551
- }
552
-
553
-
554
- //-----------------------------------------------------------------------------
555
- // dpiData_getFloat() [PUBLIC]
556
- // Return the float portion of the data.
557
- //-----------------------------------------------------------------------------
558
- float dpiData_getFloat(dpiData *data)
559
- {
560
- return data->value.asFloat;
561
- }
562
-
563
-
564
- //-----------------------------------------------------------------------------
565
- // dpiData_getInt64() [PUBLIC]
566
- // Return the integer portion of the data.
567
- //-----------------------------------------------------------------------------
568
- int64_t dpiData_getInt64(dpiData *data)
569
- {
570
- return data->value.asInt64;
571
- }
572
-
573
-
574
- //-----------------------------------------------------------------------------
575
- // dpiData_getIntervalDS() [PUBLIC]
576
- // Return the interval (days/seconds) portion of the data.
577
- //-----------------------------------------------------------------------------
578
- dpiIntervalDS *dpiData_getIntervalDS(dpiData *data)
579
- {
580
- return &data->value.asIntervalDS;
581
- }
582
-
583
-
584
- //-----------------------------------------------------------------------------
585
- // dpiData_getIntervalYM() [PUBLIC]
586
- // Return the interval (years/months) portion of the data.
587
- //-----------------------------------------------------------------------------
588
- dpiIntervalYM *dpiData_getIntervalYM(dpiData *data)
589
- {
590
- return &data->value.asIntervalYM;
591
- }
592
-
593
-
594
- //-----------------------------------------------------------------------------
595
- // dpiData_getLOB() [PUBLIC]
596
- // Return the LOB portion of the data.
597
- //-----------------------------------------------------------------------------
598
- dpiLob *dpiData_getLOB(dpiData *data)
599
- {
600
- return data->value.asLOB;
601
- }
602
-
603
-
604
- //-----------------------------------------------------------------------------
605
- // dpiData_getObject() [PUBLIC]
606
- // Return the object portion of the data.
607
- //-----------------------------------------------------------------------------
608
- dpiObject *dpiData_getObject(dpiData *data)
609
- {
610
- return data->value.asObject;
611
- }
612
-
613
-
614
- //-----------------------------------------------------------------------------
615
- // dpiData_getStmt() [PUBLIC]
616
- // Return the statement portion of the data.
617
- //-----------------------------------------------------------------------------
618
- dpiStmt *dpiData_getStmt(dpiData *data)
619
- {
620
- return data->value.asStmt;
621
- }
622
-
623
-
624
- //-----------------------------------------------------------------------------
625
- // dpiData_getTimestamp() [PUBLIC]
626
- // Return the timestamp portion of the data.
627
- //-----------------------------------------------------------------------------
628
- dpiTimestamp *dpiData_getTimestamp(dpiData *data)
629
- {
630
- return &data->value.asTimestamp;
631
- }
632
-
633
-
634
- //-----------------------------------------------------------------------------
635
- // dpiData_getUint64() [PUBLIC]
636
- // Return the unsigned integer portion of the data.
637
- //-----------------------------------------------------------------------------
638
- uint64_t dpiData_getUint64(dpiData *data)
639
- {
640
- return data->value.asUint64;
641
- }
642
-
643
-
644
- //-----------------------------------------------------------------------------
645
- // dpiData_setBool() [PUBLIC]
646
- // Set the boolean portion of the data.
647
- //-----------------------------------------------------------------------------
648
- void dpiData_setBool(dpiData *data, int value)
649
- {
650
- data->isNull = 0;
651
- data->value.asBoolean = value;
652
- }
653
-
654
-
655
- //-----------------------------------------------------------------------------
656
- // dpiData_setBytes() [PUBLIC]
657
- // Set the bytes portion of the data.
658
- //-----------------------------------------------------------------------------
659
- void dpiData_setBytes(dpiData *data, char *ptr, uint32_t length)
660
- {
661
- data->isNull = 0;
662
- data->value.asBytes.ptr = ptr;
663
- data->value.asBytes.length = length;
664
- }
665
-
666
-
667
- //-----------------------------------------------------------------------------
668
- // dpiData_setDouble() [PUBLIC]
669
- // Set the double portion of the data.
670
- //-----------------------------------------------------------------------------
671
- void dpiData_setDouble(dpiData *data, double value)
672
- {
673
- data->isNull = 0;
674
- data->value.asDouble = value;
675
- }
676
-
677
-
678
- //-----------------------------------------------------------------------------
679
- // dpiData_setFloat() [PUBLIC]
680
- // Set the float portion of the data.
681
- //-----------------------------------------------------------------------------
682
- void dpiData_setFloat(dpiData *data, float value)
683
- {
684
- data->isNull = 0;
685
- data->value.asFloat = value;
686
- }
687
-
688
-
689
- //-----------------------------------------------------------------------------
690
- // dpiData_setInt64() [PUBLIC]
691
- // Set the integer portion of the data.
692
- //-----------------------------------------------------------------------------
693
- void dpiData_setInt64(dpiData *data, int64_t value)
694
- {
695
- data->isNull = 0;
696
- data->value.asInt64 = value;
697
- }
698
-
699
-
700
- //-----------------------------------------------------------------------------
701
- // dpiData_setIntervalDS() [PUBLIC]
702
- // Set the interval (days/seconds) portion of the data.
703
- //-----------------------------------------------------------------------------
704
- void dpiData_setIntervalDS(dpiData *data, int32_t days, int32_t hours,
705
- int32_t minutes, int32_t seconds, int32_t fseconds)
706
- {
707
- dpiIntervalDS *interval = &data->value.asIntervalDS;
708
-
709
- data->isNull = 0;
710
- interval->days = days;
711
- interval->hours = hours;
712
- interval->minutes = minutes;
713
- interval->seconds = seconds;
714
- interval->fseconds = fseconds;
715
- }
716
-
717
-
718
- //-----------------------------------------------------------------------------
719
- // dpiData_setIntervalYM() [PUBLIC]
720
- // Set the interval (years/months) portion of the data.
721
- //-----------------------------------------------------------------------------
722
- void dpiData_setIntervalYM(dpiData *data, int32_t years, int32_t months)
723
- {
724
- dpiIntervalYM *interval = &data->value.asIntervalYM;
725
-
726
- data->isNull = 0;
727
- interval->years = years;
728
- interval->months = months;
729
- }
730
-
731
-
732
- //-----------------------------------------------------------------------------
733
- // dpiData_setLOB() [PUBLIC]
734
- // Set the LOB portion of the data.
735
- //-----------------------------------------------------------------------------
736
- void dpiData_setLOB(dpiData *data, dpiLob *lob)
737
- {
738
- data->isNull = 0;
739
- data->value.asLOB = lob;
740
- }
741
-
742
-
743
- //-----------------------------------------------------------------------------
744
- // dpiData_setObject() [PUBLIC]
745
- // Set the object portion of the data.
746
- //-----------------------------------------------------------------------------
747
- void dpiData_setObject(dpiData *data, dpiObject *obj)
748
- {
749
- data->isNull = 0;
750
- data->value.asObject = obj;
751
- }
752
-
753
-
754
- //-----------------------------------------------------------------------------
755
- // dpiData_setStmt() [PUBLIC]
756
- // Set the statement portion of the data.
757
- //-----------------------------------------------------------------------------
758
- void dpiData_setStmt(dpiData *data, dpiStmt *obj)
759
- {
760
- data->isNull = 0;
761
- data->value.asStmt = obj;
762
- }
763
-
764
-
765
- //-----------------------------------------------------------------------------
766
- // dpiData_setTimestamp() [PUBLIC]
767
- // Set the timestamp portion of the data.
768
- //-----------------------------------------------------------------------------
769
- void dpiData_setTimestamp(dpiData *data, int16_t year, uint8_t month,
770
- uint8_t day, uint8_t hour, uint8_t minute, uint8_t second,
771
- uint32_t fsecond, int8_t tzHourOffset, int8_t tzMinuteOffset)
772
- {
773
- dpiTimestamp *timestamp = &data->value.asTimestamp;
774
-
775
- data->isNull = 0;
776
- timestamp->year = year;
777
- timestamp->month = month;
778
- timestamp->day = day;
779
- timestamp->hour = hour;
780
- timestamp->minute = minute;
781
- timestamp->second = second;
782
- timestamp->fsecond = fsecond;
783
- timestamp->tzHourOffset = tzHourOffset;
784
- timestamp->tzMinuteOffset = tzMinuteOffset;
785
- }
786
-
787
-
788
- //-----------------------------------------------------------------------------
789
- // dpiData_setUint64() [PUBLIC]
790
- // Set the unsigned integer portion of the data.
791
- //-----------------------------------------------------------------------------
792
- void dpiData_setUint64(dpiData *data, uint64_t value)
793
- {
794
- data->isNull = 0;
795
- data->value.asUint64 = value;
796
- }
797
-