[sqlalchemy] Re: ORM mapping with Elixir compared to raw cursor query

2008-11-21 Thread SinJax

I had a feeling the bulk nature of the query would confuse the matter
so i have performed some more tests with a slightly more restricted
query with similarly poor results.

I have not posted much on mail lists much so if it is inappropriate to
post code i apologise.
Here is my code:


import time

from elixir import *
from sqlalchemy import *

metadata.bind = 'mysql://some:[EMAIL PROTECTED]/SomeTable'
metadata.echo = True
users_groups = Table('usergroup', metadata, autoload=True)
class Group(Entity):
using_options(tablename='groups', autoload=True)
users = ManyToMany('User',tablename=usergroup)

class User(Entity):
using_options(tablename='users', autoload=True)
using_mapper_options(column_prefix=py_)
groups = ManyToMany('Group',tablename=usergroup,lazy=False)

class Video(Entity):
using_options(tablename='videos', autoload=True)
#subject = ManyToMany('Subject',tablename=subjectvideo,lazy=False)

class Subject(Entity):
using_options(tablename='subjects', autoload=True)
#videos = ManyToMany('Video',tablename=subjectvideo,lazy=False)

class Field(Entity):
using_options(tablename='fields', autoload=True)

class Value(Entity):
using_options(tablename='values', autoload=True)

class Annotation(Entity):
using_options(tablename='annotations', autoload=True)
user = ManyToOne('User',lazy=False)
subject = ManyToOne('Subject',lazy=False)
field = ManyToOne('Field',lazy=False)
value = ManyToOne('Value',lazy=False)

setup_all()
allAnn = Annotation.query().filter(User.py_user == msn).filter
(Subject.id == 2 )
print allAnn
import MySQLdb
import MySQLdb.cursors

db = MySQLdb.connect(
passwd=login,
user=some,
db=someTable,
host=someServer,
cursorclass=MySQLdb.cursors.DictCursor
)

c = db.cursor()
t1 = time.time()
sql =  SELECT fields.name,values.name,users.user,subjects.leg_id
FROM annotations
LEFT JOIN `fields` ON annotations.field = fields.id
LEFT JOIN `values` ON annotations.value = `values`.id
LEFT JOIN `users` ON annotations.user = `users`.id
LEFT JOIN `subjects` ON annotations.subject = `subjects`.id
WHERE users.user = msn
AND subjects.id = 2

c.execute(sql)
results = c.fetchall()
holder = []

for res in results:
holder.append(res)
t2 = time.time()
print (t2-t1)

sql = 
SELECT annotations.id AS annotations_id, annotations.user AS
annotations_user, annotations.subject AS annotations_subject,
annotations.field AS annotations_field, annotations.value AS
annotations_value, users_1.id AS users_1_id, users_1.user AS
users_1_user, users_1.pass AS users_1_pass, users_1.lab_id AS
users_1_lab_id, users_1.email AS users_1_email, groups_1.id AS
groups_1_id, groups_1.name AS groups_1_name, subjects_1.id AS
subjects_1_id, subjects_1.leg_id AS subjects_1_leg_id,
subjects_1.`displayOrder` AS `subjects_1_displayOrder`, fields_1.id AS
fields_1_id, fields_1.name AS fields_1_name, fields_1.help AS
fields_1_help, values_1.id AS values_1_id, values_1.`parentId` AS
`values_1_parentId`, values_1.field AS values_1_field, values_1.name
AS values_1_name, values_1.image AS values_1_image, values_1.`order`
AS values_1_order
FROM users, subjects, annotations
LEFT OUTER JOIN users AS users_1 ON users_1.id = annotations.user
LEFT OUTER JOIN usergroup AS usergroup_1 ON users_1.id =
usergroup_1.`userId`
LEFT OUTER JOIN groups AS groups_1 ON groups_1.id =
usergroup_1.`groupId`
LEFT OUTER JOIN subjects AS subjects_1 ON subjects_1.id =
annotations.subject
LEFT OUTER JOIN `fields` AS fields_1 ON fields_1.id =
annotations.field
LEFT OUTER JOIN `values` AS values_1 ON values_1.id =
annotations.value
WHERE users.user = '%s' AND subjects.id = %s
ORDER BY annotations.id, users_1.id, usergroup_1.`userId`,
subjects_1.id, fields_1.id, values_1.id
%(msn,2)
t1 = time.time()
c.execute(sql)
results = c.fetchall()
holder = []

for res in results:
holder.append(res)
t2 = time.time()
print (t2-t1)
t2 = time.time()
print allAnn
# This prints:



t1 = time.time()
print len(allAnn.all())
t2 = time.time()
print (t2-t1)


Right! So what this code does is map a few classes to existing tables
in a database. The content of the tables should be made obvious by the
huge query SQLAlchemy generates.

The result of this query is 23 rows from a 24,000 row table.

I show a query i constructed by hand (Get every annotation of user
msn on subject 2) as i would run using MysqlDb and cursor. I time
this by measuring the time taken between executing the query and
putting each result in a tuple. The running time for this query is
0.05s

This is compared to running Annotation.query().filter
(User.user==msn).filter(Subject.id=2). The query generated by SQL

[sqlalchemy] Re: ORM mapping with Elixir compared to raw cursor query

2008-11-21 Thread az

 The result of this query is 23 rows from a 24,000 row table.

 I show a query i constructed by hand (Get every annotation of user
 msn on subject 2) as i would run using MysqlDb and cursor. I
 time this by measuring the time taken between executing the query
 and putting each result in a tuple. The running time for this query
 is 0.05s

 This is compared to running Annotation.query().filter
 (User.user==msn).filter(Subject.id=2). The query generated by SQL
 alchemy can be seen in the second declaration of the sql string.
 For purposes of interest i run this generated query (with fields
 filled in manually) through the same MysqlDb cursor. This takes 16
 seconds! 

 A query which returns 23 rows should NOT take 16 seconds 
 to return.
heh, not just like this. 
i have a query that returns 3 objects from about 40 and still takes 10 
seconds on postgres (and 50 on sqlite). it just happens to have about 
15 tables in the From list...

the SA sql has 3 tables as opposed to your hand-made that has 1.
i guess something's wrong with the query building - possibly u want:
allAnn = Annotation.query().join( 'user').filter( User.py_user 
== msn).join( 'subject').filter( Subject.id == 2 ) 
or
allAnn = Annotation.query().join( 'user').filter( User.py_user 
== msn).filter( Annotation.subject == somesubject ) 


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



[sqlalchemy] Re: ORM mapping with Elixir compared to raw cursor query

2008-11-21 Thread az

On Friday 21 November 2008 12:42:31 SinJax wrote:
and another way:
allAnn = Annotation.query(
   ).join( 'user').filter_by( py_user = msn
   ).reset_joinpoint().filter( Annotation.subject == somesubject )  
and
allAnn = Annotation.query(
   ).filter_by( subject = somesubject   
   ).join( 'user').filter_by( py_user = msn)
the last may or may not work depending on which SAversion you are.
see the order of filters above, u may have to tweak yours or use 
reset_joinpoint()

btw i have an enhanced version of .filter_by that takes 'a.b.c.d' as 
keys and does the joins internaly, i.e.
 A.query().filter_by( somex=5, **{'some.many.level.relation': 22})
does same as 
 A.query().filter_by( somex=5
   ).join( 'some.many.level'
 ).filter_by(relation= 22)

might seem ugly but is actualy quite short and nice to read, avoiding 
implementation details (joins in the case)

ciao
svil

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



[sqlalchemy] Re: ORM mapping with Elixir compared to raw cursor query

