From 09095684b3819b5438e3548cfdacc22d713fbc9a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 9 Jun 2014 18:49:12 -0700 Subject: [PATCH] CRM_Utils_SQL_Insert - Allow REPLACE INTO --- CRM/Utils/SQL/Insert.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/SQL/Insert.php b/CRM/Utils/SQL/Insert.php index e67457c787..20c8785347 100644 --- a/CRM/Utils/SQL/Insert.php +++ b/CRM/Utils/SQL/Insert.php @@ -22,6 +22,8 @@ */ class CRM_Utils_SQL_Insert { + private $verb = 'INSERT INTO'; + /** * @var string */ @@ -93,6 +95,17 @@ class CRM_Utils_SQL_Insert { return $this; } + /** + * Use REPLACE INTO instead of INSERT INTO + * + * @param bool $asReplace + * @return CRM_Utils_SQL_Insert + */ + public function usingReplace($asReplace = TRUE) { + $this->verb = $asReplace ? 'REPLACE INTO' : 'INSERT INTO'; + return $this; + } + /** * @param string|NULL $value * @return string SQL expression, e.g. "it\'s great" (with-quotes) or NULL (without-quotes) @@ -106,7 +119,7 @@ class CRM_Utils_SQL_Insert { */ public function toSQL() { $columns = "`" . implode('`,`', $this->columns) . "`"; - $sql = "INSERT INTO {$this->table} ({$columns}) VALUES"; + $sql = "{$this->verb} {$this->table} ({$columns}) VALUES"; $nextDelim = ''; foreach ($this->rows as $row) { -- 2.25.1