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

How to select database table using select query

By
Arunkumar
on 8/26/16, 2:31 AM 264 views

here i enter tablename in field " table_name"

@http.route('/sample/demo', auth='public',website=True)

def click(self, **post):

        print "post data===================>",post

        cr = request.cr

        pool = request.registry

        table_name=post.get('t_name',False)

        user_id = post.get('user_id',False)

        response_dict = {}

        jd=[]

        if user_id and table_name:

                print"888888888888888",type(table_name)

                print"Enterloginpage======================="

                cr.execute("select username,country from %s",(str(table_name),))

                res=cr.dictfetchall()

                print "****************",res;

                return http.request.render('json.arun1')

        else:

                print "Invalid user_id"

        return http.request.render('json.arunkumar')

if i use this it produce,

        ProgrammingError: syntax error at or near "'user_registration'"

        LINE 1: select username,country from 'user_registration'

how to get dynamic table using select query

0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 8/26/16, 8:54 AM

Arun,

remove 'str' from str(table_name), and keep this
 cr.execute("select username,country from %s",(table_name))

Hope it work!

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/26/16, 2:31 AM
Seen: 264 times
Last updated: 8/26/16, 8:54 AM