X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FSQL%2FInsert.php;h=20c87853474754702bcd72752abcb6c2434c6658;hb=1ec76f38e5f2d5dfba95faa2cc7a5e736fd455ff;hp=e67457c78759f584f70fbeb42c8dca256876c552;hpb=26537f4ce77ff8a9a3d27bbe639b136f4e09a4cf;p=civicrm-core.git 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) {