diff --git a/chemistry_starters/database.py b/chemistry_starters/database.py index f9d5d1903af6f78224e60f2f455a02c91ad1f726..d7cfb213ef48a9195611ab35c83c13230c7c320a 100644 --- a/chemistry_starters/database.py +++ b/chemistry_starters/database.py @@ -31,11 +31,12 @@ def get_db(): return chemdb -def get_hids(tablestem, null_option=None): +def get_hids(tablestem, null_option=None, null_value=-1): """ Get a list of human-readable-identifier, primary key pairs from the database for a table null_option adds an option which translates to null in the database + null_value is the value to set for it """ tablename = tablestem + "_hid" db = get_db() @@ -46,8 +47,8 @@ def get_hids(tablestem, null_option=None): hids = db.cursor.fetchall() if null_option is not None: # We need a 'no data' value. 'None' is easily confused with Python None, - # but NULL implies SQL NULL; compromising on -1 - hids.insert(0, (-1, null_option)) + # but NULL implies SQL NULL; compromising on -1 as the default for null_value + hids.insert(0, (null_value, null_option)) db.conn.rollback() return hids