abstractjdbc1statement.java
来自「PostgreSQL7.4.6 for Linux」· Java 代码 · 共 2,147 行 · 第 1/5 页
JAVA
2,147 行
newsql.append(c); break; case IN_STRING: if (c == '\'') // end of string? state = IN_SQLCODE; else if (c == '\\') // a backslash? state = BACKSLASH; newsql.append(c); break; case BACKSLASH: state = IN_STRING; newsql.append(c); break; case ESC_TIMEDATE: if (c == '}') state = IN_SQLCODE; // end of escape code. else newsql.append(c); break; } // end switch } return newsql.toString(); } else { return p_sql; } } /* * * The following methods are postgres extensions and are defined * in the interface BaseStatement * */ /* * Returns the Last inserted/updated oid. Deprecated in 7.2 because * range of OID values is greater than a java signed int. * @deprecated Replaced by getLastOID in 7.2 */ public int getInsertedOID() throws SQLException { if (result == null) return 0; return (int) result.getLastOID(); } /* * Returns the Last inserted/updated oid. * @return OID of last insert * @since 7.2 */ public long getLastOID() throws SQLException { if (result == null) return 0; return result.getLastOID(); } /* * Set a parameter to SQL NULL * * <p><B>Note:</B> You must specify the parameters SQL type (although * PostgreSQL ignores it) * * @param parameterIndex the first parameter is 1, etc... * @param sqlType the SQL type code defined in java.sql.Types * @exception SQLException if a database access error occurs */ public void setNull(int parameterIndex, int sqlType) throws SQLException { String l_pgType; switch (sqlType) { case Types.INTEGER: l_pgType = PG_INTEGER; break; case Types.TINYINT: case Types.SMALLINT: l_pgType = PG_INT2; break; case Types.BIGINT: l_pgType = PG_INT8; break; case Types.REAL: case Types.FLOAT: l_pgType = PG_FLOAT; break; case Types.DOUBLE: l_pgType = PG_DOUBLE; break; case Types.DECIMAL: case Types.NUMERIC: l_pgType = PG_NUMERIC; break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: l_pgType = PG_TEXT; break; case Types.DATE: l_pgType = PG_DATE; break; case Types.TIME: l_pgType = PG_TIME; break; case Types.TIMESTAMP: l_pgType = PG_TIMESTAMPTZ; break; case Types.BIT: l_pgType = PG_BOOLEAN; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: l_pgType = PG_BYTEA; break; case Types.OTHER: l_pgType = PG_TEXT; break; default: l_pgType = PG_TEXT; } bind(parameterIndex, "null", l_pgType); } /* * Set a parameter to a Java boolean value. The driver converts this * to a SQL BIT value when it sends it to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setBoolean(int parameterIndex, boolean x) throws SQLException { bind(parameterIndex, x ? "'1'" : "'0'", PG_BOOLEAN); } /* * Set a parameter to a Java byte value. The driver converts this to * a SQL TINYINT value when it sends it to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setByte(int parameterIndex, byte x) throws SQLException { bind(parameterIndex, Integer.toString(x), PG_INT2); } /* * Set a parameter to a Java short value. The driver converts this * to a SQL SMALLINT value when it sends it to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setShort(int parameterIndex, short x) throws SQLException { bind(parameterIndex, Integer.toString(x), PG_INT2); } /* * Set a parameter to a Java int value. The driver converts this to * a SQL INTEGER value when it sends it to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setInt(int parameterIndex, int x) throws SQLException { bind(parameterIndex, Integer.toString(x), PG_INTEGER); } /* * Set a parameter to a Java long value. The driver converts this to * a SQL BIGINT value when it sends it to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setLong(int parameterIndex, long x) throws SQLException { bind(parameterIndex, Long.toString(x), PG_INT8); } /* * Set a parameter to a Java float value. The driver converts this * to a SQL FLOAT value when it sends it to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setFloat(int parameterIndex, float x) throws SQLException { bind(parameterIndex, Float.toString(x), PG_FLOAT); } /* * Set a parameter to a Java double value. The driver converts this * to a SQL DOUBLE value when it sends it to the database * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setDouble(int parameterIndex, double x) throws SQLException { bind(parameterIndex, Double.toString(x), PG_DOUBLE); } /* * Set a parameter to a java.lang.BigDecimal value. The driver * converts this to a SQL NUMERIC value when it sends it to the * database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { if (x == null) setNull(parameterIndex, Types.DECIMAL); else { bind(parameterIndex, x.toString(), PG_NUMERIC); } } /* * Set a parameter to a Java String value. The driver converts this * to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments * size relative to the driver's limits on VARCHARs) when it sends it * to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setString(int parameterIndex, String x) throws SQLException { setString(parameterIndex, x, PG_TEXT); } public void setString(int parameterIndex, String x, String type) throws SQLException { // if the passed string is null, then set this column to null if (x == null) setNull(parameterIndex, Types.VARCHAR); else { // use the shared buffer object. Should never clash but this makes // us thread safe! synchronized (sbuf) { sbuf.setLength(0); sbuf.ensureCapacity(2 + x.length() + (int)(x.length() / 10)); sbuf.append('\''); escapeString(x, sbuf); sbuf.append('\''); bind(parameterIndex, sbuf.toString(), type); } } } private void escapeString(String p_input, StringBuffer p_output) { for (int i = 0 ; i < p_input.length() ; ++i) { char c = p_input.charAt(i); switch (c) { case '\\': case '\'': p_output.append('\\'); p_output.append(c); break; case '\0': throw new IllegalArgumentException("\\0 not allowed"); default: p_output.append(c); } } } /* * Set a parameter to a Java array of bytes. The driver converts this * to a SQL VARBINARY or LONGVARBINARY (depending on the argument's * size relative to the driver's limits on VARBINARYs) when it sends * it to the database. * * <p>Implementation note: * <br>With org.postgresql, this creates a large object, and stores the * objects oid in this column. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setBytes(int parameterIndex, byte x[]) throws SQLException { if (connection.haveMinimumCompatibleVersion("7.2")) { //Version 7.2 supports the bytea datatype for byte arrays if (null == x) { setNull(parameterIndex, Types.VARBINARY); } else { setString(parameterIndex, PGbytea.toPGString(x), PG_BYTEA); } } else { //Version 7.1 and earlier support done as LargeObjects LargeObjectManager lom = connection.getLargeObjectAPI(); int oid = lom.create(); LargeObject lob = lom.open(oid); lob.write(x); lob.close(); setInt(parameterIndex, oid); } } /* * Set a parameter to a java.sql.Date value. The driver converts this * to a SQL DATE value when it sends it to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setDate(int parameterIndex, java.sql.Date x) throws SQLException { if (null == x) { setNull(parameterIndex, Types.DATE); } else { bind(parameterIndex, "'" + x.toString() + "'", PG_DATE); } } /* * Set a parameter to a java.sql.Time value. The driver converts * this to a SQL TIME value when it sends it to the database. * * @param parameterIndex the first parameter is 1...)); * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setTime(int parameterIndex, Time x) throws SQLException { if (null == x) { setNull(parameterIndex, Types.TIME); } else { bind(parameterIndex, "'" + x.toString() + "'", PG_TIME); } } /* * Set a parameter to a java.sql.Timestamp value. The driver converts * this to a SQL TIMESTAMP value when it sends it to the database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { if (null == x) { setNull(parameterIndex, Types.TIMESTAMP); } else { // Use the shared StringBuffer synchronized (sbuf) { sbuf.setLength(0); sbuf.ensureCapacity(32); sbuf.append("'"); //format the timestamp //we do our own formating so that we can get a format //that works with both timestamp with time zone and //timestamp without time zone datatypes. //The format is '2002-01-01 23:59:59.123456-0130' //we need to include the local time and timezone offset //so that timestamp without time zone works correctly int l_year = x.getYear() + 1900; // always use four digits for the year so very // early years, like 2, don't get misinterpreted int l_yearlen = String.valueOf(l_year).length(); for (int i=4; i>l_yearlen; i--) { sbuf.append("0"); } sbuf.append(l_year); sbuf.append('-'); int l_month = x.getMonth() + 1; if (l_month < 10) sbuf.append('0'); sbuf.append(l_month); sbuf.append('-'); int l_day = x.getDate(); if (l_day < 10) sbuf.append('0'); sbuf.append(l_day); sbuf.append(' '); int l_hours = x.getHours();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?