When to close db connection on android? Every time after your operation finished or after your app exit

I don’t know of any performance penalties in frequent closing/opening of the database (regardless of its size). I think the answer to this question also depends on what type of application is accessing the database. Do you “re-query” the database a lot? Then it seems rectified to keep it open. Do you fetch different data … Read more

How to check if a double is null?

Firstly, a Java double cannot be a Java null, and cannot be compared with null. (The double type is a primitive (non-reference) type and primitive types cannot be null.) I’m therefore assuming the following: The “null” you are trying to detect is a NULL stored in the database that you are querying. You are using … Read more

Database – Data Versioning [closed]

I have done various audit schemes over the years and I am currently going to implement something like this: Person ———————————————— ID UINT NOT NULL, PersonID UINT NOT NULL, Name VARCHAR(200) NOT NULL, DOB DATE NOT NULL, Email VARCHAR(100) NOT NULL Person_History ———————————————— ID UINT NOT NULL, PersonID UINT NOT NULL, Name VARCHAR(200) NOT NULL, … Read more

PostgreSQL database service

Use services (start -> run -> services.msc) and look for the postgresql-[version] service. If it is not there you might have just installed pgAdmin and not installed PostgreSQL itself. If it is not running try to start it, if it won’t start open the event-viewer (start -> run -> eventvwr) and look for error messages … Read more

row-level trigger vs statement-level trigger

The main difference is not what can be modified by the trigger, that depends on the DBMS. A trigger (row or statement level) may modify one or many rows*, of the same or other tables as well and may have cascading effects (trigger other actions/triggers) but all these depend on the DBMS of course. The … Read more

using sqlalchemy to load csv file into a database

In case your CSV is quite large, using INSERTS is very ineffective. You should use a bulk loading mechanisms, which differ from base to base. E.g. in PostgreSQL you should use “COPY FROM” method: with open(csv_file_path, ‘r’) as f: conn = create_engine(‘postgresql+psycopg2://…’).raw_connection() cursor = conn.cursor() cmd = ‘COPY tbl_name(col1, col2, col3) FROM STDIN WITH (FORMAT … Read more