Lines 100.00% 2 / 2
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
SqliteGrammar 100.00% 2 / 2 100.00% 2 / 2 2 100.00% 1 / 1
 wrap 100.00% 1 / 1 100.00% 1 / 1 1
 usesReturning 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace BlueprintAU\Radiant\Database\Grammars;
6
7use BlueprintAU\Radiant\Database\Exceptions\UnsupportedFeatureException;
8
9/**
10 * The SQLite dialect of the SQL Grammar.
11 *
12 * Identifiers are quoted with double quotes (embedded quotes doubled).
13 * SQLite 3.35+ supports `INSERT ... RETURNING`, so {@see usesReturning()}
14 * returns true and {@see compileInsertForId()} compiles the clause in.
15 * SQLite has no row-locking syntax, so {@see compileLock()}
16 * inherits the base Grammar's {@see UnsupportedFeatureException} — a lock
17 * request fails fast rather than silently dropping the lock.
18 */
19final class SqliteGrammar extends Grammar
20{
21    /**
22     * Wrap an identifier in SQLite double quotes.
23     *
24     * @param  string  $value
25     * @return string
26     */
27    protected function wrap(string $value): string
28    {
29        return '"' . str_replace('"', '""', $value) . '"';
30    }
31
32    /**
33     * Whether the dialect supports `INSERT ... RETURNING`.
34     *
35     * @return bool
36     */
37    public function usesReturning(): bool
38    {
39        return true;
40    }
41}