~ubuntu-branches/debian/sid/php-cassandra/sid

« back to all changes in this revision

Viewing changes to cassandra-1.3.0/src/FuturePreparedStatement.c

  • Committer: Package Import Robot
  • Author(s): Ondřej Surý
  • Date: 2017-04-18 17:16:30 UTC
  • Revision ID: package-import@ubuntu.com-20170418171630-fw8udixss0879s32
Tags: upstream-1.3.0
Import upstream version 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2015-2016 DataStax, Inc.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 * http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#include "php_driver.h"
 
18
#include "php_driver_types.h"
 
19
#include "util/future.h"
 
20
 
 
21
zend_class_entry *php_driver_future_prepared_statement_ce = NULL;
 
22
 
 
23
PHP_METHOD(FuturePreparedStatement, get)
 
24
{
 
25
  zval *timeout = NULL;
 
26
  php_driver_statement *prepared_statement = NULL;
 
27
 
 
28
  php_driver_future_prepared_statement *self = PHP_DRIVER_GET_FUTURE_PREPARED_STATEMENT(getThis());
 
29
 
 
30
  if (!PHP5TO7_ZVAL_IS_UNDEF(self->prepared_statement)) {
 
31
    RETURN_ZVAL(PHP5TO7_ZVAL_MAYBE_P(self->prepared_statement), 1, 0);
 
32
  }
 
33
 
 
34
  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &timeout) == FAILURE) {
 
35
    return;
 
36
  }
 
37
 
 
38
  if (php_driver_future_wait_timed(self->future, timeout TSRMLS_CC) == FAILURE) {
 
39
    return;
 
40
  }
 
41
 
 
42
  if (php_driver_future_is_error(self->future TSRMLS_CC) == FAILURE) {
 
43
    return;
 
44
  }
 
45
 
 
46
  object_init_ex(return_value, php_driver_statement_ce);
 
47
  PHP5TO7_ZVAL_COPY(PHP5TO7_ZVAL_MAYBE_P(self->prepared_statement), return_value);
 
48
 
 
49
  prepared_statement = PHP_DRIVER_GET_STATEMENT(return_value);
 
50
 
 
51
  prepared_statement->data.prepared.prepared = cass_future_get_prepared(self->future);
 
52
}
 
53
 
 
54
ZEND_BEGIN_ARG_INFO_EX(arginfo_timeout, 0, ZEND_RETURN_VALUE, 0)
 
55
  ZEND_ARG_INFO(0, timeout)
 
56
ZEND_END_ARG_INFO()
 
57
 
 
58
static zend_function_entry php_driver_future_prepared_statement_methods[] = {
 
59
  PHP_ME(FuturePreparedStatement, get, arginfo_timeout, ZEND_ACC_PUBLIC)
 
60
  PHP_FE_END
 
61
};
 
62
 
 
63
static zend_object_handlers php_driver_future_prepared_statement_handlers;
 
64
 
 
65
static HashTable *
 
66
php_driver_future_prepared_statement_properties(zval *object TSRMLS_DC)
 
67
{
 
68
  HashTable *props = zend_std_get_properties(object TSRMLS_CC);
 
69
 
 
70
  return props;
 
71
}
 
72
 
 
73
static int
 
74
php_driver_future_prepared_statement_compare(zval *obj1, zval *obj2 TSRMLS_DC)
 
75
{
 
76
  if (Z_OBJCE_P(obj1) != Z_OBJCE_P(obj2))
 
77
    return 1; /* different classes */
 
78
 
 
79
  return Z_OBJ_HANDLE_P(obj1) != Z_OBJ_HANDLE_P(obj1);
 
80
}
 
81
 
 
82
static void
 
83
php_driver_future_prepared_statement_free(php5to7_zend_object_free *object TSRMLS_DC)
 
84
{
 
85
  php_driver_future_prepared_statement *self =
 
86
      PHP5TO7_ZEND_OBJECT_GET(future_prepared_statement, object);
 
87
 
 
88
  if (self->future) {
 
89
    cass_future_free(self->future);
 
90
    self->future = NULL;
 
91
  }
 
92
 
 
93
  PHP5TO7_ZVAL_MAYBE_DESTROY(self->prepared_statement);
 
94
 
 
95
  zend_object_std_dtor(&self->zval TSRMLS_CC);
 
96
  PHP5TO7_MAYBE_EFREE(self);
 
97
}
 
98
 
 
99
static php5to7_zend_object
 
100
php_driver_future_prepared_statement_new(zend_class_entry *ce TSRMLS_DC)
 
101
{
 
102
  php_driver_future_prepared_statement *self =
 
103
      PHP5TO7_ZEND_OBJECT_ECALLOC(future_prepared_statement, ce);
 
104
 
 
105
  self->future = NULL;
 
106
  PHP5TO7_ZVAL_UNDEF(self->prepared_statement);
 
107
 
 
108
  PHP5TO7_ZEND_OBJECT_INIT(future_prepared_statement, self, ce);
 
109
}
 
110
 
 
111
void php_driver_define_FuturePreparedStatement(TSRMLS_D)
 
112
{
 
113
  zend_class_entry ce;
 
114
 
 
115
  INIT_CLASS_ENTRY(ce, PHP_DRIVER_NAMESPACE "\\FuturePreparedStatement", php_driver_future_prepared_statement_methods);
 
116
  php_driver_future_prepared_statement_ce = zend_register_internal_class(&ce TSRMLS_CC);
 
117
  zend_class_implements(php_driver_future_prepared_statement_ce TSRMLS_CC, 1, php_driver_future_ce);
 
118
  php_driver_future_prepared_statement_ce->ce_flags     |= PHP5TO7_ZEND_ACC_FINAL;
 
119
  php_driver_future_prepared_statement_ce->create_object = php_driver_future_prepared_statement_new;
 
120
 
 
121
  memcpy(&php_driver_future_prepared_statement_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 
122
  php_driver_future_prepared_statement_handlers.get_properties  = php_driver_future_prepared_statement_properties;
 
123
  php_driver_future_prepared_statement_handlers.compare_objects = php_driver_future_prepared_statement_compare;
 
124
  php_driver_future_prepared_statement_handlers.clone_obj = NULL;
 
125
}