Class PgPreparedStatement

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.sql.PreparedStatement, java.sql.Statement, java.sql.Wrapper, BaseStatement, PGStatement
    Direct Known Subclasses:
    PgCallableStatement

    class PgPreparedStatement
    extends PgStatement
    implements java.sql.PreparedStatement
    • Field Detail

      • preparedQuery

        protected final CachedQuery preparedQuery
      • preparedParameters

        protected final ParameterList preparedParameters
      • defaultTimeZone

        private java.util.TimeZone defaultTimeZone
    • Constructor Detail

      • PgPreparedStatement

        PgPreparedStatement​(PgConnection connection,
                            java.lang.String sql,
                            int rsType,
                            int rsConcurrency,
                            int rsHoldability)
                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • PgPreparedStatement

        PgPreparedStatement​(PgConnection connection,
                            CachedQuery query,
                            int rsType,
                            int rsConcurrency,
                            int rsHoldability)
                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
    • Method Detail

      • maximumNumberOfParameters

        final int maximumNumberOfParameters()
      • executeQuery

        public java.sql.ResultSet executeQuery​(java.lang.String sql)
                                        throws java.sql.SQLException
        Specified by:
        executeQuery in interface java.sql.Statement
        Overrides:
        executeQuery in class PgStatement
        Throws:
        java.sql.SQLException
      • executeQuery

        public java.sql.ResultSet executeQuery()
                                        throws java.sql.SQLException
        Specified by:
        executeQuery in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • executeUpdate

        public int executeUpdate​(java.lang.String sql)
                          throws java.sql.SQLException
        Specified by:
        executeUpdate in interface java.sql.Statement
        Overrides:
        executeUpdate in class PgStatement
        Throws:
        java.sql.SQLException
      • executeUpdate

        public int executeUpdate()
                          throws java.sql.SQLException
        Specified by:
        executeUpdate in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • executeLargeUpdate

        public long executeLargeUpdate()
                                throws java.sql.SQLException
        Specified by:
        executeLargeUpdate in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • execute

        public boolean execute​(java.lang.String sql)
                        throws java.sql.SQLException
        Specified by:
        execute in interface java.sql.Statement
        Overrides:
        execute in class PgStatement
        Throws:
        java.sql.SQLException
      • execute

        public boolean execute()
                        throws java.sql.SQLException
        Specified by:
        execute in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • executeWithFlags

        public boolean executeWithFlags​(int flags)
                                 throws java.sql.SQLException
        Description copied from interface: BaseStatement
        Execute a prepared query, passing additional query flags.
        Specified by:
        executeWithFlags in interface BaseStatement
        Overrides:
        executeWithFlags in class PgStatement
        Parameters:
        flags - additional QueryExecutor flags for execution; these are bitwise-ORed into the default flags.
        Returns:
        true if there is a result set
        Throws:
        java.sql.SQLException - if something goes wrong.
      • isOneShotQuery

        protected boolean isOneShotQuery​(CachedQuery cachedQuery)
        Description copied from class: PgStatement
        Returns true if query is unlikely to be reused.
        Overrides:
        isOneShotQuery in class PgStatement
        Parameters:
        cachedQuery - to check (null if current query)
        Returns:
        true if query is unlikely to be reused
      • closeImpl

        public void closeImpl()
                       throws java.sql.SQLException
        Description copied from class: PgStatement
        This is guaranteed to be called exactly once even in case of concurrent PgStatement.close() calls.
        Overrides:
        closeImpl in class PgStatement
        Throws:
        java.sql.SQLException - in case of error
      • setNull

        public void setNull​(int parameterIndex,
                            int sqlType)
                     throws java.sql.SQLException
        Specified by:
        setNull in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setBoolean

        public void setBoolean​(int parameterIndex,
                               boolean x)
                        throws java.sql.SQLException
        Specified by:
        setBoolean in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setByte

        public void setByte​(int parameterIndex,
                            byte x)
                     throws java.sql.SQLException
        Specified by:
        setByte in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setShort

        public void setShort​(int parameterIndex,
                             short x)
                      throws java.sql.SQLException
        Specified by:
        setShort in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setInt

        public void setInt​(int parameterIndex,
                           int x)
                    throws java.sql.SQLException
        Specified by:
        setInt in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setLong

        public void setLong​(int parameterIndex,
                            long x)
                     throws java.sql.SQLException
        Specified by:
        setLong in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setFloat

        public void setFloat​(int parameterIndex,
                             float x)
                      throws java.sql.SQLException
        Specified by:
        setFloat in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setDouble

        public void setDouble​(int parameterIndex,
                              double x)
                       throws java.sql.SQLException
        Specified by:
        setDouble in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setBigDecimal

        public void setBigDecimal​(int parameterIndex,
                                  java.math.BigDecimal x)
                           throws java.sql.SQLException
        Specified by:
        setBigDecimal in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setString

        public void setString​(int parameterIndex,
                              java.lang.String x)
                       throws java.sql.SQLException
        Specified by:
        setString in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • getStringType

        private int getStringType()
      • setString

        protected void setString​(int parameterIndex,
                                 java.lang.String x,
                                 int oid)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setBytes

        public void setBytes​(int parameterIndex,
                             byte[] x)
                      throws java.sql.SQLException
        Specified by:
        setBytes in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setByteStreamWriter

        private void setByteStreamWriter​(int parameterIndex,
                                         ByteStreamWriter x)
                                  throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setDate

        public void setDate​(int parameterIndex,
                            java.sql.Date x)
                     throws java.sql.SQLException
        Specified by:
        setDate in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setTime

        public void setTime​(int parameterIndex,
                            java.sql.Time x)
                     throws java.sql.SQLException
        Specified by:
        setTime in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setTimestamp

        public void setTimestamp​(int parameterIndex,
                                 java.sql.Timestamp x)
                          throws java.sql.SQLException
        Specified by:
        setTimestamp in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setCharacterStreamPost71

        private void setCharacterStreamPost71​(int parameterIndex,
                                              java.io.InputStream x,
                                              int length,
                                              java.lang.String encoding)
                                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setAsciiStream

        public void setAsciiStream​(int parameterIndex,
                                   java.io.InputStream x,
                                   int length)
                            throws java.sql.SQLException
        Specified by:
        setAsciiStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setUnicodeStream

        public void setUnicodeStream​(int parameterIndex,
                                     java.io.InputStream x,
                                     int length)
                              throws java.sql.SQLException
        Specified by:
        setUnicodeStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setBinaryStream

        public void setBinaryStream​(int parameterIndex,
                                    java.io.InputStream x,
                                    int length)
                             throws java.sql.SQLException
        Specified by:
        setBinaryStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • clearParameters

        public void clearParameters()
                             throws java.sql.SQLException
        Specified by:
        clearParameters in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setPGobject

        private void setPGobject​(int parameterIndex,
                                 PGobject x)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setMap

        private void setMap​(int parameterIndex,
                            java.util.Map<?,​?> x)
                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setNumber

        private void setNumber​(int parameterIndex,
                               java.lang.Number x)
                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setObject

        public void setObject​(int parameterIndex,
                              java.lang.Object in,
                              int targetSqlType,
                              int scale)
                       throws java.sql.SQLException
        Specified by:
        setObject in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • getArrayType

        private java.lang.Class<?> getArrayType​(java.lang.Class<?> type)
      • setObjectArray

        private <A> void setObjectArray​(int parameterIndex,
                                        A in)
                                 throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • asString

        private static java.lang.String asString​(java.sql.Clob in)
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • castToInt

        private static int castToInt​(java.lang.Object in)
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • castToShort

        private static short castToShort​(java.lang.Object in)
                                  throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • castToLong

        private static long castToLong​(java.lang.Object in)
                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • castToFloat

        private static float castToFloat​(java.lang.Object in)
                                  throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • castToDouble

        private static double castToDouble​(java.lang.Object in)
                                    throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • castToBigDecimal

        private static java.math.BigDecimal castToBigDecimal​(java.lang.Object in,
                                                             int scale)
                                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • castToString

        private static java.lang.String castToString​(java.lang.Object in)
                                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • cannotCastException

        private static PSQLException cannotCastException​(java.lang.String fromType,
                                                         java.lang.String toType)
      • cannotCastException

        private static PSQLException cannotCastException​(java.lang.String fromType,
                                                         java.lang.String toType,
                                                         java.lang.Exception cause)
      • setObject

        public void setObject​(int parameterIndex,
                              java.lang.Object x,
                              int targetSqlType)
                       throws java.sql.SQLException
        Specified by:
        setObject in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setObject

        public void setObject​(int parameterIndex,
                              java.lang.Object x)
                       throws java.sql.SQLException
        Specified by:
        setObject in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • toString

        public java.lang.String toString()
        Returns the SQL statement with the current template values substituted.
        Overrides:
        toString in class java.lang.Object
        Returns:
        SQL statement with the current template values substituted
      • bindLiteral

        protected void bindLiteral​(int paramIndex,
                                   java.lang.String s,
                                   int oid)
                            throws java.sql.SQLException
        Note if s is a String it should be escaped by the caller to avoid SQL injection attacks. It is not done here for efficiency reasons as most calls to this method do not require escaping as the source of the string is known safe (i.e. Integer.toString())
        Parameters:
        paramIndex - parameter index
        s - value (the value should already be escaped)
        oid - type oid
        Throws:
        java.sql.SQLException - if something goes wrong
      • bindBytes

        protected void bindBytes​(int paramIndex,
                                 byte[] b,
                                 int oid)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • bindString

        private void bindString​(int paramIndex,
                                java.lang.String s,
                                int oid)
                         throws java.sql.SQLException
        This version is for values that should turn into strings e.g. setString directly calls bindString with no escaping; the per-protocol ParameterList does escaping as needed.
        Parameters:
        paramIndex - parameter index
        s - value
        oid - type oid
        Throws:
        java.sql.SQLException - if something goes wrong
      • isUseServerPrepare

        public boolean isUseServerPrepare()
        Description copied from interface: PGStatement
        Checks if this statement will be executed as a server-prepared statement. A return value of true indicates that the next execution of the statement will be done as a server-prepared statement, assuming the underlying protocol supports it.
        Specified by:
        isUseServerPrepare in interface PGStatement
        Overrides:
        isUseServerPrepare in class PgStatement
        Returns:
        true if the next reuse of this statement will use a server-prepared statement
      • addBatch

        public void addBatch​(java.lang.String sql)
                      throws java.sql.SQLException
        Specified by:
        addBatch in interface java.sql.Statement
        Overrides:
        addBatch in class PgStatement
        Throws:
        java.sql.SQLException
      • addBatch

        public void addBatch()
                      throws java.sql.SQLException
        Specified by:
        addBatch in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • getMetaData

        public java.sql.ResultSetMetaData getMetaData()
                                               throws java.sql.SQLException
        Specified by:
        getMetaData in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setArray

        public void setArray​(int i,
                             java.sql.Array x)
                      throws java.sql.SQLException
        Specified by:
        setArray in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • createBlob

        protected long createBlob​(int i,
                                  java.io.InputStream inputStream,
                                  long length)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setBlob

        public void setBlob​(int i,
                            java.sql.Blob x)
                     throws java.sql.SQLException
        Specified by:
        setBlob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • readerToString

        private java.lang.String readerToString​(java.io.Reader value,
                                                int maxLength)
                                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setCharacterStream

        public void setCharacterStream​(int i,
                                       java.io.Reader x,
                                       int length)
                                throws java.sql.SQLException
        Specified by:
        setCharacterStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setClob

        public void setClob​(int i,
                            java.sql.Clob x)
                     throws java.sql.SQLException
        Specified by:
        setClob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setNull

        public void setNull​(int parameterIndex,
                            int t,
                            java.lang.String typeName)
                     throws java.sql.SQLException
        Specified by:
        setNull in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setRef

        public void setRef​(int i,
                           java.sql.Ref x)
                    throws java.sql.SQLException
        Specified by:
        setRef in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setDate

        public void setDate​(int i,
                            java.sql.Date d,
                            java.util.Calendar cal)
                     throws java.sql.SQLException
        Specified by:
        setDate in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setTime

        public void setTime​(int i,
                            java.sql.Time t,
                            java.util.Calendar cal)
                     throws java.sql.SQLException
        Specified by:
        setTime in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setTimestamp

        public void setTimestamp​(int i,
                                 java.sql.Timestamp t,
                                 java.util.Calendar cal)
                          throws java.sql.SQLException
        Specified by:
        setTimestamp in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setDate

        private void setDate​(int i,
                             java.time.LocalDate localDate)
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setTime

        private void setTime​(int i,
                             java.time.LocalTime localTime)
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setTime

        private void setTime​(int i,
                             java.time.OffsetTime offsetTime)
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setTimestamp

        private void setTimestamp​(int i,
                                  java.time.LocalDateTime localDateTime)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setTimestamp

        private void setTimestamp​(int i,
                                  java.time.OffsetDateTime offsetDateTime)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • createParameterMetaData

        public java.sql.ParameterMetaData createParameterMetaData​(BaseConnection conn,
                                                                  int[] oids)
                                                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setObject

        public void setObject​(int parameterIndex,
                              java.lang.Object x,
                              java.sql.SQLType targetSqlType,
                              int scaleOrLength)
                       throws java.sql.SQLException
        Specified by:
        setObject in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setObject

        public void setObject​(int parameterIndex,
                              java.lang.Object x,
                              java.sql.SQLType targetSqlType)
                       throws java.sql.SQLException
        Specified by:
        setObject in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setRowId

        public void setRowId​(int parameterIndex,
                             java.sql.RowId x)
                      throws java.sql.SQLException
        Specified by:
        setRowId in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setNString

        public void setNString​(int parameterIndex,
                               java.lang.String value)
                        throws java.sql.SQLException
        Specified by:
        setNString in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setNCharacterStream

        public void setNCharacterStream​(int parameterIndex,
                                        java.io.Reader value,
                                        long length)
                                 throws java.sql.SQLException
        Specified by:
        setNCharacterStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setNCharacterStream

        public void setNCharacterStream​(int parameterIndex,
                                        java.io.Reader value)
                                 throws java.sql.SQLException
        Specified by:
        setNCharacterStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setCharacterStream

        public void setCharacterStream​(int parameterIndex,
                                       java.io.Reader value,
                                       long length)
                                throws java.sql.SQLException
        Specified by:
        setCharacterStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setCharacterStream

        public void setCharacterStream​(int parameterIndex,
                                       java.io.Reader value)
                                throws java.sql.SQLException
        Specified by:
        setCharacterStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setBinaryStream

        public void setBinaryStream​(int parameterIndex,
                                    java.io.InputStream value,
                                    long length)
                             throws java.sql.SQLException
        Specified by:
        setBinaryStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setBinaryStream

        public void setBinaryStream​(int parameterIndex,
                                    java.io.InputStream value)
                             throws java.sql.SQLException
        Specified by:
        setBinaryStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setAsciiStream

        public void setAsciiStream​(int parameterIndex,
                                   java.io.InputStream value,
                                   long length)
                            throws java.sql.SQLException
        Specified by:
        setAsciiStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setAsciiStream

        public void setAsciiStream​(int parameterIndex,
                                   java.io.InputStream value)
                            throws java.sql.SQLException
        Specified by:
        setAsciiStream in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setNClob

        public void setNClob​(int parameterIndex,
                             java.sql.NClob value)
                      throws java.sql.SQLException
        Specified by:
        setNClob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setClob

        public void setClob​(int parameterIndex,
                            java.io.Reader reader,
                            long length)
                     throws java.sql.SQLException
        Specified by:
        setClob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setClob

        public void setClob​(int parameterIndex,
                            java.io.Reader reader)
                     throws java.sql.SQLException
        Specified by:
        setClob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setBlob

        public void setBlob​(int parameterIndex,
                            java.io.InputStream inputStream,
                            long length)
                     throws java.sql.SQLException
        Specified by:
        setBlob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setBlob

        public void setBlob​(int parameterIndex,
                            java.io.InputStream inputStream)
                     throws java.sql.SQLException
        Specified by:
        setBlob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setNClob

        public void setNClob​(int parameterIndex,
                             java.io.Reader reader,
                             long length)
                      throws java.sql.SQLException
        Specified by:
        setNClob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setNClob

        public void setNClob​(int parameterIndex,
                             java.io.Reader reader)
                      throws java.sql.SQLException
        Specified by:
        setNClob in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setSQLXML

        public void setSQLXML​(int parameterIndex,
                              java.sql.SQLXML xmlObject)
                       throws java.sql.SQLException
        Specified by:
        setSQLXML in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • setUuid

        private void setUuid​(int parameterIndex,
                             java.util.UUID uuid)
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setURL

        public void setURL​(int parameterIndex,
                           java.net.URL x)
                    throws java.sql.SQLException
        Specified by:
        setURL in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • executeBatch

        public int[] executeBatch()
                           throws java.sql.SQLException
        Specified by:
        executeBatch in interface java.sql.Statement
        Overrides:
        executeBatch in class PgStatement
        Throws:
        java.sql.SQLException
      • getDefaultCalendar

        private java.util.Calendar getDefaultCalendar()
      • getParameterMetaData

        public java.sql.ParameterMetaData getParameterMetaData()
                                                        throws java.sql.SQLException
        Specified by:
        getParameterMetaData in interface java.sql.PreparedStatement
        Throws:
        java.sql.SQLException
      • transformQueriesAndParameters

        protected void transformQueriesAndParameters()
                                              throws java.sql.SQLException
        Overrides:
        transformQueriesAndParameters in class PgStatement
        Throws:
        java.sql.SQLException