Skip to content

Commit 59d261c

Browse files
andrehankeandrehanke
andrehanke
authored and
andrehanke
committed
fix: verificação de chaves de config nulas
1 parent 024aeee commit 59d261c

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ Update your **config/database.php's** default driver with the settings for the *
4747
return [
4848
...
4949

50+
'sybase' =>
51+
[
52+
'application_encoding' => false,
53+
'application_charset' => '',
54+
'database_charset' => ''
55+
],
56+
5057
'connections' => [
5158
...
5259

@@ -97,23 +104,24 @@ The file is usualy found in **/etc/freetds/freetds.conf**. Set the configuration
97104
tds version = 5.0
98105
```
99106

100-
## Configuring the charset between the database and the application
107+
## Configuring the charset conversion
101108
This package offers to method to charset conversion, it can be converted in application layer or in database layer, we offered both methods because it can be useful for debugging, to config the application layer conversion you need to set up the following entries on the `database.php` file. You can view an example of the application encoding setup below:
102109

103110
```database
104111
'sybase' =>
105112
[
106113
'application_encoding' => true,
107114
'application_charset' => '',
108-
'sybase_database_charset' => ''
115+
'database_charset' => ''
109116
],
110117
```
118+
To use the database layer conversion add the property charset to connection configuration on the sybase configuration array
111119

112120
```charset
113121
'charset' => 'utf8',
114122
```
115123

116-
To use the database layer conversion add the property charset to connection configuration on `database.php`
124+
117125

118126
## Configuring the cache
119127
As the library consults table information whenever it receives a request, caching can be used to avoid excessive queries

src/Database/Connection.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,16 @@ private function compileNewQuery($query, $bindings)
340340

341341
$newQuery = join(array_map(fn ($k1, $k2) => $k1.$k2, $partQuery, $bindings));
342342
$newQuery = str_replace('[]', '', $newQuery);
343-
$app_encoding = config('database.sybase.app_encoding');
344-
if (is_null($app_encoding)) {
343+
$application_encoding = config('database.sybase.application_encoding');
344+
if (is_null($application_encoding)) {
345345
return $newQuery;
346346
}
347-
$db_charset = config('database.sybase.db_charset');
348-
$app_charset = config('database.sybase.app_charset');
349-
if (is_null($db_charset) || is_null($app_charset)) {
347+
$database_charset = config('database.sybase.database_charset');
348+
$application_charset = config('database.sybase.application_charset');
349+
if (is_null($database_charset) || is_null($application_charset)) {
350350
throw new \Exception('[SYBASE] Database Charset and App Charset not set');
351351
}
352-
$newQuery = mb_convert_encoding($newQuery, $db_charset, $app_charset);
352+
$newQuery = mb_convert_encoding($newQuery, $database_charset, $application_charset);
353353

354354
return $newQuery;
355355
}
@@ -390,18 +390,18 @@ public function select($query, $bindings = [], $useReadPdo = true)
390390

391391
$result = [...$result];
392392

393-
$app_encoding = config('database.sybase.app_encoding');
394-
if (is_null($app_encoding)) {
393+
$application_encoding = config('database.sybase.application_encoding');
394+
if (is_null($application_encoding)) {
395395
return $result;
396396
}
397-
$db_charset = config('database.sybase.db_charset');
398-
$app_charset = config('database.sybase.app_charset');
399-
if (is_null($db_charset) || is_null($app_charset)) {
397+
$database_charset = config('database.sybase.database_charset');
398+
$application_charset = config('database.sybase.application_charset');
399+
if (is_null($database_charset) || is_null($application_charset)) {
400400
throw new \Exception('[SYBASE] Database Charset and App Charset not set');
401401
}
402402
foreach ($result as &$r) {
403403
foreach ($r as $k => &$v) {
404-
$v = gettype($v) === 'string' ? mb_convert_encoding($v, $app_charset, $db_charset) : $v;
404+
$v = gettype($v) === 'string' ? mb_convert_encoding($v, $application_charset, $database_charset) : $v;
405405
}
406406
}
407407

0 commit comments

Comments
 (0)