1: <?php
2:
3: namespace Yajra\Oci8\Schema;
4:
5: use Closure;
6: use Illuminate\Database\Connection;
7: use Illuminate\Database\Schema\Builder;
8:
9: class OracleBuilder extends Builder
10: {
11: 12: 13:
14: public $helper;
15:
16: 17: 18:
19: public $comment;
20:
21: 22: 23:
24: public function __construct(Connection $connection)
25: {
26: $this->connection = $connection;
27: $this->grammar = $connection->getSchemaGrammar();
28: $this->helper = new OracleAutoIncrementHelper($connection);
29: $this->comment = new Comment($connection);
30: }
31:
32: 33: 34: 35: 36: 37: 38:
39: public function create($table, Closure $callback)
40: {
41: $blueprint = $this->createBlueprint($table);
42:
43: $blueprint->create();
44:
45: $callback($blueprint);
46:
47: $this->build($blueprint);
48:
49: $this->comment->setComments($blueprint);
50:
51: $this->helper->createAutoIncrementObjects($blueprint, $table);
52: }
53:
54: 55: 56: 57: 58: 59: 60:
61: public function table($table, Closure $callback)
62: {
63: $blueprint = $this->createBlueprint($table);
64:
65: $callback($blueprint);
66:
67: foreach ($blueprint->getCommands() as $command) {
68: if ($command->get('name') == 'drop') {
69: $this->helper->dropAutoIncrementObjects($table);
70: }
71: }
72:
73: $this->build($blueprint);
74:
75: $this->comment->setComments($blueprint);
76: }
77:
78: 79: 80: 81: 82: 83: 84:
85: protected function createBlueprint($table, Closure $callback = null)
86: {
87: $blueprint = new OracleBlueprint($table, $callback);
88: $blueprint->setTablePrefix($this->connection->getTablePrefix());
89:
90: return $blueprint;
91: }
92:
93: 94: 95: 96: 97: 98:
99: public function drop($table)
100: {
101: $this->helper->dropAutoIncrementObjects($table);
102: parent::drop($table);
103: }
104:
105: 106: 107: 108: 109:
110: public function dropIfExists($table)
111: {
112: $this->helper->dropAutoIncrementObjects($table);
113: parent::dropIfExists($table);
114: }
115:
116: 117: 118: 119: 120: 121:
122: public function hasTable($table)
123: {
124: $sql = $this->grammar->compileTableExists();
125:
126: $database = $this->connection->getConfig('username');
127: $table = $this->connection->getTablePrefix() . $table;
128:
129: return count($this->connection->select($sql, [$database, $table])) > 0;
130: }
131:
132: 133: 134: 135: 136: 137:
138: public function getColumnListing($table)
139: {
140: $database = $this->connection->getConfig('username');
141: $table = $this->connection->getTablePrefix() . $table;
142:
143: $results = $this->connection->select($this->grammar->compileColumnExists($database, $table));
144:
145: return $this->connection->getPostProcessor()->processColumnListing($results);
146: }
147: }
148: