Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Schema;
4
 
5
class MySqlBuilder extends Builder
6
{
7
    /**
8
     * Create a database in the schema.
9
     *
10
     * @param  string  $name
11
     * @return bool
12
     */
13
    public function createDatabase($name)
14
    {
15
        return $this->connection->statement(
16
            $this->grammar->compileCreateDatabase($name, $this->connection)
17
        );
18
    }
19
 
20
    /**
21
     * Drop a database from the schema if the database exists.
22
     *
23
     * @param  string  $name
24
     * @return bool
25
     */
26
    public function dropDatabaseIfExists($name)
27
    {
28
        return $this->connection->statement(
29
            $this->grammar->compileDropDatabaseIfExists($name)
30
        );
31
    }
32
 
33
    /**
34
     * Determine if the given table exists.
35
     *
36
     * @param  string  $table
37
     * @return bool
38
     */
39
    public function hasTable($table)
40
    {
41
        $table = $this->connection->getTablePrefix().$table;
42
 
43
        return count($this->connection->selectFromWriteConnection(
44
            $this->grammar->compileTableExists(), [$this->connection->getDatabaseName(), $table]
45
        )) > 0;
46
    }
47
 
48
    /**
49
     * Get the column listing for a given table.
50
     *
51
     * @param  string  $table
52
     * @return array
53
     */
54
    public function getColumnListing($table)
55
    {
56
        $table = $this->connection->getTablePrefix().$table;
57
 
58
        $results = $this->connection->selectFromWriteConnection(
59
            $this->grammar->compileColumnListing(), [$this->connection->getDatabaseName(), $table]
60
        );
61
 
62
        return $this->connection->getPostProcessor()->processColumnListing($results);
63
    }
64
 
65
    /**
66
     * Drop all tables from the database.
67
     *
68
     * @return void
69
     */
70
    public function dropAllTables()
71
    {
72
        $tables = [];
73
 
74
        foreach ($this->getAllTables() as $row) {
75
            $row = (array) $row;
76
 
77
            $tables[] = reset($row);
78
        }
79
 
80
        if (empty($tables)) {
81
            return;
82
        }
83
 
84
        $this->disableForeignKeyConstraints();
85
 
86
        $this->connection->statement(
87
            $this->grammar->compileDropAllTables($tables)
88
        );
89
 
90
        $this->enableForeignKeyConstraints();
91
    }
92
 
93
    /**
94
     * Drop all views from the database.
95
     *
96
     * @return void
97
     */
98
    public function dropAllViews()
99
    {
100
        $views = [];
101
 
102
        foreach ($this->getAllViews() as $row) {
103
            $row = (array) $row;
104
 
105
            $views[] = reset($row);
106
        }
107
 
108
        if (empty($views)) {
109
            return;
110
        }
111
 
112
        $this->connection->statement(
113
            $this->grammar->compileDropAllViews($views)
114
        );
115
    }
116
 
117
    /**
118
     * Get all of the table names for the database.
119
     *
120
     * @return array
121
     */
122
    public function getAllTables()
123
    {
124
        return $this->connection->select(
125
            $this->grammar->compileGetAllTables()
126
        );
127
    }
128
 
129
    /**
130
     * Get all of the view names for the database.
131
     *
132
     * @return array
133
     */
134
    public function getAllViews()
135
    {
136
        return $this->connection->select(
137
            $this->grammar->compileGetAllViews()
138
        );
139
    }
140
}