Hi Michael,
test.py:
import MySQLdb
c=MySQLdb.connect(host='localhost',read_default_group='client')
cur=c.cursor()
cur.execute('select * from sf_user where id=1')
print cur.fetchone()
I tried several combinations. First, with nothing in any files, I get:
Traceback (most recent call last):
File "test.py", line 5, in ?
cur.execute('select * from sf_user where id=1')
File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
137, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
33, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1046, 'No database selected')
which is as we would expect, since I didn't define one. If I add a
database=sfdev line to /etc/my.cnf, I also get that error... except
that I'm on a debian system (ubuntu, actually) where the default
location is /etc/mysql/my.cnf. So if I edit /etc/mysql/my.cnf OR
~/.my.cnf, I get:
(1L, 'monty', 'mony_email', 'Monty Taylor', 'foo',
datetime.datetime(2006, 8, 23, 14, 21))
as I would expect.
I'm not sure what the behavior is on OSX. It could be like Debian with
non-standard default locations of files - but I don't have access to a
box at the moment to track it down.
Monty
On 8/25/06, Michael Bayer <[EMAIL PROTECTED]> wrote:
> I just tried read_default_group with a mysqldb connection while
> running ktrace (osx), and it doesnt seem to access my.cnf at all. I
> got the same results when i tried it with no arguments. this is not
> consistent with what the mysqldb docs say, which for
> read_default_group and read_default_file point to the mysql api docs,
> which say that "my.cnf" is the default file and the default group is
> nothing. isnt this a bug in mysqldb ? can you show me code where
> it actually works ?
>
>
> On Aug 25, 2006, at 1:44 PM, Monty Taylor wrote:
>
> > I do... and you are right - the code already supports setting
> > read_default_group. You can certainly pass it in client code.
> >
> > What I was suggesting, though, is that the general case is that people
> > don't really know all the options of the MySQL client library. Based
> > on experiences with the MySQL command line clients, almost everyone
> > expects that options set in /etc/my.cnf will affect how things
> > connect. I actually wouldn't mind this being set in the MySQLdb
> > adapter, but I doubt that will happen. I think if we give this a
> > default value, we will solve a large number of complaints and
> > confusion. On the other hand, if you don't want it, you can always
> > override it - but I imagine that to be the minority case.
> >
> > Monty
> >
> > On 8/25/06, Michael Bayer <[EMAIL PROTECTED]> wrote:
> >> do you mean the connect() function for MySQLDB ? SA can support
> >> passing keyword arguments through to connect(). i was actually
> >> cleaning that API up a little bit for a checkin to the trunk today.
> >>
> >>
> >> On Aug 23, 2006, at 4:05 PM, Monty Taylor wrote:
> >>
> >> > Hi - sorry for the cross post - but it's the same general idea.
> >> >
> >> > I've got a possible tiny patch for better MySQL support - but
> >> I'm not
> >> > 100% sure what would be the 'best' way to do it would be.
> >> >
> >> > Briefly... (this is in response to having read the turbogears wiki
> >> > article about using a socket file) if you want the python MySQL
> >> module
> >> > to actually read the /etc/my.cnf and ~/.my.cnf file information,
> >> you
> >> > have to pass read_default_group='' to the contructor. If you put a
> >> > string there (like 'sqlobject' or 'sqlalchemy') to the
> >> constructor, it
> >> > will read [sqlalchemy] or [sqlobject] sections and [client]
> >> sections
> >> > in the config files and behave as you expect it to.
> >> >
> >> > So I think it's what people expect to have the files read.
> >> Whether we
> >> > want to add a section [sqlobject] or [sqlalchemy] by default or
> >> not,
> >> > or just leave it to read the [client] sections is another
> >> question...
> >> >
> >> > Thoughts?
> >> >
> >> > Monty
> >> >
> >> >
> >> ---------------------------------------------------------------------
> >> -
> >> > ---
> >> > Using Tomcat but need to do more? Need to support web services,
> >> > security?
> >> > Get stuff done quickly with pre-integrated technology to make your
> >> > job easier
> >> > Download IBM WebSphere Application Server v.1.0.1 based on Apache
> >> > Geronimo
> >> > http://sel.as-us.falkag.net/sel?
> >> > cmd=lnk&kid=120709&bid=263057&dat=121642
> >> > _______________________________________________
> >> > Sqlalchemy-users mailing list
> >> > [email protected]
> >> > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
> >>
> >>
>
>
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss