From 9b34ac17ebdf73cc68d98f295b37570a2440971a Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Tue, 25 Jul 2017 02:19:01 +0530 Subject: [PATCH 1/2] Document new changes in CRM_Utils_SQL_Select --- docs/standards/sql.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/standards/sql.md b/docs/standards/sql.md index a320ce12..f0d2316e 100644 --- a/docs/standards/sql.md +++ b/docs/standards/sql.md @@ -12,8 +12,8 @@ $optedOut = 0; /* un-trusted data */ $query = " SELECT id - FROM civicrm_contact - WHERE + FROM civicrm_contact + WHERE display_name like %1 AND is_opt_out = %2"; @@ -44,13 +44,21 @@ Further information on this method can be found in the [CRM_Utils_SQL_Select cla ```php $columnName = CRM_Utils_Type::escape('cm.membership_status', 'MysqlColumnNameOrAlias'); -$sql = CRM_Utils_Sql_Select::from('civicrm_contact c') +$dao = CRM_Utils_Sql_Select::from('civicrm_contact c') ->join('cm', 'INNER JOIN civicrm_membership cm ON cm.contact_id = c.id') ->where('!column = @value', array( 'column' => $columnName, 'value' => 15, )) ->where('membership_type_id IN (#types)', array('types', array(1,2,3,4))) - ->toSQL(); -$result = CRM_Core_DAO::executeQuery($sql); + ->execute(); + +while ($dao->fetch()) { ... } +``` +You can chain with other DAO functions like ```fetchAll()```, ```fetchValue()``` or ```fetchMap()```. +```php +$records = CRM_Utils_SQL_Select::from('mytable') + ->select('...') + ->execute() + ->fetchAll(); ``` From 660e4f1e3fe93347a9c73b98108066ddddf296e3 Mon Sep 17 00:00:00 2001 From: Sean Madsen Date: Mon, 24 Jul 2017 15:36:18 -0600 Subject: [PATCH 2/2] Minor markdown syntax clean up --- docs/standards/sql.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/standards/sql.md b/docs/standards/sql.md index f0d2316e..6ee84f3e 100644 --- a/docs/standards/sql.md +++ b/docs/standards/sql.md @@ -55,7 +55,9 @@ $dao = CRM_Utils_Sql_Select::from('civicrm_contact c') while ($dao->fetch()) { ... } ``` -You can chain with other DAO functions like ```fetchAll()```, ```fetchValue()``` or ```fetchMap()```. + +You can chain with other DAO functions like `fetchAll()`, `fetchValue()` or `fetchMap()`. + ```php $records = CRM_Utils_SQL_Select::from('mytable') ->select('...')