Skip to content

Commit e052913

Browse files
authored
Merge pull request #44 from afgloeden/master
30-character limit added in indexes
2 parents 4894fa1 + 2acf22a commit e052913

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

Database/Query/SybaseProcessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Database\Query\Processors\Processor;
66

7-
class SybaseConnector extends Processor
7+
class SybaseProcessor extends Processor
88
{
99
//
1010
}

Database/Schema/SybaseGrammar.php

+23-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ class SybaseGrammar extends Grammar {
2929
'numeric'
3030
];
3131

32+
/**
33+
* Verify if $str length is lower to 30 characters.
34+
*
35+
* @return string
36+
*/
37+
public function limit30Characters($str)
38+
{
39+
if (strlen($str) > 30) {
40+
$result = substr($str, 0, 30);
41+
} else {
42+
$result = $str;
43+
}
44+
45+
return $result;
46+
}
47+
3248
/**
3349
* Compile the query to determine if a table exists.
3450
*
@@ -106,12 +122,7 @@ public function compilePrimary(Blueprint $blueprint, Fluent $command)
106122

107123
$table = $this->wrapTable($blueprint);
108124

109-
// Verify if constraint length is lower to 30 characters.
110-
if (strlen($command->index) > 30) {
111-
$constraint = substr($command->index, 0, 30);
112-
} else {
113-
$constraint = $command->index;
114-
}
125+
$constraint = $this->limit30Characters($command->index);
115126

116127
return "
117128
ALTER TABLE {$table}
@@ -132,7 +143,9 @@ public function compileUnique(Blueprint $blueprint, Fluent $command)
132143

133144
$table = $this->wrapTable($blueprint);
134145

135-
return "CREATE UNIQUE INDEX {$command->index} ON {$table} ({$columns})";
146+
$index = $this->limit30Characters($command->index);
147+
148+
return "CREATE UNIQUE INDEX {$index} ON {$table} ({$columns})";
136149
}
137150

138151
/**
@@ -148,7 +161,9 @@ public function compileIndex(Blueprint $blueprint, Fluent $command)
148161

149162
$table = $this->wrapTable($blueprint);
150163

151-
return "CREATE INDEX {$command->index} ON {$table} ({$columns})";
164+
$index = $this->limit30Characters($command->index);
165+
166+
return "CREATE INDEX {$index} ON {$table} ({$columns})";
152167
}
153168

154169
/**

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ return [
6262
]
6363
```
6464

65-
6665
## Configuration of freetds driver
6766

6867
In Linux systems the driver version must be set in **freetds.conf** file to the right use of charset pages.

0 commit comments

Comments
 (0)