[ticket/11469] Have all methods of phpbb_db_sql_insert_buffer provide feedback.

PHPBB3-11469
This commit is contained in:
Andreas Fischer 2013-03-27 19:19:26 +01:00
parent 8c5fcac232
commit dc766f29b4

View file

@ -86,7 +86,8 @@ class phpbb_db_sql_insert_buffer
* *
* @param array $row * @param array $row
* *
* @return null * @return bool True when some data was flushed to the database.
* False otherwise.
*/ */
public function insert(array $row) public function insert(array $row)
{ {
@ -96,15 +97,18 @@ class phpbb_db_sql_insert_buffer
// Pass data on to sql_multi_insert right away which will // Pass data on to sql_multi_insert right away which will
// immediately send an INSERT INTO query to the database. // immediately send an INSERT INTO query to the database.
$this->db->sql_multi_insert($this->table_name, array($row)); $this->db->sql_multi_insert($this->table_name, array($row));
return;
return true;
} }
$this->buffer[] = $row; $this->buffer[] = $row;
if (sizeof($this->buffer) >= $this->max_buffered_rows) if (sizeof($this->buffer) >= $this->max_buffered_rows)
{ {
$this->flush(); return $this->flush();
} }
return false;
} }
/** /**
@ -116,20 +120,26 @@ class phpbb_db_sql_insert_buffer
* *
* @param array $rows * @param array $rows
* *
* @return null * @return bool True when some data was flushed to the database.
* False otherwise.
*/ */
public function insert_all(array $rows) public function insert_all(array $rows)
{ {
$result = false;
foreach ($rows as $row) foreach ($rows as $row)
{ {
$this->insert($row); $result |= $this->insert($row);
} }
return $result;
} }
/** /**
* Flushes the buffer content to the DB and clears the buffer. * Flushes the buffer content to the DB and clears the buffer.
* *
* @return null * @return bool True when some data was flushed to the database.
* False otherwise.
*/ */
public function flush() public function flush()
{ {
@ -137,6 +147,10 @@ class phpbb_db_sql_insert_buffer
{ {
$this->db->sql_multi_insert($this->table_name, $this->buffer); $this->db->sql_multi_insert($this->table_name, $this->buffer);
$this->buffer = array(); $this->buffer = array();
return true;
} }
return false;
} }
} }