database-cursor

How to efficiently use PyMongo cursor

How to efficiently use PyMongo cursor Question: Please propose ways to access data returned from collections.find() in an efficient manner. Is a for iteration the recommended way? How do I keep the character of a cursor being an Iterable? Thx Asked By: Martin Senne || Source Answers: Briefly: A cursor implements methods of Iterable and …

Total answers: 1

psycopg2 fetchmany vs named cursor

psycopg2 fetchmany vs named cursor Question: As per Psycopg2’s server-side-cursor documentation, If the dataset is too large to be practically handled on the client side, it is possible to create a server side cursor. Using this kind of cursor it is possible to transfer to the client only a controlled amount of data, so that …

Total answers: 1

AttributeError: 'NoneType' object has no attribute 'fetchall'

AttributeError: 'NoneType' object has no attribute 'fetchall' Question: I tried to return the result of an SQL query. This works perfectly with pyodbc but not with mysql-connector. Error Output File "/mySQLDB.py", line 17, in execute_and_fetch result = conn.cursor().execute(query, params).fetchall() AttributeError: ‘NoneType’ object has no attribute ‘fetchall’ Code import mysql.connector class MYSQLDB: def __init__(self): self.host = …

Total answers: 2

How to get cursor in SQLAlchamy

How to get cursor in SQLAlchemy Question: I am newbie in Python Flask. In my project we are creating db object using below code. app = Flask(__name__) app.config[‘SQLALCHEMY_DATABASE_URI’] = ‘sqlite:////tmp/test.db’ db = SQLAlchemy(app) I want to get cursor object from db. Can someone please help me on it. I know using connection object we can …

Total answers: 4

How to use cursors in Odoo?

How to use cursors in Odoo? Question: I don’t understand using cursor in version 9! Do you need cursor? In below example after call function in console line get: <openerp.sql_db.Cursor object at 0x7f94f4c0b0d0> @api.multi def my_func(self): cursor = self.env.cr print(cursor) Any simple example when and why use cursor? Asked By: user_odoo || Source Answers: You …

Total answers: 3

How to use server side cursors with psycopg2

How to use server side cursors with psycopg2 Question: I have a table with 4million rows and I use psycopg2 to execture a: SELECT * FROM ..WHERE query I haven’t heard before of the server side cursor and I am reading its a good practice when you expect lots of results. I find the documentation …

Total answers: 3

Why do I need to reconnect to the database to see changes in table data?

Why do I need to reconnect to the database to see changes in table data? Question: I periodically query a MySQL table and check data in the same row. I use MySQLdb to do the job, querying the same table and row every 15 seconds. Actually, the row data changes every 3 seconds, but the …

Total answers: 2

Python and sqlite3.ProgrammingError: Recursive use of cursors not allowed

Python and sqlite3.ProgrammingError: Recursive use of cursors not allowed Question: i wrote a python program like this that should run in multithreading mode: def Func(host,cursor,db): cursor.execute(”’SELECT If_index, Username, Version, Community, Ip_traff FROM HOST WHERE Hostname = ?”’,(host,)) #do something #— Main — db = sqlite3.connect(os.getcwd()+’HOST’, check_same_thread = False) #opendatabase cursor = db.cursor() #generate a cursor …

Total answers: 2

Necessity of explicit cursor.close()

Necessity of explicit cursor.close() Question: From time to time, I’m executing raw queries using connection.cursor() instead of using ORM (since it is definitely not a silver bullet). I’ve noticed that in several places I don’t call explicit cursor.close() after I’m done with database. So far, this hasn’t result into any errors, or performance issues. I’m …

Total answers: 5

cursor.fetchall() vs list(cursor) in Python

cursor.fetchall() vs list(cursor) in Python Question: Both methods return a list of the returned items of the query, did I miss something here, or they have identical usages indeed? Any differences performance-wise? Asked By: NZal || Source Answers: list(cursor) works because a cursor is an iterable; you can also use cursor in a loop: for …

Total answers: 5