SqlServerGrammar::compileViewColumnListing()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Staudenmeir\LaravelMigrationViews\Schema\Grammars;
4
5
use Illuminate\Database\Schema\Grammars\SqlServerGrammar as Base;
6
7
class SqlServerGrammar extends Base
8
{
9
    use CompilesViews;
10
11
    /**
12
     * Compile the query to drop a view.
13
     *
14
     * @param string $name
15
     * @param bool $ifExists
16
     * @return string
17
     */
18
    public function compileDropView($name, $ifExists)
19
    {
20
        $ifExists = $ifExists ? 'if exists ('.$this->compileViewExists().') ' : '';
21
22
        return $ifExists.'drop view '.$this->wrapTable($name);
23
    }
24
25
    /**
26
     * Compile the query to determine if a view exists.
27
     *
28
     * @return string
29
     */
30
    public function compileViewExists()
31
    {
32
        return "select * from sys.objects where type = 'V' and name = ?";
33
    }
34
35
    /**
36
     * Compile the query to determine the column listing of a view.
37
     *
38
     * @return string
39
     */
40
    public function compileViewColumnListing()
41
    {
42
        return "select columns.name from sys.columns as columns
43
                join sys.objects as objects on objects.object_id = columns.object_id
44
                where objects.type = 'V' and objects.name = ?";
45
    }
46
}
47