php / php/php-src

SQLite3Result::fetchArray Doesn't Handle Join Statement Properly

Open
#20,300 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When i tried using ( join ) statement for fetching data , sqlite3 tend to overwrite the column name if it appears in the other table

  • eg:

table-a

ID Name Foreign_id
1 bar 2

table-b

ID Name
2 foo

When i try to join them

SELECT * FROM table-a a JOIN table-b b ON(a.foreign_id=b.id)

i get the result as follows

[
  array(
  'ID' => 2,
  'name' => 'foo',
  'foreign_id' => 2
  )
]

i suggest prefixing the columns names with the table aliases name to clarify and avoid overwriting

So the result would be like this

[
 array(
  'a.ID' => 1,
  'a.name' => 'bar',
  'a.Foreign_id' => 2,
  'b.ID' => 2,
  'b.name' => 'foo'
 )
]

thanks in advance

From manual page: https://php.net/sqlite3result.fetcharray

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.

Research direction

Start with the linked SQLite3Result::fetchArray manual page and reproduce the reported SELECT * JOIN query using the two example tables. Determine the intended handling of duplicate column names and confirm the accepted result shape before changing or testing the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sqlite
Domain
database
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.