FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
DbViewProxy.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Proxy;
20 
22 {
24  protected $dbViewName;
26  protected $dbViewQuery;
28  protected $materialized = false;
29 
34  public function __construct($dbViewQuery, $dbViewName)
35  {
36  $this->dbViewQuery = $dbViewQuery;
37  $this->dbViewName = $dbViewName;
38  }
39 
43  public function getDbViewName()
44  {
45  return $this->dbViewName;
46  }
47 
51  public function materialize()
52  {
53  if ($this->materialized) {
54  return;
55  }
56  global $container;
57  $dbManager = $container->get('db.manager');
58  $dbManager->queryOnce("CREATE TEMPORARY TABLE $this->dbViewName AS $this->dbViewQuery", "CREATE DbView ".$this->dbViewName);
59  $this->materialized = true;
60  }
61 
65  public function unmaterialize()
66  {
67  if (!$this->materialized) {
68  return;
69  }
70  global $container;
71  $dbManager = $container->get('db.manager');
72  $dbManager->queryOnce("DROP TABLE $this->dbViewName", "DROP DbView ".$this->dbViewName);
73  $this->materialized = false;
74  }
75 
80  public function asCTE()
81  {
82  return "WITH $this->dbViewName AS (".$this->dbViewQuery.")";
83  }
84 
85  public function getDbViewQuery()
86  {
87  return $this->dbViewQuery;
88  }
89 }
unmaterialize()
drops temp table
Definition: DbViewProxy.php:65
asCTE()
Common Table Expressions.
Definition: DbViewProxy.php:80
__construct($dbViewQuery, $dbViewName)
Definition: DbViewProxy.php:34
materialize()
create temp table
Definition: DbViewProxy.php:51