bugfix: can use null value for named or numbered parameters
This commit is contained in:
@@ -472,7 +472,7 @@ class MeekroDB {
|
||||
|
||||
if ($arg_number_length = strspn($sql, '0123456789', $new_pos_back)) {
|
||||
$arg_number = substr($sql, $new_pos_back, $arg_number_length);
|
||||
if (! isset($args_all[$arg_number])) $this->nonSQLError("Non existent argument reference (arg $arg_number): $sql");
|
||||
if (! array_key_exists($arg_number, $args_all)) $this->nonSQLError("Non existent argument reference (arg $arg_number): $sql");
|
||||
|
||||
$arg = $args_all[$arg_number];
|
||||
|
||||
@@ -481,8 +481,8 @@ class MeekroDB {
|
||||
$new_pos_back + $named_seperator_length) + $named_seperator_length;
|
||||
|
||||
$arg_number = substr($sql, $new_pos_back + $named_seperator_length, $arg_number_length - $named_seperator_length);
|
||||
if (count($args_all) != 1) $this->nonSQLError("If you use named parameters, the second argument must be an array of parameters");
|
||||
if (! isset($args_all[0][$arg_number])) $this->nonSQLError("Non existent argument reference (arg $arg_number): $sql");
|
||||
if (count($args_all) != 1 || !is_array($args_all[0])) $this->nonSQLError("If you use named parameters, the second argument must be an array of parameters");
|
||||
if (! array_key_exists($arg_number, $args_all[0])) $this->nonSQLError("Non existent argument reference (arg $arg_number): $sql");
|
||||
|
||||
$arg = $args_all[0][$arg_number];
|
||||
|
||||
|
||||
@@ -65,12 +65,21 @@ class BasicTest extends SimpleTest {
|
||||
'height' => 155.23,
|
||||
'favorite_word' => null,
|
||||
));
|
||||
|
||||
|
||||
$this->assert(DB::insertId() === 3);
|
||||
|
||||
$counter = DB::queryFirstField("SELECT COUNT(*) FROM accounts");
|
||||
$this->assert($counter === strval(3));
|
||||
|
||||
|
||||
DB::insert('`accounts`', array(
|
||||
'username' => 'Deer',
|
||||
'password' => '',
|
||||
'age' => 15,
|
||||
'height' => 10.371
|
||||
));
|
||||
|
||||
$username = DB::queryFirstField("SELECT username FROM accounts WHERE password=%s0", null);
|
||||
$this->assert($username === 'Deer');
|
||||
|
||||
$password = DB::queryFirstField("SELECT password FROM accounts WHERE favorite_word IS NULL");
|
||||
$this->assert($password === 'goodbye');
|
||||
|
||||
@@ -111,7 +120,7 @@ class BasicTest extends SimpleTest {
|
||||
$this->assert($results[0]['age'] == 30 && $results[0]['password'] == 'goodbye');
|
||||
|
||||
$results = DB::query("SELECT * FROM accounts WHERE username!=%s", "Charlie's Friend");
|
||||
$this->assert(count($results) === 2);
|
||||
$this->assert(count($results) === 3);
|
||||
|
||||
$columnlist = DB::columnList('accounts');
|
||||
$this->assert(count($columnlist) === 6);
|
||||
|
||||
Reference in New Issue
Block a user