Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a list of open cursors in sqlite?

Is there a option to see all the open cursors in some point of time in sqlite ? I know that there is some functions to do this on .Net (to see all the connections to database...)

But what can I do with sqlite ?

like image 251
Lukap Avatar asked Jan 21 '26 19:01

Lukap


1 Answers

I don't think there's a way of getting this information directly. What you can do, though, is create your own subclass of Cursor which tracks the currently open Cursors in a static list.

For example (pseudo-code, not tested):

public class TrackingCursor extends SQLiteCursor {

    private static List<Cursor> openCursors = new LinkedList<Cursor>();

    public TrackingCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
                          String editTable, SQLiteQuery query) {
        super(db, driver, editTable, query);
        openCursors.add(this);
    }

    public void close() {
        openCursors.remove(this);
    }

    public static List<Cursor> getOpenCursors() {
        return openCursors;
    }

}

You need to supply your own Factory to the DB, so that your TrackingCursors will be created instead of plain SQLiteCursors.

public class TrackingCursorFactory implements SQLiteDatabase.CursorFactory {

    Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery,
                     String editTable, SQLiteQuery query) {
        return new TrackingCursor(db, masterQuery, editTable, query);
    }
}

And finally tell the DB to use this factory by passing the factory as a parameter when you call openDatabase.

like image 108
Graham Borland Avatar answered Jan 23 '26 07:01

Graham Borland