summaryrefslogtreecommitdiffstats
path: root/lib/db.php
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2012-07-30 22:42:43 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2012-08-01 14:59:08 +0200
commite13f381189788c74fe08a3f3336d961977ff9dc4 (patch)
tree19b81673f6804e718534e4c6a286c94e0a2743b8 /lib/db.php
parent795e78809f55be762fb07d9a179bbdffa7aefbd9 (diff)
downloadnextcloud-server-e13f381189788c74fe08a3f3336d961977ff9dc4.tar.gz
nextcloud-server-e13f381189788c74fe08a3f3336d961977ff9dc4.zip
add limit support to OC_DB & OCP/DB
Diffstat (limited to 'lib/db.php')
-rw-r--r--lib/db.php46
1 files changed, 43 insertions, 3 deletions
diff --git a/lib/db.php b/lib/db.php
index a2dbc5dfac9..0d272f63037 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -132,7 +132,7 @@ class OC_DB {
$dsn='pgsql:dbname='.$name.';host='.$host;
}
break;
- case 'oci':
+ case 'oci': // Oracle with PDO is unsupported
if ($port) {
$dsn = 'oci:dbname=//' . $host . ':' . $port . '/' . $name;
} else {
@@ -214,6 +214,19 @@ class OC_DB {
'database' => $name
);
break;
+ case 'oci':
+ $dsn = array(
+ 'phptype' => 'oci8',
+ 'username' => $user,
+ 'password' => $pass,
+ );
+ if ($host != '') {
+ $dsn['hostspec'] = $host;
+ $dsn['database'] = $name;
+ } else { // use dbname for hostspec
+ $dsn['hostspec'] = $name;
+ }
+ break;
}
// Try to establish connection
@@ -242,8 +255,33 @@ class OC_DB {
*
* SQL query via MDB2 prepare(), needs to be execute()'d!
*/
- static public function prepare( $query ){
- // Optimize the query
+ static public function prepare( $query , $limit=null, $offset=null ){
+
+ if (!is_null($limit)) {
+ if (self::$backend == self::BACKEND_MDB2) {
+ //MDB2 uses or emulates limits & offset internally
+ self::$MDB2->setLimit($limit, $offset);
+ } else {
+ //PDO does not handle limit and offset.
+ //FIXME: check limit notation for other dbs
+ //the following sql thus might needs to take into account db ways of representing it
+ //(oracle has no LIMIT / OFFSET)
+ $limitsql = ' LIMIT ' . $limit;
+ if (!is_null($offset)) {
+ $limitsql .= ' OFFSET ' . $offset;
+ }
+ //insert limitsql
+ if (substr($query, -1) == ';') { //if query ends with ;
+ $query = substr($query, 0, -1) . $limitsql . ';';
+ } else {
+ $query.=$limitsql;
+ }
+ }
+ }
+
+
+
+ // Optimize the query
$query = self::processQuery( $query );
self::connect();
@@ -256,6 +294,7 @@ class OC_DB {
$entry = 'DB Error: "'.$result->getMessage().'"<br />';
$entry .= 'Offending command was: '.$query.'<br />';
OC_Log::write('core',$entry,OC_Log::FATAL);
+ error_log('DB error: '.$entry);
die( $entry );
}
}else{
@@ -265,6 +304,7 @@ class OC_DB {
$entry = 'DB Error: "'.$e->getMessage().'"<br />';
$entry .= 'Offending command was: '.$query.'<br />';
OC_Log::write('core',$entry,OC_Log::FATAL);
+ error_log('DB error: '.$entry);
die( $entry );
}
$result=new PDOStatementWrapper($result);