|
@@ 149-160 (lines=12) @@
|
| 146 |
|
$this->assertLastInsertIdAfterTruncate($this->createQueryInsertExecutor()); |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
private function assertLastInsertIdAfterTruncate(callable $insertExecutor) |
| 150 |
|
{ |
| 151 |
|
if (! $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { |
| 152 |
|
$this->markTestSkipped('Test only works on platforms with identity columns.'); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
$insertExecutor(); |
| 156 |
|
$truncateTableSql = $this->testConnection->getDatabasePlatform()->getTruncateTableSQL('last_insert_id_table'); |
| 157 |
|
$this->testConnection->exec($truncateTableSql); |
| 158 |
|
|
| 159 |
|
$this->assertSame('1', $this->testConnection->lastInsertId()); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
public function testLastInsertIdAfterDropTableExec() |
| 163 |
|
{ |
|
@@ 177-189 (lines=13) @@
|
| 174 |
|
$this->assertLastInsertIdAfterDropTable($this->createQueryInsertExecutor()); |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
private function assertLastInsertIdAfterDropTable(callable $insertExecutor) |
| 178 |
|
{ |
| 179 |
|
if (! $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { |
| 180 |
|
$this->markTestSkipped('Test only works on platforms with identity columns.'); |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
$this->createTable('last_insert_id_table_tmp'); |
| 184 |
|
|
| 185 |
|
$insertExecutor(); |
| 186 |
|
$this->testConnection->getSchemaManager()->dropTable('last_insert_id_table_tmp'); |
| 187 |
|
|
| 188 |
|
$this->assertSame('1', $this->testConnection->lastInsertId()); |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
public function testLastInsertIdAfterSelectExec() |
| 192 |
|
{ |
|
@@ 233-243 (lines=11) @@
|
| 230 |
|
$this->assertLastInsertIdInTransaction($this->createQueryInsertExecutor()); |
| 231 |
|
} |
| 232 |
|
|
| 233 |
|
public function assertLastInsertIdInTransaction(callable $insertExecutor) |
| 234 |
|
{ |
| 235 |
|
if (! $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { |
| 236 |
|
$this->markTestSkipped('Test only works on platforms with identity columns.'); |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
$this->testConnection->beginTransaction(); |
| 240 |
|
$insertExecutor(); |
| 241 |
|
$this->assertSame('1', $this->testConnection->lastInsertId()); |
| 242 |
|
$this->testConnection->rollBack(); |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
public function testLastInsertIdAfterTransactionCommitExec() |
| 246 |
|
{ |
|
@@ 260-271 (lines=12) @@
|
| 257 |
|
$this->assertLastInsertIdAfterTransactionCommit($this->createQueryInsertExecutor()); |
| 258 |
|
} |
| 259 |
|
|
| 260 |
|
private function assertLastInsertIdAfterTransactionCommit(callable $insertExecutor) |
| 261 |
|
{ |
| 262 |
|
if (! $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { |
| 263 |
|
$this->markTestSkipped('Test only works on platforms with identity columns.'); |
| 264 |
|
} |
| 265 |
|
|
| 266 |
|
$this->testConnection->beginTransaction(); |
| 267 |
|
$insertExecutor(); |
| 268 |
|
$this->testConnection->commit(); |
| 269 |
|
|
| 270 |
|
$this->assertSame('1', $this->testConnection->lastInsertId()); |
| 271 |
|
} |
| 272 |
|
|
| 273 |
|
public function testLastInsertIdAfterTransactionRollbackExec() |
| 274 |
|
{ |
|
@@ 288-299 (lines=12) @@
|
| 285 |
|
$this->assertLastInsertIdAfterTransactionRollback($this->createQueryInsertExecutor()); |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
private function assertLastInsertIdAfterTransactionRollback(callable $insertExecutor) |
| 289 |
|
{ |
| 290 |
|
if (! $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { |
| 291 |
|
$this->markTestSkipped('Test only works on platforms with identity columns.'); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
$this->testConnection->beginTransaction(); |
| 295 |
|
$insertExecutor(); |
| 296 |
|
$this->testConnection->rollBack(); |
| 297 |
|
|
| 298 |
|
$this->assertSame('1', $this->testConnection->lastInsertId()); |
| 299 |
|
} |
| 300 |
|
|
| 301 |
|
public function testLastInsertIdInsertAfterTransactionRollbackExec() |
| 302 |
|
{ |
|
@@ 316-334 (lines=19) @@
|
| 313 |
|
$this->assertLastInsertIdInsertAfterTransactionRollback($this->createQueryInsertExecutor()); |
| 314 |
|
} |
| 315 |
|
|
| 316 |
|
private function assertLastInsertIdInsertAfterTransactionRollback(callable $insertExecutor) |
| 317 |
|
{ |
| 318 |
|
if (! $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { |
| 319 |
|
$this->markTestSkipped('Test only works on platforms with identity columns.'); |
| 320 |
|
} |
| 321 |
|
|
| 322 |
|
$this->testConnection->beginTransaction(); |
| 323 |
|
$insertExecutor(); |
| 324 |
|
$this->testConnection->rollBack(); |
| 325 |
|
$insertExecutor(); |
| 326 |
|
|
| 327 |
|
$expected = $this->testConnection->getDatabasePlatform()->getName() === 'sqlite' |
| 328 |
|
// SQLite has a different transaction concept, that reuses rolled back IDs |
| 329 |
|
// See: http://sqlite.1065341.n5.nabble.com/Autoincrement-with-rollback-td79154.html |
| 330 |
|
? '1' |
| 331 |
|
: '2'; |
| 332 |
|
|
| 333 |
|
$this->assertSame($expected, $this->testConnection->lastInsertId()); |
| 334 |
|
} |
| 335 |
|
|
| 336 |
|
public function testLastInsertIdReusePreparedStatementPrepare() |
| 337 |
|
{ |
|
@@ 336-348 (lines=13) @@
|
| 333 |
|
$this->assertSame($expected, $this->testConnection->lastInsertId()); |
| 334 |
|
} |
| 335 |
|
|
| 336 |
|
public function testLastInsertIdReusePreparedStatementPrepare() |
| 337 |
|
{ |
| 338 |
|
if (! $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { |
| 339 |
|
$this->markTestSkipped('Test only works on platforms with identity columns.'); |
| 340 |
|
} |
| 341 |
|
|
| 342 |
|
$statement = $this->testConnection->prepare('INSERT INTO last_insert_id_table (foo) VALUES (1)'); |
| 343 |
|
|
| 344 |
|
$statement->execute(); |
| 345 |
|
$statement->execute(); |
| 346 |
|
|
| 347 |
|
$this->assertSame('2', $this->testConnection->lastInsertId()); |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
public function testLastInsertIdReusePreparedStatementQuery() |
| 351 |
|
{ |
|
@@ 350-361 (lines=12) @@
|
| 347 |
|
$this->assertSame('2', $this->testConnection->lastInsertId()); |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
public function testLastInsertIdReusePreparedStatementQuery() |
| 351 |
|
{ |
| 352 |
|
if (! $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { |
| 353 |
|
$this->markTestSkipped('Test only works on platforms with identity columns.'); |
| 354 |
|
} |
| 355 |
|
|
| 356 |
|
$statement = $this->testConnection->query('INSERT INTO last_insert_id_table (foo) VALUES (1)'); |
| 357 |
|
|
| 358 |
|
$statement->execute(); |
| 359 |
|
|
| 360 |
|
$this->assertSame('2', $this->testConnection->lastInsertId()); |
| 361 |
|
} |
| 362 |
|
|
| 363 |
|
public function testLastInsertIdConnectionScope() |
| 364 |
|
{ |