On Wed, Oct 3, 2012 at 5:23 PM, Trinath Somanchi <trinath.soman...@gmail.com> wrote: > Hi Simon- > > I have update my ORM query this way > > result = > session.query(models.Instance.hostname.distinct(),models.FixedIp.address,models.VirtualInterface.address).\ > join((models.InstanceMetadata, > models.InstanceMetadata.instance_id == > models.Instance.id)).\ > join ((models.FixedIp, > models.FixedIp.instance_id == > models.InstanceMetadata.instance_id)).\ > join ((models.VirtualInterface, > models.VirtualInterface.instance_id == > models.FixedIp.instance_id)).\ > filter(and_(models.Instance.project_id == search_opts['project_id'], > models.InstanceMetadata.key == > search_opts['key'], > models.InstanceMetadata.value == > search_opts['value'])).\ > all() > > > I have received an Programming error > > ProgrammingError: (ProgrammingError) (1064, 'You have an error in your SQL > syntax; check the manual that corresponds to your MySQL server version for > the right syntax to use near \') AND instance_metadata.value = > ("\'DOM1\'",)\' at line 3') 'SELECT DISTINCT instances.hostname AS anon_1, > fixed_ips.address AS fixed_ips_address, virtual_interfaces.address AS > virtual_interfaces_address \nFROM instances INNER JOIN instance_metadata ON > instance_metadata.instance_id = instances.id INNER JOIN fixed_ips ON > fixed_ips.instance_id = instance_metadata.instance_id INNER JOIN > virtual_interfaces ON virtual_interfaces.instance_id = fixed_ips.instance_id > \nWHERE instances.project_id = %s AND instance_metadata.`key` = %s AND > instance_metadata.value = %s' ('e216fcb54dc944a8ab16e4e325299643', ['Server > Group'], ['DOM1']) > > Can you help me troubleshoot the issue. >
The parameters you are passing to the query are: ('e216fcb54dc944a8ab16e4e325299643', ['Server Group'], ['DOM1']) but I suspect they should be ('e216fcb54dc944a8ab16e4e325299643', 'Server Group', 'DOM1') ie. the last 2 elements should be strings, not single-element lists. If you are getting these from a web form, are they perhaps multiple-selection fields? In which case you'll probably want to change the search conditions to be something like: models.InstanceMetadata.key.in_(search_opts['key']) However, you should only add that condition if search_opts['key'] is not empty. (I *think* SA warns you if you pass an empty list to "in_") 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.