From 38b3e85bc75013c2e23b1e037034e24e38b45a3d Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:13:09 +0000 Subject: [PATCH 01/11] reducing requirements for using the library --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c90ccb7..9014b9e 100644 --- a/composer.json +++ b/composer.json @@ -24,10 +24,10 @@ "wiki": "https://github.com/uepg/laravel-sybase/wiki" }, "require": { - "php": "^8.1", + "php": ">=8.1", "doctrine/dbal": "^3.5.1", - "illuminate/database": "^10", - "illuminate/support": "^10", + "illuminate/database": ">=8.0", + "illuminate/support": ">=8.0", "ext-pdo": "*" }, "require-dev": { From 5ccb789950ab2586d5aa63cca8ddb5729ac364ae Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:15:23 +0000 Subject: [PATCH 02/11] updating README --- README.md | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 7dbddfe..04da51b 100644 --- a/README.md +++ b/README.md @@ -14,23 +14,9 @@ Add the following in the require section of your **composer.json**: -### Laravel 5.1, 5.2, 5.3 - -```json -"uepg/laravel-sybase": "~1.0" -``` -### Laravel 5.4, 5.5, 5.6, 5.7, 5.8, 6.x, 7.x, 8.x, 9.x - -```json -"uepg/laravel-sybase": "~2.0" -``` - -### Laravel 10.x - +### Laravel >=7.x ```json -"uepg/laravel-sybase": "~3.0" // old version -//or The new version -"uepg/laravel-sybase": "~4.0" // new version +"uepg/laravel-sybase": "~4.0" ``` Update the package dependencies executing: From 921e2dc54095bd7ca2268cde5f3e790c23c67676 Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Tue, 11 Jun 2024 17:19:41 +0000 Subject: [PATCH 03/11] Updating `Uepg/*` to `xBu3n0/*` --- .github/ISSUE_TEMPLATE/BUG_REPORT.md | 2 +- README.md | 2 +- composer.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md index 0d3d9bf..4835dd6 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -32,7 +32,7 @@ If applicable, add screenshots to help explain your problem. If no have screensh * Laravel: Run `php artisan --version` to show the version. * PHP: Run `php --version` to show the version. * Composer: Run `composer --version` to show the version. -* uepg/laravel-sybase: Get the version in `composer.lock`. +* xbu3n0/laravel-sybase: Get the version in `composer.lock`. ## Additional context diff --git a/README.md b/README.md index 04da51b..a13b303 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add the following in the require section of your **composer.json**: ### Laravel >=7.x ```json -"uepg/laravel-sybase": "~4.0" +"xbu3n0/laravel-sybase": "~4.0" ``` Update the package dependencies executing: diff --git a/composer.json b/composer.json index 9014b9e..74e1477 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "uepg/laravel-sybase", + "name": "xbu3n0/laravel-sybase", "description": "Sybase based Eloquent module extension for Laravel 10.x", "keywords": [ "sybase" @@ -20,8 +20,8 @@ } ], "support": { - "issues": "https://github.com/uepg/laravel-sybase/issues", - "wiki": "https://github.com/uepg/laravel-sybase/wiki" + "issues": "https://github.com/xbu3n0/laravel-sybase/issues", + "wiki": "https://github.com/xbu3n0/laravel-sybase/wiki" }, "require": { "php": ">=8.1", From f4e51d8c49f19b5c5128f328ecf022b86e983bb7 Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Thu, 27 Jun 2024 20:36:19 +0000 Subject: [PATCH 04/11] performing the treatment of null fields --- src/Database/Connection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Database/Connection.php b/src/Database/Connection.php index 531e65a..815058c 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -352,6 +352,7 @@ private function compileNewQuery($query, $bindings) $bindings = array_map(fn($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings); $bindings = array_map(fn($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings); + $bindings = array_map(fn($v) => gettype($v) === 'NULL' ? 'NULL' : $v, $bindings); $newQuery = join(array_map(fn($k1, $k2) => $k1.$k2, $partQuery, $bindings)); $newQuery = str_replace('[]', '', $newQuery); From fa583d24b1733f9342ddbca60b548a9fba995ab5 Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:11:02 +0000 Subject: [PATCH 05/11] Adding compatibility with Laravel 8.x --- src/Database/Connector.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Database/Connector.php b/src/Database/Connector.php index deaaf26..3a09048 100644 --- a/src/Database/Connector.php +++ b/src/Database/Connector.php @@ -12,11 +12,15 @@ public function connect(array $config) $connection = $this->createConnection($this->getDsn($config), $config, $options); - if(array_key_exists('charset', $config) && $config['charset'] != '') { + if(isset($config['charset'])) { $connection->prepare("set char_convert '{$config['charset']}'")->execute(); } - $this->configureIsolationLevel($connection, $config); + if (isset($config['isolation_level'])) { + $connection->prepare( + "SET TRANSACTION ISOLATION LEVEL {$config['isolation_level']}" + )->execute(); + } return $connection; } From 2c51bdf6d2a291dc03765b36c6164617fabbf5f7 Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:35:18 +0000 Subject: [PATCH 06/11] Fixing problem with queries that use '.dbo.' instead of '..' --- src/Database/Connection.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Database/Connection.php b/src/Database/Connection.php index 815058c..90781c4 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -148,6 +148,7 @@ private function compile(Builder $builder) } $cache_columns = env('SYBASE_CACHE_COLUMNS'); + $types = []; foreach ($arrTables as $tables) { preg_match ( @@ -250,7 +251,8 @@ private function compile(Builder $builder) */ private function queryString($tables) { - $explicitDB = explode('..', $tables); + $tables = str_replace('..', '.dbo.', $tables); + $explicitDB = explode('.dbo.', $tables); // Has domain.table if (isset($explicitDB[1])) { From 65314dc88cf425dc5768dee93867c0657404113c Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:31:12 +0000 Subject: [PATCH 07/11] Add cached granulation of tables and more explicit variable names --- README.md | 13 +++++++------ src/Database/Connection.php | 12 +++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a13b303..40c0a39 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,9 @@ return [ 'database' => env('DB_DATABASE', 'mydatabase'), 'username' => env('DB_USERNAME', 'user'), 'password' => env('DB_PASSWORD', 'password'), - 'charset' => 'utf8', // Experimental yet, prefer use the `DB_CHARSET` and `APPLICATION_CHARSET` + 'charset' => 'utf8', 'prefix' => '', + 'cache' => true // By default it caches on all connections, if you want some connection not remembered assign `false` (Recommended when modification is performed on tables frequently [development]) ], ... @@ -96,19 +97,19 @@ The file is usualy found in **/etc/freetds/freetds.conf**. Set the configuration ``` ## Configuring the charset between the database and the application -To configure the charset between the database and the application, add the fields `DB_CHARSET` and `APPLICATION_CHARSET` in `.env` file, see the following example: +To configure the charset between the database and the application, add the fields `DATABASE_CHARSET` and `APPLICATION_CHARSET` in `.env` file, see the following example: ```env -DB_CHARSET=CP850 +DATABASE_CHARSET=CP850 APPLICATION_CHARSET=UTF8 ``` ## Configuring the cache As the library consults table information whenever it receives a request, caching can be used to avoid excessive queries -To use the cache, add the fields `SYBASE_CACHE_COLUMNS` and `SYBASE_CACHE_COLUMNS_TIME` to the `.env` file, see the following example: +To use the cache, add the fields `SYBASE_CACHE_TABLES` and `SYBASE_CACHE_TABLES_TIME` to the `.env` file, see the following example: ```dotenv -SYBASE_CACHE_COLUMNS=true -SYBASE_CACHE_COLUMNS_TIME=3600 # cache table information by `3600` seconds +SYBASE_CACHE_TABLES=true +SYBASE_CACHE_TABLES_TIME=3600 # cache table information by `3600` seconds ``` ## Setting to use numeric data type diff --git a/src/Database/Connection.php b/src/Database/Connection.php index 90781c4..357d72c 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -147,7 +147,9 @@ private function compile(Builder $builder) } } - $cache_columns = env('SYBASE_CACHE_COLUMNS'); + $cache_tables = env('SYBASE_CACHE_TABLES'); + $cache = !key_exists('cache_tables', $builder->connection->config) || $builder->connection->config['cache_tables']; + $types = []; foreach ($arrTables as $tables) { @@ -163,8 +165,8 @@ private function compile(Builder $builder) $tables = $alias['table']; } - if($cache_columns == true) { - $aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_COLUMNS_TIME') ?? 600, function() use($tables) { + if($cache_tables && $cache) { + $aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_TABLES_TIME') ?? 3600, function() use($tables) { $queryString = $this->queryString($tables); $queryRes = $this->getPdo()->query($queryString); return $queryRes->fetchAll(PDO::FETCH_NAMED); @@ -359,7 +361,7 @@ private function compileNewQuery($query, $bindings) $newQuery = join(array_map(fn($k1, $k2) => $k1.$k2, $partQuery, $bindings)); $newQuery = str_replace('[]', '', $newQuery); - $db_charset = env('DB_CHARSET'); + $db_charset = env('DATABASE_CHARSET'); $app_charset = env('APPLICATION_CHARSET'); if($db_charset && $app_charset) { @@ -395,7 +397,7 @@ public function select($query, $bindings = [], $useReadPdo = true) $result = $statement->fetchAll($this->getFetchMode()); - $db_charset = env('DB_CHARSET'); + $db_charset = env('DATABASE_CHARSET'); $app_charset = env('APPLICATION_CHARSET'); if($db_charset && $app_charset) { From f272a48dfa69a2922f6f44d429c94563d7f4bdeb Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:34:50 +0000 Subject: [PATCH 08/11] Explicit variable name for SYBASE --- README.md | 6 +++--- src/Database/Connection.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 40c0a39..b430b70 100644 --- a/README.md +++ b/README.md @@ -97,11 +97,11 @@ The file is usualy found in **/etc/freetds/freetds.conf**. Set the configuration ``` ## Configuring the charset between the database and the application -To configure the charset between the database and the application, add the fields `DATABASE_CHARSET` and `APPLICATION_CHARSET` in `.env` file, see the following example: +To configure the charset between the database and the application, add the fields `SYBASE_DATABASE_CHARSET` and `SYBASE_APPLICATION_CHARSET` in `.env` file, see the following example: ```env -DATABASE_CHARSET=CP850 -APPLICATION_CHARSET=UTF8 +SYBASE_DATABASE_CHARSET=CP850 +SYBASE_APPLICATION_CHARSET=UTF8 ``` ## Configuring the cache As the library consults table information whenever it receives a request, caching can be used to avoid excessive queries diff --git a/src/Database/Connection.php b/src/Database/Connection.php index 357d72c..6f2d1d8 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -361,8 +361,8 @@ private function compileNewQuery($query, $bindings) $newQuery = join(array_map(fn($k1, $k2) => $k1.$k2, $partQuery, $bindings)); $newQuery = str_replace('[]', '', $newQuery); - $db_charset = env('DATABASE_CHARSET'); - $app_charset = env('APPLICATION_CHARSET'); + $db_charset = env('SYBASE_DATABASE_CHARSET'); + $app_charset = env('SYBASE_APPLICATION_CHARSET'); if($db_charset && $app_charset) { $newQuery = mb_convert_encoding($newQuery, $db_charset, $app_charset); @@ -397,8 +397,8 @@ public function select($query, $bindings = [], $useReadPdo = true) $result = $statement->fetchAll($this->getFetchMode()); - $db_charset = env('DATABASE_CHARSET'); - $app_charset = env('APPLICATION_CHARSET'); + $db_charset = env('SYBASE_DATABASE_CHARSET'); + $app_charset = env('SYBASE_APPLICATION_CHARSET'); if($db_charset && $app_charset) { foreach($result as &$r) { From e9c40d5425d56bea66eab67075dca7dfb6f696a7 Mon Sep 17 00:00:00 2001 From: Bueno <66925174+xBu3n0@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:53:52 +0000 Subject: [PATCH 09/11] Adicionar suporte para retorno de `EXEC` --- src/Database/Connection.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Database/Connection.php b/src/Database/Connection.php index 6f2d1d8..0931c31 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -389,13 +389,22 @@ public function select($query, $bindings = [], $useReadPdo = true) return []; } - $statement = $this->getPdo()->query($this->compileNewQuery( + $statement = $this->getPdo()->prepare($this->compileNewQuery( $query, $bindings )); + $statement->execute(); - $result = $statement->fetchAll($this->getFetchMode()); + $result = []; + + try { + do { + $result += $statement->fetchAll($this->getFetchMode()); + } while ($statement->nextRowset()); + } catch (\Exception $e) {} + + $result = [...$result]; $db_charset = env('SYBASE_DATABASE_CHARSET'); $app_charset = env('SYBASE_APPLICATION_CHARSET'); From 29ea3bd4ca13636e9ced7e7b1b40226e5adb3481 Mon Sep 17 00:00:00 2001 From: andrehanke Date: Thu, 21 Nov 2024 11:46:14 -0300 Subject: [PATCH 10/11] =?UTF-8?q?feat:=20rollback=20de=20refer=C3=AAncias?= =?UTF-8?q?=20para=20uepg/laravel-sybase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/BUG_REPORT.md | 2 +- composer.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md index 4835dd6..0d3d9bf 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -32,7 +32,7 @@ If applicable, add screenshots to help explain your problem. If no have screensh * Laravel: Run `php artisan --version` to show the version. * PHP: Run `php --version` to show the version. * Composer: Run `composer --version` to show the version. -* xbu3n0/laravel-sybase: Get the version in `composer.lock`. +* uepg/laravel-sybase: Get the version in `composer.lock`. ## Additional context diff --git a/composer.json b/composer.json index 74e1477..9014b9e 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "xbu3n0/laravel-sybase", + "name": "uepg/laravel-sybase", "description": "Sybase based Eloquent module extension for Laravel 10.x", "keywords": [ "sybase" @@ -20,8 +20,8 @@ } ], "support": { - "issues": "https://github.com/xbu3n0/laravel-sybase/issues", - "wiki": "https://github.com/xbu3n0/laravel-sybase/wiki" + "issues": "https://github.com/uepg/laravel-sybase/issues", + "wiki": "https://github.com/uepg/laravel-sybase/wiki" }, "require": { "php": ">=8.1", From 4b91d564a69351e9981a65035f2304541670c0ae Mon Sep 17 00:00:00 2001 From: andrehanke Date: Thu, 21 Nov 2024 11:58:42 -0300 Subject: [PATCH 11/11] =?UTF-8?q?feat:=20rollback=20de=20refer=C3=AAncias?= =?UTF-8?q?=20para=20uepg/laravel-sybase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Database/Connection.php | 50 +++++++++++++++++++++---------------- src/Database/Connector.php | 2 +- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/Database/Connection.php b/src/Database/Connection.php index 0931c31..a206a6d 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -65,9 +65,9 @@ public function transaction(Closure $callback, $attempts = 1) $this->pdo->exec('COMMIT TRAN'); } - // If we catch an exception, we will roll back so nothing gets messed - // up in the database. Then we'll re-throw the exception so it can - // be handled how the developer sees fit for their applications. + // If we catch an exception, we will roll back so nothing gets messed + // up in the database. Then we'll re-throw the exception so it can + // be handled how the developer sees fit for their applications. catch (Exception $e) { $this->pdo->exec('ROLLBACK TRAN'); @@ -148,12 +148,12 @@ private function compile(Builder $builder) } $cache_tables = env('SYBASE_CACHE_TABLES'); - $cache = !key_exists('cache_tables', $builder->connection->config) || $builder->connection->config['cache_tables']; + $cache = ! key_exists('cache_tables', $builder->connection->config) || $builder->connection->config['cache_tables']; $types = []; foreach ($arrTables as $tables) { - preg_match ( + preg_match( "/(?:(?'table'.*)(?: as )(?'alias'.*))|(?'tables'.*)/", strtolower($tables), $alias @@ -165,10 +165,11 @@ private function compile(Builder $builder) $tables = $alias['table']; } - if($cache_tables && $cache) { - $aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_TABLES_TIME') ?? 3600, function() use($tables) { + if ($cache_tables && $cache) { + $aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_TABLES_TIME') ?? 3600, function () use ($tables) { $queryString = $this->queryString($tables); $queryRes = $this->getPdo()->query($queryString); + return $queryRes->fetchAll(PDO::FETCH_NAMED); }); } else { @@ -191,8 +192,10 @@ private function compile(Builder $builder) $keys = []; - $convert = function($column, $v) use($types) { - if (is_null($v)) return null; + $convert = function ($column, $v) use ($types) { + if (is_null($v)) { + return null; + } $variable_type = $types[strtolower($column)]; @@ -205,7 +208,7 @@ private function compile(Builder $builder) if (isset($builder->values)) { foreach ($builder->values as $key => $value) { - if(gettype($value) === 'array') { + if (gettype($value) === 'array') { foreach ($value as $k => $v) { $keys[] = $convert($k, $v); } @@ -233,7 +236,9 @@ private function compile(Builder $builder) } } } elseif ($w['type'] == 'between') { - if(count($w['values']) != 2) { return []; } + if (count($w['values']) != 2) { + return []; + } foreach ($w['values'] as $v) { if (gettype($v) !== 'object') { $keys[] = $convert($k, $v); @@ -316,7 +321,7 @@ private function queryString($tables) * * @param string $query * @param array $bindings - * @return mixed $newBinds + * @return mixed $newBinds */ private function compileBindings($query, $bindings) { @@ -354,17 +359,17 @@ private function compileNewQuery($query, $bindings) $bindings = $this->compileBindings($query, $bindings); $partQuery = explode('?', $query); - $bindings = array_map(fn($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings); - $bindings = array_map(fn($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings); - $bindings = array_map(fn($v) => gettype($v) === 'NULL' ? 'NULL' : $v, $bindings); + $bindings = array_map(fn ($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings); + $bindings = array_map(fn ($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings); + $bindings = array_map(fn ($v) => gettype($v) === 'NULL' ? 'NULL' : $v, $bindings); - $newQuery = join(array_map(fn($k1, $k2) => $k1.$k2, $partQuery, $bindings)); + $newQuery = join(array_map(fn ($k1, $k2) => $k1.$k2, $partQuery, $bindings)); $newQuery = str_replace('[]', '', $newQuery); $db_charset = env('SYBASE_DATABASE_CHARSET'); $app_charset = env('SYBASE_APPLICATION_CHARSET'); - if($db_charset && $app_charset) { + if ($db_charset && $app_charset) { $newQuery = mb_convert_encoding($newQuery, $db_charset, $app_charset); } @@ -402,16 +407,17 @@ public function select($query, $bindings = [], $useReadPdo = true) do { $result += $statement->fetchAll($this->getFetchMode()); } while ($statement->nextRowset()); - } catch (\Exception $e) {} + } catch (\Exception $e) { + } $result = [...$result]; $db_charset = env('SYBASE_DATABASE_CHARSET'); $app_charset = env('SYBASE_APPLICATION_CHARSET'); - if($db_charset && $app_charset) { - foreach($result as &$r) { - foreach($r as $k => &$v) { + if ($db_charset && $app_charset) { + foreach ($result as &$r) { + foreach ($r as $k => &$v) { $v = gettype($v) === 'string' ? mb_convert_encoding($v, $app_charset, $db_charset) : $v; } } @@ -425,7 +431,7 @@ public function select($query, $bindings = [], $useReadPdo = true) * Get the statement. * * @param string $query - * @param mixed|array $bindings + * @param mixed|array $bindings * @return bool */ public function statement($query, $bindings = []) diff --git a/src/Database/Connector.php b/src/Database/Connector.php index 3a09048..e658280 100644 --- a/src/Database/Connector.php +++ b/src/Database/Connector.php @@ -12,7 +12,7 @@ public function connect(array $config) $connection = $this->createConnection($this->getDsn($config), $config, $options); - if(isset($config['charset'])) { + if (isset($config['charset'])) { $connection->prepare("set char_convert '{$config['charset']}'")->execute(); }