Skip to content

Commit 5482b0b

Browse files
authored
Merge pull request #97 from andrex47/master
removing .env file dependency
2 parents a5e85a7 + 59d261c commit 5482b0b

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
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

+14-15
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ private function compile(Builder $builder)
148148
}
149149

150150
$cache = $builder->connection->config['cache_tables'];
151-
152151
$types = [];
153152

154153
foreach ($arrTables as $tables) {
@@ -165,10 +164,10 @@ private function compile(Builder $builder)
165164
}
166165

167166
if ($cache) {
168-
$aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_TABLES_TIME') ?? 3600, function () use ($tables) {
167+
$cacheTime = key_exists('cache_time',$builder->connection->config) ? $builder->connection->config['cache_time'] : 3600;
168+
$aux = cache()->remember("sybase_columns.$tables.columns_info", $cacheTime, function () use ($tables) {
169169
$queryString = $this->queryString($tables);
170170
$queryRes = $this->getPdo()->query($queryString);
171-
172171
return $queryRes->fetchAll(PDO::FETCH_NAMED);
173172
});
174173
} else {
@@ -341,16 +340,16 @@ private function compileNewQuery($query, $bindings)
341340

342341
$newQuery = join(array_map(fn ($k1, $k2) => $k1.$k2, $partQuery, $bindings));
343342
$newQuery = str_replace('[]', '', $newQuery);
344-
$app_encoding = config('database.sybase.app_encoding');
345-
if (! $app_encoding) {
343+
$application_encoding = config('database.sybase.application_encoding');
344+
if (is_null($application_encoding)) {
346345
return $newQuery;
347346
}
348-
$db_charset = config('database.sybase.db_charset');
349-
$app_charset = config('database.sybase.app_charset');
350-
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)) {
351350
throw new \Exception('[SYBASE] Database Charset and App Charset not set');
352351
}
353-
$newQuery = mb_convert_encoding($newQuery, $db_charset, $app_charset);
352+
$newQuery = mb_convert_encoding($newQuery, $database_charset, $application_charset);
354353

355354
return $newQuery;
356355
}
@@ -391,18 +390,18 @@ public function select($query, $bindings = [], $useReadPdo = true)
391390

392391
$result = [...$result];
393392

394-
$app_encoding = config('database.sybase.app_encoding');
395-
if (! $app_encoding) {
393+
$application_encoding = config('database.sybase.application_encoding');
394+
if (is_null($application_encoding)) {
396395
return $result;
397396
}
398-
$db_charset = config('database.sybase.db_charset');
399-
$app_charset = config('database.sybase.app_charset');
400-
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)) {
401400
throw new \Exception('[SYBASE] Database Charset and App Charset not set');
402401
}
403402
foreach ($result as &$r) {
404403
foreach ($r as $k => &$v) {
405-
$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;
406405
}
407406
}
408407

0 commit comments

Comments
 (0)