aboutsummaryrefslogtreecommitdiff
path: root/src/BoundVal.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/BoundVal.php')
-rw-r--r--src/BoundVal.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/BoundVal.php b/src/BoundVal.php
new file mode 100644
index 0000000..7a3560a
--- /dev/null
+++ b/src/BoundVal.php
@@ -0,0 +1,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);
+ }
+} \ No newline at end of file