libasynql
3.2.0
Asynchronous MySQL access library for PocketMine plugins.
SqliteStatementImpl.php
Go to the documentation of this file.
1
<?php
2
3
/*
4
* libasynql
5
*
6
* Copyright (C) 2018 SOFe
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*/
20
21
declare(strict_types=1);
22
23
namespace
poggit\libasynql\generic
;
24
25
use
RuntimeException
;
26
use
SQLite3
;
27
use
function
array_map
;
28
use
function
assert
;
29
use
function
implode
;
30
use
function
is_array
;
31
use
function
is_bool
;
32
use
function
is_float
;
33
use
function
is_int
;
34
use
function
is_string
;
35
36
class
SqliteStatementImpl
extends
GenericStatementImpl
{
37
public
function
getDialect
() : string{
38
return
"sqlite"
;
39
}
40
41
protected
function
formatVariable
(
GenericVariable
$variable, $value, ?
string
$placeHolder, array &$outArgs) : string{
42
if
($variable->
isList
()){
43
assert
(
is_array
($value));
44
45
// IN () works with SQLite3.
46
$unlist = $variable->
unlist
();
47
return
"("
.
implode
(
","
,
array_map
(
function
($value) use ($placeHolder, $unlist, &$outArgs){
48
return
$this->
formatVariable
($unlist, $value, $placeHolder, $outArgs);
49
}, $value)) .
")"
;
50
}
51
52
switch
($variable->
getType
()){
53
case
GenericVariable::TYPE_BOOL
:
54
assert
(
is_bool
($value));
55
return
$value ?
"1"
:
"0"
;
56
57
case
GenericVariable::TYPE_INT
:
58
assert
(
is_int
($value));
59
return
(
string
) $value;
60
61
case
GenericVariable::TYPE_FLOAT
:
62
assert
(
is_int
($value) ||
is_float
($value));
63
return
(
string
) $value;
64
65
case
GenericVariable::TYPE_STRING
:
66
assert
(
is_string
($value));
67
return
"'"
. SQLite3::escapeString($value) .
"'"
;
68
}
69
70
throw
new
RuntimeException
(
"Unsupported variable type"
);
71
}
72
}
implode
poggit\libasynql\generic\SqliteStatementImpl\getDialect
getDialect()
Definition:
SqliteStatementImpl.php:37
poggit\libasynql\generic\GenericVariable\unlist
unlist()
Definition:
GenericVariable.php:118
array_map
is_bool
poggit\libasynql\generic\SqliteStatementImpl
Definition:
SqliteStatementImpl.php:36
poggit\libasynql\generic
Definition:
GenericStatementFileParseException.php:23
poggit\libasynql\generic\GenericVariable\TYPE_BOOL
const TYPE_BOOL
Definition:
GenericVariable.php:45
is_string
SQLite3
is_array
is_int
poggit\libasynql\generic\GenericVariable\isList
isList()
Definition:
GenericVariable.php:131
poggit\libasynql\generic\SqliteStatementImpl\formatVariable
formatVariable(GenericVariable $variable, $value, ?string $placeHolder, array &$outArgs)
Definition:
SqliteStatementImpl.php:41
poggit\libasynql\generic\GenericVariable
Definition:
GenericVariable.php:41
poggit\libasynql\generic\GenericVariable\getType
getType()
Definition:
GenericVariable.php:156
poggit\libasynql\generic\GenericStatementImpl
Definition:
GenericStatementImpl.php:41
is_float
function
poggit\libasynql\generic\GenericVariable\TYPE_STRING
const TYPE_STRING
Definition:
GenericVariable.php:42
poggit\libasynql\generic\GenericVariable\TYPE_INT
const TYPE_INT
Definition:
GenericVariable.php:43
poggit\libasynql\generic\GenericVariable\TYPE_FLOAT
const TYPE_FLOAT
Definition:
GenericVariable.php:44
RuntimeException
libasynql
src
poggit
libasynql
generic
SqliteStatementImpl.php
Generated by
1.8.14