Test Failed
Push — master ( eef45f...e0c5e8 )
by P.R.
04:35
created

TestMySqlDataLayer::tstTestSingleton0bWithLob()   C

Complexity

Conditions 11
Paths 40

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 6.9006
c 0
b 0
f 0
cc 11
nc 40
nop 3

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
4
namespace SetBased\Stratum\MySql\Test;
5
6
use SetBased\Stratum\MySql\Exception\MySqlDataLayerException;
7
use SetBased\Stratum\Middle\Exception\ResultException;
8
use SetBased\Stratum\MySql\Exception\MySqlQueryErrorException;
9
use SetBased\Stratum\MySql\MySqlDataLayer;
10
11
/**
12
 * The data layer.
13
 */
14
class TestMySqlDataLayer extends MySqlDataLayer
15
{
16
  //--------------------------------------------------------------------------------------------------------------------
17
  /**
18
   * Test for magic constant.
19
   *
20
   * @return string
21
   *
22
   * @throws MySqlDataLayerException;
23
   * @throws ResultException;
24
   */
25
  public function tstMagicConstant01(): string
26
  {
27
    return $this->executeSingleton1('call tst_magic_constant01()');
28
  }
29
30
  //--------------------------------------------------------------------------------------------------------------------
31
  /**
32
   * Test for magic constant.
33
   *
34
   * @return int
35
   *
36
   * @throws MySqlDataLayerException;
37
   * @throws ResultException;
38
   */
39
  public function tstMagicConstant02(): int
40
  {
41
    return $this->executeSingleton1('call tst_magic_constant02()');
42
  }
43
44
  //--------------------------------------------------------------------------------------------------------------------
45
  /**
46
   * Test for magic constant.
47
   *
48
   * @return string
49
   *
50
   * @throws MySqlDataLayerException;
51
   * @throws ResultException;
52
   */
53
  public function tstMagicConstant03(): string
54
  {
55
    return $this->executeSingleton1('call tst_magic_constant03()');
56
  }
57
58
  //--------------------------------------------------------------------------------------------------------------------
59
  /**
60
   * Test for magic constant.
61
   *
62
   * @return string
63
   *
64
   * @throws MySqlDataLayerException;
65
   * @throws ResultException;
66
   */
67
  public function tstMagicConstant04(): string
68
  {
69
    return $this->executeSingleton1('call tst_magic_constant04()');
70
  }
71
72
  //--------------------------------------------------------------------------------------------------------------------
73
  /**
74
   * Test for magic constant.
75
   *
76
   * @return string
77
   *
78
   * @throws MySqlDataLayerException;
79
   * @throws ResultException;
80
   */
81
  public function tstMagicConstant05(): string
82
  {
83
    return $this->executeSingleton1('call tst_magic_constant05()');
84
  }
85
86
  //--------------------------------------------------------------------------------------------------------------------
87
  /**
88
   * Test for all possible types of parameters excluding LOB's.
89
   *
90
   * @param int|null              $pTstInt               Parameter of type int.
91
   *                                                     int(11)
92
   * @param int|null              $pTstSmallint          Parameter of type smallint.
93
   *                                                     smallint(6)
94
   * @param int|null              $pTstTinyint           Parameter of type tinyint.
95
   *                                                     tinyint(4)
96
   * @param int|null              $pTstMediumint         Parameter of type mediumint.
97
   *                                                     mediumint(9)
98
   * @param int|null              $pTstBigint            Parameter of type bigint.
99
   *                                                     bigint(20)
100
   * @param int|null              $pTstIntUnsigned       Parameter of type int unsigned.
101
   *                                                     int(10) unsigned
102
   * @param int|null              $pTstSmallintUnsigned  Parameter of type smallint unsigned.
103
   *                                                     smallint(5) unsigned
104
   * @param int|null              $pTstTinyintUnsigned   Parameter of type tinyint unsigned.
105
   *                                                     tinyint(3) unsigned
106
   * @param int|null              $pTstMediumintUnsigned Parameter of type mediumint unsigned.
107
   *                                                     mediumint(8) unsigned
108
   * @param int|null              $pTstBigintUnsigned    Parameter of type bigint unsigned.
109
   *                                                     bigint(20) unsigned
110
   * @param int|float|string|null $pTstDecimal           Parameter of type decimal.
111
   *                                                     decimal(10,2)
112
   * @param int|float|string|null $pTstDecimal0          Parameter of type decimal with 0 scale.
113
   *                                                     decimal(65,0)
114
   * @param float|null            $pTstFloat             Parameter of type float.
115
   *                                                     float
116
   * @param float|null            $pTstDouble            Parameter of type double.
117
   *                                                     double
118
   * @param string|null           $pTstBit               Parameter of type bit.
119
   *                                                     bit(8)
120
   * @param string|null           $pTstDate              Parameter of type date.
121
   *                                                     date
122
   * @param string|null           $pTstDatetime          Parameter of type datetime.
123
   *                                                     datetime
124
   * @param string|null           $pTstTimestamp         Parameter of type timestamp.
125
   *                                                     timestamp
126
   * @param string|null           $pTstTime              Parameter of type time.
127
   *                                                     time
128
   * @param int|null              $pTstYear              Parameter of type year.
129
   *                                                     year(4)
130
   * @param string|null           $pTstChar              Parameter of type char.
131
   *                                                     char(10) character set utf8 collation utf8_general_ci
132
   * @param string|null           $pTstVarchar           Parameter of type varchar.
133
   *                                                     varchar(10) character set utf8 collation utf8_general_ci
134
   * @param string|null           $pTstBinary            Parameter of type binary.
135
   *                                                     binary(10)
136
   * @param string|null           $pTstVarbinary         Parameter of type varbinary.
137
   *                                                     varbinary(10)
138
   * @param string|null           $pTstEnum              Parameter of type enum.
139
   *                                                     enum('a','b') character set utf8 collation utf8_general_ci
140
   * @param string|null           $pTstSet               Parameter of type set.
141
   *                                                     set('a','b') character set utf8 collation utf8_general_ci
142
   *
143
   * @return int
144
   *
145
   * @throws MySqlQueryErrorException;
146
   */
147
  public function tstTest01(?int $pTstInt, ?int $pTstSmallint, ?int $pTstTinyint, ?int $pTstMediumint, ?int $pTstBigint, ?int $pTstIntUnsigned, ?int $pTstSmallintUnsigned, ?int $pTstTinyintUnsigned, ?int $pTstMediumintUnsigned, ?int $pTstBigintUnsigned, $pTstDecimal, $pTstDecimal0, ?float $pTstFloat, ?float $pTstDouble, ?string $pTstBit, ?string $pTstDate, ?string $pTstDatetime, ?string $pTstTimestamp, ?string $pTstTime, ?int $pTstYear, ?string $pTstChar, ?string $pTstVarchar, ?string $pTstBinary, ?string $pTstVarbinary, ?string $pTstEnum, ?string $pTstSet): int
148
  {
149
    return $this->executeNone('call tst_test01('.$this->quoteInt($pTstInt).','.$this->quoteInt($pTstSmallint).','.$this->quoteInt($pTstTinyint).','.$this->quoteInt($pTstMediumint).','.$this->quoteInt($pTstBigint).','.$this->quoteInt($pTstIntUnsigned).','.$this->quoteInt($pTstSmallintUnsigned).','.$this->quoteInt($pTstTinyintUnsigned).','.$this->quoteInt($pTstMediumintUnsigned).','.$this->quoteInt($pTstBigintUnsigned).','.$this->quoteDecimal($pTstDecimal).','.$this->quoteDecimal($pTstDecimal0).','.$this->quoteFloat($pTstFloat).','.$this->quoteFloat($pTstDouble).','.$this->quoteBit($pTstBit).','.$this->quoteString($pTstDate).','.$this->quoteString($pTstDatetime).','.$this->quoteString($pTstTimestamp).','.$this->quoteString($pTstTime).','.$this->quoteInt($pTstYear).','.$this->quoteString($pTstChar).','.$this->quoteString($pTstVarchar).','.$this->quoteBinary($pTstBinary).','.$this->quoteBinary($pTstVarbinary).','.$this->quoteString($pTstEnum).','.$this->quoteString($pTstSet).')');
150
  }
151
152
  //--------------------------------------------------------------------------------------------------------------------
153
  /**
154
   * Test for all possible types of parameters including LOB's.
155
   *
156
   * @param int|null              $pTstInt        Parameter of type int.
157
   *                                              int(11)
158
   * @param int|null              $pTstSmallint   Parameter of type smallint.
159
   *                                              smallint(6)
160
   * @param int|null              $pTstTinyint    Parameter of type tinyint.
161
   *                                              tinyint(4)
162
   * @param int|null              $pTstMediumint  Parameter of type mediumint.
163
   *                                              mediumint(9)
164
   * @param int|null              $pTstBigint     Parameter of type bigint.
165
   *                                              bigint(20)
166
   * @param int|float|string|null $pTstDecimal    Parameter of type decimal.
167
   *                                              decimal(10,2)
168
   * @param int|float|string|null $pTstDecimal0   Parameter of type decimal with 0 scale.
169
   *                                              decimal(65,0)
170
   * @param float|null            $pTstFloat      Parameter of type float.
171
   *                                              float
172
   * @param float|null            $pTstDouble     Parameter of type double.
173
   *                                              double
174
   * @param string|null           $pTstBit        Parameter of type bit.
175
   *                                              bit(8)
176
   * @param string|null           $pTstDate       Parameter of type date.
177
   *                                              date
178
   * @param string|null           $pTstDatetime   Parameter of type datetime.
179
   *                                              datetime
180
   * @param string|null           $pTstTimestamp  Parameter of type timestamp.
181
   *                                              timestamp
182
   * @param string|null           $pTstTime       Parameter of type time.
183
   *                                              time
184
   * @param int|null              $pTstYear       Parameter of type year.
185
   *                                              year(4)
186
   * @param string|null           $pTstChar       Parameter of type char.
187
   *                                              char(10) character set utf8 collation utf8_general_ci
188
   * @param string|null           $pTstVarchar    Parameter of type varchar.
189
   *                                              varchar(10) character set utf8 collation utf8_general_ci
190
   * @param string|null           $pTstBinary     Parameter of type binary.
191
   *                                              binary(10)
192
   * @param string|null           $pTstVarbinary  Parameter of type varbinary.
193
   *                                              varbinary(10)
194
   * @param string|null           $pTstTinyblob   Parameter of type tinyblob.
195
   *                                              tinyblob
196
   * @param string|null           $pTstBlob       Parameter of type blob.
197
   *                                              blob
198
   * @param string|null           $pTstMediumblob Parameter of type mediumblob.
199
   *                                              mediumblob
200
   * @param string|null           $pTstLongblob   Parameter of type longblob.
201
   *                                              longblob
202
   * @param string|null           $pTstTinytext   Parameter of type tinytext.
203
   *                                              tinytext character set utf8 collation utf8_general_ci
204
   * @param string|null           $pTstText       Parameter of type text.
205
   *                                              text character set utf8 collation utf8_general_ci
206
   * @param string|null           $pTstMediumtext Parameter of type mediumtext.
207
   *                                              mediumtext character set utf8 collation utf8_general_ci
208
   * @param string|null           $pTstLongtext   Parameter of type longtext.
209
   *                                              longtext character set utf8 collation utf8_general_ci
210
   * @param string|null           $pTstEnum       Parameter of type enum.
211
   *                                              enum('a','b') character set utf8 collation utf8_general_ci
212
   * @param string|null           $pTstSet        Parameter of type set.
213
   *                                              set('a','b') character set utf8 collation utf8_general_ci
214
   *
215
   * @return int
216
   *
217
   * @throws MySqlDataLayerException;
218
   * @throws MySqlQueryErrorException;
219
   * @throws ResultException;
220
   */
221
  public function tstTest02(?int $pTstInt, ?int $pTstSmallint, ?int $pTstTinyint, ?int $pTstMediumint, ?int $pTstBigint, $pTstDecimal, $pTstDecimal0, ?float $pTstFloat, ?float $pTstDouble, ?string $pTstBit, ?string $pTstDate, ?string $pTstDatetime, ?string $pTstTimestamp, ?string $pTstTime, ?int $pTstYear, ?string $pTstChar, ?string $pTstVarchar, ?string $pTstBinary, ?string $pTstVarbinary, ?string $pTstTinyblob, ?string $pTstBlob, ?string $pTstMediumblob, ?string $pTstLongblob, ?string $pTstTinytext, ?string $pTstText, ?string $pTstMediumtext, ?string $pTstLongtext, ?string $pTstEnum, ?string $pTstSet)
222
  {
223
    $query = 'call tst_test02('.$this->quoteInt($pTstInt).','.$this->quoteInt($pTstSmallint).','.$this->quoteInt($pTstTinyint).','.$this->quoteInt($pTstMediumint).','.$this->quoteInt($pTstBigint).','.$this->quoteDecimal($pTstDecimal).','.$this->quoteDecimal($pTstDecimal0).','.$this->quoteFloat($pTstFloat).','.$this->quoteFloat($pTstDouble).','.$this->quoteBit($pTstBit).','.$this->quoteString($pTstDate).','.$this->quoteString($pTstDatetime).','.$this->quoteString($pTstTimestamp).','.$this->quoteString($pTstTime).','.$this->quoteInt($pTstYear).','.$this->quoteString($pTstChar).','.$this->quoteString($pTstVarchar).','.$this->quoteBinary($pTstBinary).','.$this->quoteBinary($pTstVarbinary).',?,?,?,?,?,?,?,?,'.$this->quoteString($pTstEnum).','.$this->quoteString($pTstSet).')';
224
    $stmt  = @$this->mysqli->prepare($query);
225
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
226
227
    $null = null;
228
    $success = @$stmt->bind_param('bbbbbbbb', $null, $null, $null, $null, $null, $null, $null, $null);
229
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
230
231
    $this->getMaxAllowedPacket();
232
233
    $this->sendLongData($stmt, 0, $pTstTinyblob);
234
    $this->sendLongData($stmt, 1, $pTstBlob);
235
    $this->sendLongData($stmt, 2, $pTstMediumblob);
236
    $this->sendLongData($stmt, 3, $pTstLongblob);
237
    $this->sendLongData($stmt, 4, $pTstTinytext);
238
    $this->sendLongData($stmt, 5, $pTstText);
239
    $this->sendLongData($stmt, 6, $pTstMediumtext);
240
    $this->sendLongData($stmt, 7, $pTstLongtext);
241
242
    if ($this->logQueries)
243
    {
244
      $time0 = microtime(true);
245
246
      $success = @$stmt->execute();
247
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
248
249
      $this->queryLog[] = ['query' => $query,
250
                           'time'  => microtime(true) - $time0];
251
    }
252
    else
253
    {
254
      $success = $stmt->execute();
255
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
256
    }
257
258
    $ret = $this->mysqli->affected_rows;
259
260
    $stmt->close();
261
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
262
263
    return $ret;
264
  }
265
266
  //--------------------------------------------------------------------------------------------------------------------
267
  /**
268
   * Test for designation bulk_insert.
269
   *
270
   * @param array[] $rows The rows that must inserted.
271
   *
272
   * @return void
273
   *
274
   * @throws MySqlQueryErrorException;
275
   */
276
  public function tstTestBulkInsert01(?array $rows): void
277
  {
278
    $this->realQuery('call tst_test_bulk_insert01()');
279
    if (is_array($rows) && !empty($rows))
280
    {
281
      $sql = "INSERT INTO `TST_TEMPO`(`tst_int`,`tst_smallint`,`tst_mediumint`,`tst_tinyint`,`tst_bigint`,`tst_int_unsigned`,`tst_smallint_unsigned`,`tst_mediumint_unsigned`,`tst_tinyint_unsigned`,`tst_bigint_unsigned`,`tst_year`,`tst_decimal`,`tst_decimal0`,`tst_float`,`tst_double`,`tst_binary`,`tst_varbinary`,`tst_char`,`tst_varchar`,`tst_time`,`tst_timestamp`,`tst_date`,`tst_datetime`,`tst_enum`,`tst_set`,`tst_bit`)".PHP_EOL;
282
      $first = true;
283
      foreach($rows as $row)
284
      {
285
        $sql .= (($first) ? 'values' : ',     ').'('.$this->quoteInt($row['field_int']).','.$this->quoteInt($row['field_smallint']).','.$this->quoteInt($row['field_mediumint']).','.$this->quoteInt($row['field_tinyint']).','.$this->quoteInt($row['field_bigint']).','.$this->quoteInt($row['field_int_unsigned']).','.$this->quoteInt($row['field_smallint_unsigned']).','.$this->quoteInt($row['field_mediumint_unsigned']).','.$this->quoteInt($row['field_tinyint_unsigned']).','.$this->quoteInt($row['field_bigint_unsigned']).','.$this->quoteInt($row['field_year']).','.$this->quoteDecimal($row['field_decimal']).','.$this->quoteDecimal($row['field_decimal0']).','.$this->quoteFloat($row['field_float']).','.$this->quoteFloat($row['field_double']).','.$this->quoteBinary($row['field_binary']).','.$this->quoteBinary($row['field_varbinary']).','.$this->quoteString($row['field_char']).','.$this->quoteString($row['field_varchar']).','.$this->quoteString($row['field_time']).','.$this->quoteString($row['field_timestamp']).','.$this->quoteString($row['field_date']).','.$this->quoteString($row['field_datetime']).','.$this->quoteString($row['field_enum']).','.$this->quoteString($row['field_set']).','.$this->quoteBit($row['field_bit']).')'.PHP_EOL;
286
        $first = false;
287
      }
288
      $this->realQuery($sql);
289
    }
290
  }
291
292
  //--------------------------------------------------------------------------------------------------------------------
293
  /**
294
   * Test for designation bulk_insert.
295
   *
296
   * @param array[] $rows The rows that must inserted.
297
   *
298
   * @return void
299
   *
300
   * @throws MySqlQueryErrorException;
301
   */
302
  public function tstTestBulkInsert02(?array $rows): void
303
  {
304
    $this->realQuery('call tst_test_bulk_insert02()');
305
    if (is_array($rows) && !empty($rows))
306
    {
307
      $sql = "INSERT INTO `TST_TEMPO`(`tst_col1`,`tst_col4`,`tst_col5`)".PHP_EOL;
308
      $first = true;
309
      foreach($rows as $row)
310
      {
311
        $sql .= (($first) ? 'values' : ',     ').'('.$this->quoteInt($row['field1']).','.$this->quoteInt($row['field4']).','.$this->quoteInt($row['field5']).')'.PHP_EOL;
312
        $first = false;
313
      }
314
      $this->realQuery($sql);
315
    }
316
  }
317
318
  //--------------------------------------------------------------------------------------------------------------------
319
  /**
320
   * Test for stored function wrapper.
321
   *
322
   * @param int|null $pA Parameter A.
323
   *                     int(11)
324
   * @param int|null $pB Parameter B.
325
   *                     int(11)
326
   *
327
   * @return int|null
328
   *
329
   * @throws MySqlDataLayerException;
330
   * @throws ResultException;
331
   */
332
  public function tstTestFunction(?int $pA, ?int $pB): ?int
333
  {
334
    return $this->executeSingleton0('select tst_test_function('.$this->quoteInt($pA).','.$this->quoteInt($pB).')');
335
  }
336
337
  //--------------------------------------------------------------------------------------------------------------------
338
  /**
339
   * Test for stored function with return type bool wrapper.
340
   *
341
   * @param int|null $pRet The return value.
342
   *                       int(11)
343
   *
344
   * @return bool
345
   *
346
   * @throws MySqlDataLayerException;
347
   * @throws ResultException;
348
   */
349
  public function tstTestFunctionBool1(?int $pRet): bool
350
  {
351
    return !empty($this->executeSingleton0('select tst_test_function_bool1('.$this->quoteInt($pRet).')'));
352
  }
353
354
  //--------------------------------------------------------------------------------------------------------------------
355
  /**
356
   * Test for stored function with return type bool wrapper.
357
   *
358
   * @param string|null $pRet The return value.
359
   *                          varchar(8) character set utf8 collation utf8_general_ci
360
   *
361
   * @return bool
362
   *
363
   * @throws MySqlDataLayerException;
364
   * @throws ResultException;
365
   */
366
  public function tstTestFunctionBool2(?string $pRet): bool
367
  {
368
    return !empty($this->executeSingleton0('select tst_test_function_bool2('.$this->quoteString($pRet).')'));
369
  }
370
371
  //--------------------------------------------------------------------------------------------------------------------
372
  /**
373
   * Test for illegal query.
374
   *
375
   * @return array[]
376
   *
377
   * @throws MySqlQueryErrorException;
378
   */
379
  public function tstTestIllegalQuery(): array
380
  {
381
    return $this->executeRows('call tst_test_illegal_query()');
382
  }
383
384
  //--------------------------------------------------------------------------------------------------------------------
385
  /**
386
   *
387
   * @param string|int[]|null $pIds The id's in CSV format.
388
   *                                varchar(255) character set utf8 collation utf8_general_ci
389
   *
390
   * @return array[]
391
   *
392
   * @throws MySqlQueryErrorException;
393
   */
394
  public function tstTestListOfInt($pIds): array
395
  {
396
    $result = $this->query('call tst_test_list_of_int('.$this->quoteListOfInt($pIds, ',', '\"', '\\').')');
397
    $ret = [];
398
    while (($row = $result->fetch_array(MYSQLI_ASSOC))) $ret[$row['tst_id']] = $row;
399
    $result->free();
400
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
401
402
    return $ret;
403
  }
404
405
  //--------------------------------------------------------------------------------------------------------------------
406
  /**
407
   * Test for designation type log.
408
   *
409
   * @return int
410
   *
411
   * @throws MySqlDataLayerException;
412
   */
413
  public function tstTestLog(): int
414
  {
415
    return $this->executeLog('call tst_test_log()');
416
  }
417
418
  //--------------------------------------------------------------------------------------------------------------------
419
  /**
420
   * Test for designation type map.
421
   *
422
   * @param int|null $pCount Number of rows selected.
423
   *                         int(11)
424
   *
425
   * @return array
426
   *
427
   * @throws MySqlQueryErrorException;
428
   */
429
  public function tstTestMap1(?int $pCount): array
430
  {
431
    $result = $this->query('call tst_test_map1('.$this->quoteInt($pCount).')');
432
    $ret = [];
433
    while (($row = $result->fetch_array(MYSQLI_NUM))) $ret[$row[0]] = $row[1];
434
    $result->free();
435
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
436
437
    return $ret;
438
  }
439
440
  //--------------------------------------------------------------------------------------------------------------------
441
  /**
442
   * Test for designation type rows_with_key with BLOB.
443
   *
444
   * @param int|null    $pCount Number of rows selected.
445
   *                            int(11)
446
   * @param string|null $pBlob  The BLOB.
447
   *                            blob
448
   *
449
   * @return array
450
   *
451
   * @throws MySqlDataLayerException;
452
   * @throws MySqlQueryErrorException;
453
   * @throws ResultException;
454
   */
455
  public function tstTestMap1WithLob(?int $pCount, ?string $pBlob)
456
  {
457
    $query = 'call tst_test_map1_with_lob('.$this->quoteInt($pCount).',?)';
458
    $stmt  = @$this->mysqli->prepare($query);
459
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
460
461
    $null = null;
462
    $success = @$stmt->bind_param('b', $null);
463
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
464
465
    $this->getMaxAllowedPacket();
466
467
    $this->sendLongData($stmt, 0, $pBlob);
468
469
    if ($this->logQueries)
470
    {
471
      $time0 = microtime(true);
472
473
      $success = @$stmt->execute();
474
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
475
476
      $this->queryLog[] = ['query' => $query,
477
                           'time'  => microtime(true) - $time0];
478
    }
479
    else
480
    {
481
      $success = $stmt->execute();
482
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
483
    }
484
485
    $result = $stmt->get_result();
486
    $ret = [];
487
    while (($row = $result->fetch_array(MYSQLI_NUM))) $ret[$row[0]] = $row[1];
488
    $result->free();
489
490
    $stmt->close();
491
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
492
493
    return $ret;
494
  }
495
496
  //--------------------------------------------------------------------------------------------------------------------
497
  /**
498
   * Test for sending data larger than max_allowed_packet.
499
   *
500
   * @param string|null $pTmpBlob The BLOB larger than max_allowed_packet.
501
   *                              longblob
502
   *
503
   * @return int
504
   *
505
   * @throws MySqlDataLayerException;
506
   * @throws MySqlQueryErrorException;
507
   * @throws ResultException;
508
   */
509
  public function tstTestMaxAllowedPacket(?string $pTmpBlob)
510
  {
511
    $query = 'call tst_test_max_allowed_packet(?)';
512
    $stmt  = @$this->mysqli->prepare($query);
513
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
514
515
    $null = null;
516
    $success = @$stmt->bind_param('b', $null);
517
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
518
519
    $this->getMaxAllowedPacket();
520
521
    $this->sendLongData($stmt, 0, $pTmpBlob);
522
523
    if ($this->logQueries)
524
    {
525
      $time0 = microtime(true);
526
527
      $success = @$stmt->execute();
528
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
529
530
      $this->queryLog[] = ['query' => $query,
531
                           'time'  => microtime(true) - $time0];
532
    }
533
    else
534
    {
535
      $success = $stmt->execute();
536
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
537
    }
538
539
    $row = [];
540
    $this->bindAssoc($stmt, $row);
541
542
    $tmp = [];
543
    while (($b = $stmt->fetch()))
544
    {
545
      $new = [];
546
      foreach($row as $value)
547
      {
548
        $new[] = $value;
549
      }
550
      $tmp[] = $new;
551
    }
552
553
    $stmt->close();
554
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
555
556
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
557
    if (sizeof($tmp)!=1) throw new ResultException([1], sizeof($tmp), $query);
558
559
    return $tmp[0][0];
560
  }
561
562
  //--------------------------------------------------------------------------------------------------------------------
563
  /**
564
   *
565
   * @return array
566
   *
567
   * @throws MySqlQueryErrorException;
568
   * @throws ResultException;
569
   */
570
  public function tstTestNoDocBlock(): array
571
  {
572
    return $this->executeRow1('call tst_test_no_doc_block()');
573
  }
574
575
  //--------------------------------------------------------------------------------------------------------------------
576
  /**
577
   * Test for designation type none.
578
   *
579
   * @param int|null $pCount The number of iterations.
580
   *                         bigint(20)
581
   *
582
   * @return int
583
   *
584
   * @throws MySqlQueryErrorException;
585
   */
586
  public function tstTestNone(?int $pCount): int
587
  {
588
    return $this->executeNone('call tst_test_none('.$this->quoteInt($pCount).')');
589
  }
590
591
  //--------------------------------------------------------------------------------------------------------------------
592
  /**
593
   * Test for designation type none with BLOB.
594
   *
595
   * @param int|null    $pCount The number of iterations.
596
   *                            bigint(20)
597
   * @param string|null $pBlob  The BLOB.
598
   *                            blob
599
   *
600
   * @return int
601
   *
602
   * @throws MySqlDataLayerException;
603
   * @throws MySqlQueryErrorException;
604
   * @throws ResultException;
605
   */
606
  public function tstTestNoneWithLob(?int $pCount, ?string $pBlob)
607
  {
608
    $query = 'call tst_test_none_with_lob('.$this->quoteInt($pCount).',?)';
609
    $stmt  = @$this->mysqli->prepare($query);
610
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
611
612
    $null = null;
613
    $success = @$stmt->bind_param('b', $null);
614
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
615
616
    $this->getMaxAllowedPacket();
617
618
    $this->sendLongData($stmt, 0, $pBlob);
619
620
    if ($this->logQueries)
621
    {
622
      $time0 = microtime(true);
623
624
      $success = @$stmt->execute();
625
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
626
627
      $this->queryLog[] = ['query' => $query,
628
                           'time'  => microtime(true) - $time0];
629
    }
630
    else
631
    {
632
      $success = $stmt->execute();
633
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
634
    }
635
636
    $ret = $this->mysqli->affected_rows;
637
638
    $stmt->close();
639
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
640
641
    return $ret;
642
  }
643
644
  //--------------------------------------------------------------------------------------------------------------------
645
  /**
646
   * Test for column%sort v.s. column%type.
647
   *
648
   * @param string|null $pTstLastName   Can be a long string.
649
   *                                    varchar(16383) character set utf8mb4 collation utf8mb4_general_ci
650
   * @param string|null $pTstFirstName  Can be a long string.
651
   *                                    varchar(21844) character set utf8 collation utf8_general_ci
652
   * @param string|null $pTstInstrument Can be a long string.
653
   *                                    varchar(65532) character set ascii collation ascii_general_ci
654
   *
655
   * @return array|null
656
   *
657
   * @throws MySqlQueryErrorException;
658
   * @throws ResultException;
659
   */
660
  public function tstTestParameterSort(?string $pTstLastName, ?string $pTstFirstName, ?string $pTstInstrument): ?array
661
  {
662
    return $this->executeRow0('call tst_test_parameter_sort('.$this->quoteString($pTstLastName).','.$this->quoteString($pTstFirstName).','.$this->quoteString($pTstInstrument).')');
663
  }
664
665
  //--------------------------------------------------------------------------------------------------------------------
666
  /**
667
   * Test for conversion of MySQL types to PHP types.
668
   *
669
   * @param int|float|string|null $pPhpType1 Must be converted to PHP type string in the TestMySqlDataLayer.
670
   *                                         decimal(10,2)
671
   * @param int|float|string|null $pPhpType2 Must be converted to PHP type string in the TestMySqlDataLayer.
672
   *                                         decimal(65,0)
673
   *
674
   * @return int
675
   *
676
   * @throws MySqlQueryErrorException;
677
   */
678
  public function tstTestParameterType($pPhpType1, $pPhpType2): int
679
  {
680
    return $this->executeNone('call tst_test_parameter_type('.$this->quoteDecimal($pPhpType1).','.$this->quoteDecimal($pPhpType2).')');
681
  }
682
683
  //--------------------------------------------------------------------------------------------------------------------
684
  /**
685
   * Test for designation type row0.
686
   *
687
   * @param int|null $pCount The number of rows selected. * 0 For a valid test. * 1 For a valid test. * 2 For a invalid test.
688
   *                         int(11)
689
   *
690
   * @return array|null
691
   *
692
   * @throws MySqlQueryErrorException;
693
   * @throws ResultException;
694
   */
695
  public function tstTestRow0a(?int $pCount): ?array
696
  {
697
    return $this->executeRow0('call tst_test_row0a('.$this->quoteInt($pCount).')');
698
  }
699
700
  //--------------------------------------------------------------------------------------------------------------------
701
  /**
702
   * Test for designation type row0 with BLOB.
703
   *
704
   * @param int|null    $pCount The number of rows selected. * 0 For a valid test. * 1 For a valid test. * 2 For a invalid test.
705
   *                            int(11)
706
   * @param string|null $pBlob  The BLOB.
707
   *                            blob
708
   *
709
   * @return array|null
710
   *
711
   * @throws MySqlDataLayerException;
712
   * @throws MySqlQueryErrorException;
713
   * @throws ResultException;
714
   */
715
  public function tstTestRow0aWithLob(?int $pCount, ?string $pBlob)
716
  {
717
    $query = 'call tst_test_row0a_with_lob('.$this->quoteInt($pCount).',?)';
718
    $stmt  = @$this->mysqli->prepare($query);
719
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
720
721
    $null = null;
722
    $success = @$stmt->bind_param('b', $null);
723
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
724
725
    $this->getMaxAllowedPacket();
726
727
    $this->sendLongData($stmt, 0, $pBlob);
728
729
    if ($this->logQueries)
730
    {
731
      $time0 = microtime(true);
732
733
      $success = @$stmt->execute();
734
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
735
736
      $this->queryLog[] = ['query' => $query,
737
                           'time'  => microtime(true) - $time0];
738
    }
739
    else
740
    {
741
      $success = $stmt->execute();
742
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
743
    }
744
745
    $row = [];
746
    $this->bindAssoc($stmt, $row);
747
748
    $tmp = [];
749
    while (($b = $stmt->fetch()))
750
    {
751
      $new = [];
752
      foreach($row as $key => $value)
753
      {
754
        $new[$key] = $value;
755
      }
756
      $tmp[] = $new;
757
    }
758
759
    $stmt->close();
760
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
761
762
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
763
    if (sizeof($tmp)>1) throw new ResultException([0, 1], sizeof($tmp), $query);
764
765
    return ($tmp) ? $tmp[0] : null;
766
  }
767
768
  //--------------------------------------------------------------------------------------------------------------------
769
  /**
770
   * Test for designation type row1.
771
   *
772
   * @param int|null $pCount The number of rows selected. * 0 For a invalid test. * 1 For a valid test. * 2 For a invalid test.
773
   *                         int(11)
774
   *
775
   * @return array
776
   *
777
   * @throws MySqlQueryErrorException;
778
   * @throws ResultException;
779
   */
780
  public function tstTestRow1a(?int $pCount): array
781
  {
782
    return $this->executeRow1('call tst_test_row1a('.$this->quoteInt($pCount).')');
783
  }
784
785
  //--------------------------------------------------------------------------------------------------------------------
786
  /**
787
   * Test for designation type row1 with BLOB.
788
   *
789
   * @param int|null    $pCount The number of rows selected. * 0 For a invalid test. * 1 For a valid test. * 2 For a invalid test.
790
   *                            int(11)
791
   * @param string|null $pBlob  The BLOB.
792
   *                            blob
793
   *
794
   * @return array
795
   *
796
   * @throws MySqlDataLayerException;
797
   * @throws MySqlQueryErrorException;
798
   * @throws ResultException;
799
   */
800
  public function tstTestRow1aWithLob(?int $pCount, ?string $pBlob)
801
  {
802
    $query = 'call tst_test_row1a_with_lob('.$this->quoteInt($pCount).',?)';
803
    $stmt  = @$this->mysqli->prepare($query);
804
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
805
806
    $null = null;
807
    $success = @$stmt->bind_param('b', $null);
808
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
809
810
    $this->getMaxAllowedPacket();
811
812
    $this->sendLongData($stmt, 0, $pBlob);
813
814
    if ($this->logQueries)
815
    {
816
      $time0 = microtime(true);
817
818
      $success = @$stmt->execute();
819
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
820
821
      $this->queryLog[] = ['query' => $query,
822
                           'time'  => microtime(true) - $time0];
823
    }
824
    else
825
    {
826
      $success = $stmt->execute();
827
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
828
    }
829
830
    $row = [];
831
    $this->bindAssoc($stmt, $row);
832
833
    $tmp = [];
834
    while (($b = $stmt->fetch()))
835
    {
836
      $new = [];
837
      foreach($row as $key => $value)
838
      {
839
        $new[$key] = $value;
840
      }
841
      $tmp[] = $new;
842
    }
843
844
    $stmt->close();
845
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
846
847
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
848
    if (sizeof($tmp)!=1) throw new ResultException([1], sizeof($tmp), $query);
849
850
    return $row;
851
  }
852
853
  //--------------------------------------------------------------------------------------------------------------------
854
  /**
855
   * Test for designation type rows.
856
   *
857
   * @param int|null $pCount The number of rows selected.
858
   *                         int(11)
859
   *
860
   * @return array[]
861
   *
862
   * @throws MySqlQueryErrorException;
863
   */
864
  public function tstTestRows1(?int $pCount): array
865
  {
866
    return $this->executeRows('call tst_test_rows1('.$this->quoteInt($pCount).')');
867
  }
868
869
  //--------------------------------------------------------------------------------------------------------------------
870
  /**
871
   * Test for designation type rows.
872
   *
873
   * @param int|null    $pCount The number of rows selected.
874
   *                            int(11)
875
   * @param string|null $pBlob  The BLOB.
876
   *                            blob
877
   *
878
   * @return array[]
879
   *
880
   * @throws MySqlDataLayerException;
881
   * @throws MySqlQueryErrorException;
882
   * @throws ResultException;
883
   */
884
  public function tstTestRows1WithLob(?int $pCount, ?string $pBlob)
885
  {
886
    $query = 'call tst_test_rows1_with_lob('.$this->quoteInt($pCount).',?)';
887
    $stmt  = @$this->mysqli->prepare($query);
888
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
889
890
    $null = null;
891
    $success = @$stmt->bind_param('b', $null);
892
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
893
894
    $this->getMaxAllowedPacket();
895
896
    $this->sendLongData($stmt, 0, $pBlob);
897
898
    if ($this->logQueries)
899
    {
900
      $time0 = microtime(true);
901
902
      $success = @$stmt->execute();
903
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
904
905
      $this->queryLog[] = ['query' => $query,
906
                           'time'  => microtime(true) - $time0];
907
    }
908
    else
909
    {
910
      $success = $stmt->execute();
911
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
912
    }
913
914
    $row = [];
915
    $this->bindAssoc($stmt, $row);
916
917
    $tmp = [];
918
    while (($b = $stmt->fetch()))
919
    {
920
      $new = [];
921
      foreach($row as $key => $value)
922
      {
923
        $new[$key] = $value;
924
      }
925
      $tmp[] = $new;
926
    }
927
928
    $stmt->close();
929
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
930
931
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
932
933
    return $tmp;
934
  }
935
936
  //--------------------------------------------------------------------------------------------------------------------
937
  /**
938
   * Test for designation type rows_with_index.
939
   *
940
   * @param int|null $pCount The number of rows selected.
941
   *                         int(11)
942
   *
943
   * @return array[]
944
   *
945
   * @throws MySqlQueryErrorException;
946
   */
947
  public function tstTestRowsWithIndex1(?int $pCount): array
948
  {
949
    $result = $this->query('call tst_test_rows_with_index1('.$this->quoteInt($pCount).')');
950
    $ret = [];
951
    while (($row = $result->fetch_array(MYSQLI_ASSOC))) $ret[$row['tst_c01']][$row['tst_c02']][] = $row;
952
    $result->free();
953
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
954
955
    return $ret;
956
  }
957
958
  //--------------------------------------------------------------------------------------------------------------------
959
  /**
960
   * Test for designation type rows_with_index with BLOB..
961
   *
962
   * @param int|null    $pCount The number of rows selected.
963
   *                            int(11)
964
   * @param string|null $pBlob  The BLOB.
965
   *                            blob
966
   *
967
   * @return array[]
968
   *
969
   * @throws MySqlDataLayerException;
970
   * @throws MySqlQueryErrorException;
971
   * @throws ResultException;
972
   */
973
  public function tstTestRowsWithIndex1WithLob(?int $pCount, ?string $pBlob)
974
  {
975
    $query = 'call tst_test_rows_with_index1_with_lob('.$this->quoteInt($pCount).',?)';
976
    $stmt  = @$this->mysqli->prepare($query);
977
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
978
979
    $null = null;
980
    $success = @$stmt->bind_param('b', $null);
981
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
982
983
    $this->getMaxAllowedPacket();
984
985
    $this->sendLongData($stmt, 0, $pBlob);
986
987
    if ($this->logQueries)
988
    {
989
      $time0 = microtime(true);
990
991
      $success = @$stmt->execute();
992
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
993
994
      $this->queryLog[] = ['query' => $query,
995
                           'time'  => microtime(true) - $time0];
996
    }
997
    else
998
    {
999
      $success = $stmt->execute();
1000
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1001
    }
1002
1003
    $row = [];
1004
    $this->bindAssoc($stmt, $row);
1005
1006
    $ret = [];
1007
    while (($b = $stmt->fetch()))
1008
    {
1009
      $new = [];
1010
      foreach($row as $key => $value)
1011
      {
1012
        $new[$key] = $value;
1013
      }
1014
      $ret[$new['tst_c01']][$new['tst_c02']][] = $new;
1015
    }
1016
1017
    $stmt->close();
1018
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
1019
1020
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
1021
1022
    return $ret;
1023
  }
1024
1025
  //--------------------------------------------------------------------------------------------------------------------
1026
  /**
1027
   * Test for designation type rows_with_key.
1028
   *
1029
   * @param int|null $pCount Number of rows selected.
1030
   *                         int(11)
1031
   *
1032
   * @return array[]
1033
   *
1034
   * @throws MySqlQueryErrorException;
1035
   */
1036
  public function tstTestRowsWithKey1(?int $pCount): array
1037
  {
1038
    $result = $this->query('call tst_test_rows_with_key1('.$this->quoteInt($pCount).')');
1039
    $ret = [];
1040
    while (($row = $result->fetch_array(MYSQLI_ASSOC))) $ret[$row['tst_c01']][$row['tst_c02']][$row['tst_c03']] = $row;
1041
    $result->free();
1042
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
1043
1044
    return $ret;
1045
  }
1046
1047
  //--------------------------------------------------------------------------------------------------------------------
1048
  /**
1049
   * Test for designation type rows_with_key with BLOB.
1050
   *
1051
   * @param int|null    $pCount The number of rows selected.
1052
   *                            int(11)
1053
   * @param string|null $pBlob  The BLOB.
1054
   *                            blob
1055
   *
1056
   * @return array[]
1057
   *
1058
   * @throws MySqlDataLayerException;
1059
   * @throws MySqlQueryErrorException;
1060
   * @throws ResultException;
1061
   */
1062
  public function tstTestRowsWithKey1WithLob(?int $pCount, ?string $pBlob)
1063
  {
1064
    $query = 'call tst_test_rows_with_key1_with_lob('.$this->quoteInt($pCount).',?)';
1065
    $stmt  = @$this->mysqli->prepare($query);
1066
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
1067
1068
    $null = null;
1069
    $success = @$stmt->bind_param('b', $null);
1070
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
1071
1072
    $this->getMaxAllowedPacket();
1073
1074
    $this->sendLongData($stmt, 0, $pBlob);
1075
1076
    if ($this->logQueries)
1077
    {
1078
      $time0 = microtime(true);
1079
1080
      $success = @$stmt->execute();
1081
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1082
1083
      $this->queryLog[] = ['query' => $query,
1084
                           'time'  => microtime(true) - $time0];
1085
    }
1086
    else
1087
    {
1088
      $success = $stmt->execute();
1089
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1090
    }
1091
1092
    $row = [];
1093
    $this->bindAssoc($stmt, $row);
1094
1095
    $ret = [];
1096
    while (($b = $stmt->fetch()))
1097
    {
1098
      $new = [];
1099
      foreach($row as $key => $value)
1100
      {
1101
        $new[$key] = $value;
1102
      }
1103
      $ret[$new['tst_c01']][$new['tst_c02']][$new['tst_c03']] = $new;
1104
    }
1105
1106
    $stmt->close();
1107
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
1108
1109
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
1110
1111
    return $ret;
1112
  }
1113
1114
  //--------------------------------------------------------------------------------------------------------------------
1115
  /**
1116
   * Test for designation type singleton0.
1117
   *
1118
   * @param int|null $pCount The number of rows selected. * 0 For a valid test. * 1 For a valid test. * 2 For a invalid test.
1119
   *                         int(11)
1120
   *
1121
   * @return int|null
1122
   *
1123
   * @throws MySqlDataLayerException;
1124
   * @throws ResultException;
1125
   */
1126
  public function tstTestSingleton0a(?int $pCount): ?int
1127
  {
1128
    return $this->executeSingleton0('call tst_test_singleton0a('.$this->quoteInt($pCount).')');
1129
  }
1130
1131
  //--------------------------------------------------------------------------------------------------------------------
1132
  /**
1133
   * Test for designation type singleton0 with BLOB..
1134
   *
1135
   * @param int|null    $pCount The number of rows selected. * 0 For a valid test. * 1 For a valid test. * 2 For a invalid test.
1136
   *                            int(11)
1137
   * @param string|null $pBlob  The BLOB.
1138
   *                            blob
1139
   *
1140
   * @return int|null
1141
   *
1142
   * @throws MySqlDataLayerException;
1143
   * @throws MySqlQueryErrorException;
1144
   * @throws ResultException;
1145
   */
1146
  public function tstTestSingleton0aWithLob(?int $pCount, ?string $pBlob)
1147
  {
1148
    $query = 'call tst_test_singleton0a_with_lob('.$this->quoteInt($pCount).',?)';
1149
    $stmt  = @$this->mysqli->prepare($query);
1150
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
1151
1152
    $null = null;
1153
    $success = @$stmt->bind_param('b', $null);
1154
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
1155
1156
    $this->getMaxAllowedPacket();
1157
1158
    $this->sendLongData($stmt, 0, $pBlob);
1159
1160
    if ($this->logQueries)
1161
    {
1162
      $time0 = microtime(true);
1163
1164
      $success = @$stmt->execute();
1165
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1166
1167
      $this->queryLog[] = ['query' => $query,
1168
                           'time'  => microtime(true) - $time0];
1169
    }
1170
    else
1171
    {
1172
      $success = $stmt->execute();
1173
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1174
    }
1175
1176
    $row = [];
1177
    $this->bindAssoc($stmt, $row);
1178
1179
    $tmp = [];
1180
    while (($b = $stmt->fetch()))
1181
    {
1182
      $new = [];
1183
      foreach($row as $value)
1184
      {
1185
        $new[] = $value;
1186
      }
1187
      $tmp[] = $new;
1188
    }
1189
1190
    $stmt->close();
1191
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
1192
1193
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
1194
    if (sizeof($tmp)>1) throw new ResultException([0, 1], sizeof($tmp), $query);
1195
1196
    return $tmp[0][0] ?? null;
1197
  }
1198
1199
  //--------------------------------------------------------------------------------------------------------------------
1200
  /**
1201
   * Test for designation type singleton0 with return type bool.
1202
   *
1203
   * @param int|null $pCount The number of rows selected. * 0 For a valid test. * 1 For a valid test. * 2 For a invalid test.
1204
   *                         int(11)
1205
   * @param int|null $pValue The selected value.
1206
   *                         int(11)
1207
   *
1208
   * @return bool
1209
   *
1210
   * @throws MySqlDataLayerException;
1211
   * @throws ResultException;
1212
   */
1213
  public function tstTestSingleton0b(?int $pCount, ?int $pValue): bool
1214
  {
1215
    return !empty($this->executeSingleton0('call tst_test_singleton0b('.$this->quoteInt($pCount).','.$this->quoteInt($pValue).')'));
1216
  }
1217
1218
  //--------------------------------------------------------------------------------------------------------------------
1219
  /**
1220
   * Test for designation type singleton0 with BLOB..
1221
   *
1222
   * @param int|null    $pCount The number of rows selected. * 0 For a valid test. * 1 For a valid test. * 2 For a invalid test.
1223
   *                            int(11)
1224
   * @param int|null    $pValue The selected value.
1225
   *                            int(11)
1226
   * @param string|null $pBlob  The BLOB.
1227
   *                            blob
1228
   *
1229
   * @return bool
1230
   *
1231
   * @throws MySqlDataLayerException;
1232
   * @throws MySqlQueryErrorException;
1233
   * @throws ResultException;
1234
   */
1235
  public function tstTestSingleton0bWithLob(?int $pCount, ?int $pValue, ?string $pBlob)
1236
  {
1237
    $query = 'call tst_test_singleton0b_with_lob('.$this->quoteInt($pCount).','.$this->quoteInt($pValue).',?)';
1238
    $stmt  = @$this->mysqli->prepare($query);
1239
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
1240
1241
    $null = null;
1242
    $success = @$stmt->bind_param('b', $null);
1243
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
1244
1245
    $this->getMaxAllowedPacket();
1246
1247
    $this->sendLongData($stmt, 0, $pBlob);
1248
1249
    if ($this->logQueries)
1250
    {
1251
      $time0 = microtime(true);
1252
1253
      $success = @$stmt->execute();
1254
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1255
1256
      $this->queryLog[] = ['query' => $query,
1257
                           'time'  => microtime(true) - $time0];
1258
    }
1259
    else
1260
    {
1261
      $success = $stmt->execute();
1262
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1263
    }
1264
1265
    $row = [];
1266
    $this->bindAssoc($stmt, $row);
1267
1268
    $tmp = [];
1269
    while (($b = $stmt->fetch()))
1270
    {
1271
      $new = [];
1272
      foreach($row as $value)
1273
      {
1274
        $new[] = $value;
1275
      }
1276
      $tmp[] = $new;
1277
    }
1278
1279
    $stmt->close();
1280
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
1281
1282
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
1283
    if (sizeof($tmp)>1) throw new ResultException([0, 1], sizeof($tmp), $query);
1284
1285
    return !empty($tmp[0][0]);
1286
  }
1287
1288
  //--------------------------------------------------------------------------------------------------------------------
1289
  /**
1290
   * Test for designation type singleton1.
1291
   *
1292
   * @param int|null $pCount The number of rows selected. * 0 For a invalid test. * 1 For a valid test. * 2 For a invalid test.
1293
   *                         int(11)
1294
   *
1295
   * @return int
1296
   *
1297
   * @throws MySqlDataLayerException;
1298
   * @throws ResultException;
1299
   */
1300
  public function tstTestSingleton1a(?int $pCount): int
1301
  {
1302
    return $this->executeSingleton1('call tst_test_singleton1a('.$this->quoteInt($pCount).')');
1303
  }
1304
1305
  //--------------------------------------------------------------------------------------------------------------------
1306
  /**
1307
   * Test for designation type singleton1 with BLOB.
1308
   *
1309
   * @param int|null    $pCount The number of rows selected. * 0 For a invalid test. * 1 For a valid test. * 2 For a invalid test.
1310
   *                            int(11)
1311
   * @param string|null $pBlob  The BLOB.
1312
   *                            blob
1313
   *
1314
   * @return int
1315
   *
1316
   * @throws MySqlDataLayerException;
1317
   * @throws MySqlQueryErrorException;
1318
   * @throws ResultException;
1319
   */
1320
  public function tstTestSingleton1aWithLob(?int $pCount, ?string $pBlob)
1321
  {
1322
    $query = 'call tst_test_singleton1a_with_lob('.$this->quoteInt($pCount).',?)';
1323
    $stmt  = @$this->mysqli->prepare($query);
1324
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
1325
1326
    $null = null;
1327
    $success = @$stmt->bind_param('b', $null);
1328
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
1329
1330
    $this->getMaxAllowedPacket();
1331
1332
    $this->sendLongData($stmt, 0, $pBlob);
1333
1334
    if ($this->logQueries)
1335
    {
1336
      $time0 = microtime(true);
1337
1338
      $success = @$stmt->execute();
1339
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1340
1341
      $this->queryLog[] = ['query' => $query,
1342
                           'time'  => microtime(true) - $time0];
1343
    }
1344
    else
1345
    {
1346
      $success = $stmt->execute();
1347
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1348
    }
1349
1350
    $row = [];
1351
    $this->bindAssoc($stmt, $row);
1352
1353
    $tmp = [];
1354
    while (($b = $stmt->fetch()))
1355
    {
1356
      $new = [];
1357
      foreach($row as $value)
1358
      {
1359
        $new[] = $value;
1360
      }
1361
      $tmp[] = $new;
1362
    }
1363
1364
    $stmt->close();
1365
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
1366
1367
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
1368
    if (sizeof($tmp)!=1) throw new ResultException([1], sizeof($tmp), $query);
1369
1370
    return $tmp[0][0];
1371
  }
1372
1373
  //--------------------------------------------------------------------------------------------------------------------
1374
  /**
1375
   * Test for designation type singleton1 with return type bool.
1376
   *
1377
   * @param int|null $pCount The number of rows selected. * 0 For a invalid test. * 1 For a valid test. * 2 For a invalid test.
1378
   *                         int(11)
1379
   * @param int|null $pValue The selected value.
1380
   *                         int(11)
1381
   *
1382
   * @return bool
1383
   *
1384
   * @throws MySqlDataLayerException;
1385
   * @throws ResultException;
1386
   */
1387
  public function tstTestSingleton1b(?int $pCount, ?int $pValue): bool
1388
  {
1389
    return !empty($this->executeSingleton1('call tst_test_singleton1b('.$this->quoteInt($pCount).','.$this->quoteInt($pValue).')'));
1390
  }
1391
1392
  //--------------------------------------------------------------------------------------------------------------------
1393
  /**
1394
   * Test for designation type singleton1 with BLOB.
1395
   *
1396
   * @param int|null    $pCount The number of rows selected. * 0 For a invalid test. * 1 For a valid test. * 2 For a invalid test.
1397
   *                            int(11)
1398
   * @param int|null    $pValue The selected value.
1399
   *                            int(11)
1400
   * @param string|null $pBlob  The BLOB.
1401
   *                            blob
1402
   *
1403
   * @return bool
1404
   *
1405
   * @throws MySqlDataLayerException;
1406
   * @throws MySqlQueryErrorException;
1407
   * @throws ResultException;
1408
   */
1409
  public function tstTestSingleton1bWithLob(?int $pCount, ?int $pValue, ?string $pBlob)
1410
  {
1411
    $query = 'call tst_test_singleton1b_with_lob('.$this->quoteInt($pCount).','.$this->quoteInt($pValue).',?)';
1412
    $stmt  = @$this->mysqli->prepare($query);
1413
    if (!$stmt) throw $this->dataLayerError('mysqli::prepare');
1414
1415
    $null = null;
1416
    $success = @$stmt->bind_param('b', $null);
1417
    if (!$success) throw $this->dataLayerError('mysqli_stmt::bind_param');
1418
1419
    $this->getMaxAllowedPacket();
1420
1421
    $this->sendLongData($stmt, 0, $pBlob);
1422
1423
    if ($this->logQueries)
1424
    {
1425
      $time0 = microtime(true);
1426
1427
      $success = @$stmt->execute();
1428
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1429
1430
      $this->queryLog[] = ['query' => $query,
1431
                           'time'  => microtime(true) - $time0];
1432
    }
1433
    else
1434
    {
1435
      $success = $stmt->execute();
1436
      if (!$success) throw $this->queryError('mysqli_stmt::execute', $query);
1437
    }
1438
1439
    $row = [];
1440
    $this->bindAssoc($stmt, $row);
1441
1442
    $tmp = [];
1443
    while (($b = $stmt->fetch()))
1444
    {
1445
      $new = [];
1446
      foreach($row as $value)
1447
      {
1448
        $new[] = $value;
1449
      }
1450
      $tmp[] = $new;
1451
    }
1452
1453
    $stmt->close();
1454
    if ($this->mysqli->more_results()) $this->mysqli->next_result();
1455
1456
    if ($b===false) throw $this->dataLayerError('mysqli_stmt::fetch');
1457
    if (sizeof($tmp)!=1) throw new ResultException([1], sizeof($tmp), $query);
1458
1459
    return !empty($tmp[0][0]);
1460
  }
1461
1462
  //--------------------------------------------------------------------------------------------------------------------
1463
  /**
1464
   * Test for designation type table.
1465
   *
1466
   * @return int
1467
   *
1468
   * @throws MySqlDataLayerException;
1469
   */
1470
  public function tstTestTable(): int
1471
  {
1472
    return $this->executeTable('call tst_test_table()');
1473
  }
1474
1475
  //--------------------------------------------------------------------------------------------------------------------
1476
}
1477
1478
//----------------------------------------------------------------------------------------------------------------------
1479