Thread: Driver.acceptsURL(String) not working correctly

Driver.acceptsURL(String) not working correctly

From
Garrick Dasbach
Date:
I'm currently writing an application which allows a user to enter a JDBC
connection string, and I make a connection using that string and the
drivers available to me.  While working with the Postgresql driver, our
primary database, I noticed that the acceptsURL() function of the JDBC
driver does not function correctly.

This is my test code:

Driver driver = // Driver Initialization
if(driver.acceptsURL("blah")){
    // report good news
} else {
    // fail to user
}

I should recieve a failure, resulting in a dialog popup to the user.
However acceptsURL returns true in this case.

I briefly looked at the source code for the JDBC driver, we are
currently using the 7.3 driver, and found the following in the
parseURL() function

boolean found = (count == 0) ? true : false;
for (int tmp = 0;tmp < protocols.length;tmp++)
{
    if (token.equals(protocols[tmp]))
    {
        // PM June 29 1997 Added this property to enable the driver
        // to handle multiple backend protocols.
        if (count == 2 && tmp > 0)
        {
            urlProps.put("Protocol", token);
            found = true;
        }
    }
}

if (found == false)
    return null;

Which in the case of my test code returns true.  Since there is only one
token "blah", thus making count == 0, and the token is not in the
protocol list, and thus never allows found to be false.

Just thought I'd bring that to your attention.

Garrick Dasbach
Software Development
Digonex Technologies, Inc.
garrick@digonex.com


Re: Driver.acceptsURL(String) not working correctly

From
Kris Jurka
Date:

On Fri, 22 Aug 2003, Garrick Dasbach wrote:

> I'm currently writing an application which allows a user to enter a JDBC
> connection string, and I make a connection using that string and the
> drivers available to me.  While working with the Postgresql driver, our
> primary database, I noticed that the acceptsURL() function of the JDBC
> driver does not function correctly.
>
> This is my test code:
>
> Driver driver = // Driver Initialization
> if(driver.acceptsURL("blah")){
>     // report good news
> } else {
>     // fail to user
> }
>
> I should recieve a failure, resulting in a dialog popup to the user.
> However acceptsURL returns true in this case.

Here is a patch that fixes this.  Also it corrects the comments describing
the protocol string to say jdbc:postgresql: instead of
jdbc:org.postgresql:

Also I've added this test case and another for IPv6 addresses to the
acceptsURL regression test.

Kris Jurka

Attachment

Re: Driver.acceptsURL(String) not working correctly

From
Dave Cramer
Date:
Patch applied

Thanks

Dave
On Mon, 2003-11-03 at 05:47, Kris Jurka wrote:
> On Fri, 22 Aug 2003, Garrick Dasbach wrote:
>
> > I'm currently writing an application which allows a user to enter a JDBC
> > connection string, and I make a connection using that string and the
> > drivers available to me.  While working with the Postgresql driver, our
> > primary database, I noticed that the acceptsURL() function of the JDBC
> > driver does not function correctly.
> >
> > This is my test code:
> >
> > Driver driver = // Driver Initialization
> > if(driver.acceptsURL("blah")){
> >     // report good news
> > } else {
> >     // fail to user
> > }
> >
> > I should recieve a failure, resulting in a dialog popup to the user.
> > However acceptsURL returns true in this case.
>
> Here is a patch that fixes this.  Also it corrects the comments describing
> the protocol string to say jdbc:postgresql: instead of
> jdbc:org.postgresql:
>
> Also I've added this test case and another for IPv6 addresses to the
> acceptsURL regression test.
>
> Kris Jurka
>
> ______________________________________________________________________
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
>                http://archives.postgresql.org