CRM_Utils_SQL_Insert
class CRM_Utils_SQL_Insert
Dear God Why Do I Have To Write This (Dumb SQL Builder)
Usage: $insert = CRM_Utils_SQL_Insert::into('mytable') ->row(array('col1' => '1', 'col2' => '2' )) ->row(array('col1' => '2b', 'col2' => '1b')); echo $insert->toSQL();
Note: In MySQL, numeric values may be escaped. Except for NULL values, it's reasonable for us to simply escape all values by default -- without any knowledge of the underlying schema.
Design principles: - Portable - No knowledge of the underlying SQL API (except for escaping -- CRM_Core_DAO::escapeString) - No knowledge of the underlying data model - Single file - SQL clauses correspond to PHP functions ($select->where("foo_id=123"))
Methods
Create a new INSERT query.
Create a new SELECT query.
Get columns.
Get rows.
Get row.
Use REPLACE INTO instead of INSERT INTO.
Escape string.
Convert to SQL.
Details
at line 50
static CRM_Utils_SQL_Insert
into(string $table)
Create a new INSERT query.
at line 61
static CRM_Utils_SQL_Insert
dao(CRM_Core_DAO $dao)
Insert a record based on a DAO.
at line 83
__construct(string $table)
Create a new SELECT query.
at line 96
CRM_Utils_SQL_Insert
columns(array $columns)
Get columns.
at line 111
CRM_Utils_SQL_Insert
rows(array $rows)
Get rows.
at line 126
CRM_Utils_SQL_Insert
row(array $row)
Get row.
at line 153
CRM_Utils_SQL_Insert
usingReplace(bool $asReplace = TRUE)
Use REPLACE INTO instead of INSERT INTO.
at line 166
protected string
escapeString(string|NULL $value)
Escape string.
at line 176
string
toSQL()
Convert to SQL.