I have done slight changes in the code and its working for select() 
statement but still facing problem in case of delete():

code:

def test():
    
    query = request.vars['keywords']
    
    if query:
        print query        
        row =str(db(query).select(db.status.ALL))
        if row:
            print row
    redirect(URL('status'))

In this case query string is : *status.id = "12"*
So I am getting result properly, but problem is:
 if I remove *db.status.ALL* from select() statement , it again gives the 
same error : 
*<type 'exceptions.SyntaxError'> Set: no tables selected*


Same applies for delete() statement, even for delete we can't specify the 
database table name as a parameter like select().



On Wednesday, 21 November 2012 12:01:08 UTC+5:30, Amit wrote:
>
> I have added button "Delete" beside Clear button on SQLFORM.grid and when 
> user selects query and click on it , I am passing the query to my 
> controller function and using regular expression I just prepending "db." 
> and changing "=" to "==" and passing the query to the db() function but it 
> throws SyntaxError : Set: no tables selected.
>
> Please check below the code:
>
> def status():
>     
>     grid = SQLFORM.grid(db.status)
>     
>     grid[0][1][1].components.append(TAG.a('Delete',_id="px-delete",\
>                                           _class 
> ="btn",_onclick="window.location 
> = '" \
>                                           + URL('default','test')+"?"+ "'+ 
> $('#web2py_keywords').serialize();\
>                                            "))
>     
>     return locals()
>
>
> def test():
>     
>     query = request.vars['keywords']
>     
>     if query:
>         modfied_query = re.sub(r'(status)', r'db.\1', query)
>         final_query = re.sub(r'(=)', r'=\1', modfied_query)               
>  
>         row =db(final_query).select().first()
>         if row:
>             print row            
>     redirect(URL('status'))
>
> here, status is the grid view where I added the Delete button and after 
> query selection If I click button , I am able to get the query like 
> status.id = "12", I changed it using regex to db.status.id == "12" and 
> passing the final string to db() function , please check test() function.
>
> I am getting error on the below statement:
>
> *row **=db(final_query).select().first()*
>
> where "final_query" value will be db.status.id == "12".
>
> But if I use the same query like this:
>
> *row =db(db.status.id == "12").select().first()*
>
> it works fine.
>
> So not sure what I am doing wrong on the passing string as query.
>
>

-- 



Reply via email to