NET-A-PORTER / scala-uri

Simple scala library for building and parsing URIs
Other
261 stars 33 forks source link

Support jdbc URLs #49

Closed electricmonk closed 9 years ago

electricmonk commented 10 years ago

When parsing a JDBC url:

Uri.parse("jdbc:mysql://localhost:3306/some_db")

it is being parsed as a relative url. This is because in UrlParser, the _scheme rule expects the scheme part to be alphanumeric.

Ideally, you could relax the parser a bit to allow for colons, thus supporting JDBC urls as well.

theon commented 10 years ago

Thanks for raising this issue.

So far I have been trying to follow rfc3986 and JDBC URLs do not adhere to that spec. Maybe we could make a separate JdbcUriParser, and I will rename the current UriParser to Rfc3986Parser. To start they could be exactly the same, except for the scheme.

From rfc3986:

Scheme names consist of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus ("+"), period ("."), or hyphen ("-")

From the JDBC 4 spec:

Note - A JDBC URL is not required to fully adhere to the URI syntax as defined in RFC 3986, Uniform Resource Identifier (URI): Generic Syntax.

theon commented 10 years ago

I will also need to add digits, +, . and - to the existng UriParser as that seems to have been missed.

electricmonk commented 10 years ago

Glad to be of help. In the mean time I'm using java.net.URI but I hate myself for doing that - would love to see this resolved eventually :)

rathboma commented 9 years ago

Ah, we just ran into this same issue also. Would be great to include JDBC url support.

philwill-nap commented 9 years ago

My opinion, after looking at some sample JDBC connection "URL"s is that they are not suitable for parsing with this library as they are not at all standardised.

You could build a library to do it, it would need to recognise the "jdbc:" prefix then delegate the rest of the parsing to the parser that matches the next prefix (e.g. "oracle:" or other vendors) which may again need to delegate to a different parser for the next prefix (e.g. "thin:" or "oci:" for oracle) to comprehend the rest of the string.

The best thing to do is to stop calling them "URL" and start calling them "Connection string"

theon commented 9 years ago

@philwill-nap makes a good point. Closing this.