python - 'long' object has no attribute 'fetchall' -


i don't know wrong in code; working fine after database migration (sqlite3 mysql) no longer working. (i using mysql).

traceback: file "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) file "/usr/lib/python2.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 23. return view_func(request, *args, **kwargs)

code:

cursor = connection.cursor()                 data = cursor.execute(query)     data_list = data.fetchall()     return redirect("http://www.example.com?code=123" , code=302)     result_count = len(data_list)                if result_count==0:         return httpresponse('<script type="text/javascript"> alert ("try again"); window.location.href = "/reports/custom/";</script>')     data_desc = data.description      j=0     """         prepare first response       """     = datetime.datetime.now().strftime('%m-%d-%y_%h:%m:%s')                 response = httpresponse(mimetype='text/csv')     response['content-disposition'] = 'attachment; filename=hiv_report_%s.csv' %              writer = csv.writer(response)      headers = []     tab_no = 0     in data_desc:         #ws.write(0, j, (i[0].replace('_', ' ')).upper())                         if i[0] == 'id':             table_name = tab_order[tab_no]             tab_no = tab_no +1          headers.append((table_name+ " | " +i[0].replace('_', ' ')).upper())         writer.writerow(headers)     """         fill data csv cells     """                 value in data_list:         k=0         no_record_check=1                         row = []         val in value:             #ws.write(j, k, val)             row.append(val)         writer.writerow(row)  

mysqldb.cursor.execute(query) returns integer number of returned rows. number objects don't have fetchall method. need call fetchall method on cursor:

data_list = cursor.fetchall() 

to quote python db api:

.execute(operation [, parameters]) prepare , execute database operation (query or command). [...] return values not defined. 

as martijn said in comment sqlite3.cursor.execute returns cursor. since return value of cursor.execute not defined db api mysqldb.cursor.execute can return (the library writers chose return number of rows).

this means portable way of working python db api ignore return value of cursor.execute.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -