/** * Gets the INSERT SQL used by the persister to persist a new entity. * * @return string */ protected function _getInsertSQL() { if ($this->_insertSql === null) { $insertSql = ''; $columns = $this->_getInsertColumnList(); if (empty($columns)) { $insertSql = $this->_platform->getEmptyIdentityInsertSQL($this->_class->getQuotedTableName($this->_platform), $this->_class->getQuotedColumnName($this->_class->identifier[0], $this->_platform)); } else { $columns = array_unique($columns); $values = array_fill(0, count($columns), '?'); $insertSql = 'INSERT INTO ' . $this->_class->getQuotedTableName($this->_platform) . ' (' . implode(', ', $columns) . ') ' . 'VALUES (' . implode(', ', $values) . ')'; } $this->_insertSql = $insertSql; } return $this->_insertSql; }
/** * Gets the INSERT SQL used by the persister to persist a new entity. * * @return string */ protected function _getInsertSQL() { if ($this->_insertSql === null) { $insertSql = ''; $columns = $this->_getInsertColumnList(); if (empty($columns)) { $insertSql = $this->_platform->getEmptyIdentityInsertSQL($this->_class->getQuotedTableName($this->_platform), $this->_class->getQuotedColumnName($this->_class->identifier[0], $this->_platform)); } else { $columns = array_unique($columns); $values = array(); foreach ($columns as $column) { $placeholder = '?'; if (isset($this->_columnTypes[$column]) && isset($this->_class->fieldMappings[$this->_class->fieldNames[$column]]['requireSQLConversion'])) { $type = Type::getType($this->_columnTypes[$column]); $placeholder = $type->convertToDatabaseValueSQL('?', $this->_platform); } $values[] = $placeholder; } $insertSql = 'INSERT INTO ' . $this->_class->getQuotedTableName($this->_platform) . ' (' . implode(', ', $columns) . ') VALUES (' . implode(', ', $values) . ')'; } $this->_insertSql = $insertSql; } return $this->_insertSql; }
/** * Gets the INSERT SQL used by the persister to persist a new entity. * * @return string */ protected function getInsertSQL() { if ($this->insertSql !== null) { return $this->insertSql; } $columns = $this->getInsertColumnList(); $tableName = $this->quoteStrategy->getTableName($this->class, $this->platform); if (empty($columns)) { $identityColumn = $this->quoteStrategy->getColumnName($this->class->identifier[0], $this->class, $this->platform); $this->insertSql = $this->platform->getEmptyIdentityInsertSQL($tableName, $identityColumn); return $this->insertSql; } $values = array(); $columns = array_unique($columns); foreach ($columns as $column) { $placeholder = '?'; if (isset($this->class->fieldNames[$column]) && isset($this->columnTypes[$this->class->fieldNames[$column]]) && isset($this->class->fieldMappings[$this->class->fieldNames[$column]]['requireSQLConversion'])) { $type = Type::getType($this->columnTypes[$this->class->fieldNames[$column]]); $placeholder = $type->convertToDatabaseValueSQL('?', $this->platform); } $values[] = $placeholder; } $columns = implode(', ', $columns); $values = implode(', ', $values); $this->insertSql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $tableName, $columns, $values); return $this->insertSql; }