db query builder - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29) +--- Thread: db query builder (/showthread.php?tid=74240) |
db query builder - maximusto - 09-01-2019 I have a need to load multiple records into a database. There is a chance that some of these records might be duplicates (existing primary key). I want this to be fast and secure (no sql injection etc). Performing a loop and error checking $this->db->insert('mytable', $data); is not performant. Performing $this->db->insert_batch('mytable', $data); will fail. When I perform a $this->db->error() catch then I capture the first statement that failed in the $data. No clean way to resolve the issue (duplication) and resolve. Effectively I want 'Insert' statements generated by the query builder to be 'Insert Ignore'. Options * I would like to extend the Database component (without hacking / properly) * Am I missing a $this->db->ignore feature? * ??? As a hack, I have added to database\DB_query_builder.php with copied functions of public function insert_batch and _insert_batch to create insert_ignore_batch and _insert_ignore_batch where the "return 'INSERT INTO'" has been changed to "return 'INSERT IGNORE INTO'" Any advise on the best way to approach? Thanks Paul RE: db query builder - InsiteFX - 09-03-2019 You broke the CodeIgniter Golden Rule - You never ever edit a System file... RE: db query builder - maximusto - 09-03-2019 (09-03-2019, 03:01 AM)InsiteFX Wrote: You broke the CodeIgniter Golden Rule - You never ever edit a System file...I know..., the only purposely unextendable controller of the lot... the holy grail, the original sin... the shame. RE: db query builder - tgix - 09-05-2019 How many times haven't I been wishing for a way to extend the database classes... |