| @@ 707-763 (lines=57) @@ | ||
| 704 | * @throws PropelException |
|
| 705 | * @see doSave() |
|
| 706 | */ |
|
| 707 | protected function doInsert(ConnectionInterface $con) |
|
| 708 | { |
|
| 709 | $modifiedColumns = array(); |
|
| 710 | $index = 0; |
|
| 711 | ||
| 712 | $this->modifiedColumns[ChannelTableMap::COL_ID] = true; |
|
| 713 | if (null !== $this->id) { |
|
| 714 | throw new PropelException('Cannot insert a value for auto-increment primary key (' . ChannelTableMap::COL_ID . ')'); |
|
| 715 | } |
|
| 716 | ||
| 717 | // check the columns in natural order for more readable SQL queries |
|
| 718 | if ($this->isColumnModified(ChannelTableMap::COL_ID)) { |
|
| 719 | $modifiedColumns[':p' . $index++] = 'id'; |
|
| 720 | } |
|
| 721 | if ($this->isColumnModified(ChannelTableMap::COL_INSTANCE_NAME)) { |
|
| 722 | $modifiedColumns[':p' . $index++] = 'instance_name'; |
|
| 723 | } |
|
| 724 | if ($this->isColumnModified(ChannelTableMap::COL_NAME)) { |
|
| 725 | $modifiedColumns[':p' . $index++] = 'name'; |
|
| 726 | } |
|
| 727 | ||
| 728 | $sql = sprintf( |
|
| 729 | 'INSERT INTO channel (%s) VALUES (%s)', |
|
| 730 | implode(', ', $modifiedColumns), |
|
| 731 | implode(', ', array_keys($modifiedColumns)) |
|
| 732 | ); |
|
| 733 | ||
| 734 | try { |
|
| 735 | $stmt = $con->prepare($sql); |
|
| 736 | foreach ($modifiedColumns as $identifier => $columnName) { |
|
| 737 | switch ($columnName) { |
|
| 738 | case 'id': |
|
| 739 | $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); |
|
| 740 | break; |
|
| 741 | case 'instance_name': |
|
| 742 | $stmt->bindValue($identifier, $this->instance_name, PDO::PARAM_STR); |
|
| 743 | break; |
|
| 744 | case 'name': |
|
| 745 | $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); |
|
| 746 | break; |
|
| 747 | } |
|
| 748 | } |
|
| 749 | $stmt->execute(); |
|
| 750 | } catch (Exception $e) { |
|
| 751 | Propel::log($e->getMessage(), Propel::LOG_ERR); |
|
| 752 | throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); |
|
| 753 | } |
|
| 754 | ||
| 755 | try { |
|
| 756 | $pk = $con->lastInsertId(); |
|
| 757 | } catch (Exception $e) { |
|
| 758 | throw new PropelException('Unable to get autoincrement id.', 0, $e); |
|
| 759 | } |
|
| 760 | $this->setId($pk); |
|
| 761 | ||
| 762 | $this->setNew(false); |
|
| 763 | } |
|
| 764 | ||
| 765 | /** |
|
| 766 | * Update the row in the database. |
|
| @@ 743-799 (lines=57) @@ | ||
| 740 | * @throws PropelException |
|
| 741 | * @see doSave() |
|
| 742 | */ |
|
| 743 | protected function doInsert(ConnectionInterface $con) |
|
| 744 | { |
|
| 745 | $modifiedColumns = array(); |
|
| 746 | $index = 0; |
|
| 747 | ||
| 748 | $this->modifiedColumns[UserTableMap::COL_ID] = true; |
|
| 749 | if (null !== $this->id) { |
|
| 750 | throw new PropelException('Cannot insert a value for auto-increment primary key (' . UserTableMap::COL_ID . ')'); |
|
| 751 | } |
|
| 752 | ||
| 753 | // check the columns in natural order for more readable SQL queries |
|
| 754 | if ($this->isColumnModified(UserTableMap::COL_ID)) { |
|
| 755 | $modifiedColumns[':p' . $index++] = 'id'; |
|
| 756 | } |
|
| 757 | if ($this->isColumnModified(UserTableMap::COL_INSTANCE_NAME)) { |
|
| 758 | $modifiedColumns[':p' . $index++] = 'instance_name'; |
|
| 759 | } |
|
| 760 | if ($this->isColumnModified(UserTableMap::COL_NAME)) { |
|
| 761 | $modifiedColumns[':p' . $index++] = 'name'; |
|
| 762 | } |
|
| 763 | ||
| 764 | $sql = sprintf( |
|
| 765 | 'INSERT INTO user (%s) VALUES (%s)', |
|
| 766 | implode(', ', $modifiedColumns), |
|
| 767 | implode(', ', array_keys($modifiedColumns)) |
|
| 768 | ); |
|
| 769 | ||
| 770 | try { |
|
| 771 | $stmt = $con->prepare($sql); |
|
| 772 | foreach ($modifiedColumns as $identifier => $columnName) { |
|
| 773 | switch ($columnName) { |
|
| 774 | case 'id': |
|
| 775 | $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); |
|
| 776 | break; |
|
| 777 | case 'instance_name': |
|
| 778 | $stmt->bindValue($identifier, $this->instance_name, PDO::PARAM_STR); |
|
| 779 | break; |
|
| 780 | case 'name': |
|
| 781 | $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); |
|
| 782 | break; |
|
| 783 | } |
|
| 784 | } |
|
| 785 | $stmt->execute(); |
|
| 786 | } catch (Exception $e) { |
|
| 787 | Propel::log($e->getMessage(), Propel::LOG_ERR); |
|
| 788 | throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); |
|
| 789 | } |
|
| 790 | ||
| 791 | try { |
|
| 792 | $pk = $con->lastInsertId(); |
|
| 793 | } catch (Exception $e) { |
|
| 794 | throw new PropelException('Unable to get autoincrement id.', 0, $e); |
|
| 795 | } |
|
| 796 | $this->setId($pk); |
|
| 797 | ||
| 798 | $this->setNew(false); |
|
| 799 | } |
|
| 800 | ||
| 801 | /** |
|
| 802 | * Update the row in the database. |
|