diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php index 374a9f359..95ad0755b 100644 --- a/classes/db/DB.class.php +++ b/classes/db/DB.class.php @@ -1213,6 +1213,23 @@ class DB return $dbParser; } + /** + * Get the number of rows affected by the last query + * @return int + */ + public function getAffectedRows() + { + return -1; + } + + /** + * Get the ID generated in the last query + * @return int + */ + public function getInsertID() + { + return 0; + } } /* End of file DB.class.php */ /* Location: ./classes/db/DB.class.php */ diff --git a/classes/db/DBCubrid.class.php b/classes/db/DBCubrid.class.php index b9b5904af..0cc8217af 100644 --- a/classes/db/DBCubrid.class.php +++ b/classes/db/DBCubrid.class.php @@ -1117,6 +1117,26 @@ class DBCubrid extends DB } } + /** + * Get the number of rows affected by the last query + * @return int + */ + function getAffectedRows() + { + $connection = $this->_getConnection('master'); + return cubrid_affected_rows($connection); + } + + /** + * Get the ID generated in the last query + * @return int + */ + function getInsertID() + { + $connection = $this->_getConnection('master'); + return cubrid_insert_id($connection); + } + /** * If have a error, return error object * @param BaseObject $queryObject diff --git a/classes/db/DBMssql.class.php b/classes/db/DBMssql.class.php index 857e8e1b3..2e26d5a66 100644 --- a/classes/db/DBMssql.class.php +++ b/classes/db/DBMssql.class.php @@ -37,6 +37,11 @@ class DBMssql extends DB 'date' => 'nvarchar(14)', 'float' => 'float', ); + + /** + * Last statement executed + */ + var $last_stmt; /** * Constructor @@ -242,6 +247,7 @@ class DBMssql extends DB $this->setError(print_r(sqlsrv_errors(), true)); } + $this->last_stmt = $stmt; $this->param = array(); return $stmt; @@ -988,6 +994,27 @@ class DBMssql extends DB } } + /** + * Get the number of rows affected by the last query + * @return int + */ + function getAffectedRows() + { + $stmt = $this->last_stmt; + return $stmt ? sqlsrv_rows_affected($stmt) : -1; + } + + /** + * Get the ID generated in the last query + * @return int + */ + function getInsertID() + { + $result = $this->_query('SELECT @@IDENTITY as id'); + $output = $this->_fetch($result); + return $output->id ?: 0; + } + /** * Return the DBParser * @param boolean $force diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php index bbb7624d3..82a68c7ee 100644 --- a/classes/db/DBMysql.class.php +++ b/classes/db/DBMysql.class.php @@ -39,6 +39,11 @@ class DBMysql extends DB 'float' => 'float', ); + /** + * Last statement executed + */ + var $last_stmt; + /** * Constructor * @return void @@ -177,6 +182,7 @@ class DBMysql extends DB $this->setError(mysql_errno($connection), mysql_error($connection)); } // Return result + $this->last_stmt = $result; return $result; } @@ -228,7 +234,7 @@ class DBMysql extends DB { $query = sprintf("insert into `%ssequence` (seq) values ('0')", $this->prefix); $this->_query($query); - $sequence = $this->db_insert_id(); + $sequence = $this->getInsertID(); if($sequence % 10000 == 0) { $query = sprintf("delete from `%ssequence` where seq < %d", $this->prefix, $sequence); @@ -800,16 +806,33 @@ class DBMysql extends DB } } + /** + * Get the number of rows affected by the last query + * @return int + */ + function getAffectedRows() + { + $connection = $this->_getConnection('master'); + return mysql_affected_rows($connection); + } + /** * Get the ID generated in the last query - * Return next sequence from sequence table - * This method use only mysql + * @return int + */ + function getInsertID() + { + $connection = $this->_getConnection('master'); + return mysql_insert_id($connection); + } + + /** + * @deprecated * @return int */ function db_insert_id() { - $connection = $this->_getConnection('master'); - return mysql_insert_id($connection); + return $this->getInsertID(); } /** diff --git a/classes/db/DBMysqli.class.php b/classes/db/DBMysqli.class.php index b14ceac08..c0c79f2aa 100644 --- a/classes/db/DBMysqli.class.php +++ b/classes/db/DBMysqli.class.php @@ -123,6 +123,7 @@ class DBMysqli extends DBMysql } // Return stmt for other processing - like retrieving resultset (_fetch) + $this->last_stmt = $stmt; return $stmt; } } @@ -135,6 +136,7 @@ class DBMysqli extends DBMysql $this->setError(mysqli_errno($connection), $error); } // Return result + $this->last_stmt = $result; return $result; } @@ -373,12 +375,20 @@ class DBMysqli extends DBMysql } /** - * Get the ID generated in the last query - * Return next sequence from sequence table - * This method use only mysql + * Get the number of rows affected by the last query * @return int */ - function db_insert_id() + function getAffectedRows() + { + $stmt = $this->last_stmt; + return $stmt ? $stmt->affected_rows : -1; + } + + /** + * Get the ID generated in the last query + * @return int + */ + function getInsertID() { $connection = $this->_getConnection('master'); return mysqli_insert_id($connection);