by maschoff » Wed Oct 28, 2009 11:57 am
Very good question, indeed! To sum it up: legacy (Oracle, which we used before, uses sequences, MySQL does not).
Both, customer_1_tbl.customer_id and customer_1_tbl_seq are used in OpenEMM:
- field customer_id of customer_1_tbl in classes MailingDaoImpl and RecipientDaoImpl
- customer_1_tbl_seq in classes ImportRecipientsDaoImpl and RecipientDaoImpl
When a new recipient is stored in the database, customer_1_tbl_seq delivers the customer_id (Recipient.DaoImpl.getNewCustomerID) before the recipient is stored in customer_1_tbl (Recipient.DaoImpl.insertNewCust).
A count(customer_id) on customer_1_tbl_seq delivers the number of recipients who are AND have been in the database while a count(customer_id) on customer_1_tbl delivers the number of recipients who are in the database right now.
So, actually, the auto_increment for customer_1_tbl.customer_id is superflous since field customer_id is overwritten anyway. It could be even harmful if someone stores new recipients in customer_1_tbl directly but does not add the same number of entries to customer_1_tbl_seq, because in this case the next to be stored recipient whose ID is taken from customer_1_tbl_seq can not be stored in customer_1_tbl because the ID is alreay taken there.
Last edited by
maschoff on Sun Nov 01, 2009 10:44 am, edited 1 time in total.
OpenEMM Maintainer