Skip to content

Commit 4b91d56

Browse files
andrehankeandrehanke
andrehanke
authored and
andrehanke
committed
feat: rollback de referências para uepg/laravel-sybase
1 parent 29ea3bd commit 4b91d56

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

src/Database/Connection.php

+28-22
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

@@ -148,12 +148,12 @@ private function compile(Builder $builder)
148148
}
149149

150150
$cache_tables = env('SYBASE_CACHE_TABLES');
151-
$cache = !key_exists('cache_tables', $builder->connection->config) || $builder->connection->config['cache_tables'];
151+
$cache = ! key_exists('cache_tables', $builder->connection->config) || $builder->connection->config['cache_tables'];
152152

153153
$types = [];
154154

155155
foreach ($arrTables as $tables) {
156-
preg_match (
156+
preg_match(
157157
"/(?:(?'table'.*)(?: as )(?'alias'.*))|(?'tables'.*)/",
158158
strtolower($tables),
159159
$alias
@@ -165,10 +165,11 @@ private function compile(Builder $builder)
165165
$tables = $alias['table'];
166166
}
167167

168-
if($cache_tables && $cache) {
169-
$aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_TABLES_TIME') ?? 3600, function() use($tables) {
168+
if ($cache_tables && $cache) {
169+
$aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_TABLES_TIME') ?? 3600, function () use ($tables) {
170170
$queryString = $this->queryString($tables);
171171
$queryRes = $this->getPdo()->query($queryString);
172+
172173
return $queryRes->fetchAll(PDO::FETCH_NAMED);
173174
});
174175
} else {
@@ -191,8 +192,10 @@ private function compile(Builder $builder)
191192

192193
$keys = [];
193194

194-
$convert = function($column, $v) use($types) {
195-
if (is_null($v)) return null;
195+
$convert = function ($column, $v) use ($types) {
196+
if (is_null($v)) {
197+
return null;
198+
}
196199

197200
$variable_type = $types[strtolower($column)];
198201

@@ -205,7 +208,7 @@ private function compile(Builder $builder)
205208

206209
if (isset($builder->values)) {
207210
foreach ($builder->values as $key => $value) {
208-
if(gettype($value) === 'array') {
211+
if (gettype($value) === 'array') {
209212
foreach ($value as $k => $v) {
210213
$keys[] = $convert($k, $v);
211214
}
@@ -233,7 +236,9 @@ private function compile(Builder $builder)
233236
}
234237
}
235238
} elseif ($w['type'] == 'between') {
236-
if(count($w['values']) != 2) { return []; }
239+
if (count($w['values']) != 2) {
240+
return [];
241+
}
237242
foreach ($w['values'] as $v) {
238243
if (gettype($v) !== 'object') {
239244
$keys[] = $convert($k, $v);
@@ -316,7 +321,7 @@ private function queryString($tables)
316321
*
317322
* @param string $query
318323
* @param array $bindings
319-
* @return mixed $newBinds
324+
* @return mixed $newBinds
320325
*/
321326
private function compileBindings($query, $bindings)
322327
{
@@ -354,17 +359,17 @@ private function compileNewQuery($query, $bindings)
354359
$bindings = $this->compileBindings($query, $bindings);
355360
$partQuery = explode('?', $query);
356361

357-
$bindings = array_map(fn($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings);
358-
$bindings = array_map(fn($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings);
359-
$bindings = array_map(fn($v) => gettype($v) === 'NULL' ? 'NULL' : $v, $bindings);
362+
$bindings = array_map(fn ($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings);
363+
$bindings = array_map(fn ($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings);
364+
$bindings = array_map(fn ($v) => gettype($v) === 'NULL' ? 'NULL' : $v, $bindings);
360365

361-
$newQuery = join(array_map(fn($k1, $k2) => $k1.$k2, $partQuery, $bindings));
366+
$newQuery = join(array_map(fn ($k1, $k2) => $k1.$k2, $partQuery, $bindings));
362367
$newQuery = str_replace('[]', '', $newQuery);
363368

364369
$db_charset = env('SYBASE_DATABASE_CHARSET');
365370
$app_charset = env('SYBASE_APPLICATION_CHARSET');
366371

367-
if($db_charset && $app_charset) {
372+
if ($db_charset && $app_charset) {
368373
$newQuery = mb_convert_encoding($newQuery, $db_charset, $app_charset);
369374
}
370375

@@ -402,16 +407,17 @@ public function select($query, $bindings = [], $useReadPdo = true)
402407
do {
403408
$result += $statement->fetchAll($this->getFetchMode());
404409
} while ($statement->nextRowset());
405-
} catch (\Exception $e) {}
410+
} catch (\Exception $e) {
411+
}
406412

407413
$result = [...$result];
408414

409415
$db_charset = env('SYBASE_DATABASE_CHARSET');
410416
$app_charset = env('SYBASE_APPLICATION_CHARSET');
411417

412-
if($db_charset && $app_charset) {
413-
foreach($result as &$r) {
414-
foreach($r as $k => &$v) {
418+
if ($db_charset && $app_charset) {
419+
foreach ($result as &$r) {
420+
foreach ($r as $k => &$v) {
415421
$v = gettype($v) === 'string' ? mb_convert_encoding($v, $app_charset, $db_charset) : $v;
416422
}
417423
}
@@ -425,7 +431,7 @@ public function select($query, $bindings = [], $useReadPdo = true)
425431
* Get the statement.
426432
*
427433
* @param string $query
428-
* @param mixed|array $bindings
434+
* @param mixed|array $bindings
429435
* @return bool
430436
*/
431437
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(isset($config['charset'])) {
15+
if (isset($config['charset'])) {
1616
$connection->prepare("set char_convert '{$config['charset']}'")->execute();
1717
}
1818

0 commit comments

Comments
 (0)