コード例 #1
0
 protected function addClosureColumn($name, Table $ct_table, Column $column)
 {
     $table = $this->getTable();
     $id_fieldname = $column->getName();
     $domain = $column->getDomain();
     if (!$ct_table->hasColumn($name)) {
         $column = new Column($name);
         $column->setDomain($domain);
         $column->setPrimaryKey(true);
         $ct_table->addColumn($column);
     } else {
         $column = $ct_table->getColumn($name);
     }
     $ct_tablename_normalized = str_replace('_', '', $ct_table->getName());
     $fk_name = $ct_tablename_normalized . '_' . $name . '_fk';
     if (!$ct_table->getColumnForeignKeys($name)) {
         $column_fk = new ForeignKey($fk_name);
         $column_fk->addReference($name, $table->getColumn($id_fieldname)->getName());
         $column_fk->setForeignTableCommonName($table->getName());
         $column_fk->setOnUpdate('cascade');
         $column_fk->setOnDelete('restrict');
         $ct_table->addForeignKey($column_fk);
     }
     $column_idx_name = $fk_name . '_idx';
     if (!$ct_table->hasIndex($column_idx_name)) {
         $column_idx = new Index($column_idx_name);
         $column_idx->addColumn(['name' => $column->getName()]);
         $ct_table->addIndex($column_idx);
     }
 }
コード例 #2
0
ファイル: MysqlPlatform.php プロジェクト: cocofile/cocofile
 /**
  * Builds the DDL SQL to add a column
  *
  * @param Column $column
  *
  * @return string
  */
 public function getAddColumnDDL(Column $column)
 {
     $pattern = "\nALTER TABLE %s ADD %s %s;\n";
     $tableColumns = $column->getTable()->getColumns();
     // Default to add first if no column is found before the current one
     $insertPositionDDL = "FIRST";
     foreach ($tableColumns as $i => $tableColumn) {
         // We found the column, use the one before it if it's not the first
         if ($tableColumn->getName() == $column->getName()) {
             // We have a column that is not the first one
             if ($i > 0) {
                 $insertPositionDDL = "AFTER " . $this->quoteIdentifier($tableColumns[$i - 1]->getName());
             }
             break;
         }
     }
     return sprintf($pattern, $this->quoteIdentifier($column->getTable()->getName()), $this->getColumnDDL($column), $insertPositionDDL);
 }
コード例 #3
0
ファイル: Table.php プロジェクト: disider/Propel2
 /**
  * Adds a new column to the table.
  *
  * @param  Column|array    $col
  * @throws EngineException
  * @return Column
  */
 public function addColumn($col)
 {
     if ($col instanceof Column) {
         if (isset($this->columnsByName[$col->getName()])) {
             throw new EngineException(sprintf('Column "%s" declared twice in table "%s"', $col->getName(), $this->getName()));
         }
         $col->setTable($this);
         if ($col->isInheritance()) {
             $this->inheritanceColumn = $col;
         }
         $this->columns[] = $col;
         $this->columnsByName[$col->getName()] = $col;
         $this->columnsByLowercaseName[strtolower($col->getName())] = $col;
         $this->columnsByPhpName[$col->getPhpName()] = $col;
         $col->setPosition(count($this->columns));
         if ($col->requiresTransactionInPostgres()) {
             $this->needsTransactionInPostgres = true;
         }
         return $col;
     }
     $column = new Column();
     $column->setTable($this);
     $column->loadMapping($col);
     return $this->addColumn($column);
     // call self w/ different param
 }
コード例 #4
0
ファイル: QueryBuilder.php プロジェクト: SwissalpS/Propel2
 /**
  * Adds the singular filterByCol method for an Array column.
  *
  * @param string &$script The script will be modified in this method.
  * @param Column $col
  */
 protected function addFilterBySetCol(&$script, Column $col)
 {
     $colPhpName = $col->getPhpName();
     $singularPhpName = $col->getPhpSingularName();
     $colName = $col->getName();
     $variableName = $col->getCamelCaseName();
     $script .= "\n    /**\n     * Filter the query on the {$colName} column\n     * @param     mixed \${$variableName} The value to use as filter\n     * @param     string \$comparison Operator to use for the column comparison, defaults to Criteria::CONTAINS_ALL\n     *\n     * @return \$this|" . $this->getQueryClassName() . " The current query, for fluid interface\n     */\n    public function filterBy{$singularPhpName}(\${$variableName} = null, \$comparison = null)\n    {\n        return \$this->filterBy{$colPhpName}(\${$variableName}, \$comparison);\n    }\n";
 }
