On Mon, 2004-01-12 at 22:28, Chris AtLee wrote:
> I don't know if I've got myself complete sidetracked with this, but I
> thought I'd share. I started hacking on DBConnection.py a little bit so
> that:
>
> - you can test if a particular connection type will work with
> DBAPI.isSupported() (e.g. SQLiteConnection.isSupported())
That's seems reasonable.
> - get a list of all supported drivers with
> SQLObject.getSupportedDrivers()
> - create an appropriate DBAPI object according to a DB URI (e.g.
> "sqlite:///home/user/database.db" or "mysql://user:pass@host/db")
> - save the connection parameters as an URI (e.g. getURI() called on a
> MySQLConnection object gives "mysql://user:pass@host/db")
The implementation seems pretty straight-forward for these too, though
you might be able to use the urlparse library to simplify this, or at
least make it more robust. Or not, it might not be that useful.
Anyway, MySQL and other databases allow for passwordless connections, so
that has to be kept in mind when parsing the connection string, among
other things.
Another option besides connectionByURI() would be to have a uri keyword
argument in the constructor.
> I haven't added the required code for all of the different connection
> drivers, so your mileage will vary.
>
> Is the right approach to take to opening up database connections in a
> generic way? I want the user of my software to be able to configure his
> database settings pretty easily.
Sure. If you are going to encode it in a string, a URI is the right way
to go. And strings are nice for settings.
Ian
|