Commits

Fausto Carrera committed 41789e8

fix codeigniter INSERT IGNORE on active record

Comments (0)

Files changed (3)

app/models/trades_model.php

 	}
 
 	public function createTradeBatch($data) {
+		$this->db->ignore();
 		$result = $this->db->insert_batch('trades', $data);
 	}
 }

system/database/DB_active_rec.php

 
 	var $ar_select				= array();
 	var $ar_distinct			= FALSE;
+	var $ar_ignore				= FALSE;
 	var $ar_from				= array();
 	var $ar_join				= array();
 	var $ar_where				= array();
 		return $this->query($sql);
 	}
 
+	/**
+	 * ignore duplicated rows
+	 * @param  boolean $val
+	 * @return object
+	 */
+	function ignore($val = TRUE) {
+		$this->ar_ignore = (is_bool($val)) ? $val : TRUE;
+		return $this;
+	}
+
 	// --------------------------------------------------------------------
 
 	/**
 			'ar_orderby'	=> array(),
 			'ar_keys'		=> array(),
 			'ar_limit'		=> FALSE,
-			'ar_order'		=> FALSE
+			'ar_order'		=> FALSE,
+			'ar_ignore'		=> FALSE
 		);
 
 		$this->_reset_run($ar_reset_items);

system/database/drivers/mysql/mysql_driver.php

 	 */
 	function _insert($table, $keys, $values)
 	{
-		return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+		$sql = ( ! $this->ar_ignore) ? 'INSERT ' : 'INSERT IGNORE ';
+		return $sql."INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
 	}
 
 	// --------------------------------------------------------------------
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.