Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Escaped/QuotedString classes

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

Escaped/QuotedString classes

Author dlr
Full name Daniel Rall
Date 2000-10-07 11:56:01 PDT
Message Dave, I was wondering if using both EscapedString and QuotedString
together handles internal single quotes? I noticed that the MySQL
driver (at least, version 2.0.2), handles the quotes in its
PreparedStatement.se​tString(String) method. There is a little conflict
using Escaped/QuotedString classes with MySQL drivers's
PreparedStatement because they both add external quotes. The MySQL
driver handles them via backslash escapes:

    public void setString(int parameterIndex, String X) throws
java.sql.SQLException
    {
    // if the passed string is null, then set this column to null

    if(X == null) {
        set(parameterIndex, "null");
    }
    else {
        StringBuffer B = new StringBuffer();
        int i;
                    
        B.append('\'');

        for (i = 0 ; i < X.length() ; ++i) {
        char c = X.charAt(i);
                
        if (c == '\\' || c == '\'' || c == '"') {
            B.append((char)'\\');
        }
        B.append(c);
        }
            
        B.append('\'');
        set(parameterIndex, B.toString());
    }
    }
--

Daniel Rall <dlr at finemaltcoding dot com>

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

Escaped/QuotedString classes dlr Daniel Rall 2000-10-07 11:56:01 PDT
Messages per page: