How to efficiently use MySQLDB SScursor?

I am in agreement with Otto Allmendinger’s answer, but to make explicit Denis Otkidach’s comment, here is how you can iterate over the results without using Otto’s fetch() function: import MySQLdb.cursors connection=MySQLdb.connect( host=”thehost”,user=”theuser”, passwd=”thepassword”,db=”thedb”, cursorclass = MySQLdb.cursors.SSCursor) cursor=connection.cursor() cursor.execute(query) for row in cursor: print(row)

Output pyodbc cursor results as python dictionary

If you don’t know columns ahead of time, use Cursor.description to build a list of column names and zip with each row to produce a list of dictionaries. Example assumes connection and query are built: >>> cursor = connection.cursor().execute(sql) >>> columns = [column[0] for column in cursor.description] >>> print(columns) [‘name’, ‘create_date’] >>> results = [] … Read more

MongoDB – Error: getMore command failed: Cursor not found

EDIT – Query performance: As @NeilLunn pointed out in his comments, you should not be filtering the documents manually, but use .find(…) for that instead: db.snapshots.find({ roundedDate: { $exists: true }, stream: { $exists: true }, sid: { $exists: false } }) Also, using .bulkWrite(), available as from MongoDB 3.2, will be far way more … Read more

android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

Whenever you are dealing with Cursors, ALWAYS check for null and check for moveToFirst() without fail. if( cursor != null && cursor.moveToFirst() ){ num = cursor.getString(cursor.getColumnIndex(“ContactNumber”)); cursor.close(); } Place logs appropriately to see whether it is returning null or an empty cursor. According to that check your query. Update Put both the checks in a … Read more

Why do people hate SQL cursors so much? [closed]

The “overhead” with cursors is merely part of the API. Cursors are how parts of the RDBMS work under the hood. Often CREATE TABLE and INSERT have SELECT statements, and the implementation is the obvious internal cursor implementation. Using higher-level “set-based operators” bundles the cursor results into a single result set, meaning less API back-and-forth. … Read more