Bug #27938 MyODBC 5/ ADO Unable to update a text field if it has single quotes in it
Submitted: 18 Apr 2007 21:31 Modified: 12 Dec 2007 19:57
Reporter: Erica Moss Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[18 Apr 2007 21:31] Erica Moss
Description:
When I try to set the value of a string type field to this:
vbSingleQuote = Chr(39)
strTest = vbSingleQuote & "test" & vbSingleQuote
fld.Value = strTest
recset.Update

The update fails to occur.  I'm testing below with a field of type CHAR(10) but it seems to be the same for any string type field.  This same test works fine in MyODBC 3.51.14

It doesn't seem to matter where in the string the single quote occurs, so this will fail the same way...
strTest = "foo" & vbSingleQuote & "test" & vbSingleQuote & "bar"

No error is generated, it just doesn't update the server.

How to repeat:
SETUP:
mysql> create database ado;
mysql> drop table if exists ado_test;
mysql> create table ado_test (C1 INT primary key, C2 CHAR(10));
mysql> insert into ado_test values (1, 'FOO'), (2, 'BAR');

VB CODE:
Private Sub Test()
    On Error GoTo EH
    Dim strSQL, strConn, vbSingleQuote, strTest  As String
    Dim connection1 As ADODB.Connection
    Dim recset1 As ADODB.Recordset
    Dim fld As Field
    Set connection1 = New ADODB.Connection
    Set recset1 = New ADODB.Recordset
    vbSingleQuote = Chr(39)
    strTest = vbSingleQuote & "test" & vbSingleQuote
    MsgBox strTest
    
    strSQL = "SELECT * FROM ado_test"
        
     strConn = "DRIVER={MySQL Connector/ODBC v5};" & _
            "SERVER=localhost;DATABASE=ado" & _
            ";UID=root;PWD=mypass;OPTION=3;"

 '   strConn = "DRIVER={MySQL ODBC 3.51 Driver};" & _
           "SERVER=localhost;DATABASE=ado" & _
           ";USER=root;PASSWORD=mypass;OPTION=3;"
        
    ' open connection
    connection1.ConnectionString = strConn
    connection1.CursorLocation = adUseClient
    connection1.Open

    recset1.Open strSQL, connection1, adOpenStatic, adLockOptimistic, adCmdText
             
    recset1.MoveFirst
    While Not recset1.EOF
        For Each fld In recset1.Fields
            If fld.Name = "C2" Then
                fld.Value = strTest
                recset1.Update
            End If
        Next
        recset1.MoveNext
    Wend
    Exit Sub
EH:
    Debug.Print Err.Description & " " & Err.Number & vbNewLine
End Sub
[19 Apr 2007 18:36] Erica Moss
I have to look more at this issue.  It may be related to another bug
[22 Oct 2007 14:21] Susanne Ebrecht
I can handle no single quotes in text fields.
Test is attached.
[12 Dec 2007 19:57] Jess Balint
This bug is not related to the single quotes.

Duplicate of bug#27961.