Skip to content

Commit 51ebb11

Browse files
committed
PCBC-534: Add profile N1QL query parameter
Change-Id: Ic91e044a28b4f78ff2f861e1c1708cd6df0b5139 Reviewed-on: http://review.couchbase.org/95122 Tested-by: Build Bot <[email protected]> Reviewed-by: Sergey Avseyev <[email protected]>
1 parent 4263284 commit 51ebb11

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

api/couchbase.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,19 @@ class N1qlQuery {
19001900
*/
19011901
const STATEMENT_PLUS = 3;
19021902

1903+
/**
1904+
* Disables profiling. This is the default
1905+
*/
1906+
const PROFILE_NONE = 'off';
1907+
/**
1908+
* Enables phase profiling.
1909+
*/
1910+
const PROFILE_PHASES = 'phases';
1911+
/**
1912+
* Enables general timing profiling.
1913+
*/
1914+
const PROFILE_TIMINGS = 'timings';
1915+
19031916
/** @ignore */
19041917
final private function __construct() {}
19051918

@@ -1979,6 +1992,16 @@ public function namedParams($params) {}
19791992
*/
19801993
public function consistency($consistency) {}
19811994

1995+
/**
1996+
* Controls the profiling mode used during query execution
1997+
*
1998+
* @param string $profileType
1999+
* @returns N1qlQuery
2000+
* @see \Couchbase\N1qlQuery::PROFILE_NONE
2001+
* @see \Couchbase\N1qlQuery::PROFILE_PHASES
2002+
* @see \Couchbase\N1qlQuery::PROFILE_TIMINGS
2003+
*/
2004+
public function profile($profileType) {}
19822005
/**
19832006
* Sets mutation state the query should be consistent with
19842007
*

src/couchbase/n1ql_query.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ zend_class_entry *pcbc_n1ql_query_ce;
2525
#define PCBC_N1QL_CONSISTENCY_REQUEST_PLUS 2
2626
#define PCBC_N1QL_CONSISTENCY_STATEMENT_PLUS 3
2727

28+
#define PCBC_N1QL_PROFILE_NONE "off"
29+
#define PCBC_N1QL_PROFILE_PHASES "phases"
30+
#define PCBC_N1QL_PROFILE_TIMINGS "timings"
31+
2832
/* {{{ proto void N1qlQuery::__construct() Should not be called directly */
2933
PHP_METHOD(N1qlQuery, __construct)
3034
{
@@ -289,6 +293,24 @@ PHP_METHOD(N1qlQuery, consistency)
289293
RETURN_ZVAL(getThis(), 1, 0);
290294
} /* }}} */
291295

296+
/* {{{ proto \Couchbase\N1qlQuery N1qlQuery::profile(string $profileType) */
297+
PHP_METHOD(N1qlQuery, profile)
298+
{
299+
char *profile_type = NULL;
300+
pcbc_str_arg_size profile_type_len = 0;
301+
int rv;
302+
zval *options;
303+
304+
rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &profile_type, &profile_type_len);
305+
if (rv == FAILURE || profile_type == NULL) {
306+
RETURN_NULL();
307+
}
308+
309+
PCBC_READ_PROPERTY(options, pcbc_n1ql_query_ce, getThis(), "options", 0);
310+
ADD_ASSOC_STRING(options, "profile", profile_type);
311+
RETURN_ZVAL(getThis(), 1, 0);
312+
} /* }}} */
313+
292314
/* {{{ proto \Couchbase\N1qlQuery N1qlQuery::consistentWith(\Couchbase\MutationState $mutationState) */
293315
PHP_METHOD(N1qlQuery, consistentWith)
294316
{
@@ -336,6 +358,10 @@ ZEND_BEGIN_ARG_INFO_EX(ai_N1qlQuery_consistency, 0, 0, 1)
336358
ZEND_ARG_INFO(0, consistency)
337359
ZEND_END_ARG_INFO()
338360

361+
ZEND_BEGIN_ARG_INFO_EX(ai_N1qlQuery_profile, 0, 0, 1)
362+
ZEND_ARG_INFO(0, profileType)
363+
ZEND_END_ARG_INFO()
364+
339365
ZEND_BEGIN_ARG_INFO_EX(ai_N1qlQuery_params, 0, 0, 1)
340366
ZEND_ARG_INFO(0, params)
341367
ZEND_END_ARG_INFO()
@@ -373,6 +399,7 @@ zend_function_entry n1ql_query_methods[] = {
373399
PHP_ME(N1qlQuery, positionalParams, ai_N1qlQuery_params, ZEND_ACC_PUBLIC)
374400
PHP_ME(N1qlQuery, namedParams, ai_N1qlQuery_params, ZEND_ACC_PUBLIC)
375401
PHP_ME(N1qlQuery, consistency, ai_N1qlQuery_consistency, ZEND_ACC_PUBLIC)
402+
PHP_ME(N1qlQuery, profile, ai_N1qlQuery_profile, ZEND_ACC_PUBLIC)
376403
PHP_ME(N1qlQuery, consistentWith, ai_N1qlQuery_consistentWith, ZEND_ACC_PUBLIC)
377404
PHP_ME(N1qlQuery, scanCap, ai_N1qlQuery_scanCap, ZEND_ACC_PUBLIC)
378405
PHP_ME(N1qlQuery, pipelineBatch, ai_N1qlQuery_pipelineBatch, ZEND_ACC_PUBLIC)
@@ -481,6 +508,12 @@ PHP_MINIT_FUNCTION(N1qlQuery)
481508
zend_declare_class_constant_long(pcbc_n1ql_query_ce, ZEND_STRL("STATEMENT_PLUS"),
482509
PCBC_N1QL_CONSISTENCY_STATEMENT_PLUS TSRMLS_CC);
483510

511+
zend_declare_class_constant_string(pcbc_n1ql_query_ce, ZEND_STRL("PROFILE_NONE"), PCBC_N1QL_PROFILE_NONE TSRMLS_CC);
512+
zend_declare_class_constant_string(pcbc_n1ql_query_ce, ZEND_STRL("PROFILE_PHASES"),
513+
PCBC_N1QL_PROFILE_PHASES TSRMLS_CC);
514+
zend_declare_class_constant_string(pcbc_n1ql_query_ce, ZEND_STRL("PROFILE_TIMINGS"),
515+
PCBC_N1QL_PROFILE_TIMINGS TSRMLS_CC);
516+
484517
zend_register_class_alias("\\CouchbaseN1qlQuery", pcbc_n1ql_query_ce);
485518
return SUCCESS;
486519
}

0 commit comments

Comments
 (0)