77use Uepg \LaravelSybase \Database \Schema \BlueprintSybase as Blueprint ;
88
99class SybaseGrammar extends Grammar {
10-
1110 /**
1211 * The possible column modifiers.
1312 *
1413 * @var array
1514 */
16- protected $ modifiers = array ('Increment ' , 'Nullable ' , 'Default ' );
15+ protected $ modifiers = [
16+ 'Increment ' ,
17+ 'Nullable ' ,
18+ 'Default '
19+ ];
1720
1821 /**
1922 * The columns available as serials.
2023 *
2124 * @var array
2225 */
23- protected $ serials = array ('bigInteger ' , 'integer ' , 'numeric ' );
26+ protected $ serials = [
27+ 'bigInteger ' ,
28+ 'integer ' ,
29+ 'numeric '
30+ ];
2431
2532 /**
2633 * Compile the query to determine if a table exists.
@@ -29,7 +36,7 @@ class SybaseGrammar extends Grammar {
2936 */
3037 public function compileTableExists ()
3138 {
32- return "select * from sysobjects where type = 'U' and name = '?' " ;
39+ return "SELECT * FROM sysobjects WHERE type = 'U' AND name = '?' " ;
3340 }
3441
3542 /**
@@ -40,9 +47,18 @@ public function compileTableExists()
4047 */
4148 public function compileColumnExists ($ table )
4249 {
43- return "select col.name from sys.columns as col
44- join sys.objects as obj on col.object_id = obj.object_id
45- where obj.type = 'U' and obj.name = ' $ table' " ;
50+ return "
51+ SELECT
52+ col.name
53+ FROM
54+ sys.columns AS col
55+ JOIN
56+ sys.objects AS obj
57+ ON
58+ col.object_id = obj.object_id
59+ WHERE
60+ obj.type = 'U' AND
61+ obj.name = ' $ table' " ;
4662 }
4763
4864 /**
@@ -56,7 +72,9 @@ public function compileCreate(Blueprint $blueprint, Fluent $command)
5672 {
5773 $ columns = implode (', ' , $ this ->getColumns ($ blueprint ));
5874
59- return 'create table ' .$ this ->wrapTable ($ blueprint )." ( $ columns) " ;
75+ return 'CREATE TABLE ' . $ this ->wrapTable ($ blueprint ) . " (
76+ $ columns
77+ ) " ;
6078 }
6179
6280 /**
@@ -72,7 +90,7 @@ public function compileAdd(Blueprint $blueprint, Fluent $command)
7290
7391 $ columns = $ this ->getColumns ($ blueprint );
7492
75- return 'alter table ' . $ table. ' add ' . implode (', ' , $ columns );
93+ return 'ALTER TABLE ' . $ table . ' ADD ' . implode (', ' , $ columns );
7694 }
7795
7896 /**
@@ -88,7 +106,7 @@ public function compilePrimary(Blueprint $blueprint, Fluent $command)
88106
89107 $ table = $ this ->wrapTable ($ blueprint );
90108
91- return "alter table {$ table } add constraint {$ command ->index } primary key ( {$ columns }) " ;
109+ return "ALTER TABLE {$ table } ADD CONSTRAINT {$ command ->index } PRIMARY KEY ( {$ columns }) " ;
92110 }
93111
94112 /**
@@ -104,7 +122,7 @@ public function compileUnique(Blueprint $blueprint, Fluent $command)
104122
105123 $ table = $ this ->wrapTable ($ blueprint );
106124
107- return "create unique index {$ command ->index } on {$ table } ( {$ columns }) " ;
125+ return "CREATE UNIQUE INDEX {$ command ->index } ON {$ table } ( {$ columns }) " ;
108126 }
109127
110128 /**
@@ -120,7 +138,7 @@ public function compileIndex(Blueprint $blueprint, Fluent $command)
120138
121139 $ table = $ this ->wrapTable ($ blueprint );
122140
123- return "create index {$ command ->index } on {$ table } ( {$ columns }) " ;
141+ return "CREATE INDEX {$ command ->index } ON {$ table } ( {$ columns }) " ;
124142 }
125143
126144 /**
@@ -132,7 +150,7 @@ public function compileIndex(Blueprint $blueprint, Fluent $command)
132150 */
133151 public function compileDrop (Blueprint $ blueprint , Fluent $ command )
134152 {
135- return 'drop table ' . $ this ->wrapTable ($ blueprint );
153+ return 'DROP TABLE ' . $ this ->wrapTable ($ blueprint );
136154 }
137155
138156 /**
@@ -144,7 +162,15 @@ public function compileDrop(Blueprint $blueprint, Fluent $command)
144162 */
145163 public function compileDropIfExists (Blueprint $ blueprint , Fluent $ command )
146164 {
147- return 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = \'' .$ blueprint ->getTable ().'\') drop table ' .$ blueprint ->getTable ();
165+ return "
166+ IF EXISTS (
167+ SELECT
168+ *
169+ FROM
170+ INFORMATION_SCHEMA.TABLES
171+ WHERE
172+ TABLE_NAME = ' " . $ blueprint ->getTable () . "'
173+ ) DROP TABLE " . $ blueprint ->getTable ();
148174 }
149175
150176 /**
@@ -160,7 +186,7 @@ public function compileDropColumn(Blueprint $blueprint, Fluent $command)
160186
161187 $ table = $ this ->wrapTable ($ blueprint );
162188
163- return 'alter table ' . $ table. ' drop column ' . implode (', ' , $ columns );
189+ return 'ALTER TABLE ' . $ table . ' DROP COLUMN ' . implode (', ' , $ columns );
164190 }
165191
166192 /**
@@ -174,7 +200,7 @@ public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
174200 {
175201 $ table = $ this ->wrapTable ($ blueprint );
176202
177- return "alter table {$ table } drop constraint {$ command ->index }" ;
203+ return "ALTER TABLE {$ table } DROP CONSTRAINT {$ command ->index }" ;
178204 }
179205
180206 /**
@@ -188,7 +214,7 @@ public function compileDropUnique(Blueprint $blueprint, Fluent $command)
188214 {
189215 $ table = $ this ->wrapTable ($ blueprint );
190216
191- return "drop index {$ command ->index } on {$ table }" ;
217+ return "DROP INDEX {$ command ->index } ON {$ table }" ;
192218 }
193219
194220 /**
@@ -202,7 +228,7 @@ public function compileDropIndex(Blueprint $blueprint, Fluent $command)
202228 {
203229 $ table = $ this ->wrapTable ($ blueprint );
204230
205- return "drop index {$ command ->index } on {$ table }" ;
231+ return "DROP INDEX {$ command ->index } ON {$ table }" ;
206232 }
207233
208234 /**
@@ -216,7 +242,7 @@ public function compileDropForeign(Blueprint $blueprint, Fluent $command)
216242 {
217243 $ table = $ this ->wrapTable ($ blueprint );
218244
219- return "alter table {$ table } drop constraint {$ command ->index }" ;
245+ return "ALTER TABLE {$ table } DROP CONSTRAINT {$ command ->index }" ;
220246 }
221247
222248 /**
@@ -230,7 +256,7 @@ public function compileRename(Blueprint $blueprint, Fluent $command)
230256 {
231257 $ from = $ this ->wrapTable ($ blueprint );
232258
233- return "sp_rename {$ from }, " . $ this ->wrapTable ($ command ->to );
259+ return "sp_rename {$ from }, " . $ this ->wrapTable ($ command ->to );
234260 }
235261
236262 /**
@@ -542,9 +568,8 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
542568 */
543569 protected function modifyDefault (Blueprint $ blueprint , Fluent $ column )
544570 {
545- if ( ! is_null ($ column ->default ))
546- {
547- return " default " .$ this ->getDefaultValue ($ column ->default );
571+ if (!is_null ($ column ->default )) {
572+ return " default " . $ this ->getDefaultValue ($ column ->default );
548573 }
549574 }
550575
@@ -557,10 +582,8 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column)
557582 */
558583 protected function modifyIncrement (Blueprint $ blueprint , Fluent $ column )
559584 {
560- if (in_array ($ column ->type , $ this ->serials ) && $ column ->autoIncrement )
561- {
585+ if (in_array ($ column ->type , $ this ->serials ) && $ column ->autoIncrement ) {
562586 return ' identity primary key ' ;
563587 }
564588 }
565-
566589}
0 commit comments