function set_relationship($table, $relate_values, $check_duplicates = true, $do_update = false, $data_values = null) { $where = ''; // make sure there is a date modified $date_modified = $this->db->convert("'" . $GLOBALS['timedate']->nowDb() . "'", 'datetime'); $row = null; if ($check_duplicates) { $query = "SELECT * FROM {$table} "; $where = "WHERE deleted = '0' "; foreach ($relate_values as $name => $value) { $where .= " AND {$name} = '{$value}' "; } $query .= $where; $result = $this->db->query($query, false, "Looking For Duplicate Relationship:" . $query); $row = $this->db->fetchByAssoc($result); } if (!$check_duplicates || empty($row)) { unset($relate_values['id']); if (isset($data_values)) { $relate_values = array_merge($relate_values, $data_values); } $query = "INSERT INTO {$table} (id, " . implode(',', array_keys($relate_values)) . ", date_modified) VALUES ('" . create_guid() . "', " . "'" . implode("', '", $relate_values) . "', " . $date_modified . ")"; $this->db->query($query, false, "Creating Relationship:" . $query); } else { if ($do_update) { $conds = array(); foreach ($data_values as $key => $value) { array_push($conds, $key . "='" . $this->db->quote($value) . "'"); } $query = "UPDATE {$table} SET " . implode(',', $conds) . ",date_modified=" . $date_modified . " " . $where; $this->db->query($query, false, "Updating Relationship:" . $query); } } }
/** * Fetch the next job in the queue and mark it running * @param string $clientID ID of the client requesting the job * @return SugarJob */ public function nextJob($clientID) { $now = $this->db->now(); $queued = SchedulersJob::JOB_STATUS_QUEUED; $try = $this->jobTries; while ($try--) { // TODO: tranaction start? $id = $this->db->getOne("SELECT id FROM {$this->job_queue_table} WHERE execute_time <= {$now} AND status = '{$queued}' ORDER BY date_entered ASC"); if (empty($id)) { return null; } $job = new SchedulersJob(); $job->retrieve($id); if (empty($job->id)) { return null; } $job->status = SchedulersJob::JOB_STATUS_RUNNING; $job->client = $clientID; $client = $this->db->quote($clientID); // using direct query here to be able to fetch affected count // if count is 0 this means somebody changed the job status and we have to try again $res = $this->db->query("UPDATE {$this->job_queue_table} SET status='{$job->status}', date_modified={$now}, client='{$client}' WHERE id='{$job->id}' AND status='{$queued}'"); if ($this->db->getAffectedRowCount($res) == 0) { // somebody stole our job, try again continue; } else { // to update dates & possible hooks $job->save(); break; } // TODO: commit/check? } return $job; }
/** * @param $where_clauses */ public function setWhereClauses(&$where_clauses) { if (isset($this->avail_fields)) { foreach ($this->avail_fields as $name => $value) { if (!empty($_REQUEST[$name])) { $where_clauses[] = $this->bean->table_name . "_cstm.{$name} LIKE '" . $this->db->quote($_REQUEST[$name]) . "%'"; } } } }
/** * @param array $value_array */ function _insert_row(&$value_array) { //add key column $value_array['id'] = create_guid(); $columns_list = ''; $values_list = ''; $delimiter = ''; foreach ($value_array as $key => $value) { $columns_list .= $delimiter . $key; $values_list .= $delimiter . "'" . $this->_db->quote($value) . "'"; $delimiter = ","; } $insert_string = 'INSERT into ' . $this->_relationship->join_table . ' (' . $columns_list . ') VALUES (' . $values_list . ')'; Log::debug("Relationship Insert String :" . $insert_string); $this->_db->query($insert_string, true); }
/** * @see DBManager::quote() */ public function quote($string, $isLike = true) { return mysql_real_escape_string(parent::quote($string), $this->getDatabase()); }
/** * @see DBManager::quote() */ public function quote($string, $isLike = true) { return mysqli_escape_string($this->getDatabase(), DBManager::quote($string)); }
/** * @param $metadata * @param $module * @return bool|resource */ public function updateDashboardsMetadata($metadata, $module) { return $this->dbManager->query(sprintf("\n UPDATE dashboards SET\n metadata = '%s'\n WHERE\n deleted = 0\n AND name = 'LBL_DEFAULT_DASHBOARD_TITLE'\n AND dashboard_module = '{$module}'\n AND view_name = 'record'\n AND dashboard_type = 'dashboard'\n ", $this->dbManager->quote(json_encode($metadata)))); }
/** * @see DBManager::quote() */ public function quote($string, $isLike = true) { return $string = str_replace("'", "''", parent::quote($string)); }