final class SqliteProvider
    extends Base
Public API: explicitly declared with @visibility public.

Faker Provider for generating syntactically valid SQLite SQL statements.

This provider uses SQLite's official Lemon grammar (parse.y) to generate SQL that is syntactically valid. Note that generated SQL may not be semantically valid (tables/columns may not exist).

maxDepth selects shortest productions once the depth is reached; it is not a SQL length limit. The basic pipeline resolves lexical spaces without inserting comments. Optional clauses may be empty. Seed the supplied Faker generator to reproduce a run within the same package version.

Register the provider with Fakerdoctest
$faker = \Faker\Factory::create();
    $faker->addProvider(new \SqlFaker\SqliteProvider($faker));
    $faker->integerLiteral(min: 42, max: 42) // => '42'

Methods§

public function __construct(
    Generator $generator,
    string|null $version = null,
    ?GrammarCoverage $coverage = null,
)
Public API: explicitly declared with @visibility public.

Register SQL formatters on the supplied Faker generator.

Parameters

$generatorGeneratorFaker generator
$versionstring|nullSQLite version tag. Null for default.
$coverage?GrammarCoverage
Choose a supported database versiondoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker, 'sqlite-3.47.2');
    $provider->integerLiteral(min: 42, max: 42) // => '42'
Reject an unsupported database versiondoctest
new \SqlFaker\SqliteProvider(\Faker\Factory::create(), 'missing-version') // throws \RuntimeException: Unsupported
Calls 5
public function planner(): PlanBuilder
Public API: explicitly declared with @visibility public.

Prepares grammar analysis for constructing concrete generation plans.

Compile input before generating SQLdoctest
$provider = new \SqlFaker\SqliteProvider(\Faker\Factory::create());
    $plan = (new \SqlFaker\Generation\Choice\BytePlanCompiler())->compile('', $provider->planner());
    $provider->generate($plan) === $provider->generate($plan) // => true
Test cases 1
Calls 1
public function generate<TRequiresNonEmpty of bool>(GenerationPlan<TRequiresNonEmpty> $plan): (TRequiresNonEmpty is true ? non-empty-string : string)
Public API: explicitly declared with @visibility public.

Generates through the same engine used by the convenience methods.

Parameters

$planGenerationPlan<TRequiresNonEmpty>

Returns

(TRequiresNonEmpty is true ? non-empty-string : string)

Throws

GenerationException When derivation fails
LexicalException When lexical realization fails
Generate a statement from deterministic choice bytesdoctest
$provider = new \SqlFaker\SqliteProvider(\Faker\Factory::create());
    $plan = \SqlFaker\Generation\Plan\GenerationPlan::all()->requiringNonEmpty()->withExpansionBudget(100);
    $provider->generate($plan) !== '' // => true
