Thread

  1. Pg.pm oddity with apostrophes

    Charles Curley <ccurley@trib.com> — 2000-08-26T16:42:11Z

    I am using pg.pm with perl to interface between a web server,
    Apache, and postgres. Pg.pm is as follows:
    
    #-------------------------------------------------------
    #
    # $Id: Pg.pm,v 1.8 1998/09/27 19:12:22 mergl Exp $
    #
    # Copyright (c) 1997, 1998  Edmund Mergl
    #
    #-------------------------------------------------------
    
    
    [PostgreSQL 6.5.1 on i686-pc-linux-gnu, compiled by gcc pgcc-2.91.66]
    
    
    The oddity I have hit is that if I try to inset a name with an apostrophe
    in it (e.g. O'Neil), pgsql belly-aches and returns an error of 7. The
    record is not inserted. If I remove the apostrophe, the otherwise identical
    record goes in just fine. I am escaping the apostrophe correctly, as far
    as I know. The insert query is as follows:
    
    Insert into contacts VALUES ( 'Mr.', 'Patrick', 'O\'Neil', blah, blah... 'http://URL' ); "
    
    I can insert the name from psql with no problems, which makes me think it
    is a Pg.pm problem.
    
    -- 
    
    		-- C^2
    
    No windows were crashed in the making of this email.
    
    Looking for fine software and/or web pages?
    http://w3.trib.com/~ccurley
  2. Re: Pg.pm oddity with apostrophes

    Jesus Aneiros <aneiros@jagua.cfg.sld.cu> — 2000-08-26T17:40:21Z

    Try '' instead of a single '.
    
    --
    Jesus Aneiros Sosa
    mailto:aneiros@jagua.cfg.sld.cu
    http://jagua.cfg.sld.cu/~aneiros
    
    On Sat, 26 Aug 2000, Charles Curley wrote:
    
    > I am using pg.pm with perl to interface between a web server,
    > Apache, and postgres. Pg.pm is as follows:
    > 
    > #-------------------------------------------------------
    > #
    > # $Id: Pg.pm,v 1.8 1998/09/27 19:12:22 mergl Exp $
    > #
    > # Copyright (c) 1997, 1998  Edmund Mergl
    > #
    > #-------------------------------------------------------
    > 
    > 
    > [PostgreSQL 6.5.1 on i686-pc-linux-gnu, compiled by gcc pgcc-2.91.66]
    > 
    > 
    > The oddity I have hit is that if I try to inset a name with an apostrophe
    > in it (e.g. O'Neil), pgsql belly-aches and returns an error of 7. The
    > record is not inserted. If I remove the apostrophe, the otherwise identical
    > record goes in just fine. I am escaping the apostrophe correctly, as far
    > as I know. The insert query is as follows:
    > 
    > Insert into contacts VALUES ( 'Mr.', 'Patrick', 'O\'Neil', blah, blah... 'http://URL' ); "
    > 
    > I can insert the name from psql with no problems, which makes me think it
    > is a Pg.pm problem.
    > 
    > -- 
    > 
    > 		-- C^2
    > 
    > No windows were crashed in the making of this email.
    > 
    > Looking for fine software and/or web pages?
    > http://w3.trib.com/~ccurley
    
    
    
  3. Re: Pg.pm oddity with apostrophes

    David Cantrell <david@cantrell.org.uk> — 2000-08-26T18:43:56Z

    On Sat, Aug 26, 2000 at 10:42:11AM -0600, Charles Curley wrote:
    
    > I am using pg.pm with perl ...
    >
    > The oddity I have hit is that if I try to inset a name with an apostrophe
    > in it (e.g. O'Neil), pgsql belly-aches and returns an error of 7. The
    > record is not inserted. If I remove the apostrophe, the otherwise identical
    > record goes in just fine. I am escaping the apostrophe correctly, as far
    > as I know. The insert query is as follows:
    >
    > Insert into contacts VALUES ( 'Mr.', 'Patrick', 'O\'Neil', blah, blah... 'http://URL' ); "
    >
    > I can insert the name from psql with no problems, which makes me think it
    > is a Pg.pm problem.
    
    Looks more like it's a problem with your understanding of perl.  Can you
    post the exact perl code you're using to execute that query?
    
    -- 
    David Cantrell | david@cantrell.org.uk | http://www.cantrell.org.uk/david
    
          I'm working on the assumption that chicks dig mad scientists
    
    
  4. Re: Pg.pm oddity with apostrophes

    Anthony E . Greene <agreene@pobox.com> — 2000-08-27T00:33:53Z

    On 26 Aug 2000 12:42 Charles Curley wrote:
    >The oddity I have hit is that if I try to inset a name with an apostrophe
    >in it (e.g. O'Neil), pgsql belly-aches and returns an error of 7. The
    >record is not inserted.
    
    Perl will escape the apostrophe and will not pass the backslash on to the
    backend. You will need to use a double backslash:
    
    $sql = "INSERT INTO contacts VALUES ('Mr.','Patrick','O\\'Neil','http://URL')";
    
    
    Tony
    -- 
    Anthony E. Greene <agreene@pobox.com> <http://www.pobox.com/~agreene/>
    PGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26  C484 A42A 60DD 6C94 239D
    Linux. The choice of a GNU Generation. <http://www.linux.org/>
    
    
  5. Re: Pg.pm oddity with apostrophes

    Charles Curley <ccurley@trib.com> — 2000-08-27T01:28:53Z

    On Sat, Aug 26, 2000 at 08:33:53PM -0400, Anthony E . Greene wrote:
    > On 26 Aug 2000 12:42 Charles Curley wrote:
    > >The oddity I have hit is that if I try to inset a name with an apostrophe
    > >in it (e.g. O'Neil), pgsql belly-aches and returns an error of 7. The
    > >record is not inserted.
    > 
    > Perl will escape the apostrophe and will not pass the backslash on to the
    > backend. You will need to use a double backslash:
    > 
    > $sql = "INSERT INTO contacts VALUES ('Mr.','Patrick','O\\'Neil','http://URL')";
    
    Thanks. That also did not work.
    
    
    -- 
    
    		-- C^2
    
    No windows were crashed in the making of this email.
    
    Looking for fine software and/or web pages?
    http://w3.trib.com/~ccurley
  6. Re: Pg.pm oddity with apostrophes

    Charles Curley <ccurley@trib.com> — 2000-08-27T01:45:29Z

    On Sat, Aug 26, 2000 at 07:43:56PM +0100, David Cantrell wrote:
    > On Sat, Aug 26, 2000 at 10:42:11AM -0600, Charles Curley wrote:
    > 
    > > I am using pg.pm with perl ...
    > >
    > > The oddity I have hit is that if I try to inset a name with an apostrophe
    > > in it (e.g. O'Neil), pgsql belly-aches and returns an error of 7. The
    > > record is not inserted. If I remove the apostrophe, the otherwise identical
    > > record goes in just fine. I am escaping the apostrophe correctly, as far
    > > as I know. The insert query is as follows:
    > >
    > > Insert into contacts VALUES ( 'Mr.', 'Patrick', 'O\'Neil', blah, blah... 'http://URL' ); "
    > >
    > > I can insert the name from psql with no problems, which makes me think it
    > > is a Pg.pm problem.
    > 
    > Looks more like it's a problem with your understanding of perl.  Can you
    > post the exact perl code you're using to execute that query?
    
    Your request prompted me to look over the code to extract it for this
    message. That lead me to look at how I was doing not only the insertion
    but also the query to send back the inserted record to the user for
    approval. In the process of doing that I realized: I was inserting an
    escaped apostrophe, but making the select on an unescaped apostrophe. The
    fix became immediately apparent.
    
    My previous two message require revision: a proper way to escape an
    apostrophe is with a slash. I have not tried doubling it.
    
    Thanks.
    
    -- 
    
    		-- C^2
    
    No windows were crashed in the making of this email.
    
    Looking for fine software and/or web pages?
    http://w3.trib.com/~ccurley