Bug #17569 ASPUpload / ASPJpge Update BLOB
Submitted: 20 Feb 2006 10:06 Modified: 2 Sep 2009 8:07
Reporter: Francisco Rios Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:3.51 OS:Windows (Windows 2003 Server)
Assigned to: CPU Architecture:Any

[20 Feb 2006 10:06] Francisco Rios
Description:
I'm moving my database from MsAccess to MySQL and I'm having a problem with one UPDATE.
The UPDATE worked with the MsAccess but not with MySQL.
The code is: 

<%
            ' Create an instance of AspUpload object
              Set Upload = Server.CreateObject("Persits.Upload")
           ' Capture uploaded file, save to memory.
             Count = Upload.Save
             If Count = 0 Then

Response.Write "No hay imagen seleccionada. <A HREF=""foto.asp"">Intente de nuevo</A>."

              Response.End
                Else
                         ' Obtain File object representing uploaded file
                            Set File = Upload.Files(1)
                          ' Is this a valid image file?
                           If File.ImageType <> "UNKNOWN" Then

                           ' create instance of AspJpeg object
                         Set jpeg = Server.CreateObject("Persits.Jpeg")

                   ' open uploaded file from memory
                       jpeg.OpenBinary( File.Binary )

              Set rs = Server.CreateObject("adodb.recordset")
            rs.Open "select image_blob from
MYIMAGES_empresa where id = 405 ",
strConnect, 2, 3

         jpeg.PreserveAspectRatio = True

           If jpeg.OriginalWidth > 399 or jpeg.OriginalHeight > 300 Then

           If jpeg.OriginalWidth > jpeg.OriginalHeight Then

           jpeg.Width = 399

           Else

            jpeg.Height = 300

          End If

        End If
           rs("image_blob").Value = Jpeg.Binary                    
               rs.Update
               rs.Close
               Set rs = Nothing

             Response.Write "Archivo Grabado<P>"
                         Else                              
         Response.Write "Imagen no vĂ¡lida. <A HREF=""foto.asp"">Try again</A>."

                                        Response.End

                            End If

                End If
    %>

The db table "MYIMAGES_empresa" has the following specification:
Id = int(10)
Image_blob = blob
Id_empresa = int(10)
 
    The error is:

    Microsoft OLE DB Provider for ODBC Drivers error '80004005' 
    Query-based update failed because the row to update could not be found.

    
The db connection is:

    strConnect = "DRIVER={MySQL ODBC 3.51 Driver};"_
    & "SERVER=localhost;"_ 
    & "DATABASE=test;"_
    & "UID=root;PWD=nyn; OPTION=35;"

     

- And the user root has all the permition into the DB.
- id = 405 : The statement has a record.  
- I did a test with another fields, rs("Id_empresa ") = 1000 replaced to rs("image_blob").Value = Jpeg.Binary, and it worked.
- If I do a "Select" this work and the image is showed.

How to repeat:
Always.
[17 Oct 2007 11:11] Susanne Ebrecht
This bug is for MyODBC 3.51. I fixed the version number at this bug report.
[2 Sep 2009 8:07] Tonci Grgin
Hi Francisco and thanks for your report. It is actually not a feature request and I apologize for missing it completely...

I am not at liberty to review your code, for that you need support contract.

It appears to me there is no bug here and here's why.
  o Unable to locate record: Please check MS documentation on how updates are done in ADO:
  http://support.microsoft.com/default.aspx?scid=kb;EN-GB;q190727&GSSNB=1:

and add 
  rs.Properties("Update Criteria").Value = 0 'adCriteriaKey

  o If this is not enough, try following code for insertion:
        Set stm = New ADODB.Stream
        stm.Type = StreamTypeEnum.adTypeBinary
        stm.Open
        stm.LoadFromFile (App.Path & "\testpicture.jpg")
        rs.Fields("picture").Value = stm.Read
        rs.Update
        stm.Close
        Set stm = Nothing
        rs.Close

and for reading back, something like:

        rs.Open "Select * from table_name where picname='pic" & CStr(I) & "'", cx, adOpenForwardOnly, adLockOptimistic
        If Not rs.EOF Then
                Set stm = New ADODB.Stream
                stm.Type = StreamTypeEnum.adTypeBinary
                stm.Open
                stm.Write rs.Fields("picture").Value
                stm.SaveToFile App.Path & "\picture" & CStr(I) & ".jpg", adSaveCreateOverWrite
        End If
        rs.Close