-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added designation type lastInsertId.
- Loading branch information
Showing
8 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace SetBased\Stratum\SqlitePdo\Wrapper; | ||
|
||
/** | ||
* Class for generating a wrapper method for a stored procedure that insert rows in a table with an auto increment key. | ||
*/ | ||
class LastInsertIdWrapper extends Wrapper | ||
{ | ||
//-------------------------------------------------------------------------------------------------------------------- | ||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getDocBlockReturnType(): string | ||
{ | ||
return 'int'; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------------------------- | ||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getReturnTypeDeclaration(): string | ||
{ | ||
return ': int'; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------------------------- | ||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function writeResultHandler(): void | ||
{ | ||
$this->codeStore->append('$this->executeNone($query);'); | ||
$this->codeStore->append(''); | ||
$this->codeStore->append('return $this->lastInsertId();'); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------------------------- | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace SetBased\Stratum\SqlitePdo\Test; | ||
|
||
/** | ||
* Test cases for stored routines with designation type lastInsertId. | ||
*/ | ||
class LastInsertIdTest extends DataLayerTestCase | ||
{ | ||
//-------------------------------------------------------------------------------------------------------------------- | ||
/** | ||
* Stored routine with designation type lastInsertId must returns IDs start with 1. | ||
*/ | ||
public function test01() | ||
{ | ||
$id = $this->dataLayer->tstTestLastIncrementId('Hello'); | ||
self::assertEquals(1, $id); | ||
|
||
$id = $this->dataLayer->tstTestLastIncrementId('World'); | ||
self::assertEquals(2, $id); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------------------------- | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Test case for designation type lastIncrementId. | ||
* | ||
* @param varchar :p_tst_test Some value. | ||
* | ||
* @type lastInsertId | ||
*/ | ||
insert into TST_LAST_INCREMENT_ID( tst_test ) | ||
values( :p_tst_test ) |