Posts

Showing posts with the label sqlite

How to share a :memory: database between different process in python using python sqlite3 package

How to share a :memory: database between different process in python using python sqlite3 package scenario is shown as below,i got many processes to do CPU-bound work and read only on the same database,i know cache and uri key words could be used for sqlite to share database cache between threads,but how about between processes?it's better to be available both for linux and windows, Thank you! def run(self): self.phyconn = apsw.Connection(self.fileName) self.memconn = apsw.Connection(":memory:") try:#backup.__exit__() just make sure copy if finished,not close backup,so with is good,memconn is still exist when out with self.memconn.backup("main", self.phyconn, "main") as backup: # call with 0 to get the total pages backup.step(0) total = backup.pagecount stepped = 0 one_percent = total if total < 100 else total // 100 last_percentage = 0 while step...

SQLiteException when querying a SELECT [on hold]

SQLiteException when querying a SELECT [on hold] I am developing an Android application with an SQLite database. It records transactions. The transactions table has the colums: transactions idTransaction INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT date DATE NOT NULL type INT NOT NULL details VARCHAR(100) NOT NULL notes VARCHAR(300) NOT NULL amount DOUBLE NOT NULL account INT NOT NULL category INT NOT NULL Also I made a method to get a cursor with all transactions: // Select all Transactions protected Cursor getTransactions() throws SQLException { Cursor mCursor = null; String colums = new String{"idTransaction", "date", "type", "details", "notes", "amount", "account", "category"}; mCursor = this.getReadableDatabase().query("Transactions", colums, null, null, null, null, "name ASC"); return mCursor; } In other class I made a method to move through the cursor that I get whe...

Cascade delete based on @ForeignKey in Android Rooms ORM

Cascade delete based on @ForeignKey in Android Rooms ORM I have two entities DBList adnd DBListContent . With one to many relationship between DBList and DBListContent . DBList DBListContent DBList DBListContent Here is the DBList class DBList @Entity(tableName = "lists") public class DBList { @PrimaryKey private String listId; private String title; private String createdDateTime; } Here is the DBListContent DBListContent @Entity(tableName = "listContents") public class DBListContent { @PrimaryKey public String listContentId; public String content; public String lastEditedBy; public String lastEditedDateTime; @ForeignKey(entity = DBList.class, parentColumns = "listId", childColumns = "dbListId", onDelete = CASCADE) public String dbListId; } When I delete a row in lists table, the corresponding rows in the listContents table are not deleted. lists listContents I deleted the rows using the following ...

Room running very slow

Room running very slow I'm trying to get/store data using the Room Persistence Library. The calls to get all data from a table is really slow, and I timed it using nanoTime to be about 1800ms, which I think is too slow. What could be going wrong? nanoTime Here's some more info: nanoTime AsyncTask The query is defined in DbDao as @Query("SELECT * FROM events") List<Event> getAllEvents(); 1 Answer 1 Async task is not good for handling Room database. I would suggest you to use executor and make a singleton class using this. Code is as follows. import android.os.Looper; import android.support.annotation.NonNull; import java.util.concurrent.Executor; import java.util.concurrent.Executors; public class AppExecutor { private static final Object LOCK = new Object(); private static AppExecutor sInstance; private final Executor diskIO; private final Executor mainThread; private final ...

query() method of Content provider returns data twice in recycler View adapter

query() method of Content provider returns data twice in recycler View adapter I am working on a android project, here i have a class CategoryProvider which extends ContentProvider class and i also implements LoaderManager.LoaderCallbacks<Cursor> in my main Activity and I also have CategoryAdapter class which extends RecyclerView.Adapter<CategoryAdapter.ViewHolder> . I have 3 records in my Sqlite database, now after initialization of Loader in main Activity when data is loading in the adapter it loads each record twice so how to fix that. CategoryProvider ContentProvider LoaderManager.LoaderCallbacks<Cursor> CategoryAdapter RecyclerView.Adapter<CategoryAdapter.ViewHolder> Sqlite CategotyAdapter.java public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHolder> { Cursor dataCursor; Context context; String global_lang = "English"; public static class ViewHolder extends RecyclerView.ViewHolder { p...