Test cases 1
Called from 31
Calls 1
public function sql(StatementType|null $type = null, int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a syntactically valid SQLite SQL statement.

Parameters

$typeStatementType|nullStatement type (null for random)
$maxDepthint

Returns

string
Select a statement type explicitlydoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->sql(\SqlFaker\Sqlite\StatementType::Select, maxDepth: 0);
    preg_match('/\b(SELECT|VALUES)\b/i', $sql) // => 1
Test cases 8
Calls 2
public function selectStatement(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite SELECT statement.

Parameters

$maxDepthint

Returns

string
Generate select statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->selectStatement(maxDepth: 0);
    preg_match('/\b(SELECT|VALUES)\b/is', $sql) // => 1
Test cases 3
Calls 3
public function insertStatement(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite INSERT statement.

Parameters

$maxDepthint

Returns

string
Generate insert statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->insertStatement(maxDepth: 0);
    preg_match('/\b(INSERT|REPLACE)\b/is', $sql) // => 1
Test cases 2
Calls 3
public function updateStatement(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite UPDATE statement.

Parameters

$maxDepthint

Returns

string
Generate update statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->updateStatement(maxDepth: 0);
    preg_match('/\bUPDATE\b/is', $sql) // => 1
Test cases 2
Calls 3
public function deleteStatement(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite DELETE statement.

Parameters

$maxDepthint

Returns

string
Generate delete statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->deleteStatement(maxDepth: 0);
    preg_match('/\bDELETE\b/is', $sql) // => 1
Test cases 2
Calls 3
public function createTableStatement(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite CREATE TABLE statement.

Parameters

$maxDepthint

Returns

string
Generate create table statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->createTableStatement(maxDepth: 0);
    preg_match('/\bCREATE\b.*\bTABLE\b/is', $sql) // => 1
Test cases 2
Calls 3
public function alterTableStatement(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite ALTER TABLE statement.

Parameters

$maxDepthint

Returns

string
Generate alter table statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->alterTableStatement(maxDepth: 0);
    preg_match('/\bALTER\b.*\bTABLE\b/is', $sql) // => 1
Test cases 2
Calls 3
public function dropTableStatement(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite DROP TABLE statement.

Parameters

$maxDepthint

Returns

string
Generate drop table statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->dropTableStatement(maxDepth: 0);
    preg_match('/\bDROP\b.*\bTABLE\b/is', $sql) // => 1
Test cases 2
Calls 3
public function simpleStatement(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate any SQLite statement.

Parameters

$maxDepthint

Returns

string
Generate simple statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->simpleStatement(maxDepth: 0);
    $sql !== '' // => true
Test cases 1
Calls 3
public function expr(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite expression.

Parameters

$maxDepthint

Returns

string
Generate expr at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->expr(maxDepth: 0);
    $sql !== '' // => true
Test cases 1
Calls 2
public function term(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a simple SQLite expression (term).

Parameters

$maxDepthint

Returns

string
Generate term at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->term(maxDepth: 0);
    $sql !== '' // => true
Test cases 1
Calls 2
public function whereClause(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite WHERE clause.

Parameters

$maxDepthint

Returns

string
An optional clause can be empty at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $provider->whereClause(maxDepth: 0) // => ''
Test cases 1
Calls 2
public function orderByClause(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite ORDER BY clause.

Parameters

$maxDepthint

Returns

string
An optional clause can be empty at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $provider->orderByClause(maxDepth: 0) // => ''
Test cases 1
Calls 2
public function limitClause(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite LIMIT clause.

Parameters

$maxDepthint

Returns

string
An optional clause can be empty at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $provider->limitClause(maxDepth: 0) // => ''
Test cases 1
Calls 2
public function groupByClause(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite GROUP BY clause.

Parameters

$maxDepthint

Returns

string
An optional clause can be empty at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $provider->groupByClause(maxDepth: 0) // => ''
Test cases 1
Calls 2
public function havingClause(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite HAVING clause.

Parameters

$maxDepthint

Returns

string
An optional clause can be empty at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $provider->havingClause(maxDepth: 0) // => ''
Test cases 1
Calls 2
public function fullname(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite full table name.

Parameters

$maxDepthint

Returns

string
Generate fullname at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->fullname(maxDepth: 0);
    $sql !== '' // => true
Test cases 1
Calls 2
public function withClause(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite WITH clause (CTE).

Parameters

$maxDepthint

Returns

string
An optional clause can be empty at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $provider->withClause(maxDepth: 0) // => ''
Test cases 1
Calls 2
public function foreignKeyConstraint(int $maxDepth = PHP_INT_MAX): non-empty-string
Public API: explicitly declared with @visibility public.

Generate a named SQLite foreign-key table constraint.

Parameters

$maxDepthint

Returns

non-empty-string
Generate foreign key constraint at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->foreignKeyConstraint(maxDepth: 0);
    preg_match('/\bCONSTRAINT\b.*\bFOREIGN\b.*\bREFERENCES\b/is', $sql) // => 1
Test cases 1
Calls 2
public function identifier(int $maxDepth = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite identifier via grammar derivation.

Parameters

$maxDepthint

Returns

string
Generate identifier at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->identifier(maxDepth: 0);
    $sql !== '' // => true
Test cases 2
Calls 2
public function quotedIdentifier(int $minLength = 1, int $maxLength = 128): string
Public API: explicitly declared with @visibility public.

Generate a double-quote-quoted SQLite identifier.

Parameters

$minLengthint
$maxLengthint

Returns

string
Constrain the generated token shapedoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $token = $provider->quotedIdentifier(minLength: 4, maxLength: 4);
    preg_match('/^"[a-z_][a-z0-9_]{3}"$/', $token) // => 1
Test cases 3
Calls 2
public function stringLiteral(int $minLength = 1, int $maxLength = 255): string
Public API: explicitly declared with @visibility public.

Generate a SQLite string literal.

Parameters

$minLengthint
$maxLengthint

Returns

string
Constrain the generated token shapedoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $token = $provider->stringLiteral(minLength: 4, maxLength: 4);
    preg_match('/^\'[A-Za-z0-9_]{4}\'$/', $token) // => 1
Test cases 3
Calls 2
public function integerLiteral(int $min = 1, int $max = PHP_INT_MAX): string
Public API: explicitly declared with @visibility public.

Generate a SQLite integer literal.

Parameters

$minint
$maxint

Returns

string
Fix both bounds to obtain one valuedoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $provider->integerLiteral(min: 42, max: 42) // => '42'
Test cases 3
Calls 2
public function decimalLiteral(int $precision = 15, int $scale = 2): string
Public API: explicitly declared with @visibility public.

Generate a SQLite decimal literal.

Parameters

$precisionint
$scaleint

Returns

string
Constrain the generated token shapedoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $token = $provider->decimalLiteral(precision: 5, scale: 2);
    preg_match('/^[0-9]{1,3}\.[0-9]{2}$/', $token) // => 1
Test cases 3
Calls 2
public function insertFunctionUpsertStatement(int $maxDepth = 40): non-empty-string
Public API: explicitly declared with @visibility public.

Generate an upsert whose update expression calls a function.

Parameters

$maxDepthint

Returns

non-empty-string
Generate insert function upsert statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->insertFunctionUpsertStatement(maxDepth: 0);
    preg_match('/\bINSERT\b.*\bCONFLICT\b.*\bUPDATE\b.*\(/is', $sql) // => 1
Test cases 1
Calls 2
public function multiDmlStatement(int $maxDepth = 40): non-empty-string
Public API: explicitly declared with @visibility public.

Generate two semicolon-terminated DML statements.

Parameters

$maxDepthint

Returns

non-empty-string
Generate multi dml statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->multiDmlStatement(maxDepth: 0);
    preg_match('/;.*;/is', $sql) // => 1
Test cases 2
Calls 2
public function fullTextSearchStatement(int $maxDepth = 40): non-empty-string
Public API: explicitly declared with @visibility public.

Generate a query using the dialect full-text search syntax.

Parameters

$maxDepthint

Returns

non-empty-string
Generate full text search statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->fullTextSearchStatement(maxDepth: 0);
    preg_match('/\bSELECT\b.*\bMATCH\b/is', $sql) // => 1
Test cases 1
Calls 2
public function temporaryTableStatement(int $maxDepth = 40): non-empty-string
Public API: explicitly declared with @visibility public.

Generate a temporary-table declaration.

Parameters

$maxDepthint

Returns

non-empty-string
Generate temporary table statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->temporaryTableStatement(maxDepth: 0);
    preg_match('/\bCREATE\b.*\bTEMP(?:ORARY)?\b.*\bTABLE\b/is', $sql) // => 1
Test cases 1
Calls 2
public function viewStatement(int $maxDepth = 40): non-empty-string
Public API: explicitly declared with @visibility public.

Generate a view declaration.

Parameters

$maxDepthint

Returns

non-empty-string
Generate view statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->viewStatement(maxDepth: 0);
    preg_match('/\bCREATE\b.*\bVIEW\b.*\bAS\b/is', $sql) // => 1
Test cases 1
Calls 2
public function generatedColumnStatement(int $maxDepth = 40): non-empty-string
Public API: explicitly declared with @visibility public.

Generate a table with a generated column.

Parameters

$maxDepthint

Returns

non-empty-string
Generate generated column statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->generatedColumnStatement(maxDepth: 0);
    preg_match('/\bGENERATED\b.*\bALWAYS\b.*\bAS\b/is', $sql) // => 1
Test cases 1
Calls 2
public function foreignKeyCascadeStatement(int $maxDepth = 40): non-empty-string
Public API: explicitly declared with @visibility public.

Generate a foreign key with cascading update and delete actions.

Parameters

$maxDepthint

Returns

non-empty-string
Generate foreign key cascade statement at the shortest depthdoctest
$faker = \Faker\Factory::create();
    $provider = new \SqlFaker\SqliteProvider($faker);
    $faker->seed(7);
    $sql = $provider->foreignKeyCascadeStatement(maxDepth: 0);
    preg_match('/\bREFERENCES\b.*\bCASCADE\b.*\bCASCADE\b/is', $sql) // => 1
Test cases 1
Calls 2

Private surface 1§

Implementation details, listed for orientation only.

private SqlGenerator $sql

Test cases 57§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 56
Other tests reaching this symbol 1