classLimits
final class Limits
Finds the constructs SQLite rejects inside the expressions of a definition.
Rule: SQLITE-DEFINITION-LIMITS-001. SQLite resolves the expressions of a CHECK constraint, a partial index WHERE clause, an index expression and a generated column against the table itself and rejects, at every one of these positions, a bound parameter and a subquery (an IN table operand is a subquery, because SQLite reads it as one); at an index expression and in a generated column also a qualified column reference, "the . operator"; and at an index expression, in a partial index WHERE clause and in a generated column also a call of a function the library does not flag as constant: random, randomblob, last_insert_rowid, changes, total_changes, current_time, current_timestamp, current_date (the keywords included), sqlite_version, sqlite_source_id, sqlite_compileoption_used, sqlite_compileoption_get and load_extension. The date functions given 'now' pass this check and fail when the index or column is used, which is not modeled. Whether a function that is not built in is deterministic is a registration on the connection and not a fact of the model.
A DEFAULT value must be constant in a different sense: it may call any function but may not contain a bound parameter, a subquery, a column reference (a double-quoted word included) or RAISE.
Each kind of construct is reported once per expression. A subquery is found at the expression that holds it and at the query itself; the inside of a subquery is not examined, as SQLite stops at the subquery. Terminates: the expression is walked once with an explicit stack. Source: https://sqlite.org/lang_createtable.html#check_constraints, https://sqlite.org/lang_createtable.html#the_default_clause, https://sqlite.org/partialindex.html, https://sqlite.org/expridx.html, https://sqlite.org/gencol.html (and sqlite3ResolveSelfReference() in resolve.c and sqlite3ExprIsConstantOrFunction() in expr.c of the release). Status: Implemented.
Methods§
Answers the nodes of an expression in depth-first order, without the inside of a subquery.
Parameters
$expression | Scalar |
Returns
list<Node>Test cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Expression\Limits::rejected() packages/sql-semantics-sqlite/src/Rules/Definition/Expression/Limits.php:139
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\Expression\Limits::nonConstant() packages/sql-semantics-sqlite/src/Rules/Definition/Expression/Limits.php:164
public function classify(Node $node): ?ProhibitedConstructAnswers the construct a node is, if it is one SQLite can reject.
Parameters
$node | Node |
Returns
Test cases 1
Called from 1
Calls 7
- class-const ProhibitedConstruct::Parameter() line 118
- class-const ProhibitedConstruct::Subquery() line 121
- class-const ProhibitedConstruct::DotOperator() line 124
- function-call
in_arrayline 126 - function-call
strtolowerline 126 - class-const Limits::NON_DETERMINISTIC() line 126
- class-const ProhibitedConstruct::NonDeterministicFunction() line 128
public function rejected(
Scalar $expression,
DefinitionPosition $position,
): list<ProhibitedConstruct>Answers the constructs of an expression that its position rejects, each once, in order of first use.
Parameters
$expression | Scalar | |
$position | DefinitionPosition |
Returns
list<ProhibitedConstruct>Test cases 1
Called from 1
Calls 4
- method-call Limits::nodes() line 139
- method-call Limits::classify() line 140
- function-call
in_arrayline 141 - class-const Limits::REJECTED() line 141
public function report(
Scalar $expression,
DefinitionPosition $position,
Derivation $derivation,
): voidReports each construct of an expression that its position rejects.
Parameters
$expression | Scalar | |
$position | DefinitionPosition | |
$derivation | Derivation |
Test cases 1
Called from 5
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnCheck::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnCheck.php:49
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Column\Generated::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Column/Generated.php:73
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\CreateIndex::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateIndex.php:110
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\CreateIndex::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateIndex.php:114
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Table\TableCheck::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Table/TableCheck.php:52
Calls 3
- method-call Limits::rejected() line 154
- method-call Derivation::report() line 155
- new ProhibitedExpression line 155
public function nonConstant(Scalar $expression): boolTells whether a DEFAULT expression is not constant in the sense of SQLite.
Parameters
$expression | Scalar |
Returns
boolTest cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:110
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnDefinition::deriveColumn() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnDefinition.php:113
Calls 1
- method-call Limits::nodes() line 164
Private surface 2§
Implementation details, listed for orientation only.
private const NON_DETERMINISTIC = ['random', 'randomblob', 'last_insert_rowid', 'changes', 'total_changes', 'curr…private const REJECTED = ['CheckConstraint' => [\SqlSemantics\Platform\Sqlite\Statement\Schema\Limit\Pro…Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
LimitsTest::testClassifyNamesEachRejectedNodecallsLimitsTest::testNodesWalksTheExpressionInOrderWithoutEnteringASubquerycallsLimitsTest::testNonConstantFindsWhatADefaultMayNotContaincallsLimitsTest::testRejectedAnswersWhatThePositionRejectsOnceEachcallsLimitsTest::testReportRecordsOneDiagnosticPerRejectedConstructcalls
Relations§
Instantiated in 6
- new SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:110
- new SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnCheck::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnCheck.php:49
- new SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnDefinition::deriveColumn() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnDefinition.php:113
- new SqlSemantics\Platform\Sqlite\Statement\Schema\Column\Generated::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Column/Generated.php:73
- new SqlSemantics\Platform\Sqlite\Statement\Schema\CreateIndex::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateIndex.php:107
- new SqlSemantics\Platform\Sqlite\Statement\Schema\Table\TableCheck::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Table/TableCheck.php:52
Method calls 7
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:110
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnCheck::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnCheck.php:49
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnDefinition::deriveColumn() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnDefinition.php:113
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Column\Generated::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Column/Generated.php:73
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\CreateIndex::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateIndex.php:110
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\CreateIndex::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/CreateIndex.php:114
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Table\TableCheck::deriveConstraint() packages/sql-semantics-sqlite/src/Statement/Schema/Table/TableCheck.php:52