protected function insert() {
		$conn = static::getConnection();
		$pk = static::getPrimaryKey();

		$fields = array();
		$values = array();
		$placeholders = array();
		foreach (static::$_columns as $column_name => &$type) {
			$value = $this->$column_name;
			if ($value === null && !$this->isColumnModified($column_name))
				continue;
			$fields[] = $conn->quoteIdentifier($column_name, true);
			$values[] = $value;
			$placeholders[] = '?';
		}

		$quoted_table = $conn->quoteIdentifier(static::getTableName(), true);
		$query_s = 'INSERT INTO ' . $quoted_table . ' (' . implode(', ', $fields) . ')';

		if ($pk && $this->isAutoIncrement() && $conn instanceof DBMSSQL) {
			$query_s .= " OUTPUT inserted.$pk";
		}

		$query_s .= ' VALUES (' . implode(', ', $placeholders) . ') ';

		if ($pk && $this->isAutoIncrement() && $conn instanceof DBPostgres) {
			$query_s .= ' RETURNING ' . $conn->quoteIdentifier($pk, true);
		}

		$statement = new QueryStatement($conn);
		$statement->setString($query_s);
		$statement->setParams($values);

		$result = $statement->bindAndExecute();
		$count = $result->rowCount();

		if ($pk && $this->isAutoIncrement()) {
			$id = null;
			if (($conn instanceof DBPostgres) || ($conn instanceof DBMSSQL)) {
				$id = $result->fetchColumn(0);
			} elseif ($conn->isGetIdAfterInsert()) {
				$id = $conn->lastInsertId();
				if (empty($id) && $conn instanceof DBRedshift) {
					$id = $conn->query('SELECT MAX(' . $conn->quoteIdentifier($pk) . ") FROM $quoted_table")->fetchColumn();
				}
			}
			if (null !== $id) {
				$this->{"set$pk"}($id);
			}
		}

		$this->resetModified();
		$this->setNew(false);

		$this->insertIntoPool($this);

		return $count;
	}
protected function insert() {
		$conn = static::getConnection();
		$pk = static::getPrimaryKey();

		$fields = array();
		$values = array();
		$placeholders = array();
		foreach (static::$_columns as $column_name => &$type) {
			$value = $this->$column_name;
			if ($value === null && !$this->isColumnModified($column_name))
				continue;
			$fields[] = $conn->quoteIdentifier($column_name, true);
			$values[] = $value;
			$placeholders[] = '?';
		}

		$quoted_table = $conn->quoteIdentifier(static::getTableName(), true);
		$query_s = 'INSERT INTO ' . $quoted_table . ' (' . implode(', ', $fields) . ')';

		if ($pk && $this->isAutoIncrement() && $conn instanceof DBMSSQL) {
			$query_s .= " OUTPUT inserted.$pk";
		}

		$query_s .= ' VALUES (' . implode(', ', $placeholders) . ') ';

		if ($pk && $this->isAutoIncrement() && $conn instanceof DBPostgres) {
			$query_s .= ' RETURNING ' . $conn->quoteIdentifier($pk, true);
		}

		$statement = new QueryStatement($conn);
		$statement->setString($query_s);
		$statement->setParams($values);

		$result = $statement->bindAndExecute();
		$count = $result->rowCount();

		if ($pk && $this->isAutoIncrement()) {
			$id = null;
			if (($conn instanceof DBPostgres) || ($conn instanceof DBMSSQL)) {
				$id = $result->fetchColumn(0);
			} elseif ($conn->isGetIdAfterInsert()) {
				$id = $conn->lastInsertId();
				if (empty($id) && $conn instanceof DBRedshift) {
					$id = $conn->query('SELECT MAX(' . $conn->quoteIdentifier($pk) . ") FROM $quoted_table")->fetchColumn();
				}
			}
			if (null !== $id) {
				$this->{"set$pk"}($id);
			}
		}

		$this->resetModified();
		$this->setNew(false);

		$this->insertIntoPool($this);

		return $count;
	}
protected function insert ( ) { $ conn = static :: getConnection ( ) ; $ pk = static :: getPrimaryKey ( ) ; $ fields = array ( ) ; $ values = array ( ) ; $ placeholders = array ( ) ; foreach ( static :: $ _columns as $ column_name => & $ type ) { $ value = $ this -> $ column_name ; if ( $ value === null && ! $ this -> isColumnModified ( $ column_name ) ) continue ; $ fields [ ] = $ conn -> quoteIdentifier ( $ column_name , true ) ; $ values [ ] = $ value ; $ placeholders [ ] = '?' ; } $ quoted_table = $ conn -> quoteIdentifier ( static :: getTableName ( ) , true ) ; $ query_s = 'INSERT INTO ' . $ quoted_table . ' (' . implode ( ', ' , $ fields ) . ')' ; if ( $ pk && $ this -> isAutoIncrement ( ) && $ conn instanceof DBMSSQL ) { $ query_s .= " OUTPUT inserted.$pk" ; } $ query_s .= ' VALUES (' . implode ( ', ' , $ placeholders ) . ') ' ; if ( $ pk && $ this -> isAutoIncrement ( ) && $ conn instanceof DBPostgres ) { $ query_s .= ' RETURNING ' . $ conn -> quoteIdentifier ( $ pk , true ) ; } $ statement = new QueryStatement ( $ conn ) ; $ statement -> setString ( $ query_s ) ; $ statement -> setParams ( $ values ) ; $ result = $ statement -> bindAndExecute ( ) ; $ count = $ result -> rowCount ( ) ; if ( $ pk && $ this -> isAutoIncrement ( ) ) { $ id = null ; if ( ( $ conn instanceof DBPostgres ) || ( $ conn instanceof DBMSSQL ) ) { $ id = $ result -> fetchColumn ( 0 ) ; } elseif ( $ conn -> isGetIdAfterInsert ( ) ) { $ id = $ conn -> lastInsertId ( ) ; if ( empty ( $ id ) && $ conn instanceof DBRedshift ) { $ id = $ conn -> query ( 'SELECT MAX(' . $ conn -> quoteIdentifier ( $ pk ) . ") FROM $quoted_table" ) -> fetchColumn ( ) ; } } if ( null !== $ id ) { $ this -> { "set$pk" } ( $ id ) ; } } $ this -> resetModified ( ) ; $ this -> setNew ( false ) ; $ this -> insertIntoPool ( $ this ) ; return $ count ; }
Creates and executes INSERT query string for this object
@return int
Creates and executes INSERT query string for this object