# [PATCH] PDO_sqlite data types

- Thread: https://externals.io/message/31935
- Original archive: https://news-web.php.net/php.internals/31935
- Started by Gwynne Raskind on 2007-08-27T10:31:17+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #31935 — Gwynne Raskind — 2007-08-27T10:31:17+00:00

URL: https://externals.io/message/31935#31935

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;

---

## #31939 — Stanislav Malyshev — 2007-08-27T17:41:05+00:00

URL: https://externals.io/message/31935#31939 · In reply to: #31935

> The attached patch adds basic support for storing properly-typed integer 
> and boolean data in SQLite3 databases. I don't really understand why 

It would be nice to have some tests to verify if it works or not :)

-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com
