Обсуждение: Syntax error with select statement
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.
^
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.
^
aravind chandu wrote:
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
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
On Wednesday 17 December 2008, justin said something like: > 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 Better yet, use placeholders and let the driver do the quoting. j -- Joshua Kugler Part-Time System Admin/Programmer http://www.eeinternet.com PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE
Hello, Thanks for your help,but i still have some problem.While executing it i encountered an error something like this: terminate called after throwing an instance of 'pqxx::syntax_error' what(): ERROR: unterminated dollar-quoted string at or near "$Password$ M^fuo|`sjyo|`so|>-?z" LINE 1: ... = $Username$ achandana $Username$ and password = $Password$... ^ I just give the query as it is in your previous mail.But still i got some problem can you please tell me. Thank You, Aravind. --- On Thu, 12/18/08, Joshua J. Kugler <joshua@eeinternet.com> wrote: From: Joshua J. Kugler <joshua@eeinternet.com> |