pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <Dave@micro-automation.net>
To: Bruce Momjian <pgman@candle.pha.pa.us>
To: Arsalan Zaidi <azaidi@directi.com>
Cc: PostgreSQL jdbc list <pgsql-jdbc@postgresql.org>
Subject: Re: Re: [INTERFACES] New code for JDBC driver
Date: Sat, 30 Jun 2001 14:21:54 -0400
Message-ID: <005301c10191$8ae2ce50$0201a8c0@inspiron> (raw)
References: <200106301642.f5UGgkj14915@candle.pha.pa.us>

Can you give us some background. What is this trying to solve?
From the look of it the purpose is to remove embedded semicolons and quotes.
From my POV this should be handled by the backend.

My reasons are as follows:

1) Any attempt at parsing the query by the driver will slow the driver down.
2) If the purpose of parsing is to make an incorrect query correct; then I
would prefer the backend fail and make me fix my code.

Dave
----- Original Message -----
From: "Bruce Momjian" <pgman@candle.pha.pa.us>
To: "Arsalan Zaidi" <azaidi@directi.com>
Cc: "PostgreSQL jdbc list" <pgsql-jdbc@postgresql.org>
Sent: Saturday, June 30, 2001 12:42 PM
Subject: [JDBC] Re: [INTERFACES] New code for JDBC driver


> > 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?
>
> --
>   Bruce Momjian                        |  http://candle.pha.pa.us
>   pgman@candle.pha.pa.us               |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
>


----------------------------------------------------------------------------
----


> *** 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");
>         }
>         file://System.out.println ("modified SQL: " + sql);
> +
> +
> +
> +
> +       file://---- Added by Arsalan
> +       String query = sql;
> +
> +       file://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 == '\'') file://is a '
> +   {
> +
> +       System.out.println("in '");
> +       int j = i;
> +       if(++j < query.length())
> +   {
> +       if(query.charAt(j) == '\'') file://is an escape
> +   {
> +       i++; file://skip them
> +       continue;
> +   }
> +       else file://genuine tick!
> +   {
> +       if(openTick == 0)
> +   {
> +       openTick = 1;
> +   }
> +       else if(openTick == 1)
> +   {
> +       openTick = 0;
> +   }
> +       else if(openTick == 2) file://initialise it
> +   {
> +       openTick = 1;
> +   }
> +   }
> +   }
> +   }
> +
> +
> +       if(oneChar == '"') file://is a "
> +   {
> +       System.out.println("in \"");
> +       int j = i;
> +       if(++j < query.length())
> +   {
> +       if(query.charAt(j) == '"') file://is an escape
> +   {
> +       i++; file://skip them
> +       continue;
> +   }
> +       else file://genuine quote!
> +   {
> +       if(openQuote == 0)
> +

> +       openQuote = 1;
> +   }
> +       else if(openQuote == 1)
> +   {
> +       openQuote = 0;
> +   }
> +       else if(openQuote == 2) file://initialise it
> +   {
> +       openQuote = 1;
> +   }
> +   }
> +   }
> +   }
> +
> +
> +   }
> +
> +
> +
> +
> +       file://------Addition ends
> +
> +
> +
> +       return sql;
>       }
>


----------------------------------------------------------------------------
----


>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>




view thread (17+ messages)  latest in thread

Message-ID: <005301c10191$8ae2ce50$0201a8c0@inspiron>
Permalink:  ../005301c10191$8ae2ce50$0201a8c0@inspiron/
Also on:    postgresql.org/message-id/005301c10191$8ae2ce50$0201a8c0@inspiron

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: Dave@micro-automation.net, pgman@candle.pha.pa.us, azaidi@directi.com, pgsql-jdbc@postgresql.org
  Subject: Re: Re: [INTERFACES] New code for JDBC driver
  In-Reply-To: <005301c10191$8ae2ce50$0201a8c0@inspiron>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox