- Completed merge
This commit is contained in:
1 parent
430cd03bc4
commit
00ebf3381f
10 files changed
+93
-34
No files matched your search
+44
-2
@@ -7,7 +7,7 @@ use Ulmus\Common\PdoObject;
|
||||
use Ulmus\Entity\Sqlite\Table;
|
||||
use Ulmus\Exception\AdapterConfigurationException;
|
||||
use Ulmus\Migration\FieldDefinition;
|
||||
use Ulmus\{ Repository, QueryBuilder };
|
||||
use Ulmus\{Repository, QueryBuilder, Ulmus};
|
||||
|
||||
class SQLite implements AdapterInterface {
|
||||
use DefaultAdapterTrait;
|
||||
@@ -38,6 +38,8 @@ class SQLite implements AdapterInterface {
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||
|
||||
$this->exportFunctions($pdo);
|
||||
}
|
||||
catch(PDOException $ex){
|
||||
throw $ex;
|
||||
@@ -126,7 +128,23 @@ class SQLite implements AdapterInterface {
|
||||
}
|
||||
}
|
||||
|
||||
return $typeOnly ? $type : $type . ( $length ? "($length" . ( $precision ? ",$precision" : "" ) . ")" : "" );
|
||||
return $typeOnly ? $type : $type . ( $length ? "($length" . ( isset($precision) ? ",$precision" : "" ) . ")" : "" );
|
||||
}
|
||||
|
||||
public function writableValue(/* mixed */ $value) /*: mixed*/
|
||||
{
|
||||
switch (true) {
|
||||
case is_object($value):
|
||||
return Ulmus::convertObject($value);
|
||||
|
||||
case is_array($value):
|
||||
return json_encode($value);
|
||||
|
||||
case is_bool($value):
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function tableSyntax() : array
|
||||
@@ -147,4 +165,28 @@ class SQLite implements AdapterInterface {
|
||||
{
|
||||
return QueryBuilder\SqliteQueryBuilder::class;
|
||||
}
|
||||
|
||||
public function exportFunctions(PdoObject $pdo) : void
|
||||
{
|
||||
$pdo->sqliteCreateFunction('lcase', fn($string) => strtolower($string), 1);
|
||||
$pdo->sqliteCreateFunction('ucase', fn($string) => strtoupper($string), 1);
|
||||
$pdo->sqliteCreateFunction('left', fn($string, $length) => substr($string, 0, $length), 2);
|
||||
$pdo->sqliteCreateFunction('right', fn($string, $length) => substr($string, -$length), 2);
|
||||
$pdo->sqliteCreateFunction('strcmp', fn($s1, $s2) => strcmp($s1, $s2), 2);
|
||||
$pdo->sqliteCreateFunction('lpad', fn($string, $length, $pad) => str_pad($string, $length, $pad, STR_PAD_LEFT), 3);
|
||||
$pdo->sqliteCreateFunction('rpad', fn($string, $length, $pad) => str_pad($string, $length, $pad, STR_PAD_RIGHT), 3);
|
||||
$pdo->sqliteCreateFunction('concat', fn(...$args) => implode('', $args), -1);
|
||||
$pdo->sqliteCreateFunction('concat_ws', fn($separator, ...$args) => implode($separator, $args), -1);
|
||||
$pdo->sqliteCreateFunction('find_in_set', function($string, $string_list) {
|
||||
if ( $string === null || $string_list === null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($string_list === "") {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) in_array($string, explode(',', $string_list));
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user