use limit parameter instead of LIMIT SQL for vcard

This commit is contained in:
jfd 2012-08-25 02:27:43 +02:00
parent 1bfe26bb09
commit e8ffd5c042
1 changed files with 5 additions and 13 deletions

View File

@ -48,31 +48,23 @@ class OC_Contacts_VCard {
* ['carddata']
*/
public static function all($id, $start=null, $num=null){
//FIXME jfd: use limit & offset as OC_DB::prepare parameters for oracle support
$limitsql = '';
if(!is_null($num)) {
$limitsql = ' LIMIT '.$num;
}
if(!is_null($start) && !is_null($num)) {
$limitsql .= ' OFFSET '.$start.' ';
}
$result = null;
if(is_array($id) && count($id)) {
$id_sql = join(',', array_fill(0, count($id), '?'));
$prep = 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `addressbookid` IN ('.$id_sql.') ORDER BY `fullname`'.$limitsql;
$sql = 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `addressbookid` IN ('.$id_sql.') ORDER BY `fullname`';
try {
$stmt = OCP\DB::prepare( $prep );
$stmt = OCP\DB::prepare( $sql, $num, $start );
$result = $stmt->execute($id);
} catch(Exception $e) {
OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR);
OCP\Util::writeLog('contacts', __METHOD__.', ids: '.join(',', $id), OCP\Util::DEBUG);
OCP\Util::writeLog('contacts', __METHOD__.'SQL:'.$prep, OCP\Util::DEBUG);
OCP\Util::writeLog('contacts', __METHOD__.'SQL:'.$sql, OCP\Util::DEBUG);
return false;
}
} elseif(is_int($id) || is_string($id)) {
try {
$sql = 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `addressbookid` = ? ORDER BY `fullname`'.$limitsql;
$stmt = OCP\DB::prepare( $sql );
$sql = 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `addressbookid` = ? ORDER BY `fullname`';
$stmt = OCP\DB::prepare( $sql, $num, $start );
$result = $stmt->execute(array($id));
} catch(Exception $e) {
OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR);