public function getMethodAll() { $result = $this->db->query("SELECT * FROM " . $this->db_prefix . "_" . $this->db_table_methods . " ORDER BY id DESC"); $result_array = array(); while ($row = $this->db->get_array($result)) { $result_array[] = array('id' => $row['id'], 'name' => $row['name'], 'secret_key' => $row['secret_key'], 'check_period' => $row['check_period'], 'enforce' => $row['enforce']); } $this->db->free($result); return $result_array; }
/** * Frees the request * @return void */ public function free() { if ($this->ev) { $this->ev->free(); $this->ev = null; } if (isset($this->upstream)) { $this->upstream->freeRequest($this); $this->upstream = null; } }
/** * method that gets all the mysql database * settings an fills them into properties of * this object * */ private function init() { if (empty($this->db)) { return false; } $sql = (string) "SHOW VARIABLES"; $res = $this->db->query((string) $sql); if (!$res) { return false; } $data = $this->db->fetch_assoc_list($res); if (!empty($data)) { foreach ($data as $variable) { $this->{$variable}[(string) 'Variable_name'] = (string) $variable['Value']; } $this->db->free($res); } // clear all the unecessary variables and the endles recursion of the db unset($this->db, $data, $variable); return true; }
function getGroup($id = 0, $search = array()) { $this->GRP = array(); $Query = "\n\t\t\tSELECT " . $this->TM_TABLE_ITEM_GRP . ".id, " . $this->TM_TABLE_ITEM_GRP . ".short, " . $this->TM_TABLE_ITEM_GRP . ".name, " . $this->TM_TABLE_ITEM_GRP . ".descr, " . $this->TM_TABLE_ITEM_GRP . ".aktiv, " . $this->TM_TABLE_ITEM_GRP . ".standard,\n\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".author,\n\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".editor,\n\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".created,\n\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".updated,\n\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".siteid\n\t\t\tFROM " . $this->TM_TABLE_ITEM_GRP . "\n\t\t\tWHERE " . $this->TM_TABLE_ITEM_GRP . ".siteid='" . TM_SITEID . "'\n\t\t\t"; if (isset($search['id']) && !empty($search['id'])) { $id = checkset_int($search['id']); } if (check_dbid($id)) { $Query .= " AND " . $this->TM_TABLE_ITEM_GRP . ".id=" . checkset_int($id); } if (isset($search['item_id']) && check_dbid($search['item_id'])) { $Query = ""; $Query .= "\n\t\t\t\tSELECT DISTINCT " . $this->TM_TABLE_ITEM_GRP . ".id, " . $this->TM_TABLE_ITEM_GRP . ".short, " . $this->TM_TABLE_ITEM_GRP . ".name, " . $this->TM_TABLE_ITEM_GRP . ".descr, " . $this->TM_TABLE_ITEM_GRP . ".aktiv, " . $this->TM_TABLE_ITEM_GRP . ".standard,\n\t\t\t\t\t\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".author,\n\t\t\t\t\t\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".editor,\n\t\t\t\t\t\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".created,\n\t\t\t\t\t\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".updated,\n\t\t\t\t\t\t\t\t\t\t\t\t" . $this->TM_TABLE_ITEM_GRP . ".siteid\n\t\t\t\tFROM " . $this->TM_TABLE_ITEM_GRP . ", " . $this->TM_TABLE_ITEM_GRP_REF . "\n\t\t\t\tWHERE " . $this->TM_TABLE_ITEM_GRP . ".id=" . $this->TM_TABLE_ITEM_GRP_REF . ".grp_id\n\t\t\t\tAND " . $this->TM_TABLE_ITEM_GRP . ".siteid='" . TM_SITEID . "'\n\t\t\t\tAND " . $this->TM_TABLE_ITEM_GRP_REF . ".siteid='" . TM_SITEID . "'\n\t\t\t\tAND " . $this->TM_TABLE_ITEM_GRP_REF . ".item_id=" . checkset_int($search['item_id']); } if (isset($search['aktiv']) && ($search['aktiv'] === "1" || $search['aktiv'] === "0")) { //!!! we have to compare strings, weird php! argh. $Query .= " AND " . $this->TM_TABLE_ITEM_GRP . ".aktiv=" . checkset_int($search['aktiv']); } if (isset($search['short']) && !empty($search['short'])) { $Query .= " AND " . $this->TM_TABLE_ITEM_GRP . ".short like '" . dbesc($search['short']) . "'"; } $Query .= "\tORDER BY " . $this->TM_TABLE_ITEM_GRP . ".name"; $this->DB->Query($Query); $c = 0; while ($this->DB->next_record()) { $this->GRP[$c]['id'] = $this->DB->Record['id']; $this->GRP[$c]['siteid'] = $this->DB->Record['siteid']; $this->GRP[$c]['short'] = $this->DB->Record['short']; $this->GRP[$c]['name'] = $this->DB->Record['name']; $this->GRP[$c]['descr'] = $this->DB->Record['descr']; $this->GRP[$c]['aktiv'] = $this->DB->Record['aktiv']; $this->GRP[$c]['standard'] = $this->DB->Record['standard']; $this->GRP[$c]['author'] = $this->DB->Record['author']; $this->GRP[$c]['editor'] = $this->DB->Record['editor']; $this->GRP[$c]['created'] = $this->DB->Record['created']; $this->GRP[$c]['updated'] = $this->DB->Record['updated']; if (isset($search['count']) && $search['count'] == 1) { $this->GRP[$c]['item_count'] = $this->count(checkset_int($this->GRP[$c]['id'])); } $c++; } $this->DB->free(); return $this->GRP; }
/** * 释放结果内存 * * @param object $result 结果集对象 */ public function free_result($result) { return empty($result) ? '' : $result->free(); }
/** * Frees up the Result object if one exists * @return void * @access private */ function freeQuery() { if (isset($this->QueryId) && is_object($this->QueryId)) { $this->QueryId->free(); $this->QueryId = NULL; } }
/** * Retrieve all batch number details link to a shipment line * * @param object $db Database object * @param int $id_line_expdet id of shipment line * * @return variant -1 if KO, array of ExpeditionLigneBatch if OK */ static function FetchAll($db, $id_line_expdet) { $sql = "SELECT rowid,"; $sql .= "fk_expeditiondet"; $sql .= ", sellby"; $sql .= ", eatby"; $sql .= ", batch"; $sql .= ", qty"; $sql .= ", fk_origin_stock"; $sql .= " FROM " . MAIN_DB_PREFIX . self::$_table_element; $sql .= " WHERE fk_expeditiondet=" . (int) $id_line_expdet; dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $tmp = new self($db); $obj = $db->fetch_object($resql); $tmp->sellby = $db->jdate($obj->sellby); $tmp->eatby = $db->jdate($obj->eatby); $tmp->batch = $obj->batch; $tmp->id = $obj->rowid; $tmp->fk_origin_stock = $obj->fk_origin_stock; $tmp->fk_expeditiondet = $obj->fk_expeditiondet; $tmp->dluo_qty = $obj->qty; $ret[] = $tmp; $i++; } $db->free($resql); return $ret; } else { return -1; } }
function fetch_duplicates($search) { $this->DUPLICATES = array(); $this->DUPLICATES['dups'] = array(); $ac = 0; //check if keep method is set, this tells the method what address should be kept, first, last or random, others get deleted!!! if (isset($search['method'])) { //create the query, this will return only addresses with at least 1 duplicate (having qty>0) //we have to use innerjoin because we have an additional unique index 'id' //query willnot return qty, so he have to count them ourself //this does the trick: #SELECT t1.id, t1.colb FROM t1 INNER JOIN (SELECT count(t1.colb) AS qty, t1.colb FROM t1 GROUP t1.colb HAVING qty>1) AS dups ON t1.colb=dups.colb ORDER BY t1.colb, t1.id $Query = "SELECT \n\t\t\t\t\t\t" . TM_TABLE_ADR . ".id, \n\t\t\t\t\t\t" . TM_TABLE_ADR . ".email \n\t\t\t\t\t\tFROM " . TM_TABLE_ADR . "\n\t\t\t\t\t\tINNER JOIN ( \n\t\t\t\t\t\t\tSELECT count(" . TM_TABLE_ADR . ".email) AS qty,\n\t\t\t\t\t\t\t\t" . TM_TABLE_ADR . ".email \n\t\t\t\t\t\t\t\tFROM " . TM_TABLE_ADR . " \n\t\t\t\t\t\t\t\tGROUP BY " . TM_TABLE_ADR . ".email\n\t\t\t\t\t\t\t\tHAVING qty >1\n\t\t\t\t\t\t\t\t"; if (isset($search['limit']) && $search['limit'] > 0) { $Query .= " LIMIT " . checkset_int($search['limit']) . "\n\t\t\t\t\t\t"; } $Query .= ") AS dups\n\t\t\t\t\t\t\tON \n\t\t\t\t\t\t\t" . TM_TABLE_ADR . ".email = dups.email \n\t\t\t\t\t\tORDER BY " . TM_TABLE_ADR . ".email ASC," . TM_TABLE_ADR . ".id ASC\n\t\t\t\t\t"; //SORT BY IST RELEVANT, DA WIR KEEP LATEST ODER KEEP FIRST ENTRY NUTZEN. //send query to db and fetch duplicates $this->DB->Query($Query); $dupcount = 0; while ($this->DB->next_record()) { //index for dupicates array is the email address! hmmmm $email = $this->DB->Record['email']; //check if index exists, otherwise create it and save data, count duplicates if (isset($this->DUPLICATES['dups'][$email])) { $qty = count($this->DUPLICATES['dups'][$email]['id']); $this->DUPLICATES['dups'][$email]['id'][$qty] = $this->DB->Record['id']; //count $this->DUPLICATES['dups'][$email]['qty']++; #++ oder $qty+1; } else { $this->DUPLICATES['dups'][$email]['email'] = $this->DB->Record['email']; $this->DUPLICATES['dups'][$email]['qty'] = 1; $this->DUPLICATES['dups'][$email]['id'][0] = $this->DB->Record['id']; } $dupcount++; #= $dupcount + $this->DUPLICATES[$email]['qty']; } //while $this->DB->free(); //array is created like so: //['dups']: 'email' - unique email adr, 'qty' count/quantity, 'id' =Array with ids //count: unique dups //cound_dup: all dups //now walk through the array and check which entry should be kept using array index foreach ($this->DUPLICATES['dups'] as $DUP) { if ($search['method'] == 'random') { $keep = rand(0, $DUP['qty'] - 1); } if ($search['method'] == 'first') { $keep = 0; } if ($search['method'] == 'last') { $keep = $DUP['qty'] - 1; } $this->DUPLICATES['dups'][$DUP['email']]['keep'] = $keep; $this->DUPLICATES['dups'][$DUP['email']]['del'] = array(); //save ids to delete in an array 'del' for ($dc = 0; $dc < $DUP['qty']; $dc++) { if ($dc != $keep) { $del = count($this->DUPLICATES['dups'][$DUP['email']]['del']); $this->DUPLICATES['dups'][$DUP['email']]['del'][$del] = $DUP['id'][$dc]; } //if } //for ###improvements: #check syntax etc and check what data should be preserved...! automagic, if keeping email is invalid, use another one etc pp } //foreach } //isst method //count $this->DUPLICATES['count'] = count($this->DUPLICATES['dups']); //must be first defined, we add more indexes later!!! $this->DUPLICATES['count_dup'] = $dupcount; //return array to display return $this->DUPLICATES; }
/** * if leaf, deletes neighbor on the right, and re-link * with the following * * @param object $next target for deletion * @param free $free seek position of last free node in free list * * @returns int new free position */ function delnext(&$next, $free) { d("delnext called:"); #print_r($this); $size = $this->size; if ($this->indices[$size] != $next->position) { trigger_error("invalid next pointer " . "{$this->indices[$size]}!={$next->position})", E_USER_ERROR); } $this->indices[$size] = $next->indices[$size]; return $next->free($free); }