[sqlalchemy] Re: checking in

2021-06-21 Thread 'Jonathan Vanasco' via sqlalchemy
> If not I wonder why messages aren't arriving in my INBOX.

Check your settings for this group.  If you do not see the option on the 
menu, try visiting https://groups.google.com/g/sqlalchemy/membership

Google sometimes has a product change de-selects the email delivery 
option.  Sometimes users de-select email delivery and forget about that too.


On Monday, June 14, 2021 at 5:25:47 PM UTC-4 rshe...@appl-ecosys.com wrote:

> I've not worked with SQLAlchemy for several years but now want to use it in
> a couple of applications. I've not seen messages on this maillist for a 
> very
> long time so I tried subscribing and learned that I'm still subscribed.
>
> Am I the only one on this list now?
>
> If not I wonder why messages aren't arriving in my INBOX.
>
> Rich
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/b9f2ec03-8dff-4796-b1a3-2efc4409729en%40googlegroups.com.


[sqlalchemy] Re: checking script validity

2013-08-29 Thread herzaso
Not quite related to sqlalchemy, but if you want a one-time check, check 
out sqlfiddle http://sqlfiddle.com/.


On Friday, August 30, 2013 8:30:09 AM UTC+3, monosij...@gmail.com wrote:

 Hello - 

 Not very familiar with sqlalchemy yet ...

 Is there a way to check if a script I have generated (not using 
 sqlalchemy) is valid for a particular DBMS (Postgres, MySQL, etc.)

 It would be an ANSI SQL script and there is module ansisql but not able to 
 find where I can check a script for validity against a particular DBMS 
 (Postgres).

 I would need to validate a create table script as well index creation 
 script and foreign key constraint script.

 Thank you.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


[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] Re: checking for C extensions at runtime

2010-07-18 Thread Michael Bayer


On Jul 16, 11:56 am, David Gardner dgard...@creatureshop.com wrote:
 I'm actually not sure, I did a bit of googling and couldn't really find
 much.
 Pep 386 talks about version comparison in 
 distutils:http://www.python.org/dev/peps/pep-0386/#id10

 As for scratching my itch it wouldn't have to be in the __version__
 string, I was just wondering how
 I would check if the SQLAlchemy on a system had the C extensions enabled
 on it or not.

at the moment, I'd probably try importing cprocessors from
sqlalchemy, or just look at
sqlalchemy.processors.str_to_date.__file__.   We haven't put any
official method for this in yet and also we'd like to have the C
extensions turned on by default at some point.


 On 07/15/2010 01:40 PM, Michael Bayer wrote:

  I was wondering if there was a way to check at runtime if the C extensions 
  were built with SQLAlchemy?

  If not I was wondering if you would consider adding something to the 
  __version__ string?

  is there some guideline for the format on that ?

 --
 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.



[sqlalchemy] Re: checking a relationship exists

2009-09-22 Thread joeformd

thanks - but how does that query specify a town?

It seems like that would just return true if the current user had any
town relationships? Or am I reading it wrong?


On Sep 19, 5:46 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Sep 19, 2009, at 11:41 AM, joeformd wrote:



  When we tried that it made a sql query to get all the towns (towns are
  loaded lazily) - that could be an awful lot of information, so this
  would be a much faster query

 so, the most succinct (and efficient) query of all is

 session.scalar(exists().where(user_towns.c.user_id==current_user.id))

 should return True/False right back





  On Sep 19, 4:33 pm, Michael Bayer mike...@zzzcomputing.com wrote:
  On Sep 19, 2009, at 10:19 AM, joeformd wrote:

  Thanks for the speedy response Michael,

  we came up with this:

   current_user_has_town = bool(session.query(User).filter
  (User.id==current_user.id).filter(User.towns.contains
  (current_user)).count())

  which maybe has slightly clearer intent?

  if you already have the current_user, why not just say town in
  current_user.towns
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: checking a relationship exists

2009-09-19 Thread joeformd

Thanks for the speedy response Michael,

we came up with this:

  current_user_has_town = bool(session.query(User).filter
(User.id==current_user.id).filter(User.towns.contains
(current_user)).count())

which maybe has slightly clearer intent?
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: checking a relationship exists

2009-09-19 Thread Michael Bayer


On Sep 19, 2009, at 10:19 AM, joeformd wrote:


 Thanks for the speedy response Michael,

 we came up with this:

  current_user_has_town = bool(session.query(User).filter
 (User.id==current_user.id).filter(User.towns.contains
 (current_user)).count())

 which maybe has slightly clearer intent?

