From 5cbb1dd96d153b2ac94bb592f3815e916d6c8331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Wed, 23 Apr 2014 11:07:00 +0200 Subject: [PATCH 1/3] Qual: Removed useless method The method is already in the DoliDB base class --- htdocs/core/db/pgsql.class.php | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index f8cb36e4044..224e5ffa71d 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -448,32 +448,6 @@ class DoliDBPgsql extends DoliDB return false; } - /** - * Start transaction - * - * @return int 1 if transaction successfuly opened or already opened, 0 if error - */ - function begin() - { - if (! $this->transaction_opened) - { - $ret=$this->query("BEGIN;"); - if ($ret) - { - $this->transaction_opened++; - dol_syslog("BEGIN Transaction",LOG_DEBUG); - dol_syslog('',0,1); - } - return $ret; - } - else - { - $this->transaction_opened++; - dol_syslog('',0,1); - return 1; - } - } - /** * Validate a database transaction * From 16ede7c52c37891d36a59dd3dec56b924394c1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Wed, 23 Apr 2014 11:12:06 +0200 Subject: [PATCH 2/3] Qual: Moved duplicate methods to base method --- htdocs/core/db/DoliDB.class.php | 49 ++++++++++++++++++++++++++++++++ htdocs/core/db/mysql.class.php | 49 -------------------------------- htdocs/core/db/mysqli.class.php | 49 -------------------------------- htdocs/core/db/pgsql.class.php | 50 --------------------------------- htdocs/core/db/sqlite.class.php | 49 -------------------------------- 5 files changed, 49 insertions(+), 197 deletions(-) diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index f85aa4ca78a..e95d31acf6e 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -125,6 +125,55 @@ abstract class DoliDB implements Database } } + /** + * Validate a database transaction + * + * @param string $log Add more log to default log line + * @return int 1 if validation is OK or transaction level no started, 0 if ERROR + */ + function commit($log='') + { + dol_syslog('',0,-1); + if ($this->transaction_opened<=1) + { + $ret=$this->query("COMMIT"); + if ($ret) + { + $this->transaction_opened=0; + dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); + } + return $ret; + } + else + { + $this->transaction_opened--; + return 1; + } + } + + /** + * Annulation d'une transaction et retour aux anciennes valeurs + * + * @param string $log Add more log to default log line + * @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur + */ + function rollback($log='') + { + dol_syslog('',0,-1); + if ($this->transaction_opened<=1) + { + $ret=$this->query("ROLLBACK"); + $this->transaction_opened=0; + dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); + return $ret; + } + else + { + $this->transaction_opened--; + return 1; + } + } + /** * Return version of database server into an array * diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index 582adbb343a..a0228a1b00c 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -239,55 +239,6 @@ class DoliDBMysql extends DoliDB return false; } - /** - * Validate a database transaction - * - * @param string $log Add more log to default log line - * @return int 1 if validation is OK or transaction level no started, 0 if ERROR - */ - function commit($log='') - { - dol_syslog('',0,-1); - if ($this->transaction_opened<=1) - { - $ret=$this->query("COMMIT"); - if ($ret) - { - $this->transaction_opened=0; - dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); - } - return $ret; - } - else - { - $this->transaction_opened--; - return 1; - } - } - - /** - * Annulation d'une transaction et retour aux anciennes valeurs - * - * @param string $log Add more log to default log line - * @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur - */ - function rollback($log='') - { - dol_syslog('',0,-1); - if ($this->transaction_opened<=1) - { - $ret=$this->query("ROLLBACK"); - $this->transaction_opened=0; - dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); - return $ret; - } - else - { - $this->transaction_opened--; - return 1; - } - } - /** * Execute a SQL request and return the resultset * diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 66fa531bf09..3c23a85e027 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -243,55 +243,6 @@ class DoliDBMysqli extends DoliDB return false; } - /** - * Validate a database transaction - * - * @param string $log Add more log to default log line - * @return int 1 if validation is OK or transaction level no started, 0 if ERROR - */ - function commit($log='') - { - dol_syslog('',0,-1); - if ($this->transaction_opened<=1) - { - $ret=$this->query("COMMIT"); - if ($ret) - { - $this->transaction_opened=0; - dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); - } - return $ret; - } - else - { - $this->transaction_opened--; - return 1; - } - } - - /** - * Annulation d'une transaction et retour aux anciennes valeurs - * - * @param string $log Add more log to default log line - * @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur - */ - function rollback($log='') - { - dol_syslog('',0,-1); - if ($this->transaction_opened<=1) - { - $ret=$this->query("ROLLBACK"); - $this->transaction_opened=0; - dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); - return $ret; - } - else - { - $this->transaction_opened--; - return 1; - } - } - /** * Execute a SQL request and return the resultset * diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 224e5ffa71d..9ed44faf548 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -448,56 +448,6 @@ class DoliDBPgsql extends DoliDB return false; } - /** - * Validate a database transaction - * - * @param string $log Add more log to default log line - * @return int 1 if validation is OK or transaction level no started, 0 if ERROR - */ - function commit($log='') - { - dol_syslog('',0,-1); - if ($this->transaction_opened<=1) - { - $ret=$this->query("COMMIT;"); - if ($ret) - { - $this->transaction_opened=0; - dol_syslog("COMMIT Transaction",LOG_DEBUG); - } - return $ret; - } - else - { - $this->transaction_opened--; - return 1; - } - } - - /** - * Annulation d'une transaction et retour aux anciennes valeurs - * - * @param string $log Add more log to default log line - * @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur - */ - function rollback($log='') - { - dol_syslog('',0,-1); - if ($this->transaction_opened<=1) - { - $ret=$this->query("ROLLBACK;"); - $this->transaction_opened=0; - dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); - return $ret; - } - else - { - $this->transaction_opened--; - return 1; - } - } - - /** * Convert request to PostgreSQL syntax, execute it and return the resultset * diff --git a/htdocs/core/db/sqlite.class.php b/htdocs/core/db/sqlite.class.php index fe3ac4718a9..d0285e57457 100644 --- a/htdocs/core/db/sqlite.class.php +++ b/htdocs/core/db/sqlite.class.php @@ -368,55 +368,6 @@ class DoliDBSqlite extends DoliDB return false; } - /** - * Validate a database transaction - * - * @param string $log Add more log to default log line - * @return int 1 if validation is OK or transaction level no started, 0 if ERROR - */ - function commit($log='') - { - dol_syslog('',0,-1); - if ($this->transaction_opened<=1) - { - $ret=$this->query("COMMIT"); - if ($ret) - { - $this->transaction_opened=0; - dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); - } - return $ret; - } - else - { - $this->transaction_opened--; - return 1; - } - } - - /** - * Annulation d'une transaction et retour aux anciennes valeurs - * - * @param string $log Add more log to default log line - * @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur - */ - function rollback($log='') - { - dol_syslog('',0,-1); - if ($this->transaction_opened<=1) - { - $ret=$this->query("ROLLBACK"); - $this->transaction_opened=0; - dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); - return $ret; - } - else - { - $this->transaction_opened--; - return 1; - } - } - /** * Execute a SQL request and return the resultset * From 98120862f790037faa3bcba0630d9578ad0321c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Wed, 23 Apr 2014 12:15:13 +0200 Subject: [PATCH 3/3] Qual: Moved duplicate method to base method --- htdocs/core/db/DoliDB.class.php | 16 ++++++++++++++++ htdocs/core/db/mssql.class.php | 18 ------------------ htdocs/core/db/mysql.class.php | 18 ------------------ htdocs/core/db/mysqli.class.php | 18 ------------------ htdocs/core/db/sqlite.class.php | 18 ------------------ 5 files changed, 16 insertions(+), 72 deletions(-) diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index e95d31acf6e..aa0792c5970 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -174,6 +174,22 @@ abstract class DoliDB implements Database } } + /** + * Define limits and offset of request + * + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) + * @param int $offset Numero of line from where starting fetch + * @return string String with SQL syntax to add a limit and offset + */ + function plimit($limit=0,$offset=0) + { + global $conf; + if (empty($limit)) return ""; + if ($limit < 0) $limit=$conf->liste_limit; + if ($offset > 0) return " LIMIT $offset,$limit "; + else return " LIMIT $limit "; + } + /** * Return version of database server into an array * diff --git a/htdocs/core/db/mssql.class.php b/htdocs/core/db/mssql.class.php index 239582a6595..855b7a71026 100644 --- a/htdocs/core/db/mssql.class.php +++ b/htdocs/core/db/mssql.class.php @@ -466,24 +466,6 @@ class DoliDBMssql extends DoliDB if (is_resource($resultset)) mssql_free_result($resultset); } - - /** - * Define limits and offset of request - * - * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) - * @param int $offset Numero of line from where starting fetch - * @return string String with SQL syntax to add a limit and offset - */ - function plimit($limit=0,$offset=0) - { - global $conf; - if (empty($limit)) return ""; - if ($limit < 0) $limit=$conf->liste_limit; - if ($offset > 0) return " LIMIT $offset,$limit "; - else return " LIMIT $limit "; - } - - /** * Escape a string to insert data * diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index a0228a1b00c..efe942caed5 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -365,24 +365,6 @@ class DoliDBMysql extends DoliDB if (is_resource($resultset)) mysql_free_result($resultset); } - - /** - * Define limits and offset of request - * - * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) - * @param int $offset Numero of line from where starting fetch - * @return string String with SQL syntax to add a limit and offset - */ - function plimit($limit=0,$offset=0) - { - global $conf; - if (empty($limit)) return ""; - if ($limit < 0) $limit=$conf->liste_limit; - if ($offset > 0) return " LIMIT $offset,$limit "; - else return " LIMIT $limit "; - } - - /** * Escape a string to insert data * diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 3c23a85e027..f2dd2e80359 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -376,24 +376,6 @@ class DoliDBMysqli extends DoliDB if (is_object($resultset)) mysqli_free_result($resultset); } - - /** - * Define limits and offset of request - * - * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) - * @param int $offset Numero of line from where starting fetch - * @return string String with SQL syntax to add a limit and offset - */ - function plimit($limit=0,$offset=0) - { - global $conf; - if (empty($limit)) return ""; - if ($limit < 0) $limit=$conf->liste_limit; - if ($offset > 0) return " LIMIT $offset,$limit "; - else return " LIMIT $limit "; - } - - /** * Escape a string to insert data * diff --git a/htdocs/core/db/sqlite.class.php b/htdocs/core/db/sqlite.class.php index d0285e57457..8c3e9fa9df3 100644 --- a/htdocs/core/db/sqlite.class.php +++ b/htdocs/core/db/sqlite.class.php @@ -510,24 +510,6 @@ class DoliDBSqlite extends DoliDB if (is_object($resultset)) $resultset->closeCursor(); } - - /** - * Define limits and offset of request - * - * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) - * @param int $offset Numero of line from where starting fetch - * @return string String with SQL syntax to add a limit and offset - */ - function plimit($limit=0,$offset=0) - { - global $conf; - if (empty($limit)) return ""; - if ($limit < 0) $limit=$conf->liste_limit; - if ($offset > 0) return " LIMIT $offset,$limit "; - else return " LIMIT $limit "; - } - - /** * Escape a string to insert data *