php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56285 PDO Sqlite NULL Handling
Submitted: 2005-02-07 06:58 UTC Modified: 2005-02-09 02:02 UTC
From: Jared dot Williams1 at ntlworld dot com Assigned: wez (profile)
Status: Closed Package: PDO (PECL)
PHP Version: 5_1 CVS-2005-02-07 (dev) OS: Windows 2000/IIS
Private report: No CVE-ID: None
 [2005-02-07 06:58 UTC] Jared dot Williams1 at ntlworld dot com
Description:
------------
Null handling in atleast PDO sqlite driver seems broken.

Seems impossible to use prepared statements with NULL values. They appear to get converted to an empty string.

Reproduce code:
---------------
<?php
	$pdo = new PDO('sqlite::memory:');
	$pdo->exec('CREATE TABLE test(ID INT NOT NULL PRIMARY KEY, Field VARCHAR(12) NULL);');
	$stmt = $pdo->prepare('INSERT INTO test(ID, Field) VALUES(?, ?)');

	$one = 1;
	$two = 2;
	$null = NULL;
// Try with PDO_PARAM_NULL
	$stmt->bindParam(1, $one, PDO_PARAM_INT);
	$stmt->bindParam(2, $null, PDO_PARAM_NULL);
	assert($stmt->execute());
// Try with PDO_PARAM_STR
	$stmt->bindParam(1, $two, PDO_PARAM_INT);
	$stmt->bindParam(2, $null, PDO_PARAM_STR);
	assert($stmt->execute());
// Check we have rows..
	$stmt = $pdo->prepare('SELECT * FROM test');
	assert($stmt->execute());
	var_dump($stmt->fetchAll(PDO_FETCH_OBJ));
// Check we have rows with field is null
	echo '<hr />';
	$stmt = $pdo->prepare('SELECT * FROM test WHERE Field IS NULL');
	assert($stmt->execute());
	var_dump($stmt->fetchAll(PDO_FETCH_OBJ));
?>

Expected result:
----------------
2 rows in table test where Field column is null.

Actual result:
--------------
2 Rows in table test with Field is an empty string.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-09 02:02 UTC] wez@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC