Class NativeSql


  • public final class NativeSql
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      NativeSql()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String parse​(java.lang.String sql, Context context)  
      private static java.lang.String replaceFunctionParameter​(java.lang.String functionString, Context context)
      Helper function to replace function parameters in escaped string.
      private static java.lang.String resolveEscapes​(java.lang.String escaped, Context context)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NativeSql

        public NativeSql()
    • Method Detail

      • parse

        public static java.lang.String parse​(java.lang.String sql,
                                             Context context)
                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • resolveEscapes

        private static java.lang.String resolveEscapes​(java.lang.String escaped,
                                                       Context context)
                                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • replaceFunctionParameter

        private static java.lang.String replaceFunctionParameter​(java.lang.String functionString,
                                                                 Context context)
        Helper function to replace function parameters in escaped string. 3 functions are handles :
        • CONVERT(value, type): replacing SQL_XXX types to convertible type, i.e SQL_BIGINT to INTEGER
        • TIMESTAMPDIFF(type, ...): replacing type SQL_TSI_XXX in type with XXX, i.e SQL_TSI_HOUR with HOUR
        • TIMESTAMPADD(type, ...): replacing type SQL_TSI_XXX in type with XXX, i.e SQL_TSI_HOUR with HOUR

        caution: this use MariaDB server conversion: 'SELECT CONVERT('2147483648', INTEGER)' will return a BIGINT. MySQL will throw a syntax error.

        Parameters:
        functionString - input string
        Returns:
        unescaped string