Moodle

META: Empty string does not CAST to zero integer in Postgres 8

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Won't Fix
  • Affects Version/s: 1.9
  • Fix Version/s: None
  • Component/s: Database SQL/XMLDB
  • Labels:
    None
  • Environment:
    PostgreSQL version 8 and up
  • Database:
    PostgreSQL
  • Affected Branches:
    MOODLE_19_STABLE

Description

In PostgreSQL 7 and in MySQL, the empty string is implicitly casted to zero integer. Therefore, you can have queries like

> select id,username from mdl_user where id='';
Empty set (0.00 sec)

In PostgreSQL 8, the empty string can not be casted to integer any more and the same query throws an error:

moodle=# select * from mdl_user where id='';
ERROR: invalid input syntax for integer: ""

This is problem as there are queries in Moodle libs that relies on MySQL/Postgres7 behaviour. Typically, when using queries like

DELETE FROM mdl_some_table WHERE id='$id'

This is a META bug to cover all found cases when this might happen. Add found problematic code as a subtask. It blocks Postgres8 support. Also, because it impacts a lot of SQL queries, I have set it as a minor security risk.

Activity

Hide
David Mudrak added a comment -

These issues should be fixed automatically once we start to use prepared statements.

Show
David Mudrak added a comment - These issues should be fixed automatically once we start to use prepared statements.
Hide
Petr Škoda (skodak) added a comment -

I would not be 100% sure in case of adodb - we need to test this in all supported databases

Show
Petr Škoda (skodak) added a comment - I would not be 100% sure in case of adodb - we need to test this in all supported databases
Hide
David Mudrak added a comment -

The new DB API takes care of this automatically.

Show
David Mudrak added a comment - The new DB API takes care of this automatically.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: