Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Database/SQLiteConnection.php
Строк: 156
<?php

namespace IlluminateDatabase;

use 
Exception;
use 
IlluminateDatabaseQueryGrammarsSQLiteGrammar as QueryGrammar;
use 
IlluminateDatabaseQueryProcessorsSQLiteProcessor;
use 
IlluminateDatabaseSchemaGrammarsSQLiteGrammar as SchemaGrammar;
use 
IlluminateDatabaseSchemaSQLiteBuilder;
use 
IlluminateDatabaseSchemaSqliteSchemaState;
use 
IlluminateFilesystemFilesystem;

class 
SQLiteConnection extends Connection
{
    
/**
     * {@inheritdoc}
     */
    
public function getDriverTitle()
    {
        return 
'SQLite';
    }

    
/**
     * Run the statement to start a new transaction.
     *
     * @return void
     */
    
protected function executeBeginTransactionStatement()
    {
        if (
version_compare(PHP_VERSION'8.4.0''>=')) {
            
$mode $this->getConfig('transaction_mode') ?? 'DEFERRED';

            
$this->getPdo()->exec("BEGIN {$mode} TRANSACTION");

            return;
        }

        
$this->getPdo()->beginTransaction();
    }

    
/**
     * Escape a binary value for safe SQL embedding.
     *
     * @param  string  $value
     * @return string
     */
    
protected function escapeBinary($value)
    {
        
$hex bin2hex($value);

        return 
"x'{$hex}'";
    }

    
/**
     * Determine if the given database exception was caused by a unique constraint violation.
     *
     * @param  Exception  $exception
     * @return bool
     */
    
protected function isUniqueConstraintError(Exception $exception)
    {
        return (bool) 
preg_match('#(column(s)? .* (is|are) not unique|UNIQUE constraint failed: .*)#i'$exception->getMessage());
    }

    
/**
     * Extract the columns that caused a unique constraint violation.
     *
     * @param  Exception  $exception
     * @return array{index: null, columns: list<string>}
     */
    
protected function parseUniqueConstraintViolation(Exception $exception): array
    {
        
preg_match('#UNIQUE constraint failed: (.+)#i'$exception->getMessage(), $matches);

        
$columns = [];

        if (isset(
$matches[1])) {
            
$columns array_map(
                static 
fn ($col) => last(explode('.'trim($col))),
                
explode(','$matches[1])
            );
        }

        return [
'columns' => $columns'index' => null];
    }

    
/**
     * Get the default query grammar instance.
     *
     * @return IlluminateDatabaseQueryGrammarsSQLiteGrammar
     */
    
protected function getDefaultQueryGrammar()
    {
        return new 
QueryGrammar($this);
    }

    
/**
     * Get a schema builder instance for the connection.
     *
     * @return IlluminateDatabaseSchemaSQLiteBuilder
     */
    
public function getSchemaBuilder()
    {
        if (
is_null($this->schemaGrammar)) {
            
$this->useDefaultSchemaGrammar();
        }

        return new 
SQLiteBuilder($this);
    }

    
/**
     * Get the default schema grammar instance.
     *
     * @return IlluminateDatabaseSchemaGrammarsSQLiteGrammar
     */
    
protected function getDefaultSchemaGrammar()
    {
        return new 
SchemaGrammar($this);
    }

    
/**
     * Get the schema state for the connection.
     *
     * @param  IlluminateFilesystemFilesystem|null  $files
     * @param  callable|null  $processFactory
     *
     * @throws RuntimeException
     */
    
public function getSchemaState(?Filesystem $files null, ?callable $processFactory null)
    {
        return new 
SqliteSchemaState($this$files$processFactory);
    }

    
/**
     * Get the default post processor instance.
     *
     * @return IlluminateDatabaseQueryProcessorsSQLiteProcessor
     */
    
protected function getDefaultPostProcessor()
    {
        return new 
SQLiteProcessor;
    }
}
Онлайн: 3
Реклама