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