[Gambas-user] putting name with apostrophe into postgres via gambas
nando
nando_f at ...951...
Wed Feb 20 00:51:33 CET 2008
Yes, you can use the built-in functions that will do it. I personally don't like
to use them because I'd rather have the client perform the work as opposed to the
server...this would be a personal preference. I like to have the server available
for Selects, Inserts, Updates and leave it alone for this type of work. Besides,
this is faster because the data doesn't have to go somewhere else.
This is used on Gambas1, I use 1.0.6 and 1.0.17.
It works.
-Fernando
PUBLIC FUNCTION GoodSQL (SQLinput AS String) AS String
'escape Apostrophe, Quote, backtick, backslash for SQL INSERT and UPDATE
DIM SQLoutput AS String
DIM i AS Integer
DIM a AS String
IF Len(SQLinput) > 0 THEN
FOR i = 1 TO Len(SQLinput)
a = Mid$(SQLinput,i,1)
IF a=Chr$(34) OR a="`" OR a="'" OR a=Chr$(92) THEN a = Chr$(92) & a
SQLoutput = SQLoutput & a
NEXT
ENDIF
RETURN SQLoutput
END
---------- Original Message -----------
From: "Arief Bayu Purwanto" <ariefbayu at ...626...>
To: rterry at ...1823..., "mailing list for gambas users"
<gambas-user at lists.sourceforge.net>
Sent: Tue, 19 Feb 2008 12:51:31 +0700
Subject: Re: [Gambas-user] putting name with apostrophe into postgres via gambas
> On Feb 19, 2008 12:32 PM, richard terry <rterry at ...1822...> wrote:
>
> > On Tue, 19 Feb 2008 03:07:10 pm nando wrote:
> > > I made a string function what escapes the following four characters: " '
> > `
> > > \ the returned string is used for each string item in INSERT or UPDATE.
> > > ..it saved a lot of headaches
> > > -Fernando
> >
> > For my slow to learn mind, I don't suppose you could post your string
> > function
> > to the list/me, so I can read something concrete?.
> >
> > I've many different strings to save, and one can never tell if there could
> > be
> > those characters in them, so perhaps all strings need to be $$string$$
> > before
> > saving. Seems to a bit tedious , unless of course where they are
> > definately
> > unwanted, they are excluded as the user types.
>
> My friend, I think you can use postgre's built in function called
> pg_escape_string[1].
>
> http://pgtclng.projects.postgresql.org/pgtcldocs-20070115/pg-escape-string.html
>
> --
> Arief Bayu Purwanto
> About : http://about.freelancer.web.id/
> Blog : http://bayu.freelancer.web.id/
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------
More information about the User
mailing list