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

« back to all changes in this revision

Viewing changes to cassandra-1.3.0/src/SimpleStatement.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
 
 
20
zend_class_entry *php_driver_simple_statement_ce = NULL;
 
21
 
 
22
PHP_METHOD(SimpleStatement, __construct)
 
23
{
 
24
  zval *cql = NULL;
 
25
  php_driver_statement *self = NULL;
 
26
 
 
27
  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cql) == FAILURE) {
 
28
    return;
 
29
  }
 
30
 
 
31
  if (Z_TYPE_P(cql) != IS_STRING) {
 
32
    INVALID_ARGUMENT(cql, "a string");
 
33
  }
 
34
 
 
35
  self = PHP_DRIVER_GET_STATEMENT(getThis());
 
36
 
 
37
  self->data.simple.cql = estrndup(Z_STRVAL_P(cql), Z_STRLEN_P(cql));
 
38
}
 
39
 
 
40
ZEND_BEGIN_ARG_INFO_EX(arginfo__construct, 0, ZEND_RETURN_VALUE, 1)
 
41
  ZEND_ARG_INFO(0, cql)
 
42
ZEND_END_ARG_INFO()
 
43
 
 
44
static zend_function_entry php_driver_simple_statement_methods[] = {
 
45
  PHP_ME(SimpleStatement, __construct, arginfo__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
 
46
  PHP_FE_END
 
47
};
 
48
 
 
49
static zend_object_handlers php_driver_simple_statement_handlers;
 
50
 
 
51
static HashTable *
 
52
php_driver_simple_statement_properties(zval *object TSRMLS_DC)
 
53
{
 
54
  HashTable *props = zend_std_get_properties(object TSRMLS_CC);
 
55
 
 
56
  return props;
 
57
}
 
58
 
 
59
static int
 
60
php_driver_simple_statement_compare(zval *obj1, zval *obj2 TSRMLS_DC)
 
61
{
 
62
  if (Z_OBJCE_P(obj1) != Z_OBJCE_P(obj2))
 
63
    return 1; /* different classes */
 
64
 
 
65
  return Z_OBJ_HANDLE_P(obj1) != Z_OBJ_HANDLE_P(obj1);
 
66
}
 
67
 
 
68
static void
 
69
php_driver_simple_statement_free(php5to7_zend_object_free *object TSRMLS_DC)
 
70
{
 
71
  php_driver_statement *self = PHP5TO7_ZEND_OBJECT_GET(statement, object);
 
72
 
 
73
  if (self->data.simple.cql) {
 
74
    efree(self->data.simple.cql);
 
75
    self->data.simple.cql = NULL;
 
76
  }
 
77
 
 
78
  zend_object_std_dtor(&self->zval TSRMLS_CC);
 
79
  PHP5TO7_MAYBE_EFREE(self);
 
80
}
 
81
 
 
82
static php5to7_zend_object
 
83
php_driver_simple_statement_new(zend_class_entry *ce TSRMLS_DC)
 
84
{
 
85
  php_driver_statement *self =
 
86
      PHP5TO7_ZEND_OBJECT_ECALLOC(statement, ce);
 
87
 
 
88
  self->type = PHP_DRIVER_SIMPLE_STATEMENT;
 
89
  self->data.simple.cql  = NULL;
 
90
 
 
91
  PHP5TO7_ZEND_OBJECT_INIT_EX(statement, simple_statement, self, ce);
 
92
}
 
93
 
 
94
void php_driver_define_SimpleStatement(TSRMLS_D)
 
95
{
 
96
  zend_class_entry ce;
 
97
 
 
98
  INIT_CLASS_ENTRY(ce, PHP_DRIVER_NAMESPACE "\\SimpleStatement", php_driver_simple_statement_methods);
 
99
  php_driver_simple_statement_ce = zend_register_internal_class(&ce TSRMLS_CC);
 
100
  zend_class_implements(php_driver_simple_statement_ce TSRMLS_CC, 1, php_driver_statement_ce);
 
101
  php_driver_simple_statement_ce->ce_flags     |= PHP5TO7_ZEND_ACC_FINAL;
 
102
  php_driver_simple_statement_ce->create_object = php_driver_simple_statement_new;
 
103
 
 
104
  memcpy(&php_driver_simple_statement_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 
105
  php_driver_simple_statement_handlers.get_properties  = php_driver_simple_statement_properties;
 
106
  php_driver_simple_statement_handlers.compare_objects = php_driver_simple_statement_compare;
 
107
  php_driver_simple_statement_handlers.clone_obj = NULL;
 
108
}