FOSSology  4.4.0
Open Source License Compliance by Open Source Software
DbViewProxy.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Proxy;
9 
11 {
13  protected $dbViewName;
15  protected $dbViewQuery;
17  protected $materialized = false;
18 
23  public function __construct($dbViewQuery, $dbViewName)
24  {
25  $this->dbViewQuery = $dbViewQuery;
26  $this->dbViewName = $dbViewName;
27  }
28 
32  public function getDbViewName()
33  {
34  return $this->dbViewName;
35  }
36 
40  public function materialize()
41  {
42  if ($this->materialized) {
43  return;
44  }
45  global $container;
46  $dbManager = $container->get('db.manager');
47  $dbManager->queryOnce("CREATE TEMPORARY TABLE $this->dbViewName AS $this->dbViewQuery", "CREATE DbView ".$this->dbViewName);
48  $this->materialized = true;
49  }
50 
54  public function unmaterialize()
55  {
56  if (!$this->materialized) {
57  return;
58  }
59  global $container;
60  $dbManager = $container->get('db.manager');
61  $dbManager->queryOnce("DROP TABLE $this->dbViewName", "DROP DbView ".$this->dbViewName);
62  $this->materialized = false;
63  }
64 
69  public function asCTE()
70  {
71  return "WITH $this->dbViewName AS (".$this->dbViewQuery.")";
72  }
73 
74  public function getDbViewQuery()
75  {
76  return $this->dbViewQuery;
77  }
78 }
materialize()
create temp table
Definition: DbViewProxy.php:40
__construct($dbViewQuery, $dbViewName)
Definition: DbViewProxy.php:23
asCTE()
Common Table Expressions.
Definition: DbViewProxy.php:69
unmaterialize()
drops temp table
Definition: DbViewProxy.php:54