Skip to content

Commit 5c8b5d6

Browse files
authored
Merge pull request #90 from andrex47/master
New functions to package compatibility
2 parents bd9c8f2 + 4384885 commit 5c8b5d6

File tree

9 files changed

+205
-107
lines changed

9 files changed

+205
-107
lines changed

src/Database/Connection.php

+24-20
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public function transaction(Closure $callback, $attempts = 1)
6565
$this->pdo->exec('COMMIT TRAN');
6666
}
6767

68-
// If we catch an exception, we will roll back so nothing gets messed
69-
// up in the database. Then we'll re-throw the exception so it can
70-
// be handled how the developer sees fit for their applications.
68+
// If we catch an exception, we will roll back so nothing gets messed
69+
// up in the database. Then we'll re-throw the exception so it can
70+
// be handled how the developer sees fit for their applications.
7171
catch (Exception $e) {
7272
$this->pdo->exec('ROLLBACK TRAN');
7373

@@ -150,7 +150,7 @@ private function compile(Builder $builder)
150150
$cache_columns = env('SYBASE_CACHE_COLUMNS');
151151

152152
foreach ($arrTables as $tables) {
153-
preg_match (
153+
preg_match(
154154
"/(?:(?'table'.*)(?: as )(?'alias'.*))|(?'tables'.*)/",
155155
strtolower($tables),
156156
$alias
@@ -162,10 +162,11 @@ private function compile(Builder $builder)
162162
$tables = $alias['table'];
163163
}
164164

165-
if($cache_columns == true) {
166-
$aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_COLUMNS_TIME') ?? 600, function() use($tables) {
165+
if ($cache_columns == true) {
166+
$aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_COLUMNS_TIME') ?? 600, function () use ($tables) {
167167
$queryString = $this->queryString($tables);
168168
$queryRes = $this->getPdo()->query($queryString);
169+
169170
return $queryRes->fetchAll(PDO::FETCH_NAMED);
170171
});
171172
} else {
@@ -188,8 +189,10 @@ private function compile(Builder $builder)
188189

189190
$keys = [];
190191

191-
$convert = function($column, $v) use($types) {
192-
if (is_null($v)) return null;
192+
$convert = function ($column, $v) use ($types) {
193+
if (is_null($v)) {
194+
return null;
195+
}
193196

194197
$variable_type = $types[strtolower($column)];
195198

@@ -202,7 +205,7 @@ private function compile(Builder $builder)
202205

203206
if (isset($builder->values)) {
204207
foreach ($builder->values as $key => $value) {
205-
if(gettype($value) === 'array') {
208+
if (gettype($value) === 'array') {
206209
foreach ($value as $k => $v) {
207210
$keys[] = $convert($k, $v);
208211
}
@@ -230,7 +233,9 @@ private function compile(Builder $builder)
230233
}
231234
}
232235
} elseif ($w['type'] == 'between') {
233-
if(count($w['values']) != 2) { return []; }
236+
if (count($w['values']) != 2) {
237+
return [];
238+
}
234239
foreach ($w['values'] as $v) {
235240
if (gettype($v) !== 'object') {
236241
$keys[] = $convert($k, $v);
@@ -312,7 +317,7 @@ private function queryString($tables)
312317
*
313318
* @param string $query
314319
* @param array $bindings
315-
* @return mixed $newBinds
320+
* @return mixed $newBinds
316321
*/
317322
private function compileBindings($query, $bindings)
318323
{
@@ -350,16 +355,16 @@ private function compileNewQuery($query, $bindings)
350355
$bindings = $this->compileBindings($query, $bindings);
351356
$partQuery = explode('?', $query);
352357

353-
$bindings = array_map(fn($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings);
354-
$bindings = array_map(fn($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings);
358+
$bindings = array_map(fn ($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings);
359+
$bindings = array_map(fn ($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings);
355360

356-
$newQuery = join(array_map(fn($k1, $k2) => $k1.$k2, $partQuery, $bindings));
361+
$newQuery = join(array_map(fn ($k1, $k2) => $k1.$k2, $partQuery, $bindings));
357362
$newQuery = str_replace('[]', '', $newQuery);
358363

359364
$db_charset = env('DB_CHARSET');
360365
$app_charset = env('APPLICATION_CHARSET');
361366

362-
if($db_charset && $app_charset) {
367+
if ($db_charset && $app_charset) {
363368
$newQuery = mb_convert_encoding($newQuery, $db_charset, $app_charset);
364369
}
365370

@@ -389,15 +394,14 @@ public function select($query, $bindings = [], $useReadPdo = true)
389394
$bindings
390395
));
391396

392-
393397
$result = $statement->fetchAll($this->getFetchMode());
394398

395399
$db_charset = env('DB_CHARSET');
396400
$app_charset = env('APPLICATION_CHARSET');
397401

398-
if($db_charset && $app_charset) {
399-
foreach($result as &$r) {
400-
foreach($r as $k => &$v) {
402+
if ($db_charset && $app_charset) {
403+
foreach ($result as &$r) {
404+
foreach ($r as $k => &$v) {
401405
$v = gettype($v) === 'string' ? mb_convert_encoding($v, $app_charset, $db_charset) : $v;
402406
}
403407
}
@@ -411,7 +415,7 @@ public function select($query, $bindings = [], $useReadPdo = true)
411415
* Get the statement.
412416
*
413417
* @param string $query
414-
* @param mixed|array $bindings
418+
* @param mixed|array $bindings
415419
* @return bool
416420
*/
417421
public function statement($query, $bindings = [])

src/Database/Connector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function connect(array $config)
1212

1313
$connection = $this->createConnection($this->getDsn($config), $config, $options);
1414

15-
if(array_key_exists('charset', $config) && $config['charset'] != '') {
15+
if (array_key_exists('charset', $config) && $config['charset'] != '') {
1616
$connection->prepare("set char_convert '{$config['charset']}'")->execute();
1717
}
1818

src/Database/Query/Grammar.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public function compileSelect(Builder $query)
6666
* SELECT B.name, 'another column'
6767
* FROM B
6868
* WHERE B.id = 1
69-
*
7069
*/
7170
/**
7271
* Compile an insert statement into SQL.
@@ -125,7 +124,6 @@ public function compileUpdate(Builder $query, array $values)
125124

126125
$where = $this->compileWheres($query);
127126

128-
129127
return trim(
130128
isset($query->joins)
131129
? $this->compileUpdateWithJoins($query, $table, $columns, $where)
@@ -224,7 +222,7 @@ protected function compileLimit(Builder $query, $limit)
224222
*/
225223
protected function compileOffset(Builder $query, $offset)
226224
{
227-
if($offset > 0) {
225+
if ($offset > 0) {
228226
return 'rows offset '.$offset;
229227
}
230228

src/Database/Query/Processor.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,43 @@
66

77
class Processor extends SqlServerProcessor
88
{
9-
//
9+
/**
10+
* Process the results of an indexes query.
11+
*
12+
* @param array $results
13+
* @return array
14+
*/
15+
public function processIndexes($results)
16+
{
17+
$array = [];
18+
$indexes = collect($results)->unique('name');
19+
foreach ($indexes as $index) {
20+
$aux = [];
21+
$aux['name'] = $index->name;
22+
$aux['columns'] = $this->concatenaCampos($results, $index->name);
23+
$aux['unique'] = $index->is_unique;
24+
$aux['primary'] = $index->is_primary;
25+
array_push($array, $aux);
26+
}
27+
28+
return $array;
29+
}
30+
31+
/**
32+
* @param $results
33+
* @param $indexName
34+
* @return array
35+
* Helper function for building index vector
36+
*/
37+
public function getColumnsFromIndexResult($results, $indexName)
38+
{
39+
$columns = [];
40+
foreach ($results as $result) {
41+
if ($result->name == $indexName) {
42+
array_push($columns, $result->column_name);
43+
}
44+
}
45+
46+
return $columns;
47+
}
1048
}

src/Database/Schema/Blueprint.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class Blueprint extends IlluminateBlueprint
1010
/**
1111
* Function for numeric type.
1212
*
13-
* @param $column
14-
* @param int $total
15-
* @param bool $autoIncrement
13+
* @param $column
14+
* @param int $total
15+
* @param bool $autoIncrement
1616
* @return ColumnDefinition
1717
*/
1818
public function numeric($column, int $total = 8, bool $autoIncrement = false)

0 commit comments

Comments
 (0)