Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

OpenERP/Odoo - Quote inside a string is not working - cr.execute(SQL)

By
Selverine
on 8/2/16, 3:58 AM 307 views

Hi all,


In OpenERP 7 , I am using a cr.execute to execute a SQL Request

cr.execute('select distinct(value) from ir_translation where name = \'product.bat3,name\' and src = \''+ str(res_bat[j][0].encode('utf-8'))+'\' and res_id = '+ str(res_bat[j][1])+' and lang = \''+ str(line2.partner_id.lang)+'\'')

However, my string res_bat[j][0] is a string with a quote. The string is: test's Thus I have the error bellow:

ProgrammingError: syntax error at or near "s"
LINE 1: ... where name = 'product.bat3,name' and src = 'test's' and res...

How can I modify my SQL request to correct this error?


Many thanks,


Selverine    

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 8/2/16, 5:48 AM

Hello

as a quick workaround you can use:

res_bat[j][0].replace("'", "''")

So with this double single quotes the postgres can skip the single quote ...

Hope this could helps ...

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/2/16, 3:58 AM
Seen: 307 times
Last updated: 8/2/16, 5:48 AM