Re: [INTERFACES] New code for JDBC driver

From: Barry Lind <barry(at)xythos(dot)com>
To: PostgreSQL jdbc list <pgsql-jdbc(at)postgresql(dot)org>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Arsalan Zaidi <azaidi(at)directi(dot)com>
Subject: Re: [INTERFACES] New code for JDBC driver
Date: 2001-07-01 01:16:43
Message-ID: 3B3E79FB.9040505@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces pgsql-jdbc

Arsalan,

I am having a hard time understanding what this patch is supposed to do.
What do you mean by "look for semicolons outside '' and ""'s"? It is
valid in postgresql to have semicolons outside quotes, so I don't
understand what you are trying to do.

After looking at the JDBC spec on what escape processing is supposed to
do (section 11 in the jdbc 1.2 spec), it is intended to be a database
independent way to specify certain constructs that are not yet
implemented in a standard way across databases. All of these special
constructs are of the form: {name parameters}
For example {d '2001-06-30'} is a way to specify a date value regardless
of the underlying databases date format. Apparently the JDBC spec uses
the same logic as is defined by ODBC for the same purposes.

thanks,
--Barry

Bruce Momjian wrote:

>>No response for my query since yesterday.
>>
>>I've changed the code in Connection.escapeSQL() to look for semicolons
>>outside '' and ""'s.
>>
>>It's not been well tested, but it seems to work. Someone might want to add
>>it to the source tree, or to their own local versions if they wish.
>>
>>
>
> OK, here is the diff, I think. Can jdbc people comment on it?
>
>
>
> ------------------------------------------------------------------------
>
> *** Connection.java Wed Jun 6 20:09:32 2001
> --- /bjm/x Sat Jun 30 12:35:39 2001
> ***************
> *** 931,937 ****
> --- 21,123 ----
> index = sql.indexOf("{d");
> }
> //System.out.println ("modified SQL: " + sql);
> +
> +
> +
> +
> + //---- Added by Arsalan
> + String query = sql;
> +
> + //2== uninitialised 1==true 0==false
> + int openTick = 2;
> + int openQuote = 2;
> + char oneChar;
> +
> + // query = query.toLowerCase();
> +
> + if(query.indexOf(";") == -1) // no semi's at all
> + {
> return sql;
> }
>
> + for(int i=0; i<query.length(); i++)
> + {
> + oneChar = query.charAt(i);
> +
> + if((oneChar == ';' && openTick == 0 && openQuote != 1) || (oneChar == ';' && openQuote == 0 && openTick != 1))
> + {
> + throw new SQLException("Found an external SEMICOLON!! at i = "+i);
> + }
> +
> + if(oneChar == '\'') //is a '
> + {
> +
> + System.out.println("in '");
> + int j = i;
> + if(++j < query.length())
> + {
> + if(query.charAt(j) == '\'') //is an escape
> + {
> + i++; //skip them
> + continue;
> + }
> + else //genuine tick!
> + {
> + if(openTick == 0)
> + {
> + openTick = 1;
> + }
> + else if(openTick == 1)
> + {
> + openTick = 0;
> + }
> + else if(openTick == 2) //initialise it
> + {
> + openTick = 1;
> + }
> + }
> + }
> + }
> +
> +
> + if(oneChar == '"') //is a "
> + {
> + System.out.println("in \"");
> + int j = i;
> + if(++j < query.length())
> + {
> + if(query.charAt(j) == '"') //is an escape
> + {
> + i++; //skip them
> + continue;
> + }
> + else //genuine quote!
> + {
> + if(openQuote == 0)
> + {
> + openQuote = 1;
> + }
> + else if(openQuote == 1)
> + {
> + openQuote = 0;
> + }
> + else if(openQuote == 2) //initialise it
> + {
> + openQuote = 1;
> + }
> + }
> + }
> + }
> +
> +
> + }
> +
> +
> +
> +
> + //------Addition ends
> +
> +
> +
> + return sql;
> }
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
> /bjm/diff
>
> Content-Type:
>
> text/plain
> Content-Encoding:
>
> 7bit
>
>
> ------------------------------------------------------------------------
> Part 1.3
>
> Content-Type:
>
> text/plain
> Content-Encoding:
>
> binary
>
>

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Barry Lind 2001-07-01 01:19:16 Re: [INTERFACES] New code for JDBC driver
Previous Message Peter Eisentraut 2001-07-01 00:11:45 Re: libpq++ on Windows

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2001-07-01 01:19:16 Re: [INTERFACES] New code for JDBC driver
Previous Message Barry Lind 2001-07-01 00:25:13 Patch to set timezone once instead of every call