summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/postgresql
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/jdbc/postgresql')
-rw-r--r--src/interfaces/jdbc/postgresql/Connection.java27
-rw-r--r--src/interfaces/jdbc/postgresql/Driver.java24
-rw-r--r--src/interfaces/jdbc/postgresql/PreparedStatement.java10
-rw-r--r--src/interfaces/jdbc/postgresql/ResultSet.java27
-rw-r--r--src/interfaces/jdbc/postgresql/ResultSetMetaData.java8
5 files changed, 59 insertions, 37 deletions
diff --git a/src/interfaces/jdbc/postgresql/Connection.java b/src/interfaces/jdbc/postgresql/Connection.java
index e79d1fe953..09344e1fe0 100644
--- a/src/interfaces/jdbc/postgresql/Connection.java
+++ b/src/interfaces/jdbc/postgresql/Connection.java
@@ -36,15 +36,20 @@ public class Connection implements java.sql.Connection
private String PG_PASSWORD;
private String PG_DATABASE;
private boolean PG_STATUS;
- private boolean PG_AUTH; // true, then password auth used
public boolean CONNECTION_OK = true;
public boolean CONNECTION_BAD = false;
+ private static final int STARTUP_LEN = 288; // Length of a startup packet
+
+ // These are defined in src/include/libpq/pqcomm.h
private int STARTUP_CODE = STARTUP_USER;
private static final int STARTUP_USER = 7; // User auth
+ private static final int STARTUP_KRB4 = 10; // Kerberos 4 (unused)
+ private static final int STARTUP_KRB5 = 11; // Kerberos 5 (unused)
+ private static final int STARTUP_HBA = 12; // Host Based
+ private static final int STARTUP_NONE = 13; // Unauthenticated (unused)
private static final int STARTUP_PASS = 14; // Password auth
- private static final int STARTUP_LEN = 288; // Length of a startup packet
private boolean autoCommit = true;
private boolean readOnly = false;
@@ -84,10 +89,22 @@ public class Connection implements java.sql.Connection
PG_HOST = new String(host);
PG_STATUS = CONNECTION_BAD;
- if(info.getProperty("auth") != null) {
- PG_AUTH=true;
+ // This handles the auth property. Any value begining with p enables
+ // password authentication, while anything begining with i enables
+ // ident (RFC 1413) authentication. Any other values default to trust.
+ //
+ // Also, the postgresql.auth system property can be used to change the
+ // local default, if the auth property is not present.
+ //
+ String auth = info.getProperty("auth",System.getProperty("postgresql.auth","trust")).toLowerCase();
+ if(auth.startsWith("p")) {
+ // Password authentication
STARTUP_CODE=STARTUP_PASS;
+ } else if(auth.startsWith("i")) {
+ // Ident (RFC 1413) authentication
+ STARTUP_CODE=STARTUP_HBA;
} else {
+ // Anything else defaults to trust authentication
STARTUP_CODE=STARTUP_USER;
}
@@ -107,7 +124,7 @@ public class Connection implements java.sql.Connection
pg_stream.Send(PG_USER.getBytes(), len);
// Send the password packet if required
- if(PG_AUTH) {
+ if(STARTUP_CODE == STARTUP_PASS) {
len=STARTUP_LEN;
pg_stream.SendInteger(len, 4); len -= 4;
pg_stream.SendInteger(STARTUP_PASS, 4); len -= 4;
diff --git a/src/interfaces/jdbc/postgresql/Driver.java b/src/interfaces/jdbc/postgresql/Driver.java
index 674c96fc66..7b711455ad 100644
--- a/src/interfaces/jdbc/postgresql/Driver.java
+++ b/src/interfaces/jdbc/postgresql/Driver.java
@@ -27,7 +27,7 @@ public class Driver implements java.sql.Driver
// These should be in sync with the backend that the driver was
// distributed with
static final int MAJORVERSION = 6;
- static final int MINORVERSION = 2;
+ static final int MINORVERSION = 3;
static
{
@@ -125,8 +125,22 @@ public class Driver implements java.sql.Driver
*/
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException
{
- return null; // We don't need anything except
- // the username, which is a default
+ Properties p = parseURL(url,info);
+
+ // naughty, but its best for speed. If anyone adds a property here, then
+ // this _MUST_ be increased to accomodate them.
+ DriverPropertyInfo d,dpi[] = new DriverPropertyInfo[1];
+ int i=0;
+
+ dpi[i++] = d = new DriverPropertyInfo("auth",p.getProperty("auth","default"));
+ d.description = "determines if password authentication is used";
+ d.choices = new String[4];
+ d.choices[0]="default"; // Get value from postgresql.auth property, defaults to trust
+ d.choices[1]="trust"; // No password authentication
+ d.choices[2]="password"; // Password authentication
+ d.choices[3]="ident"; // Ident (RFC 1413) protocol
+
+ return dpi;
}
/**
@@ -168,6 +182,10 @@ public class Driver implements java.sql.Driver
/**
* Constructs a new DriverURL, splitting the specified URL into its
* component parts
+ * @param url JDBC URL to parse
+ * @param defaults Default properties
+ * @return Properties with elements added from the url
+ * @throws SQLException
*/
Properties parseURL(String url,Properties defaults) throws SQLException
{
diff --git a/src/interfaces/jdbc/postgresql/PreparedStatement.java b/src/interfaces/jdbc/postgresql/PreparedStatement.java
index 98fdb6fb10..479f86eee9 100644
--- a/src/interfaces/jdbc/postgresql/PreparedStatement.java
+++ b/src/interfaces/jdbc/postgresql/PreparedStatement.java
@@ -7,8 +7,8 @@ import java.text.*;
import java.util.*;
/**
- * @version 1.0 15-APR-1997
- * @author <A HREF="mailto:adrian@hottub.org">Adrian Hall</A>
+ * @version 6.3 15-APR-1997
+ * @author <A HREF="mailto:adrian@hottub.org">Adrian Hall</A><A HREF="mailto:petermount@earthling.net">Peter Mount</A>
*
* A SQL Statement is pre-compiled and stored in a PreparedStatement object.
* This object can then be used to efficiently execute this statement multiple
@@ -294,9 +294,9 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
{
- DateFormat df = DateFormat.getDateInstance();
-
- set(parameterIndex, "'" + df.format(x) + "'");
+ SimpleDateFormat df = new SimpleDateFormat(connection.europeanDates?"''dd-MM-yyyy''":"''MM-dd-yyyy''");
+
+ set(parameterIndex, df.format(x));
}
/**
diff --git a/src/interfaces/jdbc/postgresql/ResultSet.java b/src/interfaces/jdbc/postgresql/ResultSet.java
index b6edf18974..017b0ad292 100644
--- a/src/interfaces/jdbc/postgresql/ResultSet.java
+++ b/src/interfaces/jdbc/postgresql/ResultSet.java
@@ -374,27 +374,12 @@ public class ResultSet implements java.sql.ResultSet
public java.sql.Date getDate(int columnIndex) throws SQLException
{
String s = getString(columnIndex);
-
- if (s != null)
- {
- try {
- if (s.length() != 10)
- throw new NumberFormatException("Wrong Length!");
- int mon = Integer.parseInt(s.substring(0,2));
- int day = Integer.parseInt(s.substring(3,5));
- int yr = Integer.parseInt(s.substring(6));
- if(connection.europeanDates) {
- // We europeans prefer dd mm yyyy
- int t = mon;
- mon = day;
- day = t;
- }
- return new java.sql.Date(yr - 1900, mon -1, day);
- } catch (NumberFormatException e) {
- throw new SQLException("Bad Date Form: " + s);
- }
- }
- return null; // SQL NULL
+ SimpleDateFormat df = new SimpleDateFormat(connection.europeanDates?"dd-MM-yyyy":"MM-dd-yyyy");
+ try {
+ return new java.sql.Date(df.parse(s).getTime());
+ } catch (ParseException e) {
+ throw new SQLException("Bad Date Format: at " + e.getErrorOffset() + " in " + s);
+ }
}
/**
diff --git a/src/interfaces/jdbc/postgresql/ResultSetMetaData.java b/src/interfaces/jdbc/postgresql/ResultSetMetaData.java
index f058e2e0ba..7d2c1ceaf3 100644
--- a/src/interfaces/jdbc/postgresql/ResultSetMetaData.java
+++ b/src/interfaces/jdbc/postgresql/ResultSetMetaData.java
@@ -190,9 +190,11 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
for (i = 0 ; i < rows.size(); ++i)
{
byte[][] x = (byte[][])(rows.elementAt(i));
- int xl = x[column - 1].length;
- if (xl > max)
- max = xl;
+ if(x[column-1]!=null) {
+ int xl = x[column - 1].length;
+ if (xl > max)
+ max = xl;
+ }
}
return max;
}