php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72621 pg_execute(): NULL Date converts to empty string
Submitted: 2016-07-19 13:33 UTC Modified: 2020-11-21 17:28 UTC
Votes:6
Avg. Score:4.2 ± 0.9
Reproduced:4 of 5 (80.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: ravisen at mail dot ru Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 7.0.8 OS: Centos 7
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: ravisen at mail dot ru
New email:
PHP Version: OS:

 

 [2016-07-19 13:33 UTC] ravisen at mail dot ru
Description:
------------
NULL Date converts to empty string

Test script:
---------------
/* SQL Table
CREATE TABLE t_lot_steps
(
  n_id_lot integer NOT NULL, 
  d_start date
)
*/

$sql = 'INSERT INTO t_lot_steps( n_id_lot,  d_start )  VALUES ( $1, $2 ) ';
$bindsData = [ 1, null ];

$conn = pg_connect(...);
pg_prepare($conn, '', $sql);
pg_execute($conn, '', $bindsData);


Expected result:
----------------
Record added to the table

Actual result:
--------------
E_WARNING pg_execute(): Query failed: ERROR: invalid input syntax for type date: ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-21 17:12 UTC] dev at dcolt dot org
Just tested this in PHP 7.4.12, on Gentoo, against Postgresql 13.1

And I do get the Expected result (Record added to the table)

I also made a reference program in C++ to test the libpq functions directly.

Reference code:
---------------
#include <array>
#include <iostream>
#include <libpq-fe.h>

int main() {
  PGconn *conn =
      PQconnectdb("dbname=test user=postgres password=postgres");

  PGresult *result = PQprepare(
      conn, "",
      "INSERT INTO t_lot_steps( n_id_lot,  d_start )  VALUES ( $1, $2 ) ", 0,
      nullptr);

  std::array<const char *, 2> params = {"1", nullptr};

  PGresult *returnResult =
      PQexecPrepared(conn, "", 2, params.data(), nullptr, nullptr, 0);

  auto status = PQresultStatus(returnResult);

  PQfinish(conn);
  return 0;
}
 [2020-11-21 17:28 UTC] kalle@php.net
-Status: Open +Status: Not a bug
 [2020-11-21 17:28 UTC] kalle@php.net
.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC