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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2023 The PHP Group
All rights reserved.
Last updated: Sat Feb 04 05:03:38 2023 UTC