Re: Which one is better between these two approaches?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Rolandpish wrote:
Hi, I'm doing an application using C# and I have this question:

I have a method called sqlQueryBD which receives a string sql query and executes it against a database.
I also have a class called sqlCompat which has one property "sqlText" with its getter and setter methods. The purpose of this class to translate the receiving sql query into an "escaped" sql query, for instance:
insert into people values ('cod001','Carl Johnson','\\computer\directory\file01.txt')
is translated into:
insert into people values ('cod001','Carl Johnson','\\\\computer\\directory\\file01.txt')

When you have put together the values into a query, it's too late to safely escape the values. If someone uses apostrophes somewhere:

insert into people values ('a00','John 'Noone' Doe','\\computer\directory\file01.txt')

How should the code know that the fourth and fifth apostrophes are to be escaped?

You need to escape each value before you put it in the query. You should consider using parameters, as [someone, can't see the thread right now] suggested.

--
Göran Andersson
_____
http://www.guffa.com
.



Relevant Pages

  • escaping * in a program from shell?
    ... I am trying to run a sql query from a c++ program on Solaris 10. ... but unfortunately shell takes * as its own wildcard and transforms ... Any idea how can I escape this *? ...
    (comp.os.linux.development.apps)
  • Escaping * in SQL query from shell
    ... I am trying to run a sql query from a c++ program on Solaris 10. ... but unfortunately shell takes * as its own wildcard and transforms ... Any idea how can I escape this *? ...
    (comp.os.linux.networking)