Moodle

ADOdb ODBC Insert_ID() function under MSSQL doesn't work

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Won't Fix
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Database SQL/XMLDB
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

Was implementing the MSSQL when I discovered that:

  • inserting records using placeholders AND
  • retrieving the last id with Insert_ID()

are completely broken!!

Explanation from: http://docs.moodle.org/en/Development:dmllib_2.0_problems

Problem: Queries using placeholders under MSSQL are executed by one sp_executesql() procedure call. In MSSQL procedures, triggers are executed into new scopes (like "shells"), so the Insert_ID() function (internally usind SCOPE_IDENTITY()) doesn't work at all, because the insert has been executed in another scope.

Solution: Patch ADOdb driver so, each time one INSERT is going to be executed by sp_executesql(), we'll add one SCOPE_IDENTITY() in the same procedure execution (that way, both the insert and the identity will be in the same scope). Once executed, return the value of the identity by the standard Insert_ID() function. BC compatible 100% with current code if implemented that way.

Issue Links

Activity

Hide
Petr Škoda (skodak) added a comment -

my +1 to abandon adodb and write a new native driver

Show
Petr Škoda (skodak) added a comment - my +1 to abandon adodb and write a new native driver
Hide
Eloy Lafuente (stronk7) added a comment -

I don't get the point about this bug. It was fixed ages ago by MDL-14886 (in fact the text is a copy/paste of the original report) . Perhaps we have messed the ADObd patch in some upgrade?

I'll add some tests for this, in case they don't exist.

Show
Eloy Lafuente (stronk7) added a comment - I don't get the point about this bug. It was fixed ages ago by MDL-14886 (in fact the text is a copy/paste of the original report) . Perhaps we have messed the ADObd patch in some upgrade? I'll add some tests for this, in case they don't exist.
Hide
Eloy Lafuente (stronk7) added a comment -

I'm closing this as won't fix as far as we are abandoning adodb drivers in favour of our native ones, see MDL-19474 (with ODBC not being one of them at all).

So, for mssql, you'll need to use the native "mssql" one (freetds based) or the "sqldrv" one (based in new MS driver for PHP, if finally it arrives on time to Moodle 2.0. See MDL-17969 about how both are going).

Ciao

Show
Eloy Lafuente (stronk7) added a comment - I'm closing this as won't fix as far as we are abandoning adodb drivers in favour of our native ones, see MDL-19474 (with ODBC not being one of them at all). So, for mssql, you'll need to use the native "mssql" one (freetds based) or the "sqldrv" one (based in new MS driver for PHP, if finally it arrives on time to Moodle 2.0. See MDL-17969 about how both are going). Ciao

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: