/** @override */
 public function toSql($tableSql, EarthIT_DBC_Namer $dbObjectNamer, EarthIT_DBC_ParamsBuilder $params)
 {
     $columnName = $dbObjectNamer->getColumnName($this->rc, $this->field);
     $fieldValueSql = $tableSql . '.{' . $params->bind(new EarthIT_DBC_SQLIdentifier($columnName)) . '}';
     $valueParamName = $params->bind($this->value);
     return "{$fieldValueSql} = {{$valueParamName}}";
 }
 /**
  * @param string $tableSql SQL fragment giving the table name or alias
  */
 public function toSql($tableSql, EarthIT_DBC_Namer $dbObjectNamer, EarthIT_DBC_ParamsBuilder $params)
 {
     $columnName = $dbObjectNamer->getColumnName($this->rc, $this->field);
     $fieldValueSql = $tableSql . '.{' . $params->bind(new EarthIT_DBC_SQLIdentifier($columnName)) . '}';
     $valueValueSql = $this->valueExpression->toSql($params);
     return $this->comparisonOp->toSql($fieldValueSql, $valueValueSql);
 }
 /** @override */
 public function toSql(EarthIT_DBC_ParamsBuilder $params)
 {
     $s = array();
     foreach ($this->values as $v) {
         $s[] = '{' . $params->bind($v) . '}';
     }
     return '(' . implode(', ', $s) . ')';
 }
 /**
  * @param string $tableSql SQL fragment giving the table name or alias
  */
 public function toSql($tableSql, EarthIT_DBC_Namer $dbObjectNamer, EarthIT_DBC_ParamsBuilder $params)
 {
     $columnName = $dbObjectNamer->getColumnName($this->rc, $this->field);
     $fieldValueSql = $tableSql . '.{' . $params->bind(new EarthIT_DBC_SQLIdentifier($columnName)) . '}';
     $patternParamName = $params->newParam('pattern', $this->getLikePattern());
     if ($this->caseInsensitive) {
         $fieldValueSql = "lower({$fieldValueSql})";
         // Works on Postgres, anyway!
     }
     return "{$fieldValueSql} LIKE {{$patternParamName}}";
 }
 public function toSql($tableSql, EarthIT_DBC_Namer $dbObjectNamer, EarthIT_DBC_ParamsBuilder $params)
 {
     if (count($this->componentFilters) == 0) {
         return '{' . $params->newParam('truth', true) . '}';
     }
     $sqlz = array();
     foreach ($this->componentFilters as $f) {
         $sqlz[] = $f->toSql($tableSql, $dbObjectNamer, $params);
     }
     return '(' . implode(' AND ', $sqlz) . ')';
 }
 /** @override */
 public function toSql($tableSql, EarthIT_DBC_Namer $dbObjectNamer, EarthIT_DBC_ParamsBuilder $params)
 {
     $columnSqls = array();
     foreach ($this->fields as $field) {
         $columnName = $dbObjectNamer->getColumnName($this->rc, $field);
         $fieldValueSql = $tableSql . '.{' . $params->bind(new EarthIT_DBC_SQLIdentifier($columnName)) . '}';
         $columnSqls[] = $fieldValueSql;
     }
     $valueTupleSqls = array();
     foreach ($this->valueTuples as $valueTuple) {
         $valueSqls = array();
         foreach ($valueTuple as $value) {
             $valueSqls[] = '{' . $params->bind($value) . '}';
         }
         $valueTupleSqls[] = '(' . implode(', ', $valueSqls) . ')';
     }
     return "(" . implode(', ', $columnSqls) . ") IN (" . implode(', ', $valueTupleSqls) . ')';
 }
 public function toSql($tableSql, EarthIT_DBC_Namer $dbObjectNamer, EarthIT_DBC_ParamsBuilder $params)
 {
     static $aliasNum;
     // More properly this would be done with a join,
     // but that requires cooperation from code outside this filter.
     // Let's see if we can make this work with sub-selects...
     $table = EarthIT_DBC_SQLExpressionUtil::tableExpression($this->targetRc, $dbObjectNamer);
     $subItemTableSql = "{" . $params->newParam('t', $table) . "}";
     $subItemAlias = 'subitem' . ++$aliasNum;
     $subItemFilterSql = str_replace("\n", "\n\t", $this->targetFilter->toSql($subItemAlias, $dbObjectNamer, $params));
     $originFieldNames = $this->reference->getOriginFieldNames();
     $targetFieldNames = $this->reference->getTargetFieldNames();
     $joinConditionSqls = array();
     for ($i = 0; $i < count($targetFieldNames); ++$i) {
         $targetCol = $dbObjectNamer->getColumnName($this->targetRc, $this->targetRc->getField($targetFieldNames[$i]));
         $originCol = $dbObjectNamer->getColumnName($this->originRc, $this->originRc->getField($originFieldNames[$i]));
         $joinConditionSqls[] = "{$subItemAlias}.{" . $params->newParam('c', new EarthIT_DBC_SQLIdentifier($targetCol)) . "} = " . "{$tableSql}.{" . $params->newParam('c', new EarthIT_DBC_SQLIdentifier($originCol)) . "}";
     }
     $joinConditionSql = implode(" AND ", $joinConditionSqls);
     return "(\n" . "\tSELECT COUNT(*)\n" . "\tFROM {$subItemTableSql} AS {$subItemAlias}\n" . "\tWHERE {$subItemFilterSql} AND {$joinConditionSql}\n" . ") > 0";
 }
 public function makeDbExternalFieldValueSqls(array $fields, EarthIT_Schema_ResourceClass $rc, $tableSql, EarthIT_DBC_ParamsBuilder $params)
 {
     $z = array();
     foreach ($fields as $f) {
         $columnName = $this->dbObjectNamer->getColumnName($rc, $f);
         $columnParamName = $params->newParam('c', new EarthIT_DBC_SQLIdentifier($columnName));
         $z[$columnName] = $this->dbInternalToExternalValueSql($f, $rc, "{$tableSql}.{{$columnParamName}}");
     }
     return $z;
 }
 /** @override */
 public function toSql(EarthIT_DBC_ParamsBuilder $params)
 {
     return '{' . $params->bind($this->value) . '}';
 }
예제 #10
0
 /**
  * @param array $selects array of alias => SQL expression text
  * @return array of select parts [x, y, ...] of 'SELECT x, y, ... FROM yaddah yaddah'
  */
 public static function formatSelectComponents(array $selects, EarthIT_DBC_ParamsBuilder $PB)
 {
     $sqlz = array();
     foreach ($selects as $k => $selSql) {
         if (is_integer($k)) {
             $sqlz[] = $selSql;
         } else {
             $aliasParamName = $PB->bind(new EarthIT_DBC_SQLIdentifier($k));
             $sqlz[] = "{$selSql} AS {{$aliasParamName}}";
         }
     }
     return $sqlz;
 }