aboutsummaryrefslogtreecommitdiff
path: root/src/BoundVal.php
blob: 7a3560ac6be45273c44cb2b974133318459edd80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php


namespace Micropoly;


use SQLite3Stmt;

class BoundVal
{
    private $val;
    private $type = null;

    public function __construct($val, $type = null)
    {
        $this->val = $val;
        $this->type = $type;
    }

    public function getVal() { return $this->val; }
    public function getType() { return $this->type; }

    public static function ofInt($val): self { return new self($val, SQLITE3_INTEGER); }
    public static function ofFloat($val): self { return new self($val, SQLITE3_FLOAT); }
    public static function ofText($val): self { return new self($val, SQLITE3_TEXT); }
    public static function ofBlob($val): self { return new self($val, SQLITE3_BLOB); }
    public static function ofNull($val): self { return new self($val, SQLITE3_NULL); }

    public function bind(SQLite3Stmt $stmt, $where): void
    {
        if ($this->type === null)
            $stmt->bindValue($where, $this->val);
        else
            $stmt->bindValue($where, $this->val, $this->type);
    }
}