2008-11-21 Thread King Simon-NFHD78

 -Original Message-
 From: sqlalchemy@googlegroups.com 
 [mailto:[EMAIL PROTECTED] On Behalf Of SinJax
 Sent: 21 November 2008 10:43
 To: sqlalchemy
 Subject: [sqlalchemy] Re: ORM mapping with Elixir compared to 
 raw cursor query
 

[SNIP]

 sql = 
 SELECT annotations.id AS annotations_id, annotations.user AS
 annotations_user, annotations.subject AS annotations_subject,
 annotations.field AS annotations_field, annotations.value AS
 annotations_value, users_1.id AS users_1_id, users_1.user AS
 users_1_user, users_1.pass AS users_1_pass, users_1.lab_id AS
 users_1_lab_id, users_1.email AS users_1_email, groups_1.id AS
 groups_1_id, groups_1.name AS groups_1_name, subjects_1.id AS
 subjects_1_id, subjects_1.leg_id AS subjects_1_leg_id,
 subjects_1.`displayOrder` AS `subjects_1_displayOrder`, fields_1.id AS
 fields_1_id, fields_1.name AS fields_1_name, fields_1.help AS
 fields_1_help, values_1.id AS values_1_id, values_1.`parentId` AS
 `values_1_parentId`, values_1.field AS values_1_field, values_1.name
 AS values_1_name, values_1.image AS values_1_image, values_1.`order`
 AS values_1_order
 FROM users, subjects, annotations
   LEFT OUTER JOIN users AS users_1 ON users_1.id = 
 annotations.user
   LEFT OUTER JOIN usergroup AS usergroup_1 ON users_1.id =
 usergroup_1.`userId`
   LEFT OUTER JOIN groups AS groups_1 ON groups_1.id =
 usergroup_1.`groupId`
   LEFT OUTER JOIN subjects AS subjects_1 ON subjects_1.id =
 annotations.subject
   LEFT OUTER JOIN `fields` AS fields_1 ON fields_1.id =
 annotations.field
   LEFT OUTER JOIN `values` AS values_1 ON values_1.id =
 annotations.value
 WHERE users.user = '%s' AND subjects.id = %s
 ORDER BY annotations.id, users_1.id, usergroup_1.`userId`,
 subjects_1.id, fields_1.id, values_1.id
 %(msn,2)

[SNIP]

Your problem is the 'FROM users, subjects, annotations' part of that
query. There is no join condition between the three tables, so you are
getting a cartesian product, and a very large number of rows.

In your query, you need to explcitly join to other tables before you use
them as filters.

For example, something like:

allAnn = (Annotation.query()
  .join(Annotation.user)
  .filter(User.py_user == msn)
  .join(Annotation.subject)
  .filter(Subject.id == 2 ))

This page in the docs describes querying with joins:

http://www.sqlalchemy.org/docs/05/ormtutorial.html#datamapping_joins

Hope that helps,

Simon

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



[sqlalchemy] Cross Join

2008-11-21 Thread Ash

Hello,

I want to know how to implement the cross join using sqlalchemy

I create the metadata say metadata

i have table a and b which i want to cross join.

a_o = sqlalchemy.Table('a',metadata,autoload=True)
b_o = sqlalchemy.Table('b',metadata,autoload=True)

j = join(a_o,b_o, onclause=a_o.c.b_id==b_o.c.id)

This gives me the join thing

select = sqlachemy.select(from_obj=[j],columns=[a_o.c.name])

result = select.execute()

output = result.fetchall()

But this is not the cross join.

Thanks in the advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: ORM mapping with Elixir compared to raw cursor query

2008-11-21 Thread Sina Samangooei


On 21 Nov 2008, at 03:32, Michael Bayer wrote:



 On Nov 20, 2008, at 8:47 PM, Michael Bayer wrote:

 The first scenario is a single table with 24,000 rows. The problem  
 is
 that using SQLAlchemy through Elixir to map this table to an object,
 and performing a fairly naive MappedThing.query().all() the process
 takes roughly 4.8 seconds to return every item!

 you know, I read this as 4.8 seconds for the full result set.  4.8
 seconds per item means something is extremely wrong.   SQLA can fetch
 20,000 rows generally in under two seconds, so please post some test
 code so we can see where you're going wrong.

I had a feeling the bulk nature of the query would confuse the matter  
so i have performed some more tests with a slightly more restricted  
query with similarly poor results.

I have not posted much on mail lists much so if it is inappropriate to  
post code i apologise.
Here is my code:


import time

from elixir import *
from sqlalchemy import *

metadata.bind = 'mysql://some:[EMAIL PROTECTED]/SomeTable'
metadata.echo = True
users_groups = Table('usergroup', metadata, autoload=True)
class Group(Entity):
using_options(tablename='groups', autoload=True)
users = ManyToMany('User',tablename=usergroup)

class User(Entity):
using_options(tablename='users', autoload=True)
using_mapper_options(column_prefix=py_)
groups = ManyToMany('Group',tablename=usergroup,lazy=False)

class Video(Entity):
using_options(tablename='videos', autoload=True)
#subject = ManyToMany('Subject',tablename=subjectvideo,lazy=False)

class Subject(Entity):
using_options(tablename='subjects', autoload=True)
#videos = ManyToMany('Video',tablename=subjectvideo,lazy=False)

class Field(Entity):
using_options(tablename='fields', autoload=True)

class Value(Entity):
using_options(tablename='values', autoload=True)

class Annotation(Entity):
using_options(tablename='annotations', autoload=True)
user = ManyToOne('User',lazy=False)
subject = ManyToOne('Subject',lazy=False)
field = ManyToOne('Field',lazy=False)
value = ManyToOne('Value',lazy=False)   

setup_all()
allAnn = Annotation.query().filter(User.py_user ==  
msn).filter(Subject.id == 2 )
print allAnn
import MySQLdb
import MySQLdb.cursors

db = MySQLdb.connect(
passwd=login,
user=some,
db=someTable,
host=someServer,
cursorclass=MySQLdb.cursors.DictCursor
)

c = db.cursor()
t1 = time.time()
sql =  SELECT fields.name,values.name,users.user,subjects.leg_id
FROM annotations
LEFT JOIN `fields` ON annotations.field = fields.id
LEFT JOIN `values` ON annotations.value = `values`.id
LEFT JOIN `users` ON annotations.user = `users`.id
LEFT JOIN `subjects` ON annotations.subject = `subjects`.id
WHERE users.user = msn
AND subjects.id = 2

c.execute(sql)
results = c.fetchall()
holder = []

for res in results:
holder.append(res)
t2 = time.time()
print (t2-t1)

sql = 
SELECT annotations.id AS annotations_id, annotations.user AS  
annotations_user, annotations.subject AS annotations_subject,  
annotations.field AS annotations_field, annotations.value AS  
annotations_value, users_1.id AS users_1_id, users_1.user AS  
users_1_user, users_1.pass AS users_1_pass, users_1.lab_id AS  
users_1_lab_id, users_1.email AS users_1_email, groups_1.id AS  
groups_1_id, groups_1.name AS groups_1_name, subjects_1.id AS  
subjects_1_id, subjects_1.leg_id AS subjects_1_leg_id,  
subjects_1.`displayOrder` AS `subjects_1_displayOrder`, fields_1.id AS  
fields_1_id, fields_1.name AS fields_1_name, fields_1.help AS  
fields_1_help, values_1.id AS values_1_id, values_1.`parentId` AS  
`values_1_parentId`, values_1.field AS values_1_field, values_1.name  
AS values_1_name, values_1.image AS values_1_image, values_1.`order`  
AS values_1_order
FROM users, subjects, annotations
LEFT OUTER JOIN users AS users_1 ON users_1.id = annotations.user
LEFT OUTER JOIN usergroup AS usergroup_1 ON users_1.id =  
usergroup_1.`userId`
LEFT OUTER JOIN groups AS groups_1 ON groups_1.id =  
usergroup_1.`groupId`
LEFT OUTER JOIN subjects AS subjects_1 ON subjects_1.id =  
annotations.subject
LEFT OUTER JOIN `fields` AS fields_1 ON fields_1.id = annotations.field
LEFT OUTER JOIN `values` AS values_1 ON values_1.id = annotations.value
WHERE users.user = '%s' AND subjects.id = %s
ORDER BY annotations.id, users_1.id, usergroup_1.`userId`,  
subjects_1.id, fields_1.id, values_1.id
%(msn,2)
t1 = time.time()
c.execute(sql)
results = c.fetchall()
holder = []

for res in results:
holder.append(res)
t2 = time.time()
print (t2-t1)
t2 = time.time()
print allAnn
# This prints:



t1 = time.time()
print len(allAnn.all())
t2 = time.time()
print (t2-t1)

[sqlalchemy] Re: Cross Join

2008-11-21 Thread Michael Bayer

cross joins can be performed using implicit cross join.  no ON CLAUSE  
is needed:

select([a_o, b_o])


On Nov 21, 2008, at 6:49 AM, Ash wrote:


 Hello,

 I want to know how to implement the cross join using sqlalchemy

 I create the metadata say metadata

 i have table a and b which i want to cross join.

 a_o = sqlalchemy.Table('a',metadata,autoload=True)
 b_o = sqlalchemy.Table('b',metadata,autoload=True)

 j = join(a_o,b_o, onclause=a_o.c.b_id==b_o.c.id)

 This gives me the join thing

 select = sqlachemy.select(from_obj=[j],columns=[a_o.c.name])

 result = select.execute()

 output = result.fetchall()

 But this is not the cross join.

 Thanks in the advance.
 


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



[sqlalchemy] from sqlalchemy all() to subquery to threaded process?

2008-11-21 Thread Lukasz Szybalski

Hello,

I am pulling a list of files I need to print from a database and I
have all the records after doing the sqlalchemy query with .all()

Now I have a list of 3000 files I need to print, around 3 files per
userID, I want to print all 3 at the same time in different threads,
and my only requirement is that all files are printed for user 1
before we start printing for user 2.

Because the process doesn't use full power of the CPU when I print one
by one, I want to thread the process so it prints all 3 files at the
same time in different threads. When its done it moves on to the next
userid.

How can I sub query by user Id?

results= 
Session.query(PrintTable).filter(PrintTable.Date='20081120').order_by(PrintTable.Username).all()

How can I from above result go to:

1. In a for loop,
 a.  get a list of files for userid=1   (userid=1 files to print
file1,file2,file3)
 b. pass the 3 filenames to a thread function that will print the files
 c. go to the next userid

Any idea how can this be done? I can find some tutorials on threading
but I'm not sure how can I subquery to get the 3 file names?

Thanks,
Lucas

-- 
Turbogears2 Manual
http://lucasmanual.com/mywiki/TurboGears2
Bazaar and Launchpad
http://lucasmanual.com/mywiki/Bazaar

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



[sqlalchemy] how to write a dirty relation to the db?

2008-11-21 Thread robert rottermann

Hi there,
I try to grasp relations ..

I have an m:n association between two tables.

this is what I do:
engine = sa.create_engine('mysql://[EMAIL PROTECTED]/energie_2', echo=True)
Session = sessionmaker(bind=engine)
session = Session()

this is what I have:
tblPersonTable and tblSupplierTable derived from BASE and work fine on
their own

class User(tblPersonTable):
suppliers = relation(
tblSupplierTable,
secondary=tblPersonSupplierTable.__table__,
backref='suppliers')


def getRecordsForUser():
supplier = session.query(tblSupplierTable).filter_by(id=12).one()
user=session.query(User).filter_by(plone_id='johndoe').one()
user.suppliers.append(supplier)
session.update(user)
...

as you can see User has a relation that connects to Supplier via an
association table.
in the above method I get supplier and user as expected.
user.suppliers has one entry as it should have, so the relation works.

user.suppliers.append(supplier) adds a second supplier.
now session.update(user) should write a new entry into the association
table I *think*.
but it does not.

can somebody give me a hint what I should do to make it happen?

robert

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



[sqlalchemy] Re: how to write a dirty relation to the db?

2008-11-21 Thread robert rottermann

found it out myself.
a commit was missing
thanks for your time
robert
robert rottermann schrieb:
 Hi there,
 I try to grasp relations ..

 I have an m:n association between two tables.

 this is what I do:
 engine = sa.create_engine('mysql://[EMAIL PROTECTED]/energie_2', echo=True)
 Session = sessionmaker(bind=engine)
 session = Session()

 this is what I have:
 tblPersonTable and tblSupplierTable derived from BASE and work fine on
 their own

 class User(tblPersonTable):
 suppliers = relation(
 tblSupplierTable,
 secondary=tblPersonSupplierTable.__table__,
 backref='suppliers')


 def getRecordsForUser():
 supplier = session.query(tblSupplierTable).filter_by(id=12).one()
 user=session.query(User).filter_by(plone_id='johndoe').one()
 user.suppliers.append(supplier)
 session.update(user)
 ...

 as you can see User has a relation that connects to Supplier via an
 association table.
 in the above method I get supplier and user as expected.
 user.suppliers has one entry as it should have, so the relation works.

 user.suppliers.append(supplier) adds a second supplier.
 now session.update(user) should write a new entry into the association
 table I *think*.
 but it does not.

 can somebody give me a hint what I should do to make it happen?

 robert

 

   


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



[sqlalchemy] Re: Insert.params() broken?

2008-11-21 Thread bukzor

On Nov 20, 7:39 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Nov 20, 2008, at 9:05 PM, bukzor wrote:

  Would it make sense to rename Insert.values to Insert.params? Or make
  Insert.params call Insert.values.
  It seems quite strange for an object to have functions that aren't
  usable...

 its an entirely different function.  If you said this:

 t = table.update().where(table.c.col1==bindparam('x', value=5))

 Saying this:

 t2 = t.params('x', 12)

 would in theory produce (with bind values inlined) UPDATE table WHERE  
 x=12

 while saying this:

 t3 = t.values('x', 12)

 would produce UPDATE TABLE SET x=12 WHERE x=5

 for an INSERT, the difference would apply to bind params that are  
 perhaps embedded in subqueries within the VALUES clause.


Thanks for explaining. My problem was that I thought the insert values
would be implemented as bindparams.


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



[sqlalchemy] Re: Insert.params() broken?

2008-11-21 Thread bukzor

On Nov 20, 6:20 pm, Empty [EMAIL PROTECTED] wrote:
  Different, but related question: How do I print out the statement in
  copy-paste-able format? More specifically, how do i get an ordered
  list of bound values out of the statement?

  This code does what I want, but it's really clunky and fragile:

  def print_statement(stmt):
     s = str(stmt).replace(?, %s)
     from re import search
     args = search(\((.*?)\), s).group(1).split(, )
     print s % tuple(repr(stmt.params[arg]) for arg in args)

  There's also a UsageRecipe for this:
 http://www.sqlalchemy.org/trac/wiki/DebugInlineParams

 Michael

Thanks! That was exactly what I was looking for. I tried to dig though
the dialects and compilers and everything to figure this out, but
after a few hours, no success.

It would be great if we had a sqlalchemy utility to print out our
statements in an expanded way. Yes, it's unsafe, but it's pretty
essential for debugging.

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



[sqlalchemy] can't connect with 0.5rc4 (pylons)

2008-11-21 Thread Anil

bash-3.2$ paster setup-app development.ini
...
  File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc4-py2.5.egg/
sqlalchemy/engine/strategies.py, line 81, in connect
raise exc.DBAPIError.instance(None, None, e)
sqlalchemy.exc.OperationalError: (OperationalError) (1045, Access
denied for user
'admin'@'netblock-68-183-235-157.dslextreme.com' (using password:
YES)) None None

I get that error.

In the same terminal window, i am doing a command line run of 'mysql':

mysql -h db.host.com -u admin -p graph_db, it works fine... but I have
no idea why that is failing.

I did a print cparams in the strategies.py file:
{'passwd': 'pass', 'db': 'graph_db', 'port': 3306, 'host':
'db.host.com', 'user': 'admin', 'client_flag': 2}


Looks right to me. I have no idea what else is causing this. Very
weird. I am using mysql 5.1.25.

How else can I trouble shoot this?

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