classCreateFunction
final class CreateFunction
implements Statement
uses Snapshot
Public API: explicitly declared with
@visibility public.CREATE FUNCTION of a stored function: its parameters, return type, characteristics and body.
The statement is structured as a request: it declares nothing to a context. The facts follow MYSQL-ROUTINE-001. Source: https://dev.mysql.com/doc/refman/8.4/en/create-procedure.html.
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE FUNCTION twice(a INT) RETURNS BIGINT DETERMINISTIC RETURN a * 2');
[$create->statement->returns->name(), $create->facts->diagnostics] // => ['BIGINT', []]Properties§
public list<Characteristic> $characteristicspublic ExternalBody|ProgramStatement|Statement $bodypublic QualifiedName $namepublic ParameterList $parameterspublic TypeName $returnspublic CollationName|null $collation = nullpublic Account|null $definer = nullpublic bool $ifNotExists = falseMethods§
public function __construct(
public QualifiedName $name,
public ParameterList $parameters,
public TypeName $returns,
Node $body,
public CollationName|null $collation = null,
list<Characteristic> $characteristics = [],
public Account|null $definer = null,
public bool $ifNotExists = false,
)Parameters
$name | QualifiedName | The function name with its optional database |
$parameters | ParameterList | The parameters; none has a direction |
$returns | TypeName | The return type |
$body | Node | The body: a program statement, an SQL statement, or external code |
$collation | CollationName|null | The COLLATE clause of the return type |
$characteristics | list<Characteristic> | The characteristics in written order |
$definer | Account|null | The DEFINER clause, when written |
$ifNotExists | bool | Whether IF NOT EXISTS is written (MySQL 8.0.29 and later) |
Throws
InvalidConstruction When a parameter has a direction, or the body or a characteristic is of another classCalls 5
- static-call Check::input() line 70
- static-call Check::listOf() line 74
- class-const Characteristic::class() line 74
- method-call ProgramFacts::body() line 75
- new ProgramFacts line 75
public function deriveStatement(Derivation $derivation): voidDerives the parameters and the body, and checks that the body returns.
Parameters
$derivation | Derivation |
Calls 3
- method-call ProgramFacts::routine() line 83
- new ProgramFacts line 83
- class-const ProgramKind::Function() line 83
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 6
- method-call Output::keyword() line 91
- method-call ProgramNames::qualified() line 99
- new ProgramNames line 99
- method-call Output::glue() line 100
- method-call ProgramNames::type() line 101
- method-call Output::node() line 103
Test cases 23§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 20
CharacteristicRuleTest::testCharacteristicLowersTheDeterminismOfAFunctioncallsCharacteristicRuleTest::testCharacteristicLowersTheLanguagecallsDefinitionRuleTest::testRoutineLowersAFunctionWithItsReturnCollationcallsDefinitionRuleTest::testRoutineLowersAStoredRoutineBodycallsDefinitionRuleTest::testRoutineReadsIfNotExistscallsParameterRuleTest::testDeclaredLowersATypeWithItsCollationcallsParameterRuleTest::testParametersLowersAFunctionListcallsParameterRuleTest::testParametersLowersAnEmptyListcallsFlowRuleTest::testJumpLowersReturnLeaveAndIteratecallsStatementRuleTest::testBodyLowersAnExternalBodycallsStatementRuleTest::testBodyLowersAProgramStatementcallsStatementRuleTest::testStatementRoutesEveryKindOfProgramStatementcallsRoutineRulesTest::testCreateLowersEveryKindOfStoredProgramcallsFlowFactsTest::testReturnedResolvesTheValueToALocalVariablecallsProgramFactsTest::testRoutineDerivesNothingFromExternalCodecallsProgramNamesTest::testTypeWritesTheCollateClauseWhenPresentcallsDeterminismTest::testRenderWritesNotBeforeANonDeterministicRoutinecallsRoutineLanguageTest::testRenderWritesTheNameOfAnExternalLanguagecallsExternalBodyTest::testRenderKeepsAQuotedCodecallsReturnStatementTest::testDeriveProgramResolvesTheParametercalls