duckdb 0.5.2-dev1468.0 → 0.5.2-dev1473.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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.5.2-dev1468.0",
5
+ "version": "0.5.2-dev1473.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -27954,6 +27954,16 @@ struct IntegerCastOperation {
27954
27954
  return true;
27955
27955
  }
27956
27956
 
27957
+ template <class T, bool NEGATIVE>
27958
+ static bool HandleHexDigit(T &state, uint8_t digit) {
27959
+ using result_t = typename T::Result;
27960
+ if (state.result > (NumericLimits<result_t>::Maximum() - digit) / 16) {
27961
+ return false;
27962
+ }
27963
+ state.result = state.result * 16 + digit;
27964
+ return true;
27965
+ }
27966
+
27957
27967
  template <class T, bool NEGATIVE>
27958
27968
  static bool HandleExponent(T &state, int32_t exponent) {
27959
27969
  using result_t = typename T::Result;
@@ -28078,6 +28088,36 @@ static bool IntegerCastLoop(const char *buf, idx_t len, T &result, bool strict)
28078
28088
  return pos > start_pos;
28079
28089
  }
28080
28090
 
28091
+ template <class T, bool NEGATIVE, bool ALLOW_EXPONENT, class OP = IntegerCastOperation>
28092
+ static bool IntegerHexCastLoop(const char *buf, idx_t len, T &result, bool strict) {
28093
+ if (ALLOW_EXPONENT || NEGATIVE) {
28094
+ return false;
28095
+ }
28096
+ idx_t start_pos = 1;
28097
+ idx_t pos = start_pos;
28098
+ char current_char;
28099
+ while (pos < len) {
28100
+ current_char = StringUtil::CharacterToLower(buf[pos]);
28101
+ if (!StringUtil::CharacterIsHex(current_char)) {
28102
+ return false;
28103
+ }
28104
+ uint8_t digit;
28105
+ if (current_char >= 'a') {
28106
+ digit = current_char - 'a' + 10;
28107
+ } else {
28108
+ digit = current_char - '0';
28109
+ }
28110
+ pos++;
28111
+ if (!OP::template HandleHexDigit<T, NEGATIVE>(result, digit)) {
28112
+ return false;
28113
+ }
28114
+ }
28115
+ if (!OP::template Finalize<T, NEGATIVE>(result)) {
28116
+ return false;
28117
+ }
28118
+ return pos > start_pos;
28119
+ }
28120
+
28081
28121
  template <class T, bool IS_SIGNED = true, bool ALLOW_EXPONENT = true, class OP = IntegerCastOperation,
28082
28122
  bool ZERO_INITIALIZE = true>
28083
28123
  static bool TryIntegerCast(const char *buf, idx_t len, T &result, bool strict) {
@@ -28091,11 +28131,21 @@ static bool TryIntegerCast(const char *buf, idx_t len, T &result, bool strict) {
28091
28131
  }
28092
28132
  int negative = *buf == '-';
28093
28133
 
28134
+ // If it starts with 0x or 0X, we parse it as a hex value
28135
+ int hex = len > 1 && *buf == '0' && (buf[1] == 'x' || buf[1] == 'X');
28136
+
28094
28137
  if (ZERO_INITIALIZE) {
28095
28138
  memset(&result, 0, sizeof(T));
28096
28139
  }
28097
28140
  if (!negative) {
28098
- return IntegerCastLoop<T, false, ALLOW_EXPONENT, OP>(buf, len, result, strict);
28141
+ if (hex) {
28142
+ // Skip the 0x
28143
+ buf++;
28144
+ len--;
28145
+ return IntegerHexCastLoop<T, false, false, OP>(buf, len, result, strict);
28146
+ } else {
28147
+ return IntegerCastLoop<T, false, ALLOW_EXPONENT, OP>(buf, len, result, strict);
28148
+ }
28099
28149
  } else {
28100
28150
  if (!IS_SIGNED) {
28101
28151
  // Need to check if its not -0
@@ -28601,6 +28651,11 @@ struct HugeIntegerCastOperation {
28601
28651
  return true;
28602
28652
  }
28603
28653
 
28654
+ template <class T, bool NEGATIVE>
28655
+ static bool HandleHexDigit(T &result, uint8_t digit) {
28656
+ return false;
28657
+ }
28658
+
28604
28659
  template <class T, bool NEGATIVE>
28605
28660
  static bool HandleExponent(T &result, int32_t exponent) {
28606
28661
  if (!result.Flush()) {
@@ -28696,6 +28751,11 @@ struct DecimalCastOperation {
28696
28751
  return true;
28697
28752
  }
28698
28753
 
28754
+ template <class T, bool NEGATIVE>
28755
+ static bool HandleHexDigit(T &state, uint8_t digit) {
28756
+ return false;
28757
+ }
28758
+
28699
28759
  template <class T, bool NEGATIVE>
28700
28760
  static void RoundUpResult(T &state) {
28701
28761
  if (NEGATIVE) {
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "4f495e8eea"
15
- #define DUCKDB_VERSION "v0.5.2-dev1468"
14
+ #define DUCKDB_SOURCE_ID "e8fb74f8e7"
15
+ #define DUCKDB_VERSION "v0.5.2-dev1473"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -6279,6 +6279,9 @@ public:
6279
6279
  DUCKDB_API static bool CharacterIsDigit(char c) {
6280
6280
  return c >= '0' && c <= '9';
6281
6281
  }
6282
+ DUCKDB_API static bool CharacterIsHex(char c) {
6283
+ return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
6284
+ }
6282
6285
  DUCKDB_API static char CharacterToLower(char c) {
6283
6286
  if (c >= 'A' && c <= 'Z') {
6284
6287
  return c - ('A' - 'a');