From lapo@deepie.home.lapo.it  Sat Nov 29 13:21:34 2008
Return-Path: <lapo@deepie.home.lapo.it>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 4AA2D106564A;
	Sat, 29 Nov 2008 13:21:34 +0000 (UTC)
	(envelope-from lapo@deepie.home.lapo.it)
Received: from deepie.home.lapo.it (unknown [IPv6:2002:514a:2847::1])
	by mx1.freebsd.org (Postfix) with ESMTP id 317F98FC08;
	Sat, 29 Nov 2008 13:21:28 +0000 (UTC)
	(envelope-from lapo@deepie.home.lapo.it)
Received: from deepie.home.lapo.it (localhost [127.0.0.1])
	by deepie.home.lapo.it (8.14.3/8.14.3) with ESMTP id mATDL5EI054336;
	Sat, 29 Nov 2008 14:21:05 +0100 (CET)
	(envelope-from lapo@deepie.home.lapo.it)
Received: (from lapo@localhost)
	by deepie.home.lapo.it (8.14.3/8.14.3/Submit) id mATDL4Th054335;
	Sat, 29 Nov 2008 14:21:04 +0100 (CET)
	(envelope-from lapo)
Message-Id: <200811291321.mATDL4Th054335@deepie.home.lapo.it>
Date: Sat, 29 Nov 2008 14:21:04 +0100 (CET)
From: Lapo Luchini <lapo@lapo.it>
Reply-To: Lapo Luchini <lapo@lapo.it>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Lapo Luchini <lapo@lapo.it>, Alex Dupre <ale@freebsd.org>
Subject: databases/php5-pdo_sqlite doesn't manage BLOB types
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         129277
>Category:       ports
>Synopsis:       databases/php5-pdo_sqlite doesn't manage BLOB types
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    ale
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 29 13:30:01 UTC 2008
>Closed-Date:    Sun Dec 07 11:59:05 UTC 2008
>Last-Modified:  Sun Dec 07 11:59:05 UTC 2008
>Originator:     Lapo Luchini
>Release:        FreeBSD 7.1-PRERELEASE amd64
>Organization:
>Environment:
System: FreeBSD deepie.home.lapo.it 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #11: Sun Oct 19 15:29:12 CEST 2008 root@deepie.home.lapo.it:/usr/obj/usr/src/sys/DEEPIE amd64

>Description:

PHP's 5.3 SQLite PDO doesn't really support PARAM_LOB type,
it falls through to PARAM_STR, thus the DB doesn't know the
data received is meant to be a BLOB type.

>How-To-Repeat:

1. insert some binary data in the DB
2. SELECT TYPEOF(column), LENGTH(column) FROM table;
3. notice the TEXT type in the first column
4. notice the wrong length in the second column (ends at first \0)

>Fix:

An official patch from
http://bugs.php.net/bug.php?id=42443
seems to have landed in 5.3+.

This is the patch from the comment applied on the current sources,
ready for the files/ subdirectory.

--- patch-sqlite_statement.c begins here ---
--- sqlite_statement.c.orig	2007-12-31 08:20:10.000000000 +0100
+++ sqlite_statement.c	2008-11-29 14:00:33.074007425 +0100
@@ -104,6 +104,21 @@ static int pdo_sqlite_stmt_param_hook(pd
 						pdo_sqlite_error_stmt(stmt);
 						return 0;
 					
+					case PDO_PARAM_INT:
+					case PDO_PARAM_BOOL:
+						if (Z_TYPE_P(param->parameter) == IS_NULL) {
+							if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
+								return 1;
+							}
+						} else {
+							convert_to_long(param->parameter);
+							if (SQLITE_OK == sqlite3_bind_int(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
+								return 1;
+							}
+						}
+						pdo_sqlite_error_stmt(stmt);
+						return 0;
+
 					case PDO_PARAM_LOB:
 						if (Z_TYPE_P(param->parameter) == IS_RESOURCE) {
 							php_stream *stm;
@@ -117,8 +132,24 @@ static int pdo_sqlite_stmt_param_hook(pd
 								pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource" TSRMLS_CC);
 								return 0;
 							}
+						} else if (Z_TYPE_P(param->parameter) == IS_NULL) {
+							if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
+								return 1;
+							}
+							pdo_sqlite_error_stmt(stmt);
+							return 0;
+						} else {
+							convert_to_string(param->parameter);
+ 						}
+
+						if (SQLITE_OK == sqlite3_bind_blob(S->stmt, param->paramno + 1,
+								Z_STRVAL_P(param->parameter),
+								Z_STRLEN_P(param->parameter),
+								SQLITE_STATIC)) {
+							return 1;
 						}
-						/* fall through */
+						pdo_sqlite_error_stmt(stmt);
+						return 0;
 		
 					case PDO_PARAM_STR:
 					default:
--- patch-sqlite_statement.c ends here ---
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->ale 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Sat Nov 29 13:30:12 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=129277 
State-Changed-From-To: open->closed 
State-Changed-By: ale 
State-Changed-When: Sun Dec 7 11:58:49 UTC 2008 
State-Changed-Why:  
Committed, thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=129277 
>Unformatted:
