[sqlalchemy] Re: self referencing column

2010-08-27 Thread waugust
Hmmm... can't seem to pickle WSGI functions in Pylons...we'll have to
take it to the Pylons bored :)

On Aug 26, 10:37 pm, Wojtek Augustynski waugustyn...@gmail.com
wrote:
 Thanks, though! :)

 Don't suppose you would have an idea on how I could store a procedure? :)
 the actions to which I'm pertaining I envisioned as controller actions
 (Pylons) that I could define an associate with an execution flow... (don't
 know if that makes sense)...
 I was thinking of just storing the Route url and execute it with app.get or
 app.post though idk...

 On Thu, Aug 26, 2010 at 10:21 PM, Alexandre Conrad 



 alexandre.con...@gmail.com wrote:
  This is the documentation for self referential mapper:

 http://www.sqlalchemy.org/docs/mappers.html#adjacency-list-relationships

  I guess you have found the recipes for doing it the declarative way.

  2010/8/26 waugust waugustyn...@gmail.com:
   I'm guessing that the answer would be as at:

 http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DeclarativeSelfRefer...

   ?

   On Aug 26, 8:02 pm, waugust waugustyn...@gmail.com wrote:
   I've been looking through the documentation and I could have sworn I
   saw it before but It seem I can't find it once more...
   I'm looking for how to set up a self referencing column like in this
   pseudo scenerio:

   class Action(DeclarativeBase):

              __tablename__ = 'action'

              id = Column(Integer, autoincrement=True, primary_key=True)

   onsuccess = Column(Integer, ForeignKey=('action.id')  

   I would want to have an id of an action upon the success of an
   action...

   --
   You received this message because you are subscribed to the Google Groups
  sqlalchemy group.
   To post to this group, send email to sqlalch...@googlegroups.com.
   To unsubscribe from this group, send email to
  sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegrou 
  ps.com
  .
   For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.

  --
  Alex
  twitter.com/alexconrad

  --
  You received this message because you are subscribed to the Google Groups
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to
  sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegrou 
  ps.com
  .
  For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Sudden Connection issues

2010-08-27 Thread Warwick Prince
Hi Michael

OK, I've invested (wasted?) my entire day on this connection issue and have the 
following to report.  Hopefully, the hints I've managed to find may trigger 
something with you that will point me in the right direction.

In recap; the issue was I could not get a simple engine to connect to the MySQL 
database.  This used to work on this server with the current configuration and 
simply seemed to stop working.

e = create_engine('mysql+mysqlconnector://user:passw...@127.0.0.1/testdb', 
encoding='utf8', echo=False)
e.connect()

(Traceback below from previous messages)

So, I followed all the code through and found that it actually failing at the 
point where in cursor.py it's attempting to create a new cursor.

def set_connection(self, db):
try:
if isinstance(db.conn.protocol,protocol.MySQLProtocol):
self.db = weakref.ref(db)
if self not in self.db().cursors:
self.db().cursors.append(self)
except Exception as message:
raise errors.InterfaceError(errno=2048)

The db appears to be correct (I looked), protocol.MySQLProtocol appears to be 
correct BUT db.conn = None !  Therefore it raises 2048

So, after many hours I can not find where db.conn is set or what it is supposed 
to be in the first place!Note: I have a virtually identical setup on my XP 
VM, and the same example of engine.connect() works fine.

What I'm looking for is a little info on what db.conn should be, where is it 
set, how can it be NOT set etc.Your help would be most appreciated.

Incidentally, all was not a waste of time as I traversed nearly ALL of the SA 
code today and picked up a few nice tips..  Thanks! :-)

Cheers
Warwick




Warwick Prince 
Managing Director 
mobile: +61 411 026 992 
skype: warwickprince  
 
phone: +61 7 3102 3730 
fax:  +61 7 3319 6734 
web: www.mushroomsys.com 

On 26/08/2010, at 3:37 PM, Michael Bayer wrote:

 
 On Aug 25, 2010, at 11:09 PM, Warwick Prince wrote:
 
 HI Michael
 
 Excellent.  Thanks for the pointers - I'll investigate further and get back 
 to you.  This is really strange as I do not believe that I changed anything 
 from the point it all worked, to the point at which it didn't!   (I'm sure 
 there will be something however - there always is..).  :-)   I'll let you 
 know how I go.   When I get it going again, I'll hit you with the REAL 
 questions I have..  
 
 those connection issues are fixed in tip (not your MySQL problem, though).
 
 
 
 Cheers
 Warwick
 
 On 26/08/2010, at 12:43 PM, Michael Bayer wrote:
 
 
 On Aug 25, 2010, at 10:11 PM, Warwick Prince wrote:
 
 Hi All
 
 This is my first post here, so I wish it were a little more spectacular..  
 :-)
 
 I have been working happily with SA 0.6.x on Windows 2003 server with 
 MySQL and the Sun Python Connector.  I have an identical config running 
 (and working) on XP.
 
 I was testing my code which had been working perfectly, and suddenly 
 started getting this message which I had never seen before;
 
 Traceback (most recent call last):
 File pyshell#3, line 1, in module
 e.connect()
 File C:\Python26\lib\site-packages\sqlalchemy\engine\base.py, line 1731, 
 in connect
 return self.Connection(self, **kwargs)
 File C:\Python26\lib\site-packages\sqlalchemy\engine\base.py, line 821, 
 in __init__
 self.__connection = connection or engine.raw_connection()
 File C:\Python26\lib\site-packages\sqlalchemy\engine\base.py, line 1787, 
 in raw_connection
 return self.pool.unique_connection()
 File C:\Python26\lib\site-packages\sqlalchemy\pool.py, line 135, in 
 unique_connection
 return _ConnectionFairy(self).checkout()
 File C:\Python26\lib\site-packages\sqlalchemy\pool.py, line 329, in 
 __init__
 rec = self._connection_record = pool.get()
 File C:\Python26\lib\site-packages\sqlalchemy\pool.py, line 177, in get
 return self.do_get()
 File C:\Python26\lib\site-packages\sqlalchemy\pool.py, line 692, in 
 do_get
 con = self.create_connection()
 File C:\Python26\lib\site-packages\sqlalchemy\pool.py, line 138, in 
 create_connection
 return _ConnectionRecord(self)
 File C:\Python26\lib\site-packages\sqlalchemy\pool.py, line 218, in 
 __init__
 l.first_connect(self.connection, self)
 File C:\Python26\lib\site-packages\sqlalchemy\engine\strategies.py, line 
 145, in first_connect
 dialect.initialize(c)
 File C:\Python26\lib\site-packages\sqlalchemy\dialects\mysql\base.py, 
 line 1774, in initialize
 default.DefaultDialect.initialize(self, connection)
 File C:\Python26\lib\site-packages\sqlalchemy\engine\default.py, line 
 144, in initialize
 self._get_default_schema_name(connection)
 File C:\Python26\lib\site-packages\sqlalchemy\dialects\mysql\base.py, 
 line 1739, in _get_default_schema_name
 return connection.execute('SELECT DATABASE()').scalar()
 File C:\Python26\lib\site-packages\sqlalchemy\engine\base.py, line 1157, 
 in execute
 params)
 File C:\Python26\lib\site-packages\sqlalchemy\engine\base.py, line 1252, 
 in _execute_text
 

Re: [sqlalchemy] Sudden Connection issues

2010-08-27 Thread Michael Bayer

On Aug 27, 2010, at 4:39 AM, Warwick Prince wrote:

 Hi Michael
 
 OK, I've invested (wasted?) my entire day on this connection issue and have 
 the following to report.  Hopefully, the hints I've managed to find may 
 trigger something with you that will point me in the right direction.
 
 In recap; the issue was I could not get a simple engine to connect to the 
 MySQL database.  This used to work on this server with the current 
 configuration and simply seemed to stop working.
 
 e = create_engine('mysql+mysqlconnector://user:passw...@127.0.0.1/testdb', 
 encoding='utf8', echo=False)
 e.connect()
 
 (Traceback below from previous messages)
 
 So, I followed all the code through and found that it actually failing at the 
 point where in cursor.py it's attempting to create a new cursor.
 
 def set_connection(self, db):
 try:
 if isinstance(db.conn.protocol,protocol.MySQLProtocol):
 self.db = weakref.ref(db)
 if self not in self.db().cursors:
 self.db().cursors.append(self)
 except Exception as message:
 raise errors.InterfaceError(errno=2048)
 
 The db appears to be correct (I looked), protocol.MySQLProtocol appears to be 
 correct BUT db.conn = None !  Therefore it raises 2048
 
 So, after many hours I can not find where db.conn is set or what it is 
 supposed to be in the first place!Note: I have a virtually identical 
 setup on my XP VM, and the same example of engine.connect() works fine.
 
 What I'm looking for is a little info on what db.conn should be, where is it 
 set, how can it be NOT set etc.Your help would be most appreciated.
 
 Incidentally, all was not a waste of time as I traversed nearly ALL of the SA 
 code today and picked up a few nice tips..  Thanks! :-)

Well, that above is not part of SQLAlchemy.   I would assume, since its called 
cursor.py and is dealing with MySQL internals, that its part of MySQL 
connector, so you should email on their list (and also you can test things 
without SQLAlchemy at all, just use a script with MySQL connector directly).

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Checking internals of query object

2010-08-27 Thread Bryan
I am writing a function that adds particular columns and groupings to
a query based on some options.  I am trying to write some unit tests
for the function, and would like to check that the correct columns are
being added/grouped.

Give a query like:

q = session.query(Employee.firstName, Employee.lastName)

How can I check later that the query object has included
Employee.firstName in the output columns?

Similarly, how can I check, for instance, that the query object is
grouping on Employee.lastName?

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Checking internals of query object

2010-08-27 Thread Bryan
I'm considering just checking for terms in the sql statement produced
from str(query).  That way I don't have to muddle with the internals
of Query.  However, I do introduce table and column names from the DB
into my test code as strings, which of course defeats one of the
reasons for using SA.  However, this is *just* test code, and when I
change column names in the DB and the tests fail, I''l change the
tests.  The alternative would to be to change the tests when the
internals of Query change, which I don't have as much control over.

Thanks for the insight.

On Aug 27, 10:58 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Aug 27, 1:24 pm, Bryan bryanv...@gmail.com wrote:

  I am writing a function that adds particular columns and groupings to
  a query based on some options.  I am trying to write some unit tests
  for the function, and would like to check that the correct columns are
  being added/grouped.

  Give a query like:

  q = session.query(Employee.firstName, Employee.lastName)

  How can I check later that the query object has included
  Employee.firstName in the output columns?

 for output columns, we have recently added a method for this purpose
 as of version 0.6.3:

 http://www.sqlalchemy.org/docs/reference/orm/query.html#sqlalchemy.or...

 I'm using it successfully in a library that converts Query objects
 into Excel spreadsheets with xlwt.

  Similarly, how can I check, for instance, that the query object is
  grouping on Employee.lastName?

 stuff like that is semi-private but relatively stable, most are
 available by names like query._group_by, query._order_by,
 query._criterion.  If you look at the top of the Query class (the
 source), they are all defaulted at the class level.

 Semi-private because I really don't want to push things like that to
 be first class accessors until we are super certain nothing is
 changing there.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] string_agg() with order by clause

2010-08-27 Thread David Gardner

Recently Postgres added a new aggregate function called string_agg().
I have been able to use it like:
Session.query(Asset, func.string_agg(some_col, ','))

This works, but according to the docs I should be able to do 
string_agg(some_col, ',' ORDER BY some_col)

Is there a way to do this in SQLAlchemy?

--
David Gardner
Pipeline Tools Programmer
Jim Henson Creature Shop
dgard...@creatureshop.com


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] string_agg() with order by clause

2010-08-27 Thread David Gardner

I should have linked to the docs in question
http://developer.postgresql.org/pgdocs/postgres/sql-expressions.html#SYNTAX-AGGREGATES

On 08/27/2010 03:03 PM, David Gardner wrote:

Recently Postgres added a new aggregate function called string_agg().
I have been able to use it like:
Session.query(Asset, func.string_agg(some_col, ','))

This works, but according to the docs I should be able to do
string_agg(some_col, ',' ORDER BY some_col)
Is there a way to do this in SQLAlchemy?

   



--
David Gardner
Pipeline Tools Programmer
Jim Henson Creature Shop
dgard...@creatureshop.com


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] string_agg() with order by clause

2010-08-27 Thread Conor
On 08/27/2010 05:06 PM, David Gardner wrote:
 I should have linked to the docs in question
 http://developer.postgresql.org/pgdocs/postgres/sql-expressions.html#SYNTAX-AGGREGATES


 On 08/27/2010 03:03 PM, David Gardner wrote:
 Recently Postgres added a new aggregate function called string_agg().
 I have been able to use it like:
 Session.query(Asset, func.string_agg(some_col, ','))

 This works, but according to the docs I should be able to do
 string_agg(some_col, ',' ORDER BY some_col)
 Is there a way to do this in SQLAlchemy?

I think you have to write your own compiler extension:

import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import ColumnElement
from StringIO import StringIO

class string_agg(ColumnElement):
type = sa.String()

def __init__(self, expr, separator=None, order_by=None):
self.expr = expr
self.order_by = order_by
self.separator = separator

@compiles(string_agg, 'mysql')
def _compile_string_agg_mysql(element, compiler, **kw):
buf = StringIO()
buf.write('group_concat(')
buf.write(compiler.process(element.expr))
if element.order_by is not None:
buf.write(' ORDER BY ')
buf.write(compiler.process(element.order_by))
if element.separator is not None:
buf.write(' SEPARATOR ')
buf.write(compiler.process(sa.literal(element.separator)))
buf.write(')')
return buf.getvalue()

# Use 'postgres' for SQLAlchemy  0.6.
@compiles(string_agg, 'postgresql')
def _compile_string_agg_postgresql(element, compiler, **kw):
buf = StringIO()
buf.write('string_agg(')
buf.write(compiler.process(element.expr))
if element.separator is not None:
buf.write(', ')
buf.write(compiler.process(sa.literal(element.separator)))
if element.order_by is not None:
buf.write(' ORDER BY ')
buf.write(compiler.process(element.order_by))
buf.write(')')
return buf.getvalue()

if __name__ == '__main__':
clause = string_agg(sa.literal_column('some_column'),
', ',
order_by=sa.literal_column('some_other_column').asc())

mysql_engine = sa.create_engine('mysql:///')
print 'MySQL: %s' % clause.compile(dialect=mysql_engine.dialect)

pg_engine = sa.create_engine('postgresql:///')
print 'PostgreSQL: %s' % clause.compile(dialect=pg_engine.dialect)

-Conor

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] string_agg() with order by clause

2010-08-27 Thread David Gardner

Fantastic! That works.

Out of curiosity I noticed that the compile function expects to receive 
instances of Column.
This isn't a big problem because I just reverted to doing 
table_var.c.my_col, but is there

a simpler way to use MyClassName.Col?


On 08/27/2010 04:02 PM, Conor wrote:

On 08/27/2010 05:06 PM, David Gardner wrote:

I should have linked to the docs in question
http://developer.postgresql.org/pgdocs/postgres/sql-expressions.html#SYNTAX-AGGREGATES 



On 08/27/2010 03:03 PM, David Gardner wrote:

Recently Postgres added a new aggregate function called string_agg().
I have been able to use it like:
Session.query(Asset, func.string_agg(some_col, ','))

This works, but according to the docs I should be able to do
string_agg(some_col, ',' ORDER BY some_col)
Is there a way to do this in SQLAlchemy?


I think you have to write your own compiler extension:

import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import ColumnElement
from StringIO import StringIO

class string_agg(ColumnElement):
 type = sa.String()

 def __init__(self, expr, separator=None, order_by=None):
 self.expr = expr
 self.order_by = order_by
 self.separator = separator

@compiles(string_agg, 'mysql')
def _compile_string_agg_mysql(element, compiler, **kw):
 buf = StringIO()
 buf.write('group_concat(')
 buf.write(compiler.process(element.expr))
 if element.order_by is not None:
 buf.write(' ORDER BY ')
 buf.write(compiler.process(element.order_by))
 if element.separator is not None:
 buf.write(' SEPARATOR ')
 buf.write(compiler.process(sa.literal(element.separator)))
 buf.write(')')
 return buf.getvalue()

# Use 'postgres' for SQLAlchemy  0.6.
@compiles(string_agg, 'postgresql')
def _compile_string_agg_postgresql(element, compiler, **kw):
 buf = StringIO()
 buf.write('string_agg(')
 buf.write(compiler.process(element.expr))
 if element.separator is not None:
 buf.write(', ')
 buf.write(compiler.process(sa.literal(element.separator)))
 if element.order_by is not None:
 buf.write(' ORDER BY ')
 buf.write(compiler.process(element.order_by))
 buf.write(')')
 return buf.getvalue()

if __name__ == '__main__':
 clause = string_agg(sa.literal_column('some_column'),
 ', ',
 order_by=sa.literal_column('some_other_column').asc())

 mysql_engine = sa.create_engine('mysql:///')
 print 'MySQL: %s' % clause.compile(dialect=mysql_engine.dialect)

 pg_engine = sa.create_engine('postgresql:///')
 print 'PostgreSQL: %s' % clause.compile(dialect=pg_engine.dialect)
   


-Conor

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.

To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



--
David Gardner
Pipeline Tools Programmer
Jim Henson Creature Shop
dgard...@creatureshop.com

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] string_agg() with order by clause

2010-08-27 Thread Michael Bayer

On Aug 27, 2010, at 8:56 PM, David Gardner wrote:

 Fantastic! That works.
 
 Out of curiosity I noticed that the compile function expects to receive 
 instances of Column. 
 This isn't a big problem because I just reverted to doing table_var.c.my_col, 
 but is there
 a simpler way to use MyClassName.Col?

you coerce incoming arguments into expressions at the constructor level:

from sqlalchemy.sql.expression import _literal_as_column

class MyWhatever(ColumnElement):
def __init__(self, expr, ...):
self.expr = _literal_as_column(expr)


_literal_as_column basically calls __clause_element__() on the incoming object, 
and if not present tries turning it into a literal_column() if its a string.  
You might also try _no_literals, _only_column_elements, etc. based on what 
you'd expect to see there, all of which do the __clause_element__() conversion.


 
 
 On 08/27/2010 04:02 PM, Conor wrote:
 
 On 08/27/2010 05:06 PM, David Gardner wrote:
 
 I should have linked to the docs in question 
 http://developer.postgresql.org/pgdocs/postgres/sql-expressions.html#SYNTAX-AGGREGATES
  
 
 On 08/27/2010 03:03 PM, David Gardner wrote: 
 Recently Postgres added a new aggregate function called string_agg(). 
 I have been able to use it like: 
 Session.query(Asset, func.string_agg(some_col, ',')) 
 
 This works, but according to the docs I should be able to do 
 string_agg(some_col, ',' ORDER BY some_col) 
 Is there a way to do this in SQLAlchemy?
 I think you have to write your own compiler extension:
 import sqlalchemy as sa
 from sqlalchemy.ext.compiler import compiles
 from sqlalchemy.sql.expression import ColumnElement
 from StringIO import StringIO
 
 class string_agg(ColumnElement):
 type = sa.String()
 
 def __init__(self, expr, separator=None, order_by=None):
 self.expr = expr
 self.order_by = order_by
 self.separator = separator
 
 @compiles(string_agg, 'mysql')
 def _compile_string_agg_mysql(element, compiler, **kw):
 buf = StringIO()
 buf.write('group_concat(')
 buf.write(compiler.process(element.expr))
 if element.order_by is not None:
 buf.write(' ORDER BY ')
 buf.write(compiler.process(element.order_by))
 if element.separator is not None:
 buf.write(' SEPARATOR ')
 buf.write(compiler.process(sa.literal(element.separator)))
 buf.write(')')
 return buf.getvalue()
 
 # Use 'postgres' for SQLAlchemy  0.6.
 @compiles(string_agg, 'postgresql')
 def _compile_string_agg_postgresql(element, compiler, **kw):
 buf = StringIO()
 buf.write('string_agg(')
 buf.write(compiler.process(element.expr))
 if element.separator is not None:
 buf.write(', ')
 buf.write(compiler.process(sa.literal(element.separator)))
 if element.order_by is not None:
 buf.write(' ORDER BY ')
 buf.write(compiler.process(element.order_by))
 buf.write(')')
 return buf.getvalue()
 
 if __name__ == '__main__':
 clause = string_agg(sa.literal_column('some_column'),
 ', ',
 
 order_by=sa.literal_column('some_other_column').asc())
 
 mysql_engine = sa.create_engine('mysql:///')
 print 'MySQL: %s' % clause.compile(dialect=mysql_engine.dialect)
 
 pg_engine = sa.create_engine('postgresql:///')
 print 'PostgreSQL: %s' % clause.compile(dialect=pg_engine.dialect)
   
 -Conor
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 
 
 -- 
 David Gardner
 Pipeline Tools Programmer
 Jim Henson Creature Shop
 dgard...@creatureshop.com
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Sudden Connection issues

2010-08-27 Thread Warwick Prince
Hi Michael

Sorry about that - it had been a long day and I didn't realise I was quoting 
code from the connector!   I'll get onto them and see if they can help.

Cheers
Warwick

Warwick Prince 
Managing Director 
mobile: +61 411 026 992 
skype: warwickprince  
 
phone: +61 7 3102 3730 
fax:  +61 7 3319 6734 
web: www.mushroomsys.com 


On 27/08/2010, at 11:40 PM, Michael Bayer wrote:

 
 On Aug 27, 2010, at 4:39 AM, Warwick Prince wrote:
 
 Hi Michael
 
 OK, I've invested (wasted?) my entire day on this connection issue and have 
 the following to report.  Hopefully, the hints I've managed to find may 
 trigger something with you that will point me in the right direction.
 
 In recap; the issue was I could not get a simple engine to connect to the 
 MySQL database.  This used to work on this server with the current 
 configuration and simply seemed to stop working.
 
 e = create_engine('mysql+mysqlconnector://user:passw...@127.0.0.1/testdb', 
 encoding='utf8', echo=False)
 e.connect()
 
 (Traceback below from previous messages)
 
 So, I followed all the code through and found that it actually failing at 
 the point where in cursor.py it's attempting to create a new cursor.
 
 def set_connection(self, db):
 try:
 if isinstance(db.conn.protocol,protocol.MySQLProtocol):
 self.db = weakref.ref(db)
 if self not in self.db().cursors:
 self.db().cursors.append(self)
 except Exception as message:
 raise errors.InterfaceError(errno=2048)
 
 The db appears to be correct (I looked), protocol.MySQLProtocol appears to 
 be correct BUT db.conn = None !  Therefore it raises 2048
 
 So, after many hours I can not find where db.conn is set or what it is 
 supposed to be in the first place!Note: I have a virtually identical 
 setup on my XP VM, and the same example of engine.connect() works fine.
 
 What I'm looking for is a little info on what db.conn should be, where is it 
 set, how can it be NOT set etc.Your help would be most appreciated.
 
 Incidentally, all was not a waste of time as I traversed nearly ALL of the 
 SA code today and picked up a few nice tips..  Thanks! :-)
 
 Well, that above is not part of SQLAlchemy.   I would assume, since its 
 called cursor.py and is dealing with MySQL internals, that its part of MySQL 
 connector, so you should email on their list (and also you can test things 
 without SQLAlchemy at all, just use a script with MySQL connector directly).
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.