Bouncy Melons 0.1
declarative style orm
SqliteDriver.php
Go to the documentation of this file.
1 <?php
2 
3 namespace bm;
4 
5 class SqliteDriver extends Driver implements IDriver {
6 
7  public function getTableFields($table) {
8  $list = $this->pdo->query("PRAGMA table_info(`".$table."`)")->fetchAll(\PDO::FETCH_ASSOC);
9  $re = [];
10  foreach($list as $item) {
11  $re[] = [
12  'field' => $item['name'],
13  'type' => $item['type']
14  ];
15  }
16  return $re;
17  }
18 
19  public function insertOrUpdate($table, $items) {
20  $columns = array_keys($items);
21  $values = array_values($items);
22  $sql = "REPLACE INTO `".$table."`
23  (`".implode("`,`",$columns)."`)
24  VALUES ('".implode("','",$values)."')";
25  $re = $this->pdo->query($sql);
26  if($re === false) {
27  list($errno, $errint, $msg) = $this->getPDO()->errorInfo();
28  throw new EInsertFail($msg, $errint);
29  }
30  $id = $this->pdo->lastInsertId();
31  if($id == 0) {
32  throw new EInsertFail();
33  }
34  return $id;
35  }
36 
37  public function createViewAs($view, $sql) {
38  $this->exec("DROP VIEW IF EXISTS `".$view."`");
39  $this->exec("CREATE VIEW `".$view."` AS ".$sql);
40  }
41 
42  public function truncate($table) {
43  //this is 2 step process, first - delete all data
44  $this->exec("DELETE FROM `".$table."`");
45  // vacuum?
46  $this->exec("VACUUM");
47  }
48 
49 }
getTableFields($table)
Definition: SqliteDriver.php:7
insertOrUpdate($table, $items)
createViewAs($view, $sql)