Storm\Drivers\Base\Relational\PrimaryKeys\ReturningDataKeyGenerator::FillPrimaryKeys PHP Method

FillPrimaryKeys() public method

public FillPrimaryKeys ( IConnection $Connection, array $UnkeyedRows, array $ReturnedKeyData )
$Connection IConnection
$UnkeyedRows array
$ReturnedKeyData array
    public function FillPrimaryKeys(IConnection $Connection, array $UnkeyedRows, array $ReturnedKeyData)
    {
        if (count($UnkeyedRows) !== count($ReturnedKeyData)) {
            throw new \Storm\Core\Relational\RelationalException('The amouny unkeyed rows must match the amount of returned key data arrays: %d rows != %d key data', count($UnkeyedRows), count($ReturnedKeyData));
        } else {
            $this->FillPrimaryKeyValues($Connection, array_values($UnkeyedRows), array_values($ReturnedKeyData));
        }
    }

Usage Example

Example #1
0
 protected final function SaveRows(IConnection $Connection, Table $Table, array $RowsWithoutPrimaryKey, array $RowsWithPrimaryKeys, ReturningDataKeyGenerator $ReturningDataKeyGenerator = null, PostIndividualInsertKeyGenerator $PostIndividualInsertKeyGenerator = null)
 {
     if (count($RowsWithPrimaryKeys) === 0 && count($RowsWithoutPrimaryKey) === 0) {
         return;
     }
     $RowsToUpsert = null;
     if ($PostIndividualInsertKeyGenerator !== null) {
         $this->InsertRowsIndividually($Connection, $Table, $RowsWithoutPrimaryKey, function (Relational\Row $Row) use(&$Connection, &$PostIndividualInsertKeyGenerator) {
             $PostIndividualInsertKeyGenerator->FillPrimaryKey($Connection, $Row);
         });
         $RowsToUpsert = $RowsWithPrimaryKeys;
     } else {
         $RowsToUpsert = array_merge($RowsWithoutPrimaryKey, $RowsWithPrimaryKeys);
     }
     if (count($RowsToUpsert) > 0) {
         $ShouldReturnKeyData = $ReturningDataKeyGenerator !== null;
         $ReturnedKeyData = $this->UpsertRows($Connection, $Table, $RowsToUpsert, $ShouldReturnKeyData);
         if ($ShouldReturnKeyData) {
             $ReturningDataKeyGenerator->FillPrimaryKeys($Connection, $RowsWithoutPrimaryKey, $ReturnedKeyData);
         }
     }
 }