if you already have the current_user, why not just say town in  
current_user.towns


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: checking a relationship exists

2009-09-19 Thread joeformd

When we tried that it made a sql query to get all the towns (towns are
loaded lazily) - that could be an awful lot of information, so this
would be a much faster query

On Sep 19, 4:33 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Sep 19, 2009, at 10:19 AM, joeformd wrote:



  Thanks for the speedy response Michael,

  we came up with this:

   current_user_has_town = bool(session.query(User).filter
  (User.id==current_user.id).filter(User.towns.contains
  (current_user)).count())

  which maybe has slightly clearer intent?

 if you already have the current_user, why not just say town in  
 current_user.towns
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: checking a relationship exists

2009-09-19 Thread Michael Bayer


On Sep 19, 2009, at 11:41 AM, joeformd wrote:


 When we tried that it made a sql query to get all the towns (towns are
 loaded lazily) - that could be an awful lot of information, so this
 would be a much faster query

so, the most succinct (and efficient) query of all is

session.scalar(exists().where(user_towns.c.user_id==current_user.id))

should return True/False right back





 On Sep 19, 4:33 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Sep 19, 2009, at 10:19 AM, joeformd wrote:



 Thanks for the speedy response Michael,

 we came up with this:

  current_user_has_town = bool(session.query(User).filter
 (User.id==current_user.id).filter(User.towns.contains
 (current_user)).count())

 which maybe has slightly clearer intent?

 if you already have the current_user, why not just say town in
 current_user.towns
 


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: checking a relationship exists

2009-09-18 Thread Michael Bayer


On Sep 18, 2009, at 7:44 PM, joeformd wrote:


 Is there a simple way in SQLA to check if a relationship exists
 between two rows in a many-to-many situation, where the relationship
 is defined using another table?

 eg. the join table might look like this:

 user_towns = Table('user_towns', Base.metadata,
Column('user_id', Integer, ForeignKey('users.id')),
Column('town_id', Integer, ForeignKey('towns.id'))
 )

 to check if a relationship exists, the SQL would be fairly simple,
 with no joins required (is there a row in this table where user.id =
 user_id and town.id = town_id)

 Is there a simple way of asking this using SQLA, with the query
 syntax?

the simplest would be query(User.id).join(User.towns).filter 
(User.id==uid).filter(Town.id==tid). 
  

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: checking if a column is in a list

2009-01-21 Thread Michael Bayer


On Jan 21, 2009, at 7:46 PM, Jack Stahl wrote:

 Hello,

 I've got a few SQL interfaces where I'd like to change my query  
 based on the columns required by the client.  For example, in one  
 situation, I only join against my User table if my client requires a  
 photo id:

 # cols is the list of columns the client would like selected
 if User.c.photo_id in cols:
 table = table.join(User.table)

 In another situation, I'd like to include the flags column in the  
 query even if the client ask for it

 if not cols:
 cols = [cls]
 elif not (cls.c.flags in cols):
 # ensure flags are there so we can add is_active
 cols.append(cls.c.flags)

 However, my tests for membership pass regardless of whether column  
 is actually in the list cols.  That is,

 Column('flags', BitField(), table=foo_table) in [Column('foo',  
 String(length=84, convert_unicode=False, assert_unicode=None),  
 table=foo_table), Column('bar', Text(length=None,  
 convert_unicode=False, table=foo_table)]

 evaluates to True

 Is the == operator not properly implemented for SQLAlchemy Columns?   
 (I'm using version 0.42)

it is not properly implemented in the sense that it does not return  
True or False, but if you''ve used SQLalchemy, you'd know that we  
redefine the == operator to return ClauseElement objects.   That's  
why you can say somecolumn==5 and get an expression from it.

So you cannot use the in operator to search for a Column object in a  
list.  The solution however is simple.  Use a set() instead, where the  
objects will be compared based on the return value of __hash__() which  
results in an object identity comparison.

if User.c.photo_id in set(cols):


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: checking if a column is in a list

2009-01-21 Thread Jack Stahl
Thanks Michael!
Properly was a poor choice of words on my part.  Yes, of course, == is
overloaded to make where (etc) clauses pretty, I just didn't put two and two
together.
--jack

On Wed, Jan 21, 2009 at 5:38 PM, Michael Bayer mike...@zzzcomputing.comwrote:



 On Jan 21, 2009, at 7:46 PM, Jack Stahl wrote:

  Hello,
 
  I've got a few SQL interfaces where I'd like to change my query
  based on the columns required by the client.  For example, in one
  situation, I only join against my User table if my client requires a
  photo id:
 
  # cols is the list of columns the client would like selected
  if User.c.photo_id in cols:
  table = table.join(User.table)
 
  In another situation, I'd like to include the flags column in the
  query even if the client ask for it
 
  if not cols:
  cols = [cls]
  elif not (cls.c.flags in cols):
  # ensure flags are there so we can add is_active
  cols.append(cls.c.flags)
 
  However, my tests for membership pass regardless of whether column
  is actually in the list cols.  That is,
 
  Column('flags', BitField(), table=foo_table) in [Column('foo',
  String(length=84, convert_unicode=False, assert_unicode=None),
  table=foo_table), Column('bar', Text(length=None,
  convert_unicode=False, table=foo_table)]
 
  evaluates to True
 
  Is the == operator not properly implemented for SQLAlchemy Columns?
  (I'm using version 0.42)

 it is not properly implemented in the sense that it does not return
 True or False, but if you''ve used SQLalchemy, you'd know that we
 redefine the == operator to return ClauseElement objects.   That's
 why you can say somecolumn==5 and get an expression from it.

 So you cannot use the in operator to search for a Column object in a
 list.  The solution however is simple.  Use a set() instead, where the
 objects will be compared based on the return value of __hash__() which
 results in an object identity comparison.

if User.c.photo_id in set(cols):


 


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Checking active transactions

2008-02-22 Thread Michael Bayer


On Feb 22, 2008, at 5:29 AM, Christoph Zwerschke wrote:


 In TurboGears 1, requests are encapsulated between a session.begin()  
 and
 session.commit() call (or session.rollback(), if there was an error).

 Starting with SA 0.4.3, the commit() raises an exception if the
 transaction has been already rolled back in the request (explicitly or
 due to an error). So TurboGears needs to check whether the transaction
 is active before the session.commit() call. We currently do this by
 storing the transaction as the return value of session.begin() and  
 then
 checking transaction.is_active (or transaction.session.transaction for
 earlier SA versions).

 This gets complicated since the transaction may be restarted during a
 request and can change. So I think it would be handy to tell directly
 from the session whether the transaction is active or not.

 We are using *scoped* sessions in TruboGears, and the problem is that
 the transaction attribute is not available in ScopedSessions, so I can
 not check for session.transaction.is_active. I can get the original
 Session by calling session, so session().transaction.is_active would
 work, but it does not feel right. I guess it is by intent that the
 session attributes are not visible in scoped sessions.

 So how about adding a property is_active to the Session that would  
 call
 session.transaction.is_active? Then you could do:

 if session.is_active:
session.commit()


thats fine...but also why cant you just say try: session.commit()  
except: session.rollback(); raise   ?




--~--~-~--~~~---~--~~
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: Checking active transactions

2008-02-22 Thread Christoph Zwerschke

Michael Bayer schrieb:
 thats fine...but also why cant you just say try: session.commit()  
 except: session.rollback(); raise   ?

This would raise an error when the session is already inactive. I don't 
want an error in this case. On the other hand, if I remove the raise 
statement, then errors on commit would be swallowed. I thought about 
catching only InvalidRequestError, but this might also catch too much.

-- Christoph

--~--~-~--~~~---~--~~
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: checking the sql string.

2007-05-29 Thread Michael Bayer


On May 27, 2007, at 4:23 PM, SamDonaldson wrote:


 How do I look to see what sql is being constructed in the query
 object?  So if I have something like:

 q = query.session(User)
 q = q.add_column()
 q = q.group_by(.).select()

 How do I check what sql string has been constructed in q?

the Select object is returned by query.compile().  but also you can  
just enable logging of 'sqlalchemy.engine' or  use echo=True on  
create_engine() which may be more expedient.


 Also, say I want to do a group by a particular column name on the User
 table and I have two aggregates, sum, and count?  How do I add these
 two columns to q?  Do I just call add_column twice?  It's not working,
 I'm getting an empty result set.

 q = query.session(User)
 q = q.add_column(func.sum(User.c.id).label('sum'))
 q = q.add_column(func.count(User.c.id).label('count'))
 q = q.group_by([User.c.blah]).select()

 I'm getting an empty result set.  What exactly does label do here?

its going to use the AS keyword to apply a column label, such as:

select users.id as users_id, users.name as users_name, sum(users.id)  
as sum, count(users.id) as count
FROM users GROUP BY users.blah

take a look what its generating and play around with the resulting  
SQL manually to get an idea about what will return results.



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---