@@ -45,13 +45,13 @@ map<int, Client*> clientMap;
45
45
46
46
#ifdef COMPILE_DL_SEASCLICK
47
47
extern " C" {
48
- ZEND_GET_MODULE (SeasClick)
48
+ ZEND_GET_MODULE (SeasClick)
49
49
}
50
50
#endif
51
51
52
52
PHP_FUNCTION (SeasClick_version)
53
53
{
54
- SC_RETURN_STRINGL (PHP_SEASCLICK_VERSION, strlen (PHP_SEASCLICK_VERSION));
54
+ SC_RETURN_STRINGL (PHP_SEASCLICK_VERSION, strlen (PHP_SEASCLICK_VERSION));
55
55
}
56
56
57
57
static PHP_METHOD (SEASCLICK_RES_NAME, __construct);
@@ -81,9 +81,10 @@ ZEND_ARG_INFO(0, params)
81
81
ZEND_END_ARG_INFO()
82
82
83
83
/* {{{ SeasClick_functions[] */
84
- const zend_function_entry SeasClick_functions[] = {
85
- PHP_FE (SeasClick_version, NULL )
86
- PHP_FE_END
84
+ const zend_function_entry SeasClick_functions[] =
85
+ {
86
+ PHP_FE (SeasClick_version, NULL )
87
+ PHP_FE_END
87
88
};
88
89
/* }}} */
89
90
@@ -116,61 +117,62 @@ PHP_MINIT_FUNCTION(SeasClick)
116
117
zend_declare_property_bool (SeasClick_ce, " compression" , strlen (" compression" ), false , ZEND_ACC_PROTECTED TSRMLS_CC);
117
118
118
119
SeasClick_ce->ce_flags = ZEND_ACC_IMPLICIT_PUBLIC;
119
- return SUCCESS;
120
+ return SUCCESS;
120
121
}
121
122
/* }}} */
122
123
123
124
/* {{{ PHP_MSHUTDOWN_FUNCTION
124
125
*/
125
126
PHP_MSHUTDOWN_FUNCTION (SeasClick)
126
127
{
127
- return SUCCESS;
128
+ return SUCCESS;
128
129
}
129
130
/* }}} */
130
131
131
132
/* {{{ PHP_RINIT_FUNCTION
132
133
*/
133
134
PHP_RINIT_FUNCTION (SeasClick)
134
135
{
135
- return SUCCESS;
136
+ return SUCCESS;
136
137
}
137
138
/* }}} */
138
139
139
140
/* {{{ PHP_RSHUTDOWN_FUNCTION
140
141
*/
141
142
PHP_RSHUTDOWN_FUNCTION (SeasClick)
142
143
{
143
- return SUCCESS;
144
+ return SUCCESS;
144
145
}
145
146
/* }}} */
146
147
147
148
/* {{{ PHP_MINFO_FUNCTION
148
149
*/
149
150
PHP_MINFO_FUNCTION (SeasClick)
150
151
{
151
- php_info_print_table_start ();
152
- php_info_print_table_header (2 , " SeasClick support" , " enabled" );
152
+ php_info_print_table_start ();
153
+ php_info_print_table_header (2 , " SeasClick support" , " enabled" );
153
154
php_info_print_table_row (2 , " Version" , PHP_SEASCLICK_VERSION);
154
155
php_info_print_table_row (
2 ,
" Author" ,
" SeasX Group[email: [email protected] ]" );
155
- php_info_print_table_end ();
156
+ php_info_print_table_end ();
156
157
157
- DISPLAY_INI_ENTRIES ();
158
+ DISPLAY_INI_ENTRIES ();
158
159
}
159
160
/* }}} */
160
161
161
162
/* {{{ SeasClick_module_entry
162
163
*/
163
- zend_module_entry SeasClick_module_entry = {
164
- STANDARD_MODULE_HEADER,
165
- SEASCLICK_RES_NAME,
166
- SeasClick_functions,
167
- PHP_MINIT (SeasClick),
168
- PHP_MSHUTDOWN (SeasClick),
169
- PHP_RINIT (SeasClick),
170
- PHP_RSHUTDOWN (SeasClick),
171
- PHP_MINFO (SeasClick),
172
- PHP_SEASCLICK_VERSION,
173
- STANDARD_MODULE_PROPERTIES
164
+ zend_module_entry SeasClick_module_entry =
165
+ {
166
+ STANDARD_MODULE_HEADER,
167
+ SEASCLICK_RES_NAME,
168
+ SeasClick_functions,
169
+ PHP_MINIT (SeasClick),
170
+ PHP_MSHUTDOWN (SeasClick),
171
+ PHP_RINIT (SeasClick),
172
+ PHP_RSHUTDOWN (SeasClick),
173
+ PHP_MINFO (SeasClick),
174
+ PHP_SEASCLICK_VERSION,
175
+ STANDARD_MODULE_PROPERTIES
174
176
};
175
177
/* }}} */
176
178
@@ -181,14 +183,15 @@ PHP_METHOD(SEASCLICK_RES_NAME, __construct)
181
183
zval *connectParames;
182
184
183
185
#ifndef FAST_ZPP
184
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, " z" , &connectParames) == FAILURE) {
186
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, " z" , &connectParames) == FAILURE)
187
+ {
185
188
return ;
186
189
}
187
190
#else
188
191
#undef IS_UNDEF
189
192
#define IS_UNDEF Z_EXPECTED_LONG
190
193
ZEND_PARSE_PARAMETERS_START (1 , 1 )
191
- Z_PARAM_ARRAY (connectParames)
194
+ Z_PARAM_ARRAY (connectParames)
192
195
ZEND_PARSE_PARAMETERS_END ();
193
196
#undef IS_UNDEF
194
197
#define IS_UNDEF 0
@@ -222,10 +225,11 @@ PHP_METHOD(SEASCLICK_RES_NAME, __construct)
222
225
zval *compression = sc_zend_read_property (SeasClick_ce, this_obj, " compression" , sizeof (" compression" ) - 1 , 0 );
223
226
224
227
ClientOptions Options = ClientOptions ()
225
- .SetHost (Z_STRVAL_P (host))
226
- .SetPort (Z_LVAL_P (port))
227
- .SetPingBeforeQuery (false );
228
- if (Z_TYPE_P (compression) == IS_TRUE) {
228
+ .SetHost (Z_STRVAL_P (host))
229
+ .SetPort (Z_LVAL_P (port))
230
+ .SetPingBeforeQuery (false );
231
+ if (Z_TYPE_P (compression) == IS_TRUE)
232
+ {
229
233
Options = Options.SetCompressionMethod (CompressionMethod::LZ4);
230
234
}
231
235
@@ -250,13 +254,16 @@ PHP_METHOD(SEASCLICK_RES_NAME, __construct)
250
254
Options = Options.SetPassword (Z_STRVAL_P (value));
251
255
}
252
256
253
- try {
257
+ try
258
+ {
254
259
Client *client = new Client (Options);
255
260
int key = Z_OBJ_HANDLE (*this_obj);
256
261
257
262
clientMap.insert (std::pair<int , Client*>(key, client));
258
263
259
- } catch (const std::exception& e) {
264
+ }
265
+ catch (const std::exception& e)
266
+ {
260
267
sc_zend_throw_exception (NULL , e.what (), 0 TSRMLS_CC);
261
268
}
262
269
@@ -280,9 +287,12 @@ void getInsertSql(string *sql, char *table_name, zval *columns)
280
287
SC_HASHTABLE_FOREACH_START2 (columns_ht, key, keylen, keytype, pzval)
281
288
{
282
289
convert_to_string (pzval);
283
- if (index >= (count - 1 )) {
290
+ if (index >= (count - 1 ))
291
+ {
284
292
fields_section << (string)Z_STRVAL_P (pzval);
285
- } else {
293
+ }
294
+ else
295
+ {
286
296
fields_section << (string)Z_STRVAL_P (pzval) << " ," ;
287
297
}
288
298
index++;
@@ -300,24 +310,28 @@ PHP_METHOD(SEASCLICK_RES_NAME, select)
300
310
zval* params = NULL ;
301
311
302
312
#ifndef FAST_ZPP
303
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, " s|z" , &sql, &l_sql, ¶ms) == FAILURE) {
313
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, " s|z" , &sql, &l_sql, ¶ms) == FAILURE)
314
+ {
304
315
return ;
305
316
}
306
317
#else
307
318
#undef IS_UNDEF
308
319
#define IS_UNDEF Z_EXPECTED_LONG
309
320
ZEND_PARSE_PARAMETERS_START (1 , 2 )
310
- Z_PARAM_STRING (sql, l_sql)
311
- Z_PARAM_OPTIONAL
312
- Z_PARAM_ARRAY (params)
321
+ Z_PARAM_STRING (sql, l_sql)
322
+ Z_PARAM_OPTIONAL
323
+ Z_PARAM_ARRAY (params)
313
324
ZEND_PARSE_PARAMETERS_END ();
314
325
#undef IS_UNDEF
315
326
#define IS_UNDEF 0
316
327
#endif
317
- try {
328
+ try
329
+ {
318
330
string sql_s = (string)sql;
319
- if (ZEND_NUM_ARGS () > 1 && params != NULL ) {
320
- if (Z_TYPE_P (params) != IS_ARRAY) {
331
+ if (ZEND_NUM_ARGS () > 1 && params != NULL )
332
+ {
333
+ if (Z_TYPE_P (params) != IS_ARRAY)
334
+ {
321
335
throw std::runtime_error (" The second argument to the select function must be an array" );
322
336
}
323
337
@@ -341,21 +355,25 @@ PHP_METHOD(SEASCLICK_RES_NAME, select)
341
355
array_init (return_value);
342
356
343
357
client->Select (sql_s, [return_value](const Block& block)
358
+ {
359
+ zval *return_tmp;
360
+ for (size_t row = 0 ; row < block.GetRowCount (); ++row)
344
361
{
345
- zval *return_tmp;
346
- for (size_t row = 0 ; row < block.GetRowCount (); ++row) {
347
- SC_MAKE_STD_ZVAL (return_tmp);
348
- array_init (return_tmp);
349
- for (size_t column = 0 ; column < block.GetColumnCount (); ++column) {
350
- string column_name = block.GetColumnName (column);
351
- convertToZval (return_tmp, block[column], row, column_name, 0 );
352
- }
353
- add_next_index_zval (return_value, return_tmp);
362
+ SC_MAKE_STD_ZVAL (return_tmp);
363
+ array_init (return_tmp);
364
+ for (size_t column = 0 ; column < block.GetColumnCount (); ++column)
365
+ {
366
+ string column_name = block.GetColumnName (column);
367
+ convertToZval (return_tmp, block[column], row, column_name, 0 );
354
368
}
369
+ add_next_index_zval (return_value, return_tmp);
355
370
}
356
- );
371
+ }
372
+ );
357
373
358
- } catch (const std::exception& e) {
374
+ }
375
+ catch (const std::exception& e)
376
+ {
359
377
sc_zend_throw_exception (NULL , e.what (), 0 TSRMLS_CC);
360
378
}
361
379
}
@@ -373,22 +391,24 @@ PHP_METHOD(SEASCLICK_RES_NAME, insert)
373
391
string sql;
374
392
375
393
#ifndef FAST_ZPP
376
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, " szz" , &table, &l_table, &columns, &values) == FAILURE) {
394
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, " szz" , &table, &l_table, &columns, &values) == FAILURE)
395
+ {
377
396
return ;
378
397
}
379
398
#else
380
399
#undef IS_UNDEF
381
400
#define IS_UNDEF Z_EXPECTED_LONG
382
401
ZEND_PARSE_PARAMETERS_START (3 , 3 )
383
- Z_PARAM_STRING (table, l_table)
384
- Z_PARAM_ARRAY (columns)
385
- Z_PARAM_ARRAY (values)
402
+ Z_PARAM_STRING (table, l_table)
403
+ Z_PARAM_ARRAY (columns)
404
+ Z_PARAM_ARRAY (values)
386
405
ZEND_PARSE_PARAMETERS_END ();
387
406
#undef IS_UNDEF
388
407
#define IS_UNDEF 0
389
408
#endif
390
409
391
- try {
410
+ try
411
+ {
392
412
HashTable *columns_ht = Z_ARRVAL_P (columns);
393
413
HashTable *values_ht = Z_ARRVAL_P (values);
394
414
size_t columns_count = zend_hash_num_elements (columns_ht);
@@ -411,11 +431,13 @@ PHP_METHOD(SEASCLICK_RES_NAME, insert)
411
431
412
432
SC_HASHTABLE_FOREACH_START2 (values_ht, str_key, str_keylen, keytype, pzval)
413
433
{
414
- if (Z_TYPE_P (pzval) != IS_ARRAY) {
434
+ if (Z_TYPE_P (pzval) != IS_ARRAY)
435
+ {
415
436
throw std::runtime_error (" The insert function needs to pass in a two-dimensional array" );
416
437
}
417
438
fzval = sc_zend_hash_index_find (Z_ARRVAL_P (pzval), i);
418
- if (NULL == fzval) {
439
+ if (NULL == fzval)
440
+ {
419
441
throw std::runtime_error (" The number of parameters inserted per line is inconsistent" );
420
442
}
421
443
sc_zval_add_ref (fzval);
@@ -432,11 +454,12 @@ PHP_METHOD(SEASCLICK_RES_NAME, insert)
432
454
int key = Z_OBJ_HANDLE (*getThis ());
433
455
Client *client = clientMap.at (key);
434
456
435
- client->InsertQuery (sql, [&blockQuery](const Block& block) {
436
- blockQuery = block;
437
- }
438
- );
439
-
457
+ client->InsertQuery (sql, [&blockQuery](const Block& block)
458
+ {
459
+ blockQuery = block;
460
+ }
461
+ );
462
+
440
463
Block blockInsert;
441
464
size_t index = 0 ;
442
465
@@ -450,7 +473,9 @@ PHP_METHOD(SEASCLICK_RES_NAME, insert)
450
473
client->InsertData (blockInsert);
451
474
sc_zval_ptr_dtor (&return_should);
452
475
453
- } catch (const std::exception& e) {
476
+ }
477
+ catch (const std::exception& e)
478
+ {
454
479
sc_zend_throw_exception (NULL , e.what (), 0 TSRMLS_CC);
455
480
}
456
481
RETURN_TRUE;
@@ -466,25 +491,29 @@ PHP_METHOD(SEASCLICK_RES_NAME, execute)
466
491
zval* params = NULL ;
467
492
468
493
#ifndef FAST_ZPP
469
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, " s|z" , &sql, &l_sql, ¶ms) == FAILURE) {
494
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, " s|z" , &sql, &l_sql, ¶ms) == FAILURE)
495
+ {
470
496
return ;
471
497
}
472
498
#else
473
499
#undef IS_UNDEF
474
500
#define IS_UNDEF Z_EXPECTED_LONG
475
501
ZEND_PARSE_PARAMETERS_START (1 , 2 )
476
- Z_PARAM_STRING (sql, l_sql)
477
- Z_PARAM_OPTIONAL
478
- Z_PARAM_ARRAY (params)
502
+ Z_PARAM_STRING (sql, l_sql)
503
+ Z_PARAM_OPTIONAL
504
+ Z_PARAM_ARRAY (params)
479
505
ZEND_PARSE_PARAMETERS_END ();
480
506
#undef IS_UNDEF
481
507
#define IS_UNDEF 0
482
508
#endif
483
509
484
- try {
510
+ try
511
+ {
485
512
string sql_s = (string)sql;
486
- if (ZEND_NUM_ARGS () > 1 && params != NULL ) {
487
- if (Z_TYPE_P (params) != IS_ARRAY) {
513
+ if (ZEND_NUM_ARGS () > 1 && params != NULL )
514
+ {
515
+ if (Z_TYPE_P (params) != IS_ARRAY)
516
+ {
488
517
throw std::runtime_error (" The second argument to the select function must be an array" );
489
518
}
490
519
@@ -506,7 +535,9 @@ PHP_METHOD(SEASCLICK_RES_NAME, execute)
506
535
Client *client = clientMap.at (key);
507
536
client->Execute (sql_s);
508
537
509
- } catch (const std::exception& e) {
538
+ }
539
+ catch (const std::exception& e)
540
+ {
510
541
sc_zend_throw_exception (NULL , e.what (), 0 TSRMLS_CC);
511
542
}
512
543
RETURN_TRUE;
@@ -517,13 +548,16 @@ PHP_METHOD(SEASCLICK_RES_NAME, execute)
517
548
*/
518
549
PHP_METHOD (SEASCLICK_RES_NAME, __destruct)
519
550
{
520
- try {
551
+ try
552
+ {
521
553
int key = Z_OBJ_HANDLE (*getThis ());
522
554
Client *client = clientMap.at (key);
523
555
delete client;
524
556
clientMap.erase (key);
525
557
526
- } catch (const std::exception& e) {
558
+ }
559
+ catch (const std::exception& e)
560
+ {
527
561
sc_zend_throw_exception (NULL , e.what (), 0 TSRMLS_CC);
528
562
}
529
563
RETURN_TRUE;
0 commit comments