/**
 * Build a temporary table with the list of new and changed locations we will process, so that we have
 * consistency if changes are happening concurrently. 
 * @param type $db 
 */
function spatial_index_builder_get_location_list($last_run_date, $db)
{
    $filter = spatial_index_builder_get_type_filter();
    list($join, $where) = $filter;
    $query = "select l.id, now() as timepoint into temporary loclist \nfrom locations l\n{$join}\nwhere l.deleted=false \nand l.updated_on>'{$last_run_date}'\n{$where}";
    $db->query($query);
    $r = $db->query('select count(*) as count from loclist')->result_array(false);
    $message = "Building spatial index for " . $r[0]['count'] . " locations(s)";
    echo "{$message}<br/>";
    Kohana::log('debug', $message);
    return $r[0]['count'];
}
Exemple #2
0
 protected function _initStatement()
 {
     // \MUtil_Echo::track($this->_select->__toString());
     $this->_i = 0;
     $this->_statement = $this->_select->query();
     $this->_row = $this->_statement->fetch();
 }
Exemple #3
0
 /**
  *
  * @param type $conn
  * @param type $query
  * @return type
  */
 public static function query($table, $conn, $query)
 {
     $sql = "INSERT INTO {$table} VALUES ({$query})";
     if ($conn->query($sql) === FALSE) {
         return "Error: " . $sql . "<br>" . $conn->error;
     }
 }
 /**
  * 
  * @param type $db
  * @return type
  */
 public static function showTables($db)
 {
     $sql = $db->query('SHOW FULL TABLES ');
     while ($data = $sql->fetch(PDO::FETCH_ASSOC)) {
         $tables[] = $data;
     }
     return $tables;
 }
 /**
  * 
  * Gets all configuration information 
  * @param type $db -> DB connection
  */
 public static function get_config($db)
 {
     $qry = 'SELECT * FROM codo_config';
     $res = $db->query($qry);
     $conf = $res->fetchAll();
     $info = array();
     foreach ($conf as $c) {
         $info[$c['option_name']] = self::valid_JSON($c['option_value']);
     }
     self::$options = $info;
 }
Exemple #6
0
 /**
  * @brief 事务队列bootstrap
  * @return type 若返回值为false,说明事务开启失败
  */
 public function execute($callback = null)
 {
     if (null !== $callback) {
         $this->setCallback($callback);
     }
     if (!empty(self::$_TransGc)) {
         //事务对象回收 更快的内存回收和资源释放
         foreach (self::$_TransGc as $key => $val) {
             unset(self::$_TransGc[$key]);
         }
     }
     if (count($this->_arrQueueKey) <= 1) {
         throw new Exception("Transaction require more then two write style sql");
     }
     $sql = 'set autocommit=0';
     return $this->_dbObj->query($sql, array($this, 'transCallback'), false);
 }
Exemple #7
0
/**
 * Esta función devuelve los campos de una tabla separados por '|'
 * Se supone que ya estas conectado a la BD
 * @param type $db    |  conexión a una BD
 * @param type $tabla |  tabla a la que se desea consultar
 * @return type       |  cadena con la lista de campos
 */
function averigua_campos_tabla($db, $tabla)
{
    try {
        $consulta = "describe " . $tabla . ";";
        $result = $db->query($consulta);
        $cad = "";
        foreach ($result as $i) {
            //                    print $i['Field'];
            $cad = $cad . $i['Field'] . '|';
        }
        return $cad;
        $db = null;
    } catch (Exception $e) {
        echo 'Excepción capturada: ', $e->getMessage(), "\n";
        $db = null;
        return $e->getMessage();
    }
}
Exemple #8
0
 /**
  * Ejecuta una sentencia SQL de tipo select, pero con paginación,
  * y devuelve un array con los resultados,
  * o false en caso de fallo.
  * Limit es el número de elementos que quieres que devuelve.
  * Offset es el número de resultado desde el que quieres que empiece.
  * @param type $sql
  * @param type $limit
  * @param type $offset
  * @return type
  */
 public function select_limit($sql, $limit, $offset)
 {
     $resultado = FALSE;
     if (self::$link) {
         $sql .= ' LIMIT ' . $limit . ' OFFSET ' . $offset . ';';
         self::$history[] = $sql;
         $filas = self::$link->query($sql);
         if ($filas) {
             $resultado = array();
             while ($row = $filas->fetch_array(MYSQLI_ASSOC)) {
                 $resultado[] = $row;
             }
             $filas->free();
         } else {
             self::$errors[] = self::$link->error;
         }
         self::$t_selects++;
     }
     return $resultado;
 }
/** Add relation between zone record and template
 *
 * @param type $db DB link
 * @param type $domain_id Domain id
 * @param type $record_id Record id
 * @param type $zone_templ_id Zone template id
 */
function add_record_relation_to_templ($db, $domain_id, $record_id, $zone_templ_id)
{
    $query = "INSERT INTO records_zone_templ (domain_id, record_id, zone_templ_id) VALUES (" . $db->quote($domain_id, 'integer') . "," . $db->quote($record_id, 'integer') . "," . $db->quote($zone_templ_id, 'integer') . ")";
    $db->query($query);
}
Exemple #10
0
/**
 * 更新统计记录
 * @param type $cus_id
 * @param type $platform
 * @param type $counter
 * @param type $db
 * @return type
 */
function updateCount($cus_id, $platform, $counter, $db)
{
    $today = date("Y-m-d");
    $lastday = date('Y-m-d', strtotime("-1 day"));
    if ($platform == "pc") {
        if ($counter['record_date'] == $today) {
            //最后访问当天访问
            $res = $db->query("update up_statis set count_all=count_all+1, count_today=count_today+1 where cus_id={$cus_id}");
        } elseif ($counter['record_date'] == $lastday) {
            //最后访问是昨天
            $res = $db->query("update up_statis set count_all=count_all+1, count_lastday={$counter['count_today']}, count_today=1, record_date='{$today}' where cus_id={$cus_id}");
        } else {
            //最后访问是很久以前
            $res = $db->query("update up_statis set count_all=count_all+1, count_lastday=0, count_today=1, record_date='{$today}' where cus_id={$cus_id}");
        }
    } elseif ($platform == "mobile") {
        if ($counter['record_date'] == $today) {
            //最后访问当天访问
            $res = $db->query("update up_statis set count_all=count_all+1, count_today=count_today+1, mobile_count=mobile_count+1 where cus_id={$cus_id}");
        } elseif ($counter['record_date'] == $lastday) {
            //最后访问是昨天
            $res = $db->query("update up_statis set count_all=count_all+1, count_lastday={$counter['count_today']}, count_today=1, mobile_count=mobile_count+1, record_date='{$today}' where cus_id={$cus_id}");
        } else {
            //最后访问是很久以前
            $res = $db->query("update up_statis set count_all=count_all+1, count_lastday=0, count_today=1, mobile_count=mobile_count+1, record_date='{$today}' where cus_id={$cus_id}");
        }
    }
    return $res;
}
Exemple #11
0
/**
 * Permet de réatribuer un mot de passe composé de 5 caractères (lettres minuscules et chiffres) généré aléatoirement
 * pour chaque visiteur
 * @param type $pdo
 */
function updateMdpVisiteur($pdo)
{
    $req = "select * from Visiteur";
    $res = $pdo->query($req);
    $lesLignes = $res->fetchAll();
    $lettres = "azertyuiopqsdfghjkmwxcvbn123456789";
    foreach ($lesLignes as $unVisiteur) {
        $mdp = "";
        $id = $unVisiteur['id'];
        for ($i = 1; $i <= 5; $i++) {
            $uneLettrehasard = substr($lettres, rand(33, 1), 1);
            $mdp = $mdp . $uneLettrehasard;
        }
        $req = "update Visiteur set mdp ='{$mdp}' where Visiteur.id ='{$id}' ";
        $pdo->exec($req);
    }
}
/**
 * Update the metadata associated with each occurrence so we know the rules have been run.
 * @param type $db Kohana database instance.
 */
function data_cleaner_update_occurrence_metadata($db, $endtime)
{
    // Note we use the information from the point when we started the process, in case
    // any changes have happened in the meanwhile which might otherwise be missed.
    $query = "update occurrences o\nset last_verification_check_date='{$endtime}'\nfrom occdelta\nwhere occdelta.id=o.id and occdelta.record_status not in ('I','V','R','D')";
    $db->query($query);
}
 /**
  * Checks if the rich snippet property element whose name is specified
  * by $prop_name exists within the wrapper article element.
  * 
  * @author Leo Fajardo (@leorw)
  * @since  2.5.2
  *
  * @param type $xpath
  * @param type $article_wrapper_element
  * @param type $property_name
  * @return boolean
  */
 function rich_snippet_property_exists($xpath, $article_wrapper_element, $property_name)
 {
     RWLogger::LogEnterence('rich_snippet_property_exists');
     try {
         // Find the ancestors with "itemscope" and "itemtype" attributes of the elements in the specified wrapper element
         // whose itemprop attribute's value is specified by $property_name.
         $ancestors = $xpath->query(".//*[@itemprop = '{$property_name}']/ancestor::*[@itemscope and @itemtype]", $article_wrapper_element);
         if ($ancestors->length) {
             $ancestor = $ancestors->item(0);
             if ('http://schema.org/Article' === $ancestor->getAttribute('itemtype')) {
                 return true;
             }
         }
     } catch (Exception $e) {
         if (RWLogger::IsOn()) {
             RWLogger::Log('rich_snippet_property_exists', 'Error: ' . $e->getMessage());
         }
     }
     RWLogger::LogDeparture('rich_snippet_property_exists');
     return false;
 }
Exemple #14
0
 /**
  * @brief 协程执行
  * @param type $callback
  */
 public function execute($callback)
 {
     $this->_mysqli->query($this->_sql, $callback);
 }
/**
 * Update the metadata associated with each occurrence so we know the rules have been run.
 * @param type $db Kohana database instance.
 */
function data_cleaner_update_occurrence_metadata($db)
{
    // Note we use the information from the point when we started the process, in case
    // any changes have happened in the meanwhile which might otherwise be missed.
    $query = 'update occurrences o
set last_verification_check_date=occlist.timepoint, 
    last_verification_check_taxa_taxon_list_id=occlist.taxa_taxon_list_id
from occlist
where occlist.id=o.id';
    $db->query($query);
}