php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52295 SQLite's PDO fetch converts integers, reals to strings
Submitted: 2010-07-09 00:27 UTC Modified: 2010-07-09 01:04 UTC
From: parke dot bostrom at gmail dot com Assigned:
Status: Not a bug Package: SQLite related
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: parke dot bostrom at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-09 00:27 UTC] parke dot bostrom at gmail dot com
Description:
------------
When you select and fetch integers and reals from an SQLite database, they are returned as strings.  Why?  I would prefer that when I fetch an integer (or a float), the SQLite PDO driver give me an integer (or a float) rather than converting everything to a string (which is annoying).  Thanks!

Test script:
---------------
<?php

$pdo = new PDO ('sqlite::memory:');
// $select = $pdo->query ('select 5 as foo, typeof (5) as bar;');
$select = $pdo->query ('select 5.0 as foo, typeof (5.0) as bar;');
$row = $select->fetch (PDO::FETCH_ASSOC);

print "actual result:\n";
var_dump ($row);

print "\n";

print "expected result:\n";
$row['foo'] = (float) 5.0;
var_dump ($row);

?>


Expected result:
----------------
array(2) {
  ["foo"]=>
  float(5)
  ["bar"]=>
  string(4) "real"
}


Actual result:
--------------
array(2) {
  ["foo"]=>
  string(3) "5.0"
  ["bar"]=>
  string(4) "real"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-09 01:04 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-07-09 01:04 UTC] johannes@php.net
SQLite stores all data as string. As PHP is dynamically typed we don't have a reason to do the conversion as it is done when needed and would just cost performance,
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 02:01:27 2024 UTC