mirror of
https://github.com/postgres/postgres.git
synced 2025-07-11 10:01:57 +03:00
Minor bug fixes. Replaced DateStyle support with ISO.
This commit is contained in:
@ -10,7 +10,7 @@ import postgresql.largeobject.*;
|
||||
import postgresql.util.*;
|
||||
|
||||
/**
|
||||
* $Id: Connection.java,v 1.15 1999/04/11 18:03:00 peter Exp $
|
||||
* $Id: Connection.java,v 1.16 1999/05/17 22:43:23 peter Exp $
|
||||
*
|
||||
* This abstract class is used by postgresql.Driver to open either the JDBC1 or
|
||||
* JDBC2 versions of the Connection class.
|
||||
@ -67,38 +67,6 @@ public abstract class Connection
|
||||
// be across all connections, which could be to different backends.
|
||||
public Hashtable fieldCache = new Hashtable();
|
||||
|
||||
/**
|
||||
* This is the current date style of the backend
|
||||
*/
|
||||
public int currentDateStyle;
|
||||
|
||||
/**
|
||||
* This defines the formats for dates, according to the various date styles.
|
||||
*
|
||||
* <p>There are two strings for each entry. The first is the string to search
|
||||
* for in the datestyle message, and the second the format to use.
|
||||
*
|
||||
* <p>To add a new date style, work out the format. Then with psql running
|
||||
* in the date style you wish to add, type: show datestyle;
|
||||
*
|
||||
* <p>eg:
|
||||
* <br><pre>
|
||||
* => show datestyle;
|
||||
* NOTICE: Datestyle is SQL with European conventions
|
||||
* ^^^^^^^^^^^^^^^^^
|
||||
* </pre>The marked part of the string is the first string below. The second
|
||||
* is your format. If a style (like ISO) ignores the US/European variants,
|
||||
* then you can ignore the "with" part of the string.
|
||||
*/
|
||||
protected static final String dateStyles[] = {
|
||||
"Postgres with European", "dd-MM-yyyy",
|
||||
"Postgres with US", "MM-dd-yyyy",
|
||||
"ISO", "yyyy-MM-dd",
|
||||
"SQL with European", "dd/MM/yyyy",
|
||||
"SQL with US", "MM/dd/yyyy",
|
||||
"German", "dd.MM.yyyy"
|
||||
};
|
||||
|
||||
// Now handle notices as warnings, so things like "show" now work
|
||||
public SQLWarning firstWarning = null;
|
||||
|
||||
@ -242,22 +210,24 @@ public abstract class Connection
|
||||
throw new SQLException("Connection failed: " + e.toString());
|
||||
}
|
||||
|
||||
// Find out the date style by issuing the SQL: show datestyle
|
||||
// This actually issues a warning, and our own warning handling
|
||||
// code handles this itself.
|
||||
//
|
||||
// Also, this query replaced the NULL query issued to test the
|
||||
// connection.
|
||||
//
|
||||
// Originally we issued a SHOW DATESTYLE statement to find the databases default
|
||||
// datestyle. However, this caused some problems with timestamps, so in 6.5, we
|
||||
// went the way of ODBC, and set the connection to ISO.
|
||||
//
|
||||
// This may cause some clients to break when they assume anything other than ISO,
|
||||
// but then - they should be using the proper methods ;-)
|
||||
//
|
||||
//
|
||||
firstWarning = null;
|
||||
ExecSQL("show datestyle");
|
||||
|
||||
// Initialise object handling
|
||||
initObjectTypes();
|
||||
|
||||
// Mark the connection as ok, and cleanup
|
||||
|
||||
ExecSQL("set datestyle to 'ISO'");
|
||||
|
||||
// Initialise object handling
|
||||
initObjectTypes();
|
||||
|
||||
// Mark the connection as ok, and cleanup
|
||||
firstWarning = null;
|
||||
PG_STATUS = CONNECTION_OK;
|
||||
PG_STATUS = CONNECTION_OK;
|
||||
}
|
||||
|
||||
// These methods used to be in the main Connection implementation. As they
|
||||
@ -280,23 +250,18 @@ public abstract class Connection
|
||||
|
||||
// Now check for some specific messages
|
||||
|
||||
// This is obsolete in 6.5, but I've left it in here so if we need to use this
|
||||
// technique again, we'll know where to place it.
|
||||
//
|
||||
// This is generated by the SQL "show datestyle"
|
||||
if(msg.startsWith("NOTICE:") && msg.indexOf("DateStyle")>0) {
|
||||
// 13 is the length off "DateStyle is "
|
||||
msg = msg.substring(msg.indexOf("DateStyle is ")+13);
|
||||
|
||||
for(int i=0;i<dateStyles.length;i+=2)
|
||||
if(msg.startsWith(dateStyles[i]))
|
||||
currentDateStyle=i+1; // this is the index of the format
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the date format for the current date style of the backend
|
||||
*/
|
||||
public String getDateStyle()
|
||||
{
|
||||
return dateStyles[currentDateStyle];
|
||||
//if(msg.startsWith("NOTICE:") && msg.indexOf("DateStyle")>0) {
|
||||
//// 13 is the length off "DateStyle is "
|
||||
//msg = msg.substring(msg.indexOf("DateStyle is ")+13);
|
||||
//
|
||||
//for(int i=0;i<dateStyles.length;i+=2)
|
||||
//if(msg.startsWith(dateStyles[i]))
|
||||
//currentDateStyle=i+1; // this is the index of the format
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user