Beispiel #1
0
 private function formatValue($value)
 {
     if (is_string($value)) {
         if (strlen($value) > 20) {
             $this->remaining[] = $value;
             return '?';
         } else {
             return $this->connection->quote($value);
         }
     } elseif (is_int($value)) {
         return (string) $value;
     } elseif (is_float($value)) {
         return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
     } elseif (is_bool($value)) {
         return $this->driver->formatBool($value);
     } elseif ($value === NULL) {
         return 'NULL';
     } elseif ($value instanceof TableRow) {
         return $value->getPrimary();
     } elseif (is_array($value) || $value instanceof Traversable) {
         $vx = $kx = array();
         if (isset($value[0])) {
             // non-associative; value, value, value
             foreach ($value as $v) {
                 $vx[] = $this->formatValue($v);
             }
             return implode(', ', $vx);
         } elseif ($this->arrayMode === 'values') {
             // (key, key, ...) VALUES (value, value, ...)
             $this->arrayMode = 'multi';
             foreach ($value as $k => $v) {
                 $kx[] = $this->driver->delimite($k);
                 $vx[] = $this->formatValue($v);
             }
             return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
         } elseif ($this->arrayMode === 'assoc') {
             // key=value, key=value, ...
             foreach ($value as $k => $v) {
                 $vx[] = $this->driver->delimite($k) . '=' . $this->formatValue($v);
             }
             return implode(', ', $vx);
         } elseif ($this->arrayMode === 'multi') {
             // multiple insert (value, value, ...), ...
             foreach ($value as $k => $v) {
                 $vx[] = $this->formatValue($v);
             }
             return '(' . implode(', ', $vx) . ')';
         }
     } elseif ($value instanceof DateTime) {
         return $this->driver->formatDateTime($value);
     } elseif ($value instanceof SqlLiteral) {
         return $value->__toString();
     } else {
         $this->remaining[] = $value;
         return '?';
     }
 }
Beispiel #2
0
	protected function buildJoins($val, $inner = FALSE)
	{
		$joins = array();
		preg_match_all('~\\b([a-z][\\w.:]*[.:])([a-z]\\w*|\*)(\\s+IS\\b|\\s*<=>)?~i', $val, $matches);
		foreach ($matches[1] as $names) {
			$parent = $parentAlias = $this->tableName;
			if ($names !== "$parent.") { // case-sensitive
				preg_match_all('~\\b([a-z][\\w]*|\*)([.:])~i', $names, $matches, PREG_SET_ORDER);
				foreach ($matches as $match) {
					list(, $name, $delimiter) = $match;

					if ($delimiter === ':') {
						list($table, $primary) = $this->databaseReflection->getHasManyReference($parent, $name);
						$column = $this->databaseReflection->getPrimary($parent);
					} else {
						list($table, $column) = $this->databaseReflection->getBelongsToReference($parent, $name);
						$primary = $this->databaseReflection->getPrimary($table);
					}

					$joins[$name] = ' '
						. (!isset($joins[$name]) && $inner && !isset($match[3]) ? 'INNER' : 'LEFT')
						. ' JOIN ' . $this->driver->delimite($table) . ($table !== $name ? ' AS ' . $this->driver->delimite($name) : '')
						. ' ON ' . $this->driver->delimite($parentAlias) . '.' . $this->driver->delimite($column)
						. ' = ' . $this->driver->delimite($name) . '.' . $this->driver->delimite($primary);

					$parent = $table;
					$parentAlias = $name;
				}
			}
		}
		return $joins;
	}