Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31935 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4135 invoked by uid 1010); 27 Aug 2007 10:31:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 4104 invoked from network); 27 Aug 2007 10:31:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Aug 2007 10:31:32 -0000 Authentication-Results: pb1.pair.com header.from=gwynne@wanderingknights.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=gwynne@wanderingknights.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain wanderingknights.org from 208.97.132.74 cause and error) X-PHP-List-Original-Sender: gwynne@wanderingknights.org X-Host-Fingerprint: 208.97.132.74 sd-green-bigip-74.dreamhost.com Linux 2.4/2.6 Received: from [208.97.132.74] ([208.97.132.74:40082] helo=postalmail-a4.g.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/E9-43728-208A2D64 for ; Mon, 27 Aug 2007 06:31:32 -0400 Received: from [192.168.2.197] (c-24-61-79-221.hsd1.ma.comcast.net [24.61.79.221]) by postalmail-a4.g.dreamhost.com (Postfix) with ESMTP id 002FA11E4FA for ; Mon, 27 Aug 2007 03:31:22 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v752.3) Content-Transfer-Encoding: 7bit Message-ID: <74ABDB2B-EDB7-4E99-876C-88B45FDA6832@wanderingknights.org> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed To: PHP Developers Mailing List Date: Mon, 27 Aug 2007 06:31:17 -0400 X-Mailer: Apple Mail (2.752.3) Subject: [PATCH] PDO_sqlite data types From: gwynne@wanderingknights.org (Gwynne Raskind) The attached patch adds basic support for storing properly-typed integer and boolean data in SQLite3 databases. I don't really understand why this kind of support has been so consistently lacking in PHP database driver implementations. Similar problems have plagued the MySQL and MySQLi extensions for a long time, and PDO seems to struggle for the support at times. This diff is against PHP 5.2.3, but I've verified that it works in 5.2.4RC3, 5.2.4 CVS, and HEAD. This by itself disturbs me because it indicates that in all this time this code hasn't been touched at all. Was it really that hard to add this very simple code? -- Gwynne, Daughter of the Code "This whole world is an asylum for the incurable." Index: ext/pdo_sqlite/sqlite_statement.c =================================================================== RCS file: /repository/php-src/ext/pdo_sqlite/sqlite_statement.c,v retrieving revision 1.18.2.4.2.2 diff -u -r1.18.2.4.2.2 sqlite_statement.c --- ext/pdo_sqlite/sqlite_statement.c 1 Jan 2007 09:36:05 -0000 1.18.2.4.2.2 +++ ext/pdo_sqlite/sqlite_statement.c 27 Aug 2007 10:08:42 -0000 @@ -96,7 +96,22 @@ switch (PDO_PARAM_TYPE(param->param_type)) { case PDO_PARAM_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_NULL: if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) { return 1;