Class JdbcMarshaling

java.lang.Object
dev.frostlake.jdbc.JdbcMarshaling

public final class JdbcMarshaling extends Object
Shared marshaling between the engine's stored values / type names and JDBC types, used by both the HTTP-backed (Database*) and in-process (Direct*) ResultSet and metadata implementations so the conversion lives in ONE place. The engine stores temporal values as java.time types (see DateTimeType) and BINARY as byte[] (see BinaryType); over the HTTP/JSON wire a LocalDateTime arrives as an ISO string and a byte[] as Base64, so the converters accept both the live objects and their string renderings.
  • Method Details

    • toSqlType

      public static int toSqlType(DataType type)
      Map an engine DataType to a Types constant, using its PARAMETERS where they decide the answer. Every integer alias is NUMBER(38,0) in the catalog, as on a real account, so the name alone can no longer tell an integer column from a decimal one — the SCALE does, and live agrees: an INT column reports Types.BIGINT over JDBC and a NUMBER(10,2) reports Types.DECIMAL. It is the same rule this driver's metadata queries already apply to INFORMATION_SCHEMA rows.
    • toSqlType

      public static int toSqlType(String typeName, int scale)
      As above, for a caller that has the type's NAME and SCALE rather than the type itself.
    • toSqlType

      public static int toSqlType(String typeName)
      Map an engine DataType name to a Types constant.
    • columnClassName

      public static String columnClassName(int sqlType)
      The class name ResultSet.getObject yields for a Types constant. Integral types map to Long because the engine stores INTEGER/BIGINT/etc. as Long (not Integer).
    • toTimestamp

      public static Timestamp toTimestamp(Object v)
    • toDate

      public static Date toDate(Object v)
    • toTime

      public static Time toTime(Object v)
    • toBytes

      public static byte[] toBytes(Object v)
    • substitutePlaceholders

      public static String substitutePlaceholders(String sql, List<Object> values)
      Bind an ordered list of values to the ? placeholders in sql (1-based, positional) — e.g. Snowflake's EXECUTE IMMEDIATE '… ? … ?' USING (v1, v2).
    • substitutePlaceholders

      public static String substitutePlaceholders(String sql, Map<Integer,Object> params)
      Substitute ? placeholders in sql with the formatted parameters (1-based keys), skipping any ? that sits inside a single-quoted string literal so a literal like 'a?b' doesn't consume a placeholder slot. (PreparedStatement params are inlined client-side; there is no server-side binding.)
    • namedParametersToPositional

      public static String namedParametersToPositional(String sql)
      Rewrite named parameters (:name) in a callable-statement SQL to positional ? placeholders. Driven by the lexer, so a : that sits inside a string literal (part of a STRING_LITERAL token) — or :: / := (their own tokens) — is never a parameter.
    • namedParameterOrder

      public static List<String> namedParameterOrder(String sql)
      The named parameters (:name) of sql, uppercased, in order of appearance.
    • formatLiteral

      public static String formatLiteral(Object value)
      Render a parameter value as a SQL literal. Strings escape BOTH backslash and single-quote — the lexer honors \-escapes (see the STRING_LITERAL grammar rule), so doubling only the quote would let a trailing backslash break out of the literal. Temporal values are emitted in ISO form the engine parses.
    • countPlaceholders

      public static int countPlaceholders(String sql)
      Count the ? placeholders in sql, skipping any inside single-quoted string literals.
    • readToString

      public static String readToString(Reader reader) throws SQLException
      Read a character stream fully into a String (for PreparedStatement character/clob parameters).
      Throws:
      SQLException
    • readToString

      public static String readToString(InputStream in) throws SQLException
      Read a byte stream fully into a UTF-8 String (for PreparedStatement ASCII/unicode-stream parameters).
      Throws:
      SQLException
    • readToBytes

      public static byte[] readToBytes(InputStream in) throws SQLException
      Read a byte stream fully into a byte[] (for PreparedStatement binary/blob parameters).
      Throws:
      SQLException