sql: limit 1 for UPDATE and DELETE is not supported by the SQL standard and postgresql

(see: https://www.postgresql.org/message-id/flat/1291109101.26137.35.camel%40pcd12478 )
This commit is contained in:
Florian Steinel 2016-10-27 02:41:32 +02:00
parent c3af36d33b
commit c1c96e01fa
11 changed files with 19 additions and 19 deletions

View File

@ -448,7 +448,7 @@ class Connedit extends \Zotlabs\Web\Controller {
} }
if($cmd === 'resetphoto') { if($cmd === 'resetphoto') {
q("update xchan set xchan_photo_date = '2001-01-01 00:00:00' where xchan_hash = '%s' limit 1", q("update xchan set xchan_photo_date = '2001-01-01 00:00:00' where xchan_hash = '%s'",
dbesc($orig_record[0]['xchan_hash']) dbesc($orig_record[0]['xchan_hash'])
); );
$cmd = 'refresh'; $cmd = 'refresh';

View File

@ -707,7 +707,7 @@ class Events extends \Zotlabs\Web\Controller {
$sync_event = $r[0]; $sync_event = $r[0];
if($r) { if($r) {
$r = q("delete from event where event_hash = '%s' and uid = %d limit 1", $r = q("delete from event where event_hash = '%s' and uid = %d",
dbesc($event_id), dbesc($event_id),
intval(local_channel()) intval(local_channel())
); );

View File

@ -226,7 +226,7 @@ class Like extends \Zotlabs\Web\Controller {
$z[0]['deleted'] = 1; $z[0]['deleted'] = 1;
build_sync_packet($ch[0]['channel_id'],array('likes' => $z)); build_sync_packet($ch[0]['channel_id'],array('likes' => $z));
q("delete from likes where id = %d limit 1", q("delete from likes where id = %d",
intval($z[0]['id']) intval($z[0]['id'])
); );
if($z[0]['i_mid']) { if($z[0]['i_mid']) {

View File

@ -259,7 +259,7 @@ class Photos extends \Zotlabs\Web\Controller {
@file_put_contents($r[0]['content'],$ph->imageString()); @file_put_contents($r[0]['content'],$ph->imageString());
$data = $r[0]['content']; $data = $r[0]['content'];
$fsize = @filesize($r[0]['content']); $fsize = @filesize($r[0]['content']);
q("update attach set filesize = %d where hash = '%s' and uid = %d limit 1", q("update attach set filesize = %d where hash = '%s' and uid = %d",
intval($fsize), intval($fsize),
dbesc($resource_id), dbesc($resource_id),
intval($page_owner_uid) intval($page_owner_uid)

View File

@ -70,7 +70,7 @@ class Regdir extends \Zotlabs\Web\Controller {
if(! $result['success']) if(! $result['success'])
$valid = 0; $valid = 0;
q("update site set site_valid = %d where site_url = '%s' limit 1", q("update site set site_valid = %d where site_url = '%s'",
intval($valid), intval($valid),
strtolower($url) strtolower($url)
); );

View File

@ -18,7 +18,7 @@ function group_add($uid,$name,$public = 0) {
intval($r) intval($r)
); );
if(($z) && $z[0]['deleted']) { if(($z) && $z[0]['deleted']) {
/*$r = q("UPDATE groups SET deleted = 0 WHERE uid = %d AND gname = '%s' LIMIT 1", /*$r = q("UPDATE groups SET deleted = 0 WHERE uid = %d AND gname = '%s'",
intval($uid), intval($uid),
dbesc($name) dbesc($name)
);*/ );*/

View File

@ -227,7 +227,7 @@ function sync_objs($channel,$objs) {
foreach($objs as $obj) { foreach($objs as $obj) {
if(array_key_exists('obj_deleted',$obj) && $obj['obj_deleted'] && $obj['obj_obj']) { if(array_key_exists('obj_deleted',$obj) && $obj['obj_deleted'] && $obj['obj_obj']) {
q("delete from obj where obj_obj = '%s' and obj_channel = %d limit 1", q("delete from obj where obj_obj = '%s' and obj_channel = %d",
dbesc($obj['obj_obj']), dbesc($obj['obj_obj']),
intval($channel['channel_id']) intval($channel['channel_id'])
); );
@ -351,7 +351,7 @@ function sync_apps($channel,$apps) {
} }
if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) {
q("delete from app where app_id = '%s' and app_channel = %d limit 1", q("delete from app where app_id = '%s' and app_channel = %d",
dbesc($app['app_id']), dbesc($app['app_id']),
intval($channel['channel_id']) intval($channel['channel_id'])
); );
@ -416,7 +416,7 @@ function sync_apps($channel,$apps) {
create_table_from_array('app',$app); create_table_from_array('app',$app);
if($term) { if($term) {
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", $x = q("select * from app where app_id = '%s' and app_channel = %d",
dbesc($hash), dbesc($hash),
intval($channel['channel_id']) intval($channel['channel_id'])
); );
@ -466,7 +466,7 @@ function sync_chatrooms($channel,$chatrooms) {
continue; continue;
if(array_key_exists('cr_deleted',$chatroom) && $chatroom['cr_deleted']) { if(array_key_exists('cr_deleted',$chatroom) && $chatroom['cr_deleted']) {
q("delete from chatroom where cr_name = '%s' and cr_uid = %d limit 1", q("delete from chatroom where cr_name = '%s' and cr_uid = %d",
dbesc($chatroom['cr_name']), dbesc($chatroom['cr_name']),
intval($channel['channel_id']) intval($channel['channel_id'])
); );
@ -635,7 +635,7 @@ function sync_events($channel,$events) {
continue; continue;
if($event['event_deleted']) { if($event['event_deleted']) {
$r = q("delete from event where event_hash = '%s' and uid = %d limit 1", $r = q("delete from event where event_hash = '%s' and uid = %d",
dbesc($event['event_hash']), dbesc($event['event_hash']),
intval($channel['channel_id']) intval($channel['channel_id'])
); );
@ -889,14 +889,14 @@ function import_mail($channel,$mails,$sync = false) {
if($channel && $mails) { if($channel && $mails) {
foreach($mails as $mail) { foreach($mails as $mail) {
if(array_key_exists('flags',$mail) && in_array('deleted',$mail['flags'])) { if(array_key_exists('flags',$mail) && in_array('deleted',$mail['flags'])) {
q("delete from mail where mid = '%s' and uid = %d limit 1", q("delete from mail where mid = '%s' and uid = %d",
dbesc($mail['message_id']), dbesc($mail['message_id']),
intval($channel['channel_id']) intval($channel['channel_id'])
); );
continue; continue;
} }
if(array_key_exists('flags',$mail) && in_array('recalled',$mail['flags'])) { if(array_key_exists('flags',$mail) && in_array('recalled',$mail['flags'])) {
q("update mail set mail_recalled = 1 where mid = '%s' and uid = %d limit 1", q("update mail set mail_recalled = 1 where mid = '%s' and uid = %d",
dbesc($mail['message_id']), dbesc($mail['message_id']),
intval($channel['channel_id']) intval($channel['channel_id'])
); );

View File

@ -284,7 +284,7 @@ function menu_delete_id($menu_id, $uid) {
intval($menu_id), intval($menu_id),
intval($uid) intval($uid)
); );
return q("delete from menu where menu_id = %d and menu_channel_id = %d limit 1", return q("delete from menu where menu_id = %d and menu_channel_id = %d",
intval($menu_id), intval($menu_id),
intval($uid) intval($uid)
); );

View File

@ -1434,7 +1434,7 @@ function discover_by_webbie($webbie) {
dbesc($address) dbesc($address)
); );
if($r) { if($r) {
$r = q("update xchan set xchan_name = '%s', xchan_network = '%s', xchan_name_date = '%s' where xchan_hash = '%s' limit 1", $r = q("update xchan set xchan_name = '%s', xchan_network = '%s', xchan_name_date = '%s' where xchan_hash = '%s'",
dbesc($fullname), dbesc($fullname),
dbesc($network), dbesc($network),
dbesc(datetime_convert()), dbesc(datetime_convert()),
@ -2328,4 +2328,4 @@ function probe_api_path($host) {
} }
return ''; return '';
} }

View File

@ -118,7 +118,7 @@ function queue_deliver($outq, $immediate = false) {
dbesc($base) dbesc($base)
); );
} }
q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
dbesc('accepted for delivery'), dbesc('accepted for delivery'),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($outq['outq_hash']) dbesc($outq['outq_hash'])

View File

@ -1095,7 +1095,7 @@ function update_r1097() {
$r = q("select hubloc_id, hubloc_addr from hubloc where hubloc_addr like '%%/%%'"); $r = q("select hubloc_id, hubloc_addr from hubloc where hubloc_addr like '%%/%%'");
if($r) { if($r) {
foreach($r as $rr) { foreach($r as $rr) {
q("update hubloc set hubloc_addr = '%s' where hubloc_id = %d limit 1", q("update hubloc set hubloc_addr = '%s' where hubloc_id = %d",
dbesc(substr($rr['hubloc_addr'],0,strpos($rr['hubloc_addr'],'/'))), dbesc(substr($rr['hubloc_addr'],0,strpos($rr['hubloc_addr'],'/'))),
intval($rr['hubloc_id']) intval($rr['hubloc_id'])
); );
@ -2462,4 +2462,4 @@ function update_r1183() {
if($r1 && $r2) if($r1 && $r2)
return UPDATE_SUCCESS; return UPDATE_SUCCESS;
return UPDATE_FAILED; return UPDATE_FAILED;
} }