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

Looping Over Result Sets in MySQL

Something like this should do the trick (However, read after the snippet for more info) CREATE PROCEDURE GetFilteredData() BEGIN DECLARE bDone INT; DECLARE var1 CHAR(16); — or approriate type DECLARE var2 INT; DECLARE var3 VARCHAR(50); DECLARE curs CURSOR FOR SELECT something FROM somewhere WHERE some stuff; DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = … 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

SQL Call Stored Procedure for each Row without using a cursor

Generally speaking I always look for a set based approach (sometimes at the expense of changing the schema). However, this snippet does have its place.. — Declare & init (2008 syntax) DECLARE @CustomerID INT = 0 — Iterate over all customers WHILE (1 = 1) BEGIN — Get next customerId SELECT TOP 1 @CustomerID = … Read more

Why is it considered bad practice to use cursors in SQL Server?

Because cursors take up memory and create locks. What you are really doing is attempting to force set-based technology into non-set based functionality. And, in all fairness, I should point out that cursors do have a use, but they are frowned upon because many folks who are not used to using set-based solutions use cursors … Read more