@@ -1598,81 +1598,8 @@ public function setSearchPath(): void
1598
1598
/**
1599
1599
* @inheritDoc
1600
1600
*/
1601
- public function insert ( Table $ table , array $ row ): void
1601
+ protected function getInsertOverride ( ): string
1602
1602
{
1603
- $ sql = sprintf (
1604
- 'INSERT INTO %s ' ,
1605
- $ this ->quoteTableName ($ table ->getName ())
1606
- );
1607
- $ columns = array_keys ($ row );
1608
- $ sql .= '( ' . implode (', ' , array_map ([$ this , 'quoteColumnName ' ], $ columns )) . ') ' ;
1609
-
1610
- foreach ($ row as $ column => $ value ) {
1611
- if (is_bool ($ value )) {
1612
- $ row [$ column ] = $ this ->castToBool ($ value );
1613
- }
1614
- }
1615
-
1616
- $ override = '' ;
1617
- if ($ this ->useIdentity ) {
1618
- $ override = self ::OVERRIDE_SYSTEM_VALUE . ' ' ;
1619
- }
1620
-
1621
- if ($ this ->isDryRunEnabled ()) {
1622
- $ sql .= ' ' . $ override . 'VALUES ( ' . implode (', ' , array_map ([$ this , 'quoteValue ' ], $ row )) . '); ' ;
1623
- $ this ->output ->writeln ($ sql );
1624
- } else {
1625
- $ sql .= ' ' . $ override . 'VALUES ( ' . implode (', ' , array_fill (0 , count ($ columns ), '? ' )) . ') ' ;
1626
- $ stmt = $ this ->getConnection ()->prepare ($ sql );
1627
- $ stmt ->execute (array_values ($ row ));
1628
- }
1629
- }
1630
-
1631
- /**
1632
- * @inheritDoc
1633
- */
1634
- public function bulkinsert (Table $ table , array $ rows ): void
1635
- {
1636
- $ sql = sprintf (
1637
- 'INSERT INTO %s ' ,
1638
- $ this ->quoteTableName ($ table ->getName ())
1639
- );
1640
- $ current = current ($ rows );
1641
- $ keys = array_keys ($ current );
1642
-
1643
- $ override = '' ;
1644
- if ($ this ->useIdentity ) {
1645
- $ override = self ::OVERRIDE_SYSTEM_VALUE . ' ' ;
1646
- }
1647
-
1648
- $ sql .= '( ' . implode (', ' , array_map ([$ this , 'quoteColumnName ' ], $ keys )) . ') ' . $ override . 'VALUES ' ;
1649
-
1650
- if ($ this ->isDryRunEnabled ()) {
1651
- $ values = array_map (function ($ row ) {
1652
- return '( ' . implode (', ' , array_map ([$ this , 'quoteValue ' ], $ row )) . ') ' ;
1653
- }, $ rows );
1654
- $ sql .= implode (', ' , $ values ) . '; ' ;
1655
- $ this ->output ->writeln ($ sql );
1656
- } else {
1657
- $ count_keys = count ($ keys );
1658
- $ query = '( ' . implode (', ' , array_fill (0 , $ count_keys , '? ' )) . ') ' ;
1659
- $ count_vars = count ($ rows );
1660
- $ queries = array_fill (0 , $ count_vars , $ query );
1661
- $ sql .= implode (', ' , $ queries );
1662
- $ stmt = $ this ->getConnection ()->prepare ($ sql );
1663
- $ vals = [];
1664
-
1665
- foreach ($ rows as $ row ) {
1666
- foreach ($ row as $ v ) {
1667
- if (is_bool ($ v )) {
1668
- $ vals [] = $ this ->castToBool ($ v );
1669
- } else {
1670
- $ vals [] = $ v ;
1671
- }
1672
- }
1673
- }
1674
-
1675
- $ stmt ->execute ($ vals );
1676
- }
1603
+ return $ this ->useIdentity ? self ::OVERRIDE_SYSTEM_VALUE . ' ' : '' ;
1677
1604
}
1678
1605
}
0 commit comments