Bug #34621 ODBC - Update fails, if a "ORDER BY" clause is specified

Submitted: 16 Feb 2008 21:05 Modified: 23 Feb 2008 7:04
Reporter: Diego Milazzo Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:ODBC 5.1.2 - MySQL 5.0.51a OS:Windows (XP with SP2)
Assigned to: Assigned Account CPU Architecture:Any
Tags: ODBC, order, order by, UPDATE

[16 Feb 2008 21:05] Diego Milazzo
Description:
In the code below, when I try to update I have an error:

80004005 (-2147467259)
 - Insufficient key column information for updating (or similar)

It seems to be related to the "ORDER BY" clause, if I remove, it works!

My config:
- MySQL 5.0.51a
- Connector ODBC 5.1.2
- VB6
- Windows XP with SP2

How to repeat:
CREATE SCHEMA IF NOT EXISTS `DBTest` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `DBTest`;

CREATE  TABLE IF NOT EXISTS `DBTest`.`Catg` (
  `ID` INT UNSIGNED NOT NULL ,
  `DESC` VARCHAR(60) NOT NULL ,
  PRIMARY KEY (`ID`) );

CREATE  TABLE IF NOT EXISTS `DBTest`.`Art` (
  `ID` INT UNSIGNED NOT NULL ,
  `ID_CATG` INT UNSIGNED NOT NULL ,
  `DESC` VARCHAR(60) NOT NULL ,
  PRIMARY KEY (`ID`, `ID_CATG`) ,
  INDEX fk_Art_Catg (`ID_CATG` ASC) ,
  CONSTRAINT `fk_Art_Catg`
    FOREIGN KEY (`ID_CATG`)
    REFERENCES `DBTest`.`Catg` (`ID`));

INSERT INTO  `DBTest`.`Catg` VALUES (1, 'DESCCATG1'),(2, 'DESCCATG2');
INSERT INTO  `DBTest`.`Art` VALUES (1, 1, 'DESCART1'),(2, 1, 'DESCART2'),(3, 2, 'DESCART3');

VB Code:
Private Sub cmdTest_Click()
    Dim oConnDB As ADODB.Connection
    Dim oRS As ADODB.Recordset
    Dim sQuery As String

    On Error GoTo ErrHandler
    
    ' Connection
    Set oConnDB = New ADODB.Connection
    oConnDB.ConnectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=DBTest;User=root;Password=notime;Option=35;"
    oConnDB.Properties("PROMPT") = adPromptNever
    oConnDB.Open

    sQuery = "SELECT Art.ID, Art.DESC, Art.ID_CATG, Catg.DESC AS DESC_CATG " & _
             "FROM Art, Catg WHERE Art.ID_CATG=Catg.ID ORDER BY Art.ID"

    'sQuery = "SELECT Art.ID, Art.DESC, Art.ID_CATG, Catg.DESC AS DESC_CATG " & _
    '         "FROM Art, Catg WHERE Art.ID_CATG=Catg.ID"

    Set oRS = New ADODB.Recordset
    oRS.CursorLocation = adUseClient
    oRS.Open sQuery, oConnDB, adOpenStatic, adLockOptimistic

    oRS.MoveFirst
    oRS.Fields("DESC").Value = "newdesc"
    oRS.Update

ExitPoint:
    Set oRS = Nothing
    Set oConnDB = Nothing

    Exit Sub
ErrHandler:
    MsgBox Hex(Err.Number) & " - " & Err.Description
    Resume ExitPoint
End Sub
[16 Feb 2008 21:12] Diego Milazzo
...
[18 Feb 2008 13:55] MySQL Verification Team
Do a new comment here saying what are you want to correct.
[18 Feb 2008 19:46] Diego Milazzo
No, nothing.
This is sufficient.
[23 Feb 2008 0:02] Erica Moss
trace file of this test case against sql server

Attachment: SQL.LOG (application/octet-stream, text), 109.95 KiB.

[3 Dec 2010 8:37] Bogdan Degtyariov
Verified with Connector/ODBC 5.1.8

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.