Re: Syntax error with select statement

From: justin <justin(at)emproshunts(dot)com>
To: aravind chandu <avin_friends(at)yahoo(dot)com>
Cc: postgresql Forums <pgsql-general(at)postgresql(dot)org>
Subject: Re: Syntax error with select statement
Date: 2008-12-17 20:13:41
Message-ID: 49495D75.1060905@emproshunts.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

aravind chandu wrote:
> Hello,
> I have problem with select statement in c++ program I am
> using pqxx library to connect to postgresql database.My query is
>
> result R(T.exec(" select * from dbtable where username = '
> "+user+" ' and password = ' "+st+" ' "));
>
> here st is in encrypted format and the string is st =
> M^fuo|`sjyo|`so|>-?z this is the string i stored in the table .
>
> The error I was encountered is "terminate called after
> throwing an instance of 'pqxx::syntax_error'
> what(): ERROR: unterminated quoted string at or near
> "'M^fuo|`sjyo|`so|>-?z"
> LINE 1: ...table where username = 'achandana' and password = 'M^fuo|`sj...
>
> ^ "
>
> I am not able to identify what the actual problem is can you guys
> please help to solve this problem?Your help is greatly appreciated.
>
> Thank You,
> Aravind

Well its telling you in the error the quotes are flaky. It apears that
the password portion contains another sing quote.

I would move to double dollar quoting when dealing with strings that
contain special characters

example
R(T.exec(" select * from dbtable where username = $UserName$ " + user +
" $Username$ and password = $Password$ " + st + " $Password$ "));

see http://www.postgresql.org/docs/8.3/static/sql-syntax-lexical.html
on dollar quoting

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Grzegorz Jaśkiewicz 2008-12-17 20:18:55 Re: what happens to indexes when TRUNCATEing
Previous Message Joshua J. Kugler 2008-12-17 20:11:43 Re: Other queries locked out during long insert