| @@ 83-127 (lines=45) @@ | ||
| 80 | 'ezkeyword' => array(), |
|
| 81 | ); |
|
| 82 | $handler = $this->getDatabaseHandler(); |
|
| 83 | foreach ($data as $table => $rows) { |
|
| 84 | // Cleanup before inserting |
|
| 85 | $deleteQuery = $handler->createDeleteQuery(); |
|
| 86 | $deleteQuery->deleteFrom($handler->quoteIdentifier($table)); |
|
| 87 | $stmt = $deleteQuery->prepare(); |
|
| 88 | $stmt->execute(); |
|
| 89 | ||
| 90 | // Check that at least one row exists |
|
| 91 | if (!isset($rows[0])) { |
|
| 92 | continue; |
|
| 93 | } |
|
| 94 | ||
| 95 | $q = $handler->createInsertQuery(); |
|
| 96 | $q->insertInto($handler->quoteIdentifier($table)); |
|
| 97 | ||
| 98 | // Contains the bound parameters |
|
| 99 | $values = array(); |
|
| 100 | ||
| 101 | // Binding the parameters |
|
| 102 | foreach ($rows[0] as $col => $val) { |
|
| 103 | $q->set( |
|
| 104 | $handler->quoteIdentifier($col), |
|
| 105 | $q->bindParam($values[$col]) |
|
| 106 | ); |
|
| 107 | } |
|
| 108 | ||
| 109 | $stmt = $q->prepare(); |
|
| 110 | ||
| 111 | foreach ($rows as $row) { |
|
| 112 | try { |
|
| 113 | // This CANNOT be replaced by: |
|
| 114 | // $values = $row |
|
| 115 | // each $values[$col] is a PHP reference which should be |
|
| 116 | // kept for parameters binding to work |
|
| 117 | foreach ($row as $col => $val) { |
|
| 118 | $values[$col] = $val; |
|
| 119 | } |
|
| 120 | ||
| 121 | $stmt->execute(); |
|
| 122 | } catch (Exception $e) { |
|
| 123 | echo "$table ( ", implode(', ', $row), " )\n"; |
|
| 124 | throw $e; |
|
| 125 | } |
|
| 126 | } |
|
| 127 | } |
|
| 128 | ||
| 129 | $this->applyStatements($this->getPostInsertStatements($dbType)); |
|
| 130 | } |
|
| @@ 180-222 (lines=43) @@ | ||
| 177 | $data['ezmedia'] = array(); |
|
| 178 | $data['ezkeyword'] = array(); |
|
| 179 | ||
| 180 | foreach ($data as $table => $rows) { |
|
| 181 | // Cleanup before inserting (using TRUNCATE for speed, however not possible to rollback) |
|
| 182 | $q = $dbPlatform->getTruncateTableSql($handler->quoteIdentifier($table)); |
|
| 183 | $connection->executeUpdate($q); |
|
| 184 | ||
| 185 | // Check that at least one row exists |
|
| 186 | if (!isset($rows[0])) { |
|
| 187 | continue; |
|
| 188 | } |
|
| 189 | ||
| 190 | $q = $handler->createInsertQuery(); |
|
| 191 | $q->insertInto($handler->quoteIdentifier($table)); |
|
| 192 | ||
| 193 | // Contains the bound parameters |
|
| 194 | $values = array(); |
|
| 195 | ||
| 196 | // Binding the parameters |
|
| 197 | foreach ($rows[0] as $col => $val) { |
|
| 198 | $q->set( |
|
| 199 | $handler->quoteIdentifier($col), |
|
| 200 | $q->bindParam($values[$col]) |
|
| 201 | ); |
|
| 202 | } |
|
| 203 | ||
| 204 | $stmt = $q->prepare(); |
|
| 205 | ||
| 206 | foreach ($rows as $row) { |
|
| 207 | try { |
|
| 208 | // This CANNOT be replaced by: |
|
| 209 | // $values = $row |
|
| 210 | // each $values[$col] is a PHP reference which should be |
|
| 211 | // kept for parameters binding to work |
|
| 212 | foreach ($row as $col => $val) { |
|
| 213 | $values[$col] = $val; |
|
| 214 | } |
|
| 215 | ||
| 216 | $stmt->execute(); |
|
| 217 | } catch (Exception $e) { |
|
| 218 | echo "$table ( ", implode(', ', $row), " )\n"; |
|
| 219 | throw $e; |
|
| 220 | } |
|
| 221 | } |
|
| 222 | } |
|
| 223 | ||
| 224 | $this->applyStatements($this->getPostInsertStatements()); |
|
| 225 | } |
|