In the original Team Calendar plugin, I find:

        timetable_cursor.execute('SELECT ondate, username, availability '
                                 'FROM %s '
                                 'WHERE ondate >= "%s" AND ondate <= "%s" '
'GROUP BY ondate, username' % (self.table_name,

from_date.isoformat(),

to_date.isoformat(),))

which fails in PostgreSQL.  I changed it to:

        timetable_cursor.execute("SELECT ondate, username, availability "
                                 "FROM %s "
                                 "WHERE ondate >= '%s' AND ondate <= '%s' "
"GROUP BY ondate, username" % (self.table_name,

from_date.isoformat(),

to_date.isoformat(),))

That is, I reversed the use of single and double quotes.

Clearly neither of these can work on both MySQL and PostgreSQL. But http://trac-hacks.org/ticket/7115#comment:5 says:

  An even simple alternative for the example above is just to pass it
  as argument, and Trac will do whatever needed for quotes and types
  depending on backend:

  cursor.execute("SELECT * FROM myTable WHERE foo=%s", ('bar',))

So I try:

        timetable_cursor.execute('SELECT ondate, username, availability '
                                 'FROM %s '
                                 'WHERE ondate >= %s AND ondate <= %s '
'GROUP BY ondate, username, availability',
                                 (self.table_name,
                                  from_date.isoformat(),
                                  to_date.isoformat(),))

That is, unquote the date strings and replace the '%' format operator with a comma. With this change, the Team Calendar page shows:

  Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/web/api.py", line 377, in send_error
    'text/html')
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/web/chrome.py", line 743, in render_template
    message = req.session.pop('chrome.%s.%d' % (type_, i))
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/web/api.py", line 195, in __getattr__
    value = self.callbacks[name](self)
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/web/main.py", line 265, in _get_session
    return Session(self.env, req)
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/web/session.py", line 160, in __init__
    self.get_session(req.authname, authenticated=True)
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/web/session.py", line 176, in get_session
    super(Session, self).get_session(sid, authenticated)
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/web/session.py", line 59, in get_session
    (sid, int(authenticated)))
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/db/util.py", line 64, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
File "/usr/local/lib/python2.6/dist-packages/Trac-0.11.6-py2.6.egg/trac/db/util.py", line 64, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
InternalError: current transaction is aborted, commands ignored until end of transaction block

and trac.log says:

  ProgrammingError: syntax error at or near "E'team_availability'"
  LINE 1: SELECT ondate, username, availability FROM E'team_availabili...
                                                   ^
  ProgrammingError: syntax error at or near "E'team_availability'"
  LINE 1: SELECT ondate, username, availability FROM E'team_availabili...

Where's that 'E' come from? More usefully, what am I doing wrong? How can I pass strings to cursor.execute() and have it do the right thing?

                                                 Chris
--
Christopher Nelson, Software Engineering Manager
SIXNET - Solutions for Your Industrial Networking Challenges
331 Ushers Road, Ballston Lake, NY  12019
Tel: +1.518.877.5173, Fax: +1.518.877.8346 www.sixnet.com

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

Reply via email to