/** * Create a new database connection mock object for every test. * * @return void */ protected function setUp() { parent::setUp(); $this->concreteQueryBuilder = $this->prophesize(\Doctrine\DBAL\Query\QueryBuilder::class); $this->connection = $this->prophesize(Connection::class); $this->connection->getDatabasePlatform()->willReturn(new MockPlatform()); $this->subject = GeneralUtility::makeInstance(QueryBuilder::class, $this->connection->reveal(), null, $this->concreteQueryBuilder->reveal()); }
/** * Create a new database connection mock object for every test. * * @return void */ protected function setUp() { parent::setUp(); $this->connection = $this->prophesize(Connection::class); $this->connection->quoteIdentifier(Argument::cetera())->will(function ($args) { return '"' . join('"."', explode('.', $args[0])) . '"'; }); $this->connection->quote(Argument::cetera())->will(function ($args) { return "'" . $args[0] . "'"; }); $this->connection->getDatabasePlatform()->willReturn(new MockPlatform()); $this->queryContext = GeneralUtility::makeInstance(QueryContext::class); $this->expressionBuilder = GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal()); }
/** * Creates a bitwise AND expression with the given arguments. * * @param string $fieldName The fieldname. Will be quoted according to database platform automatically. * @param int $value Argument to be used in the bitwise AND operation * @return string */ public function bitAnd(string $fieldName, int $value) : string { switch ($this->connection->getDatabasePlatform()->getName()) { case 'oci8': case 'pdo_oracle': return sprintf('BITAND(%s, %s)', $this->connection->quoteIdentifier($fieldName), $value); default: return $this->comparison($this->connection->quoteIdentifier($fieldName), '&', $value); } }
/** * @test */ public function bitwiseAndForOracle() { $databasePlatform = $this->prophesize(MockPlatform::class); $databasePlatform->getName()->willReturn('pdo_oracle'); $this->connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($args) { return '"' . $args[0] . '"'; }); $this->connectionProphet->getDatabasePlatform()->willReturn($databasePlatform->reveal()); $this->assertSame('BITAND("aField", 1)', $this->subject->bitAnd('aField', 1)); }
/** * Transform the table information to conform to specific * requirements of different database platforms like removing * the index substring length for Non-MySQL Platforms. * * @param Table[] $tables * @param \TYPO3\CMS\Core\Database\Connection $connection * @return Table[] * @throws \InvalidArgumentException */ protected function transformTablesForDatabasePlatform(array $tables, Connection $connection) : array { foreach ($tables as &$table) { $indexes = []; foreach ($table->getIndexes() as $key => $index) { $indexName = $index->getName(); // PostgreSQL requires index names to be unique per database/schema. if ($connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { $indexName = $indexName . '_' . hash('crc32b', $table->getName() . '_' . $indexName); } // Remove the length information from column names for indexes if required. $cleanedColumnNames = array_map(function (string $columnName) use($connection) { if ($connection->getDatabasePlatform() instanceof MySqlPlatform) { // Returning the unquoted, unmodified version of the column name since // it can include the length information for BLOB/TEXT columns which // may not be quoted. return $columnName; } return $connection->quoteIdentifier(preg_replace('/\\(\\d+\\)$/', '', $columnName)); }, $index->getUnquotedColumns()); $indexes[$key] = GeneralUtility::makeInstance(Index::class, $connection->quoteIdentifier($indexName), $cleanedColumnNames, $index->isUnique(), $index->isPrimary(), $index->getFlags(), $index->getOptions()); } $table = GeneralUtility::makeInstance(Table::class, $table->getQuotedName($connection->getDatabasePlatform()), $table->getColumns(), $indexes, $table->getForeignKeys(), 0, $table->getOptions()); } return $tables; }