#673: CatWalk creates Queries that PostgreSQL chokes on
--------------------------------+-------------------------------------------
 Reporter:  [EMAIL PROTECTED]  |       Owner:  anonymous
     Type:  defect              |      Status:  new      
 Priority:  normal              |   Milestone:           
Component:  Toolbox             |     Version:           
 Severity:  major               |    Keywords:           
--------------------------------+-------------------------------------------
 When using CatWalk on an empty table with foreign keys, it creates Queries
 like this one:

 {{{SELECT tg_group_permission.permission_id,
 Count(tg_group_permission.group_id) FROM tg_group_permission WHERE
 tg_group_permission.permission_id IN() GROUP BY
 tg_group_permission.permission_id}}}

 PostgreSQL 8.1.3 chokes on the {{{IN()}}}. (empty set)

 Now I do not know (nor do I care ;)) whether it's a bug in PostgreSQL's
 SQL parser or not. However, since this query results in an empty set
 anyway, I've patched browse.py to return instead of executing this query.

 Patch follows:
 {{{
 Index: browse.py
 ===================================================================
 --- browse.py   (revision 982)
 +++ browse.py   (working copy)
 @@ -100,6 +100,8 @@
      def relation_values(self,object_name,rows):
          obj = self.load_object(object_name)
          ids = rows.keys()
 +        if not ids:
 +            return []
          conn = obj._connection
          joins = {}
          for column in obj.sqlmeta.joins:
 @@ -151,6 +153,8 @@
          return rows

      def foreign_key_query(self,column,alias,ids):
 +        if not ids:
 +            return []
          sql_object = self.load_object(column.foreignKey)
          conn = sql_object._connection
          query = conn.sqlrepr( Select( [
 sql_object.q.id,getattr(sql_object.q,alias) ],
 }}}

-- 
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/673>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Tickets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-tickets
-~----------~----~----~----~------~----~------~--~---

Reply via email to