summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/appframework/db/mapper.php30
-rw-r--r--lib/public/idb.php2
-rw-r--r--lib/public/idbconnection.php2
-rw-r--r--lib/public/iservercontainer.php3
4 files changed, 22 insertions, 15 deletions
diff --git a/lib/public/appframework/db/mapper.php b/lib/public/appframework/db/mapper.php
index 0edc38ade54..4424ef3622b 100644
--- a/lib/public/appframework/db/mapper.php
+++ b/lib/public/appframework/db/mapper.php
@@ -22,7 +22,7 @@
*/
namespace OCP\AppFramework\Db;
-use \OCP\IDb;
+use \OCP\IDBConnection;
/**
@@ -36,12 +36,12 @@ abstract class Mapper {
protected $db;
/**
- * @param IDb $db Instance of the Db abstraction layer
+ * @param IDBConnection $db Instance of the Db abstraction layer
* @param string $tableName the name of the table. set this to allow entity
* @param string $entityClass the name of the entity that the sql should be
* mapped to queries without using sql
*/
- public function __construct(IDb $db, $tableName, $entityClass=null){
+ public function __construct(IDBConnection $db, $tableName, $entityClass=null){
$this->db = $db;
$this->tableName = '*PREFIX*' . $tableName;
@@ -70,7 +70,8 @@ abstract class Mapper {
*/
public function delete(Entity $entity){
$sql = 'DELETE FROM `' . $this->tableName . '` WHERE `id` = ?';
- $this->execute($sql, [$entity->getId()]);
+ $stmt = $this->execute($sql, [$entity->getId()]);
+ $stmt->closeCursor();
return $entity;
}
@@ -103,7 +104,7 @@ abstract class Mapper {
$values .= ',';
}
- array_push($params, $entity->$getter());
+ $params[] = $entity->$getter();
$i++;
}
@@ -111,9 +112,11 @@ abstract class Mapper {
$sql = 'INSERT INTO `' . $this->tableName . '`(' .
$columns . ') VALUES(' . $values . ')';
- $this->execute($sql, $params);
+ $stmt = $this->execute($sql, $params);
+
+ $entity->setId((int) $this->db->lastInsertId($this->tableName));
- $entity->setId((int) $this->db->getInsertId($this->tableName));
+ $stmt->closeCursor();
return $entity;
}
@@ -162,15 +165,16 @@ abstract class Mapper {
$columns .= ',';
}
- array_push($params, $entity->$getter());
+ $params[] = $entity->$getter();
$i++;
}
$sql = 'UPDATE `' . $this->tableName . '` SET ' .
$columns . ' WHERE `id` = ?';
- array_push($params, $id);
+ $params[] = $id;
- $this->execute($sql, $params);
+ $stmt = $this->execute($sql, $params);
+ $stmt->closeCursor();
return $entity;
}
@@ -185,7 +189,7 @@ abstract class Mapper {
* @return \PDOStatement the database query result
*/
protected function execute($sql, array $params=[], $limit=null, $offset=null){
- $query = $this->db->prepareQuery($sql, $limit, $offset);
+ $query = $this->db->prepare($sql, $limit, $offset);
$index = 1; // bindParam is 1 indexed
foreach($params as $param) {
@@ -209,7 +213,9 @@ abstract class Mapper {
$index++;
}
- return $query->execute();
+ $query->execute();
+
+ return $query;
}
diff --git a/lib/public/idb.php b/lib/public/idb.php
index 5b4001b7578..690fd9155c5 100644
--- a/lib/public/idb.php
+++ b/lib/public/idb.php
@@ -24,7 +24,7 @@ namespace OCP;
/**
* Small Facade for being able to inject the database connection for tests
*/
-interface IDb {
+interface IDb extends IDBConnection {
/**
diff --git a/lib/public/idbconnection.php b/lib/public/idbconnection.php
index 81d34094a80..7249f6148c1 100644
--- a/lib/public/idbconnection.php
+++ b/lib/public/idbconnection.php
@@ -31,7 +31,7 @@ namespace OCP;
*/
interface IDBConnection {
/**
- * Used to abstract the owncloud database access away
+ * Used to abstract the ownCloud database access away
* @param string $sql the sql query with ? placeholder for params
* @param int $limit the maximum number of rows
* @param int $offset from which row we want to start
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index f2806529a4c..1dbabb3452a 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -144,6 +144,7 @@ interface IServerContainer {
/**
* Returns an instance of the db facade
+ * @deprecated use getDatabaseConnection, will be removed in ownCloud 10
* @return \OCP\IDb
*/
function getDb();
@@ -255,7 +256,7 @@ interface IServerContainer {
* @return \OCP\ICertificateManager
*/
function getCertificateManager($user = null);
-
+
/**
* Create a new event source
*