php / php/php-src

SQLite3Result::fetchArray runs the query again. [O: Bug #64531 ]

Open
#13,587 2 comments 0 reactions 1 assignee View on GitHub

@SakiTakamachi is already working on this.

Since Mar 5, 2024.

Bug Extension: sqlite3 Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

Already reported 11 years ago. Here: https://bugs.php.net/bug.php?id=64531

The following code:

<?php

$conn = new SQLite3('Log.sqlite', \SQLITE3_OPEN_READWRITE);

$res = $conn->query('CREATE TABLE myTable (id INTEGER PRIMARY KEY AUTOINCREMENT, a INTEGER, b INTEGER, c INTEGER)');
//$res = $conn->query('DELETE FROM myTable');

$res = $conn->query('INSERT INTO myTable VALUES (null, 1, 2, 3)'); // Inserts a row here (the null is an auto-incrementing PK).

$res->fetchArray(); // Inserts the *same* row data as above, again (with the next auto-incrementing PK number).
$res->fetchArray(); // And yet again...
$res = $conn->query('SELECT COUNT(id) FROM myTable');
$data = $res->fetchArray();

var_dump($data[0]);

Resulted in this output:

int(3)

But I expected this output instead:

int(1)
PHP Version

PHP 8.2

Operating System

Debian

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.