Skip to Content
Menu
This question has been flagged
1 Reply
5582 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

Avatar
Discard
Best Answer

Arun,

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

Hope it work!

Avatar
Discard