コード例 #5
0
ファイル: ObjectBuilder.php プロジェクト: rouffj/Propel2
 /**
  * Adds setter method for "normal" columns.
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        parent::addColumnMutators()
  */
 protected function addDefaultMutator(&$script, Column $col)
 {
     $clo = strtolower($col->getName());
     $this->addMutatorOpen($script, $col);
     // Perform type-casting to ensure that we can use type-sensitive
     // checking in mutators.
     if ($col->isPhpPrimitiveType()) {
         $script .= "\n        if (\$v !== null) {\n            \$v = (" . $col->getPhpType() . ") \$v;\n        }\n";
     }
     $script .= "\n        if (\$this->{$clo} !== \$v) {\n            \$this->{$clo} = \$v;\n            \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . ";\n        }\n";
     $this->addMutatorClose($script, $col);
 }
コード例 #6
0
 protected function addFindOne(Column $column)
 {
     return $this->renderTemplate('queryFindOne', ['objectClassName' => $this->builder->getClassNameFromBuilder($this->builder->getStubObjectBuilder($column->getTable())), 'columnPhpName' => $column->getPhpName(), 'columnName' => $column->getName(), 'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName()]);
 }
コード例 #7
0
 /**
  * Get the column constant name (e.g. TableMapName::COLUMN_NAME).
  *
  * @param Column $col       The column we need a name for.
  * @param string $classname The TableMap classname to use.
  *
  * @return string If $classname is provided, then will return $classname::COLUMN_NAME; if not, then the TableMapName is looked up for current table to yield $currTableTableMap::COLUMN_NAME.
  */
 public function getColumnConstant($col, $classname = null)
 {
     if (null === $col) {
         throw new InvalidArgumentException('No columns were specified.');
     }
     if (null === $classname) {
         return $this->getBuildProperty('classPrefix') . $col->getConstantName();
     }
     // was it overridden in schema.xml ?
     if ($col->getTableMapName()) {
         $const = strtoupper($col->getTableMapName());
     } else {
         $const = strtoupper($col->getName());
     }
     return $classname . '::' . $const;
 }
コード例 #8
0
ファイル: ObjectBuilder.php プロジェクト: SwissalpS/Propel2
 /**
  * Adds the body of the close part of a mutator.
  *
  * @param string &$script
  * @param Column $column
  */
 protected function addMutatorCloseBody(&$script, Column $column)
 {
     $table = $this->getTable();
     if ($column->isForeignKey()) {
         foreach ($column->getForeignKeys() as $fk) {
             $tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
             $colFK = $tblFK->getColumn($fk->getMappedForeignColumn($column->getName()));
             if (!$colFK) {
                 continue;
             }
             $varName = $this->getFKVarName($fk);
             $script .= "\n        if (\$this->{$varName} !== null && \$this->" . $varName . "->get" . $colFK->getPhpName() . "() !== \$v) {\n            \$this->{$varName} = null;\n        }\n";
         }
         // foreach fk
     }
     /* if col is foreign key */
     foreach ($column->getReferrers() as $refFK) {
         $tblFK = $this->getDatabase()->getTable($refFK->getForeignTableName());
         if ($tblFK->getName() != $table->getName()) {
             foreach ($column->getForeignKeys() as $fk) {
                 $tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
                 $colFK = $tblFK->getColumn($fk->getMappedForeignColumn($column->getName()));
                 if ($refFK->isLocalPrimaryKey()) {
                     $varName = $this->getPKRefFKVarName($refFK);
                     $script .= "\n        // update associated " . $tblFK->getPhpName() . "\n        if (\$this->{$varName} !== null) {\n            \$this->{$varName}->set" . $colFK->getPhpName() . "(\$v);\n        }\n";
                 } else {
                     $collName = $this->getRefFKCollVarName($refFK);
                     $script .= "\n\n        // update associated " . $tblFK->getPhpName() . "\n        if (\$this->{$collName} !== null) {\n            foreach (\$this->{$collName} as \$referrerObject) {\n                    \$referrerObject->set" . $colFK->getPhpName() . "(\$v);\n                }\n            }\n";
                 }
                 // if (isLocalPrimaryKey
             }
             // foreach col->getPrimaryKeys()
         }
         // if tablFk != table
     }
     // foreach
 }
コード例 #9
0
 /**
  * Adds the actual column which want to track.
  *
  * @param Table  $logTable
  * @param Column $column
  */
 protected function addColumnToLog(Table $logTable, Column $column)
 {
     if ($logTable->hasColumn($column->getName())) {
         return;
     }
     $columnInLogTable = clone $column;
     if ($columnInLogTable->hasReferrers()) {
         $columnInLogTable->clearReferrers();
     }
     $columnInLogTable->setAutoIncrement(false);
     $columnInLogTable->setPrimaryKey(false);
     $logTable->addColumn($columnInLogTable);
 }
コード例 #10
0
 /**
  * @param Column $column
  *
  * @return bool
  *
  * @throws PropelException
  */
 protected function isColumnForeignKeyOrDuplicated(Column $column)
 {
     $delegateTable = $column->getTable();
     $table = $this->getTable();
     $fks = [];
     if (!isset($this->double_defined)) {
         $this->double_defined = [];
         foreach ($this->delegates + [$table->getName() => 1] as $key => $value) {
             $delegateTable = $this->getDelegateTable($key);
             foreach ($delegateTable->getColumns() as $columnDelegated) {
                 if (isset($this->double_defined[$columnDelegated->getName()])) {
                     $this->double_defined[$columnDelegated->getName()]++;
                 } else {
                     $this->double_defined[$columnDelegated->getName()] = 1;
                 }
             }
         }
     }
     if (1 < $this->double_defined[$column->getName()]) {
         return true;
     }
     foreach ($delegateTable->getForeignKeysReferencingTable($table->getName()) as $fk) {
         /** @var \Propel\Generator\Model\ForeignKey $fk */
         $fks[] = $fk->getForeignColumnName();
     }
     foreach ($table->getForeignKeysReferencingTable($delegateTable->getName()) as $fk) {
         $fks[] = $fk->getForeignColumnName();
     }
     if (in_array($column->getName(), $fks) || $table->hasColumn($column->getName())) {
         return true;
     }
     return false;
 }
コード例 #11
0
ファイル: Validator.php プロジェクト: norfil/Propel2
 /**
  * Gets the name of the column that this Validator applies to.
  * @return     string
  */
 public function getColumnName()
 {
     return $this->column->getName();
 }
コード例 #12
0
ファイル: PeerBuilder.php プロジェクト: RafalFilipek/Propel2
 /**
  * COMPATIBILITY: Get the column constant name (e.g. PeerName::COLUMN_NAME).
  *
  * This method exists simply because it belonged to the 'PeerBuilder' that this
  * class is replacing (because of name conflict more than actual functionality overlap).
  * When the new builder model is finished this method will be removed.
  *
  * @param      Column $col The column we need a name for.
  * @param      string $phpName The PHP Name of the peer class. The 'Peer' is appended automatically.
  *
  * @return     string If $phpName is provided, then will return {$phpName}Peer::COLUMN_NAME; if not, just COLUMN_NAME.
  * @deprecated
  */
 public static function getColumnName(Column $col, $phpName = null)
 {
     // was it overridden in schema.xml ?
     if ($col->getPeerName()) {
         $const = strtoupper($col->getPeerName());
     } else {
         $const = strtoupper($col->getName());
     }
     if ($phpName !== null) {
         return $phpName . 'Peer::' . $const;
     } else {
         return $const;
     }
 }
コード例 #13
0
 /**
  * Builds the DDL SQL to change a column
  * @return string
  */
 public function getChangeColumnDDL(Column $fromColumn, Column $toColumn)
 {
     $pattern = "\nALTER TABLE %s CHANGE %s %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($fromColumn->getTable()->getName()), $this->quoteIdentifier($fromColumn->getName()), $this->getColumnDDL($toColumn));
 }
コード例 #14
0
ファイル: QueryBuilder.php プロジェクト: spryker/Propel
 /**
  * Adds the filterByCol method for this object.
  *
  * @param string &$script The script will be modified in this method.
  * @param \Propel\Generator\Model\Column $col
  *
  * @return void
  */
 protected function addFilterByCol(&$script, Column $col)
 {
     $allowedArrayFilters = $this->getAllowedArrayFilters();
     $implodedArrayComparisons = implode(', ', $allowedArrayFilters);
     $this->declareClass('Spryker\\Zed\\Propel\\Business\\Exception\\AmbiguousComparisonException');
     $this->declareClass('Spryker\\Zed\\Propel\\Business\\Runtime\\ActiveQuery\\Criteria', 'Spryker');
     $colPhpName = $col->getPhpName();
     $colName = $col->getName();
     $variableName = $col->getCamelCaseName();
     $qualifiedName = $this->getColumnConstant($col);
     $script .= $this->addFilterByColBetween($col);
     $script .= $this->addFilterByColIn($col);
     $script .= $this->addFilterByColLike($col);
     $script .= "\n    /**\n     * Filter the query on the {$colName} column\n     *";
     if ($col->isNumericType()) {
         $script .= "\n     * Example usage:\n     * <code>\n     * \$query->filterBy{$colPhpName}(1234); // WHERE {$colName} = 1234\n     * \$query->filterBy{$colPhpName}(array(12, 34), Criteria::IN); // WHERE {$colName} IN (12, 34)\n     * \$query->filterBy{$colPhpName}(array('min' => 12), SprykerCriteria::BETWEEN); // WHERE {$colName} > 12\n     * </code>";
         if ($col->isForeignKey()) {
             foreach ($col->getForeignKeys() as $fk) {
                 $script .= "\n     *\n     * @see       filterBy" . $this->getFKPhpNameAffix($fk) . "()";
             }
         }
         $script .= "\n     *\n     * @param     mixed \${$variableName} The value to use as filter.\n     *              Use scalar values for equality.\n     *              Use array values for in_array() equivalent. Add Criteria::IN explicitly.\n     *              Use associative array('min' => \$minValue, 'max' => \$maxValue) for intervals. Add SprykerCriteria::BETWEEN explicitly.";
     } elseif ($col->isTemporalType()) {
         $script .= "\n     * Example usage:\n     * <code>\n     * \$query->filterBy{$colPhpName}('2011-03-14'); // WHERE {$colName} = '2011-03-14'\n     * \$query->filterBy{$colPhpName}('now'); // WHERE {$colName} = '2011-03-14'\n     * \$query->filterBy{$colPhpName}(array('max' => 'yesterday'), SprykerCriteria::BETWEEN); // WHERE {$colName} > '2011-03-13'\n     * </code>\n     *\n     * @param     mixed \${$variableName} The value to use as filter.\n     *              Values can be integers (unix timestamps), DateTime objects, or strings.\n     *              Empty strings are treated as NULL.\n     *              Use scalar values for equality.\n     *              Use array values for in_array() equivalent. Add Criteria::IN explicitly.\n     *              Use associative array('min' => \$minValue, 'max' => \$maxValue) for intervals. Add SprykerCriteria::BETWEEN explicitly.";
     } elseif ($col->getType() == PropelTypes::PHP_ARRAY) {
         $script .= "\n     * @param     array \${$variableName} The values to use as filter. Use Criteria::LIKE to enable like matching of array values.";
     } elseif ($col->isTextType()) {
         $script .= "\n     * Example usage:\n     * <code>\n     * \$query->filterBy{$colPhpName}('fooValue');   // WHERE {$colName} = 'fooValue'\n     * \$query->filterBy{$colPhpName}('%fooValue%', Criteria::LIKE); // WHERE {$colName} LIKE '%fooValue%'\n     * </code>\n     *\n     * @param     string \${$variableName} The value to use as filter.\n     *              Accepts wildcards (* and % trigger a LIKE). Add Criteria::LIKE explicitly.";
     } elseif ($col->isBooleanType()) {
         $script .= "\n     * Example usage:\n     * <code>\n     * \$query->filterBy{$colPhpName}(true); // WHERE {$colName} = true\n     * \$query->filterBy{$colPhpName}('yes'); // WHERE {$colName} = true\n     * </code>\n     *\n     * @param     boolean|string \${$variableName} The value to use as filter.\n     *              Non-boolean arguments are converted using the following rules:\n     *                * 1, '1', 'true',  'on',  and 'yes' are converted to boolean true\n     *                * 0, '0', 'false', 'off', and 'no'  are converted to boolean false\n     *              Check on string values is case insensitive (so 'FaLsE' is seen as 'false').";
     } else {
         $script .= "\n     * @param     mixed \${$variableName} The value to use as filter";
     }
     $script .= "\n     * @param     string \$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL\n     *\n     * @return \$this|" . $this->getQueryClassName() . " The current query, for fluid interface\n     *\n     * @throws \\Spryker\\Zed\\Propel\\Business\\Exception\\AmbiguousComparisonException\n     */\n    public function filterBy{$colPhpName}(\${$variableName} = null, \$comparison = Criteria::EQUAL)\n    {";
     if ($col->isNumericType() || $col->isTemporalType()) {
         $script .= "\n\n        if (is_array(\${$variableName})) {\n            \$useMinMax = false;\n            if (isset(\${$variableName}['min'])) {\n                if (\$comparison != SprykerCriteria::BETWEEN && \$comparison != Criteria::GREATER_EQUAL) {\n                    throw new AmbiguousComparisonException('\\'min\\' requires explicit Criteria::GREATER_EQUAL or SprykerCriteria::BETWEEN when \\'max\\' is also needed as comparison criteria.');\n                }\n                \$this->addUsingAlias({$qualifiedName}, \${$variableName}['min'], Criteria::GREATER_EQUAL);\n                \$useMinMax = true;\n            }\n            if (isset(\${$variableName}['max'])) {\n                if (\$comparison != SprykerCriteria::BETWEEN && \$comparison != Criteria::LESS_EQUAL) {\n                    throw new AmbiguousComparisonException('\\'max\\' requires explicit Criteria::LESS_EQUAL or SprykerCriteria::BETWEEN when \\'min\\' is also needed as comparison criteria.');\n                }\n                \$this->addUsingAlias({$qualifiedName}, \${$variableName}['max'], Criteria::LESS_EQUAL);\n                \$useMinMax = true;\n            }\n            if (\$useMinMax) {\n                return \$this;\n            }\n\n            if (!in_array(\$comparison, [{$implodedArrayComparisons}])) {\n                throw new AmbiguousComparisonException('\${$variableName} of type array requires one of [{$implodedArrayComparisons}] as comparison criteria.');\n            }\n        }";
     } elseif ($col->getType() == PropelTypes::OBJECT) {
         $script .= "\n        if (is_object(\${$variableName})) {\n            \${$variableName} = serialize(\${$variableName});\n        }";
     } elseif ($col->getType() == PropelTypes::PHP_ARRAY) {
         $script .= "\n        \$key = \$this->getAliasedColName({$qualifiedName});\n        if (null === \$comparison || \$comparison == Criteria::CONTAINS_ALL) {\n            foreach (\${$variableName} as \$value) {\n                \$value = '%| ' . \$value . ' |%';\n                if (\$this->containsKey(\$key)) {\n                    \$this->addAnd(\$key, \$value, Criteria::LIKE);\n                } else {\n                    \$this->add(\$key, \$value, Criteria::LIKE);\n                }\n            }\n\n            return \$this;\n        } elseif (\$comparison == Criteria::CONTAINS_SOME) {\n            foreach (\${$variableName} as \$value) {\n                \$value = '%| ' . \$value . ' |%';\n                if (\$this->containsKey(\$key)) {\n                    \$this->addOr(\$key, \$value, Criteria::LIKE);\n                } else {\n                    \$this->add(\$key, \$value, Criteria::LIKE);\n                }\n            }\n\n            return \$this;\n        } elseif (\$comparison == Criteria::CONTAINS_NONE) {\n            foreach (\${$variableName} as \$value) {\n                \$value = '%| ' . \$value . ' |%';\n                if (\$this->containsKey(\$key)) {\n                    \$this->addAnd(\$key, \$value, Criteria::NOT_LIKE);\n                } else {\n                    \$this->add(\$key, \$value, Criteria::NOT_LIKE);\n                }\n            }\n            \$this->addOr(\$key, null, Criteria::ISNULL);\n\n            return \$this;\n        }";
     } elseif ($col->getType() == PropelTypes::ENUM) {
         $script .= "\n        \$valueSet = " . $this->getTableMapClassName() . "::getValueSet(" . $this->getColumnConstant($col) . ");\n        if (is_scalar(\${$variableName})) {\n            if (!in_array(\${$variableName}, \$valueSet)) {\n                throw new PropelException(sprintf('Value \"%s\" is not accepted in this enumerated column', \${$variableName}));\n            }\n            \${$variableName} = array_search(\${$variableName}, \$valueSet);\n        } elseif (is_array(\${$variableName})) {\n            if (!in_array(\$comparison, [{$implodedArrayComparisons}])) {\n                throw new AmbiguousComparisonException('array requires one of [{$implodedArrayComparisons}] as comparison criteria.');\n            }\n            \$convertedValues = array();\n            foreach (\${$variableName} as \$value) {\n                if (!in_array(\$value, \$valueSet)) {\n                    throw new PropelException(sprintf('Value \"%s\" is not accepted in this enumerated column', \$value));\n                }\n                \$convertedValues []= array_search(\$value, \$valueSet);\n            }\n            \${$variableName} = \$convertedValues;\n        }";
     } elseif ($col->isTextType()) {
         $script .= "\n        if (\$comparison == Criteria::LIKE) {\n            \${$variableName} = str_replace('*', '%', \${$variableName});\n        }\n\n        if (is_array(\${$variableName}) && !in_array(\$comparison, [{$implodedArrayComparisons}])) {\n            throw new AmbiguousComparisonException('\${$variableName} of type array requires one of [{$implodedArrayComparisons}] as comparison criteria.');\n        }";
     } elseif ($col->isBooleanType()) {
         $script .= "\n        if (is_string(\${$variableName})) {\n            \${$variableName} = in_array(strtolower(\${$variableName}), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;\n        }";
     }
     $script .= "\n\n        return \$this->addUsingAlias({$qualifiedName}, \${$variableName}, \$comparison);\n    }\n";
 }
コード例 #15
0
 /**
  * Builds the DDL SQL to rename a column
  *
  * @return string
  */
 public function getRenameColumnDDL(Column $fromColumn, Column $toColumn)
 {
     $pattern = "\nALTER TABLE %s RENAME COLUMN %s TO %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($fromColumn->getTable()->getName()), $this->quoteIdentifier($fromColumn->getName()), $this->quoteIdentifier($toColumn->getName()));
 }
コード例 #16
0
ファイル: PgsqlPlatform.php プロジェクト: disider/Propel2
 public function getUsingCast(Column $fromColumn, Column $toColumn)
 {
     $fromSqlType = strtoupper($fromColumn->getDomain()->getSqlType());
     $toSqlType = strtoupper($toColumn->getDomain()->getSqlType());
     $name = $fromColumn->getName();
     if ($this->isNumber($fromSqlType) && $this->isString($toSqlType)) {
         //cast from int to string
         return '  ';
     }
     if ($this->isString($fromSqlType) && $this->isNumber($toSqlType)) {
         //cast from string to int
         return "\n   USING CASE WHEN trim({$name}) SIMILAR TO '[0-9]+'\n        THEN CAST(trim({$name}) AS integer)\n        ELSE NULL END";
     }
     if ($this->isNumber($fromSqlType) && 'BYTEA' === $toSqlType) {
         return " USING decode(CAST({$name} as text), 'escape')";
     }
     if ('DATE' === $fromSqlType && 'TIME' === $toSqlType) {
         return " USING NULL";
     }
     if ($this->isNumber($fromSqlType) && $this->isNumber($toSqlType)) {
         return '';
     }
     if ($this->isString($fromSqlType) && $this->isString($toSqlType)) {
         return '';
     }
     return " USING NULL";
 }
コード例 #17
0
 public function getColumnDDL(Column $col)
 {
     $domain = $col->getDomain();
     $ddl = array($this->quoteIdentifier($col->getName()));
     $sqlType = $domain->getSqlType();
     $table = $col->getTable();
     if ($col->isAutoIncrement() && $table && $table->getIdMethodParameters() == null) {
         $sqlType = $col->getType() === PropelTypes::BIGINT ? 'bigserial' : 'serial';
     }
     if ($this->hasSize($sqlType) && $col->isDefaultSqlType($this)) {
         $ddl[] = $sqlType . $domain->printSize();
     } else {
         $ddl[] = $sqlType;
     }
     if ($default = $this->getColumnDefaultValueDDL($col)) {
         $ddl[] = $default;
     }
     if ($notNull = $this->getNullString($col->isNotNull())) {
         $ddl[] = $notNull;
     }
     if ($autoIncrement = $col->getAutoIncrementString()) {
         $ddl[] = $autoIncrement;
     }
     return implode(' ', $ddl);
 }
コード例 #18
0
 public function testSetupObjectWithDomain()
 {
     $database = $this->getDatabaseMock('bookstore');
     $database->expects($this->once())->method('getDomain')->with($this->equalTo('BOOLEAN'))->will($this->returnValue($this->getDomainMock('INTEGER')));
     $table = $this->getTableMock('books', array('database' => $database));
     $column = new Column();
     $column->setTable($table);
     $column->setDomain($this->getDomainMock('BOOLEAN'));
     $column->loadMapping(array('domain' => 'BOOLEAN', 'name' => 'is_published', 'phpName' => 'IsPublished', 'phpType' => 'boolean', 'tableMapName' => 'IS_PUBLISHED', 'prefix' => 'col_', 'accessorVisibility' => 'public', 'mutatorVisibility' => 'public', 'primaryString' => 'false', 'primaryKey' => 'false', 'nodeKey' => 'false', 'nestedSetLeftKey' => 'false', 'nestedSetRightKey' => 'false', 'treeScopeKey' => 'false', 'required' => 'false', 'autoIncrement' => 'false', 'lazyLoad' => 'true', 'sqlType' => 'TINYINT', 'size' => 1, 'defaultValue' => 'true', 'valueSet' => 'FOO, BAR, BAZ'));
     $this->assertSame('is_published', $column->getName());
     $this->assertSame('IsPublished', $column->getPhpName());
     $this->assertSame('boolean', $column->getPhpType());
     $this->assertSame('IS_PUBLISHED', $column->getTableMapName());
     $this->assertSame('public', $column->getAccessorVisibility());
     $this->assertSame('public', $column->getMutatorVisibility());
     $this->assertFalse($column->isPrimaryString());
     $this->assertFalse($column->isPrimaryKey());
     $this->assertFalse($column->isNodeKey());
     $this->assertFalse($column->isNestedSetLeftKey());
     $this->assertFalse($column->isNestedSetRightKey());
     $this->assertFalse($column->isTreeScopeKey());
     $this->assertTrue($column->isLazyLoad());
     $this->assertCount(3, $column->getValueSet());
 }
コード例 #19
0
ファイル: QueryBuilder.php プロジェクト: ktounet/Propel2
 /**
  * Adds the singular filterByCol method for an Array column.
  * @param string &$script The script will be modified in this method.
  * @param Column $col
  */
 protected function addFilterByArrayCol(&$script, Column $col)
 {
     $colPhpName = $col->getPhpName();
     $singularPhpName = $col->getPhpSingularName();
     $colName = $col->getName();
     $variableName = $col->getCamelCaseName();
     $qualifiedName = $this->getColumnConstant($col);
     $script .= "\n    /**\n     * Filter the query on the {$colName} column\n     * @param     mixed \${$variableName} The value to use as filter\n     * @param     string \$comparison Operator to use for the column comparison, defaults to Criteria::CONTAINS_ALL\n     *\n     * @return \$this|" . $this->getQueryClassName() . " The current query, for fluid interface\n     */\n    public function filterBy{$singularPhpName}(\${$variableName} = null, \$comparison = null)\n    {\n        if (null === \$comparison || \$comparison == Criteria::CONTAINS_ALL) {\n            if (is_scalar(\${$variableName})) {\n                \${$variableName} = '%| ' . \${$variableName} . ' |%';\n                \$comparison = Criteria::LIKE;\n            }\n        } elseif (\$comparison == Criteria::CONTAINS_NONE) {\n            \${$variableName} = '%| ' . \${$variableName} . ' |%';\n            \$comparison = Criteria::NOT_LIKE;\n            \$key = \$this->getAliasedColName({$qualifiedName});\n            if (\$this->containsKey(\$key)) {\n                \$this->addAnd(\$key, \${$variableName}, \$comparison);\n            } else {\n                \$this->addAnd(\$key, \${$variableName}, \$comparison);\n            }\n            \$this->addOr(\$key, null, Criteria::ISNULL);\n\n            return \$this;\n        }\n\n        return \$this->addUsingAlias({$qualifiedName}, \${$variableName}, \$comparison);\n    }\n";
 }
コード例 #20
0
ファイル: XmlDumper.php プロジェクト: SwissalpS/Propel2
 /**
  * Appends the generated <column> XML node to its parent node.
  *
  * @param Column   $column     The Column model instance
  * @param \DOMNode $parentNode The parent DOMNode object
  */
 private function appendColumnNode(Column $column, \DOMNode $parentNode)
 {
     $columnNode = $parentNode->appendChild($this->document->createElement('column'));
     $columnNode->setAttribute('name', $column->getName());
     if ($phpName = $column->getPhpName()) {
         $columnNode->setAttribute('phpName', $phpName);
     }
     $columnNode->setAttribute('type', $column->getType());
     $domain = $column->getDomain();
     if ($size = $domain->getSize()) {
         $columnNode->setAttribute('size', $size);
     }
     if (null !== ($scale = $domain->getScale())) {
         $columnNode->setAttribute('scale', $scale);
     }
     $platform = $column->getPlatform();
     if ($platform && !$column->isDefaultSqlType($platform)) {
         $columnNode->setAttribute('sqlType', $domain->getSqlType());
     }
     if ($description = $column->getDescription()) {
         $columnNode->setAttribute('description', $description);
     }
     if ($column->isPrimaryKey()) {
         $columnNode->setAttribute('primaryKey', 'true');
     }
     if ($column->isAutoIncrement()) {
         $columnNode->setAttribute('autoIncrement', 'true');
     }
     if ($column->isNotNull()) {
         $columnNode->setAttribute('required', 'true');
     }
     $defaultValue = $domain->getDefaultValue();
     if ($defaultValue) {
         $type = $defaultValue->isExpression() ? 'defaultExpr' : 'defaultValue';
         $columnNode->setAttribute($type, $defaultValue->getValue());
     }
     if ($column->isInheritance()) {
         $columnNode->setAttribute('inheritance', $column->getInheritanceType());
         foreach ($column->getInheritanceList() as $inheritance) {
             $this->appendInheritanceNode($inheritance, $columnNode);
         }
     }
     if ($column->isNodeKey()) {
         $columnNode->setAttribute('nodeKey', 'true');
         if ($nodeKeySeparator = $column->getNodeKeySep()) {
             $columnNode->setAttribute('nodeKeySep', $nodeKeySeparator);
         }
     }
     foreach ($column->getVendorInformation() as $vendorInformation) {
         $this->appendVendorInformationNode($vendorInformation, $columnNode);
     }
 }
コード例 #21
0
 /**
  * Builds the DDL SQL to remove a column
  *
  * @return string
  */
 public function getRemoveColumnDDL(Column $column)
 {
     $pattern = "\nALTER TABLE %s DROP %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($column->getTable()->getName()), $this->quoteIdentifier($column->getName()));
 }
コード例 #22
0
 /**
  * @param Column $column
  *
  * @return bool
  *
  * @throws PropelException
  */
 protected function isColumnForeignKeyOrDuplicated(Column $column)
 {
     $delegateTable = $column->getTable();
     $table = $this->getTable();
     $fks = [];
     foreach ($delegateTable->getForeignKeysReferencingTable($table->getName()) as $fk) {
         /** @var \Propel\Generator\Model\ForeignKey $fk */
         $fks[] = $fk->getForeignColumnName();
     }
     foreach ($table->getForeignKeysReferencingTable($delegateTable->getName()) as $fk) {
         $fks[] = $fk->getForeignColumnName();
     }
     if (in_array($column->getName(), $fks)) {
         return true;
     } else {
         if ($table->hasColumn($column->getName())) {
             throw new PropelException('Column with name «' . $column->getName() . '» (delegated from table «' . $delegateTable->getName() . '») already exists in table «' . $table->getName() . '». Probably database design mistake');
         }
         return false;
     }
 }