Example #1
0
 private function generateGeneralWherePart($pattern)
 {
     $whereParts = [$this->db->replacePlaceholders("ao.title ilike '?e%'", [$pattern])];
     if ($this->maxAddressLevel) {
         $whereParts[] = $this->db->replacePlaceholders('ao.address_level <= ?q', [$this->maxAddressLevel]);
     }
     if ($this->regions) {
         $whereParts[] = $this->db->replacePlaceholders('ao.region IN (?l)', [$this->regions]);
     }
     return '(' . implode(') AND (', $whereParts) . ')';
 }
Example #2
0
 private function getQuery($rowExample)
 {
     if (!$this->sqlHeader) {
         $fields = [];
         foreach ($rowExample as $attribute => $devNull) {
             $fields[] = $this->fields[$attribute]['name'];
         }
         $headerPart = $this->db->replacePlaceholders('INSERT INTO ?f(?i) VALUES ', [$this->table, $fields]);
         $this->sqlHeader = $headerPart . ' ?v';
     }
     return $this->sqlHeader;
 }
Example #3
0
 private function findPlaces(array $placeWords, array $type, $parentId)
 {
     $pattern = implode(' ', $placeWords);
     $sql = "\n            SELECT full_title title, (CASE WHEN have_children THEN 0 ELSE 1 END)  is_complete, pt.system_name type_system_name\n            FROM places p\n            INNER JOIN place_types pt\n                ON p.type_id = pt.id\n            WHERE ?p\n            ORDER BY p.title\n            LIMIT ?e";
     $whereParts = [$this->db->replacePlaceholders("p.title ilike '?e%'", [$pattern])];
     if ($type) {
         $whereParts[] = $this->db->replacePlaceholders('type_id = ?q', [$type['id']]);
     }
     if ($parentId) {
         $whereParts[] = $this->db->replacePlaceholders('p.parent_id = ?q', [$parentId]);
     }
     $values = ['(' . implode($whereParts, ') AND (') . ')', $this->limit];
     $items = $this->db->execute($sql, $values)->fetchAll();
     if ($items) {
         foreach ($items as $key => $item) {
             $items[$key]['is_complete'] = $item['is_complete'] ? true : false;
             $items[$key]['tags'] = ['place', $item['type_system_name']];
         }
     }
     return $items;
 }
Example #4
0
 private function getFieldsSQL(ConnectionInterface $db, TypeConverter $typeConverter, ModelElement $config)
 {
     $sql = array();
     foreach ($config->properties as $propName => $propConfig) {
         if (!$propConfig->isLocalInDb) {
             continue;
         }
         $type = $typeConverter->getDbType($propConfig->type);
         $nullSql = $propConfig->isNullable ? '' : 'NOT NULL';
         $sql[] = $db->replacePlaceholders("?f ?p {$nullSql}", array($propName, $type));
     }
     return implode(",\n", $sql);
 }