array_shift($argv);
$parameters = json_encode($argv);
- $found = dba::select('workerqueue', array('id'), array('parameter' => $parameters, 'done' => false), array('limit' => 1));
+ $found = dba::exists('workerqueue', array('parameter' => $parameters, 'done' => false));
- if (!dbm::is_result($found)) {
+ if (!$found) {
dba::insert('workerqueue', array('parameter' => $parameters, 'created' => $created, 'priority' => $priority));
}
/**
* @brief Check if data exists
*
- * @param string $sql SQL statement
- * @return boolean Are there rows for that query?
+ * @param string $table Table name
+ * @param array $condition array of fields for condition
+ *
+ * @return boolean Are there rows for that condition?
*/
- static public function exists($sql) {
- $params = self::getParam(func_get_args());
+ static public function exists($table, $condition) {
+ if (empty($table)) {
+ return false;
+ }
- $stmt = self::p($sql, $params);
+ $fields = array_keys($condition);
+
+ $stmt = self::select($table, array($fields[0]), $condition, array('limit' => 1, 'only_query' => true));
if (is_bool($stmt)) {
$retval = $stmt;
$param_string = substr($param_string, 0, -2);
}
- if (isset($params['limit'])) {
- if (is_int($params['limit'])) {
- $param_string .= " LIMIT ".$params['limit'];
- $single_row =($params['limit'] == 1);
- }
+ if (isset($params['limit']) && is_int($params['limit'])) {
+ $param_string .= " LIMIT ".$params['limit'];
+ $single_row = ($params['limit'] == 1);
+ }
+
+ if (isset($params['only_query']) && $params['only_query']) {
+ $single_row = !$params['only_query'];
}
$sql = "SELECT ".$select_fields." FROM `".$table."`".$condition_string.$param_string;
$profile_url = normalise_link(App::get_baseurl()."/profile/".$profile["nickname"]);
}
- $r = dba::select('contact', array('id'),
- array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url), array('limit' => 1));
- if (dbm::is_result($r))
- $connect = false;
+ $connect = !dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url));
}
if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
* @return boolean
*/
function plugin_enabled($plugin) {
- $r = dba::select('addon', array('id'), array('installed' => true, 'name' => $plugin), array('limit' => 1));
- return ((dbm::is_result($r)) && (count($r) > 0));
+ return dba::exists('addon', array('installed' => true, 'name' => $plugin));
}
$id = intval($argv[1]);
// Only delete if the contact doesn't exist (anymore)
- $r = dba::select('contact', array('id'), array('id' => $id), array('limit' => 1));
- if (dbm::is_result($r)) {
+ $r = dba::exists('contact', array('id' => $id));
+ if ($r) {
return;
}
function item_new_uri($hostname, $uid, $guid = "") {
do {
- $dups = false;
-
if ($guid == "") {
$hash = get_guid(32);
} else {
$uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash;
- $r = dba::select('item', array('id'), array('uri' => $uri), array('limit' => 1));
- if (dbm::is_result($r)) {
- $dups = true;
- }
+ $dups = dba::exists('item', array('uri' => $uri));
} while ($dups == true);
return $uri;
}
// We are displaying an "alternate" link if that post was public. See issue 2864
- $items = dba::select('item', array('id'), array('id' => $item_id, 'private' => false, 'wall' => true));
- if (dbm::is_result($items)) {
+ $is_public = dba::exists('item', array('id' => $item_id, 'private' => false, 'wall' => true));
+ if ($is_public) {
$alternate = App::get_baseurl().'/display/'.$nick.'/'.$item_id.'.atom';
} else {
$alternate = '';
$sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
if ($update) {
- $r = dba::exists("SELECT `id` FROM `item` WHERE `item`.`uid` = ?
+ $r = dba::p("SELECT `id` FROM `item` WHERE `item`.`uid` = ?
AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = ?)
$sql_extra AND `unseen`",
$a->profile['uid'],
$item_id
);
- if (!$r) {
+ if (dba::num_rows($r) == 0) {
return '';
}
}
if (!$group && !$cid && !$star) {
- $unseen = dba::select('item', array('id'), array('unseen' => true, 'uid' => local_user()), array('limit' => 1));
+ $unseen = dba::exists('item', array('unseen' => true, 'uid' => local_user()));
- if (dbm::is_result($unseen)) {
+ if ($unseen) {
$r = dba::update('item', array('unseen' => false), array('uid' => local_user(), 'unseen' => true));
}
} elseif ($update_unseen) {
if ($is_owner) {
- $unseen = dba::select('item', array('id'), array('wall' => true, 'unseen' => true, 'uid' => local_user()),
- array('limit' => 1));
- if (dbm::is_result($unseen)) {
+ $unseen = dba::exists('item', array('wall' => true, 'unseen' => true, 'uid' => local_user()));
+ if ($unseen) {
$r = dba::update('item', array('unseen' => false),
array('wall' => true, 'unseen' => true, 'uid' => local_user()));
}