Skip to content

Commit

Permalink
Fixes compat with Laravel 10
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed Aug 7, 2024
1 parent 0bd6864 commit 876bcb5
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion src/Database/Connections/MySqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,84 @@
use Illuminate\Database\Schema\MySqlBuilder;
use Illuminate\Database\Schema\MySqlSchemaState;
use Illuminate\Filesystem\Filesystem;
use Exception;
use PDO;

/**
* MySqlConnection
*/
class MySqlConnection extends Connection
{
/**
* The last inserted ID generated by the server
*
* @var string|int|null
*/
protected $lastInsertId;

/**
* Run an insert statement against the database.
*
* @param string $query
* @param array $bindings
* @param string|null $sequence
* @return bool
*/
public function insert($query, $bindings = [], $sequence = null)
{
return $this->run($query, $bindings, function ($query, $bindings) use ($sequence) {
if ($this->pretending()) {
return true;
}

$statement = $this->getPdo()->prepare($query);

$this->bindValues($statement, $this->prepareBindings($bindings));

$this->recordsHaveBeenModified();

$result = $statement->execute();

$this->lastInsertId = $this->getPdo()->lastInsertId($sequence);

return $result;
});
}

/**
* Get the last insert ID.
*
* @return int
*/
public function getLastInsertId()
{
return $this->lastInsertId;
}

/**
* 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 boolval(preg_match('#Integrity constraint violation: 1062#i', $exception->getMessage()));
}

/**
* Determine if the connected database is a MariaDB database.
*
Expand All @@ -35,7 +106,7 @@ protected function getDefaultQueryGrammar()
if (method_exists($grammar, 'setConnection')) {
$grammar->setConnection($this);
}

return $this->withTablePrefix($grammar);
}

Expand Down

0 comments on commit 876bcb5

Please sign in to comment.