modifs.mineures sans commentaires
This commit is contained in:
		
							parent
							
								
									bdc0ce23ed
								
							
						
					
					
						commit
						b6d20261e2
					
				@ -11,8 +11,14 @@ class ValueException extends UserException {
 | 
			
		||||
    } elseif (is_array($value)) {
 | 
			
		||||
      $values = $value;
 | 
			
		||||
      $parts = [];
 | 
			
		||||
      foreach ($values as $value) {
 | 
			
		||||
      $index = 0;
 | 
			
		||||
      foreach ($values as $key => $value) {
 | 
			
		||||
        if ($key === $index) {
 | 
			
		||||
          $index++;
 | 
			
		||||
          $parts[] = self::value($value);
 | 
			
		||||
        } else {
 | 
			
		||||
          $parts[] = "$key=>".self::value($value);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      return "[" . implode(", ", $parts) . "]";
 | 
			
		||||
    } elseif (is_string($value)) {
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace nur\sery\db\sqlite;
 | 
			
		||||
 | 
			
		||||
use Exception;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use SQLite3;
 | 
			
		||||
 | 
			
		||||
@ -10,4 +11,8 @@ class SqliteException extends RuntimeException {
 | 
			
		||||
    elseif (!$throw) return null;
 | 
			
		||||
    else throw new static($db->lastErrorMsg(), $db->lastErrorCode());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static final function wrap(Exception $e): self{
 | 
			
		||||
    return new static($e->getMessage(), $e->getCode(), $e);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ namespace nur\sery\db\sqlite;
 | 
			
		||||
 | 
			
		||||
use nur\sery\cl;
 | 
			
		||||
use nur\sery\str;
 | 
			
		||||
use nur\sery\UserException;
 | 
			
		||||
use nur\sery\ValueException;
 | 
			
		||||
use SQLite3;
 | 
			
		||||
use SQLite3Stmt;
 | 
			
		||||
@ -24,7 +25,7 @@ class _Query {
 | 
			
		||||
      } elseif (self::is_delete($prefix)) {
 | 
			
		||||
        $query = self::parse_delete($query, $params);
 | 
			
		||||
      } else {
 | 
			
		||||
        throw new ValueException("requête invalide");
 | 
			
		||||
        throw SqliteException::wrap(ValueException::invalid_kind($query, "query"));
 | 
			
		||||
      }
 | 
			
		||||
    } elseif (!is_string($query)) {
 | 
			
		||||
      $query = strval($query);
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,9 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace nur\sery\db\sqlite;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Exception;
 | 
			
		||||
use nulib\tests\TestCase;
 | 
			
		||||
use nur\sery\ValueException;
 | 
			
		||||
 | 
			
		||||
class SqliteTest extends TestCase {
 | 
			
		||||
  const CREATE_PERSON = "create table person(nom varchar, prenom varchar, age integer)";
 | 
			
		||||
@ -34,9 +36,15 @@ class SqliteTest extends TestCase {
 | 
			
		||||
    ], iterator_to_array($sqlite->all("select key, value, done from _migration")));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function testException() {
 | 
			
		||||
    $sqlite = new Sqlite(":memory:");
 | 
			
		||||
    self::assertException(Exception::class, [$sqlite, "exec"], "prout");
 | 
			
		||||
    self::assertException(SqliteException::class, [$sqlite, "exec"], ["prout"]);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function testInsert() {
 | 
			
		||||
    $sqlite = new Sqlite(":memory:", [
 | 
			
		||||
      "migrate" => "create table mapping (i integer, s varchar)"
 | 
			
		||||
      "migrate" => "create table mapping (i integer, s varchar)",
 | 
			
		||||
    ]);
 | 
			
		||||
    $sqlite->exec(["insert into mapping", "values" => ["i" => 1, "s" => "un"]]);
 | 
			
		||||
    $sqlite->exec(["insert mapping", "values" => ["i" => 2, "s" => "deux"]]);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user