pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Kim Ho <kho@redhat.com>
To: pgsql-jdbc-list <pgsql-jdbc@postgresql.org>
Subject: Re: Prepared Statements
Date: 18 Jul 2003 15:08:06 -0400
Message-ID: <1058555286.20165.197.camel@topanga.toronto.redhat.com> (raw )
In-Reply-To: <F17255C2B596D3119A5600508B44FA68052EB869@courier.maplesoft.on.ca >
References: <F17255C2B596D3119A5600508B44FA68052EB869@courier.maplesoft.on.ca >
Here is the patch that only parses once. =/ Thanks Dmitry.
I have to say that I agree with Darin. If it's just an exploit, it
doesn't really belong in the JDBC driver.
Cheers,
Kim
Attachments:
setObjectNumbers.diff (text/plain, 7.0K) download
? temp.diff
Index: org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java,v
retrieving revision 1.13
diff -c -p -r1.13 AbstractJdbc1ResultSet.java
*** org/postgresql/jdbc1/AbstractJdbc1ResultSet.java 30 Jun 2003 21:10:55 -0000 1.13
--- org/postgresql/jdbc1/AbstractJdbc1ResultSet.java 18 Jul 2003 18:33:56 -0000
*************** public abstract class AbstractJdbc1Resul
*** 805,811 ****
try
{
s = s.trim();
! return Integer.parseInt(s);
}
catch (NumberFormatException e)
{
--- 805,811 ----
try
{
s = s.trim();
! return Float.valueOf(s).intValue();
}
catch (NumberFormatException e)
{
*************** public abstract class AbstractJdbc1Resul
*** 822,828 ****
try
{
s = s.trim();
! return Long.parseLong(s);
}
catch (NumberFormatException e)
{
--- 822,828 ----
try
{
s = s.trim();
! return Double.valueOf(s).longValue();
}
catch (NumberFormatException e)
{
Index: org/postgresql/jdbc1/AbstractJdbc1Statement.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v
retrieving revision 1.27
diff -c -p -r1.27 AbstractJdbc1Statement.java
*** org/postgresql/jdbc1/AbstractJdbc1Statement.java 9 Jul 2003 05:12:04 -0000 1.27
--- org/postgresql/jdbc1/AbstractJdbc1Statement.java 18 Jul 2003 18:33:58 -0000
*************** public abstract class AbstractJdbc1State
*** 920,926 ****
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! bind(parameterIndex, Integer.toString(x), PG_TEXT);
}
/*
--- 920,926 ----
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! bind(parameterIndex, "'" + Integer.toString(x) + "'", PG_TEXT);
}
/*
*************** public abstract class AbstractJdbc1State
*** 933,939 ****
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! bind(parameterIndex, Integer.toString(x), PG_INT2);
}
/*
--- 933,939 ----
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! bind(parameterIndex, "'" + Integer.toString(x) + "'" , PG_INT2);
}
/*
*************** public abstract class AbstractJdbc1State
*** 946,952 ****
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! bind(parameterIndex, Integer.toString(x), PG_INTEGER);
}
/*
--- 946,952 ----
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! bind(parameterIndex, "'" + Integer.toString(x) + "'", PG_INTEGER);
}
/*
*************** public abstract class AbstractJdbc1State
*** 959,965 ****
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! bind(parameterIndex, Long.toString(x), PG_INT8);
}
/*
--- 959,965 ----
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! bind(parameterIndex, "'" + Long.toString(x) + "'", PG_INT8);
}
/*
*************** public abstract class AbstractJdbc1State
*** 972,978 ****
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! bind(parameterIndex, Float.toString(x), PG_FLOAT);
}
/*
--- 972,978 ----
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! bind(parameterIndex, "'" + Float.toString(x) + "'", PG_FLOAT);
}
/*
*************** public abstract class AbstractJdbc1State
*** 985,991 ****
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! bind(parameterIndex, Double.toString(x), PG_DOUBLE);
}
/*
--- 985,991 ----
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! bind(parameterIndex, "'" + Double.toString(x) + "'", PG_DOUBLE);
}
/*
*************** public abstract class AbstractJdbc1State
*** 1003,1009 ****
setNull(parameterIndex, Types.DECIMAL);
else
{
! bind(parameterIndex, x.toString(), PG_NUMERIC);
}
}
--- 1003,1009 ----
setNull(parameterIndex, Types.DECIMAL);
else
{
! bind(parameterIndex, "'" + x.toString() + "'", PG_NUMERIC);
}
}
*************** public abstract class AbstractJdbc1State
*** 1464,1486 ****
switch (targetSqlType)
{
case Types.INTEGER:
- if (x instanceof Boolean)
- bind(parameterIndex,((Boolean)x).booleanValue() ? "1" :"0", PG_BOOLEAN);
- else
- bind(parameterIndex, x.toString(), PG_INTEGER);
- break;
case Types.TINYINT:
case Types.SMALLINT:
case Types.BIGINT:
case Types.REAL:
case Types.FLOAT:
case Types.DOUBLE:
case Types.DECIMAL:
case Types.NUMERIC:
! if (x instanceof Boolean)
! bind(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0", PG_BOOLEAN);
! else
! bind(parameterIndex, x.toString(), PG_NUMERIC);
break;
case Types.CHAR:
case Types.VARCHAR:
--- 1464,1482 ----
switch (targetSqlType)
{
case Types.INTEGER:
case Types.TINYINT:
case Types.SMALLINT:
+ bindNumber(parameterIndex, x, Types.INTEGER);
+ break;
case Types.BIGINT:
+ bindNumber(parameterIndex, x, Types.BIGINT);
+ break;
case Types.REAL:
case Types.FLOAT:
case Types.DOUBLE:
case Types.DECIMAL:
case Types.NUMERIC:
! bindNumber(parameterIndex,x,Types.NUMERIC);
break;
case Types.CHAR:
case Types.VARCHAR:
*************** public abstract class AbstractJdbc1State
*** 2026,2033 ****
if (parameterIndex != 1)
throw new PSQLException("postgresql.call.noinout");
}
!
public void setUseServerPrepare(boolean flag) throws SQLException {
//Server side prepared statements were introduced in 7.3
--- 2022,2060 ----
if (parameterIndex != 1)
throw new PSQLException("postgresql.call.noinout");
}
+
+ private void bindNumber(int parameterIndex, Object x, int type) throws SQLException
+ {
+ String pgtype = PG_NUMERIC;
+ if (x instanceof Boolean)
+ bind(parameterIndex,((Boolean)x).booleanValue() ? "'1'" :"'0'", PG_BOOLEAN);
+ else
+ {
+ try
+ {
+ switch (type)
+ {
+ case Types.BIGINT:
+ x = String.valueOf(Double.valueOf(x.toString()).longValue());
+ pgtype = PG_INT8;
+ break;
+ case Types.INTEGER:
+ x = String.valueOf(Float.valueOf(x.toString()).intValue());
+ pgtype = PG_INTEGER;
+ break;
+ default:
+ Double.valueOf(x.toString());
+ break;
+ }
+ bind(parameterIndex, "'"+x.toString()+"'", pgtype);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new PSQLException("postgresql.bad.double", x.toString());
+ }
+ }
! }
public void setUseServerPrepare(boolean flag) throws SQLException {
//Server side prepared statements were introduced in 7.3
view thread (105+ messages) latest in thread
Message-ID: <1058555286.20165.197.camel@topanga.toronto.redhat.com>
Permalink: ../1058555286.20165.197.camel@topanga.toronto.redhat.com/
Also on: postgresql.org/message-id/1058555286.20165.197.camel@topanga.toronto.redhat.com
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: kho@redhat.com
Subject: Re: Prepared Statements
In-Reply-To: <1058555286.20165.197.camel@topanga.toronto.redhat.com>
References: <F17255C2B596D3119A5600508B44FA68052EB869@courier.maplesoft.on.ca> <1058555286.20165.197.camel@topanga.toronto.redhat.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox