*
*/
-define('MDB2_SCHEMA_DUMP_STRUCTURE', '1');
-
/**
* This class manages the access to the database. It basically is a wrapper for
* Doctrine with some adaptions.
*
* @return \OC\DB\MDB2SchemaManager
*/
- private static function getMDB2SchemaManager()
- {
+ private static function getMDB2SchemaManager() {
return new \OC\DB\MDB2SchemaManager(\OC::$server->getDatabaseConnection());
}
return \OC::$server->getDatabaseConnection()->lastInsertId($table);
}
- /**
- * Insert a row if a matching row doesn't exists.
- * @param string $table The table to insert into in the form '*PREFIX*tableName'
- * @param array $input An array of fieldname/value pairs
- * @return boolean number of updated rows
- */
- public static function insertIfNotExist($table, $input, $compare = null) {
- return \OC::$server->getDatabaseConnection()->insertIfNotExist($table, $input, $compare);
- }
-
/**
* Start a transaction
*/
*
* TODO: write more documentation
*/
- public static function getDbStructure( $file, $mode = 0) {
+ public static function getDbStructure($file) {
$schemaManager = self::getMDB2SchemaManager();
return $schemaManager->getDbStructure($file);
}
* insert the @input values when they do not exist yet
* @param string $table name
* @param array $input key->value pair, key has to be sanitized properly
- * @throws \OC\HintException
+ * @throws \Doctrine\DBAL\DBALException
* @return int count of inserted rows
*/
public function insertIfNotExist($table, $input, $compare = null) {
$query = substr($query, 0, strlen($query) - 5);
$query .= ' HAVING COUNT(*) = 0';
- try {
- return $this->conn->executeUpdate($query, $inserts);
- } catch(\Doctrine\DBAL\DBALException $e) {
- $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
- $entry .= 'Offending command was: ' . $query.'<br />';
- \OC_Log::write('core', $entry, \OC_Log::FATAL);
- $l = \OC::$server->getL10N('lib');
- throw new \OC\HintException(
- $l->t('Database Error'),
- $l->t('Please contact your system administrator.'),
- 0,
- $e
- );
- }
+ return $this->conn->executeUpdate($query, $inserts);
}
}
return $statement;
}
+ /**
+ * @param string $table
+ * @param array $input
+ * @param null $compare
+ * @return int
+ * @throws \Doctrine\DBAL\DBALException
+ */
public function insertIfNotExist($table, $input, $compare = null) {
if ($compare === null) {
$compare = array_keys($input);
$query = substr($query, 0, strlen($query) - 5);
$query .= ')';
- try {
- return $this->conn->executeUpdate($query, $inserts);
- } catch(\Doctrine\DBAL\DBALException $e) {
- $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
- $entry .= 'Offending command was: ' . $query.'<br />';
- \OC_Log::write('core', $entry, \OC_Log::FATAL);
- $l = \OC::$server->getL10N('lib');
- throw new \OC\HintException(
- $l->t('Database Error'),
- $l->t('Please contact your system administrator.'),
- 0,
- $e
- );
- }
+ return $this->conn->executeUpdate($query, $inserts);
}
}
}
// internal use
- public function realLastInsertId($seqName = null)
- {
+ public function realLastInsertId($seqName = null) {
return parent::lastInsertId($seqName);
}
/**
- * Insert a row if a matching row doesn't exists.
+ * Insert a row if a matching row does not exists.
* @param string $table. The table to insert into in the form '*PREFIX*tableName'
- * @param array $input. An array of fieldname/value pairs
- * @throws \OC\HintException
+ * @param array $input. An array of field name/value pairs
+ * @param array $compare
+ * @throws \Doctrine\DBAL\DBALException
* @return bool The return value from execute()
*/
public function insertIfNotExist($table, $input, $compare = null) {
*
* TODO: write more documentation
*/
- public function getDbStructure($file, $mode = MDB2_SCHEMA_DUMP_STRUCTURE) {
+ public function getDbStructure($file) {
return \OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $this->conn);
}
*
*/
public static function insertIfNotExist($table, $input, $compare = null) {
- return(\OC_DB::insertIfNotExist($table, $input, $compare));
+ return \OC::$server->getDatabaseConnection()->insertIfNotExist($table, $input, $compare);
}
/**
* Insert a row if a matching row doesn't exists.
* @param string $table The table name (will replace *PREFIX*) to perform the replace on.
* @param array $input
- * @throws \OC\HintException
+ * @throws \Doctrine\DBAL\DBALException
*
* The input array if in the form:
*
);
foreach($categoryEntries as $entry) {
- $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table3,
+ $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table3,
array(
'uid' => $entry['user'],
'type' => $entry['type'],
);
foreach($categoryEntries as $entry) {
- $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2,
+ $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table2,
array(
'addressbookid' => $entry['addressbookid'],
'fullname' => $entry['fullname'],
$this->assertEquals($carddata, $rowset[0]['carddata']);
// Try to insert a new row
- $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2,
+ $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table2,
array(
'fullname' => $fullName,
'uri' => $uri,
}
public function testInsertIfNotExistsViolating() {
- $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table5,
+ $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table5,
array(
'storage' => 1,
'path_hash' => md5('welcome.txt'),
));
$this->assertEquals(1, $result);
- $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table5,
+ $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table5,
array(
'storage' => 1,
'path_hash' => md5('welcome.txt'),