Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf118c36

Browse files
author
Peter Mount
committed
Added an alternative constructor to PGSQLException so that debugging
some more osteric bugs is easier. If only 1 arg is supplied and it's of type Exception, then that Exception's stacktrace is now included.This was done as there's been a report of an unusual bug during connection.This will make this sort of bug hunting easier from now on.
1 parent97f447b commitf118c36

File tree

3 files changed

+71
-37
lines changed

3 files changed

+71
-37
lines changed

‎src/interfaces/jdbc/CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Thu Jan 25 09:11:00 GMT 2001 peter@retep.org.uk
2+
- Added an alternative constructor to PGSQLException so that debugging
3+
some more osteric bugs is easier. If only 1 arg is supplied and it's
4+
of type Exception, then that Exception's stacktrace is now included.
5+
16
Wed Jan 24 09:18:00 GMT 2001 peter@retep.org.uk
27
- Removed the 8k limit by setting it to 64k
38

‎src/interfaces/jdbc/org/postgresql/Driver.java.in

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import org.postgresql.util.PSQLException;
2424
* @see org.postgresql.Connection
2525
* @see java.sql.Driver
2626
*/
27-
public class Driver implements java.sql.Driver
27+
public class Driver implements java.sql.Driver
2828
{
29-
30-
static
29+
30+
static
3131
{
3232
try {
3333
// moved the registerDriver from the constructor to here
@@ -39,7 +39,7 @@ public class Driver implements java.sql.Driver
3939
e.printStackTrace();
4040
}
4141
}
42-
42+
4343
/**
4444
* Construct a new driver and register it with DriverManager
4545
*
@@ -54,7 +54,7 @@ public class Driver implements java.sql.Driver
5454
//} else {
5555
//connectClass = "postgresql.jdbc2.Connection";
5656
//}
57-
57+
5858
// Ok, when the above code was introduced in 6.5 it's intention was to allow
5959
// the driver to automatically detect which version of JDBC was being used
6060
// and to detect the version of the JVM accordingly.
@@ -71,7 +71,7 @@ public class Driver implements java.sql.Driver
7171
// For this to work, the Makefile creates a pseudo class which contains the class
7272
// name that will actually make the connection.
7373
}
74-
74+
7575
/**
7676
* Try to make a database connection to the given URL. The driver
7777
* should return "null" if it realizes it is the wrong kind of
@@ -85,12 +85,12 @@ public class Driver implements java.sql.Driver
8585
*
8686
* <p>The java.util.Properties argument can be used to pass arbitrary
8787
* string tag/value pairs as connection arguments. Normally, at least
88-
* "user" and "password" properties should be included in the
89-
* properties. In addition, the "charSet" property can be used to
90-
* set a character set encoding (e.g. "utf-8") other than the platform
91-
* default (typically Latin1). This is necessary in particular if storing
88+
* "user" and "password" properties should be included in the
89+
* properties. In addition, the "charSet" property can be used to
90+
* set a character set encoding (e.g. "utf-8") other than the platform
91+
* default (typically Latin1). This is necessary in particular if storing
9292
* multibyte characters in the database. For a list of supported
93-
* character encoding , see
93+
* character encoding , see
9494
* http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html
9595
* Note that you will probably want to have set up the Postgres database
9696
* itself to use the same encoding, with the "-E <encoding>" argument
@@ -112,7 +112,7 @@ public class Driver implements java.sql.Driver
112112
{
113113
if((props = parseURL(url,info))==null)
114114
return null;
115-
115+
116116
try {
117117
org.postgresql.Connection con = (org.postgresql.Connection)(Class.forName("@JDBCCONNECTCLASS@").newInstance());
118118
con.openConnection (host(), port(), props, database(), url, this);
@@ -127,7 +127,7 @@ public class Driver implements java.sql.Driver
127127
throw new PSQLException("postgresql.unusual",ex2);
128128
}
129129
}
130-
130+
131131
/**
132132
* Returns true if the driver thinks it can open a connection to the
133133
* given URL. Typically, drivers will return true if they understand
@@ -146,7 +146,7 @@ public class Driver implements java.sql.Driver
146146
return false;
147147
return true;
148148
}
149-
149+
150150
/**
151151
* The getPropertyInfo method is intended to allow a generic GUI
152152
* tool to discover what properties it should prompt a human for
@@ -168,23 +168,23 @@ public class Driver implements java.sql.Driver
168168
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException
169169
{
170170
Properties p = parseURL(url,info);
171-
171+
172172
// naughty, but its best for speed. If anyone adds a property here, then
173173
// this _MUST_ be increased to accomodate them.
174174
DriverPropertyInfo d,dpi[] = new DriverPropertyInfo[0];
175175
//int i=0;
176-
176+
177177
//dpi[i++] = d = new DriverPropertyInfo("auth",p.getProperty("auth","default"));
178178
//d.description = "determines if password authentication is used";
179179
//d.choices = new String[4];
180180
//d.choices[0]="default";// Get value from org.postgresql.auth property, defaults to trust
181181
//d.choices[1]="trust";// No password authentication
182182
//d.choices[2]="password";// Password authentication
183183
//d.choices[3]="ident";// Ident (RFC 1413) protocol
184-
184+
185185
return dpi;
186186
}
187-
187+
188188
/**
189189
* Gets the drivers major version number
190190
*
@@ -194,7 +194,7 @@ public class Driver implements java.sql.Driver
194194
{
195195
return @MAJORVERSION@;
196196
}
197-
197+
198198
/**
199199
* Get the drivers minor version number
200200
*
@@ -204,21 +204,21 @@ public class Driver implements java.sql.Driver
204204
{
205205
return @MINORVERSION@;
206206
}
207-
207+
208208
/**
209209
* Returns the VERSION variable from Makefile.global
210210
*/
211211
public static String getVersion()
212212
{
213213
return "@VERSION@";
214214
}
215-
215+
216216
/**
217217
* Report whether the driver is a genuine JDBC compliant driver. A
218218
* driver may only report "true" here if it passes the JDBC compliance
219219
* tests, otherwise it is required to return false. JDBC compliance
220220
* requires full support for the JDBC API and full support for SQL 92
221-
* Entry Level.
221+
* Entry Level.
222222
*
223223
* <p>For PostgreSQL, this is not yet possible, as we are not SQL92
224224
* compliant (yet).
@@ -227,11 +227,11 @@ public class Driver implements java.sql.Driver
227227
{
228228
return false;
229229
}
230-
230+
231231
private Properties props;
232-
232+
233233
static private String[] protocols = { "jdbc","postgresql" };
234-
234+
235235
/**
236236
* Constructs a new DriverURL, splitting the specified URL into its
237237
* component parts
@@ -246,17 +246,17 @@ public class Driver implements java.sql.Driver
246246
Properties urlProps = new Properties(defaults);
247247
String key = "";
248248
String value = "";
249-
249+
250250
StringTokenizer st = new StringTokenizer(url, ":/;=&?", true);
251251
for (int count = 0; (st.hasMoreTokens()); count++) {
252252
String token = st.nextToken();
253-
253+
254254
// PM June 29 1997
255255
// Added this, to help me understand how this works.
256256
// Unless you want each token to be processed, leave this commented out
257257
// but don't delete it.
258258
//DriverManager.println("wellFormedURL: state="+state+" count="+count+" token='"+token+"'");
259-
259+
260260
// PM Aug 2 1997 - Modified to allow multiple backends
261261
if (count <= 3) {
262262
if ((count % 2) == 1 && token.equals(":"))
@@ -273,7 +273,7 @@ public class Driver implements java.sql.Driver
273273
}
274274
}
275275
}
276-
276+
277277
if(found == false)
278278
return null;
279279
} else return null;
@@ -322,42 +322,42 @@ public class Driver implements java.sql.Driver
322322
}
323323
}
324324
}
325-
325+
326326
// PM June 29 1997
327327
// This now outputs the properties only if we are logging
328328
// PM Sep 13 1999 Commented out, as it throws a Deprecation warning
329329
// when compiled under JDK1.2.
330330
//if(DriverManager.getLogStream() != null)
331331
// urlProps.list(DriverManager.getLogStream());
332-
332+
333333
return urlProps;
334-
334+
335335
}
336-
336+
337337
/**
338338
* @return the hostname portion of the URL
339339
*/
340340
public String host()
341341
{
342342
return props.getProperty("PGHOST","localhost");
343343
}
344-
344+
345345
/**
346346
* @return the port number portion of the URL or -1 if no port was specified
347347
*/
348348
public int port()
349349
{
350350
return Integer.parseInt(props.getProperty("PGPORT","5432"));
351351
}
352-
352+
353353
/**
354354
* @return the database name of the URL
355355
*/
356356
public String database()
357357
{
358358
return props.getProperty("PGDBNAME");
359359
}
360-
360+
361361
/**
362362
* @return the value of any property specified in the URL or properties
363363
* passed to connect(), or null if not found.
@@ -366,7 +366,7 @@ public class Driver implements java.sql.Driver
366366
{
367367
return props.getProperty(name);
368368
}
369-
369+
370370
/**
371371
* This method was added in v6.5, and simply throws an SQLException
372372
* for an unimplemented method. I decided to do it this way while

‎src/interfaces/jdbc/org/postgresql/util/PSQLException.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packageorg.postgresql.util;
22

3+
importjava.io.*;
34
importjava.sql.*;
45
importjava.text.*;
56
importjava.util.*;
@@ -45,6 +46,34 @@ public PSQLException(String error,Object arg)
4546
translate(error,argv);
4647
}
4748

49+
/**
50+
* Helper version for 1 arg. This is used for debug purposes only with
51+
* some unusual Exception's. It allows the originiating Exceptions stack
52+
* trace to be returned.
53+
*/
54+
publicPSQLException(Stringerror,Exceptionex)
55+
{
56+
super();
57+
58+
Object[]argv =newObject[1];
59+
60+
try {
61+
ByteArrayOutputStreambaos =newByteArrayOutputStream();
62+
PrintWriterpw =newPrintWriter(baos);
63+
pw.println("Exception: "+ex.toString()+"\nStack Trace:\n");
64+
ex.printStackTrace(pw);
65+
pw.println("End of Stack Trace");
66+
pw.flush();
67+
argv[0] =baos.toString();
68+
pw.close();
69+
baos.close();
70+
}catch(Exceptionioe) {
71+
argv[0] =ex.toString()+"\nIO Error on stack trace generation! "+ioe.toString();
72+
}
73+
74+
translate(error,argv);
75+
}
76+
4877
/**
4978
* Helper version for 2 args
5079
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp