Documentation

CRM_Utils_SQL_Insert
in package
uses CRM_Utils_SQL_EscapeStringTrait

Object-oriented SQL builder for INSERT queries.

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"))

Table of Contents

Properties

$allowLiterals  : mixed
$columns  : array<string|int, mixed>
Array<string> list of column names
$rows  : array<string|int, mixed>
$table  : string
$verb  : string

Methods

__construct()  : mixed
Create a new SELECT query.
allowLiterals()  : mixed
columns()  : CRM_Utils_SQL_Insert
Get columns.
dao()  : CRM_Utils_SQL_Insert
Insert a record based on a DAO.
escapeString()  : string
execute()  : CRM_Core_DAO
Execute the query.
into()  : CRM_Utils_SQL_Insert
Create a new INSERT query.
row()  : CRM_Utils_SQL_Insert
Get row.
rows()  : CRM_Utils_SQL_Insert
Get rows.
toSQL()  : string
Convert to SQL.
usingReplace()  : CRM_Utils_SQL_Insert
Use REPLACE INTO instead of INSERT INTO.

Properties

$columns

Array<string> list of column names

private array<string|int, mixed> $columns

$rows

private array<string|int, mixed> $rows

$verb

private string $verb

Ex: 'INSERT INTO', 'REPLACE INTO'

Methods

__construct()

Create a new SELECT query.

public __construct(string $table[, string $verb = 'INSERT INTO' ]) : mixed
Parameters
$table : string

Table-name and optional alias.

$verb : string = 'INSERT INTO'

Ex: 'INSERT INTO', 'REPLACE INTO'

allowLiterals()

public allowLiterals([bool $allowLiterals = TRUE ]) : mixed
Parameters
$allowLiterals : bool = TRUE

escapeString()

public escapeString(string|null $value) : string
Parameters
$value : string|null
Return values
string

SQL expression, e.g. "it's great" (with-quotes) or NULL (without-quotes)

execute()

Execute the query.

public execute([bool $i18nRewrite = TRUE ]) : CRM_Core_DAO
Parameters
$i18nRewrite : bool = TRUE

If the system has multilingual features, should the field/table names be rewritten?

Tags
see
CRM_Core_DAO::executeQuery
see
CRM_Core_I18n_Schema::rewriteQuery
Return values
CRM_Core_DAO

into()

Create a new INSERT query.

public static into(string $table[, string $verb = 'INSERT INTO' ]) : CRM_Utils_SQL_Insert
Parameters
$table : string

Table-name and optional alias.

$verb : string = 'INSERT INTO'

Ex: 'INSERT INTO', 'REPLACE INTO'

Return values
CRM_Utils_SQL_Insert

toSQL()

Convert to SQL.

public toSQL() : string
Return values
string

SQL statement


        
On this page

Search results