Gossamer Forum
Home : Products : Gossamer Links : Discussions :

SQL UPDATE in DOCS

Quote Reply
SQL UPDATE in DOCS
Looking throught the docs under SQL - UPDATE for the correct sytax to include a 'replace' in the SET clause.

my $result = $obj->update(
{
REPLACE(Title,'Dogs','Cats'), <<<<<< ???????
col2 => $val2,
...
},
$condition
);


The docs may have a simple ommision also: "The condition can now do much more complex where clauses though. " Do might be an appropriate insertion.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] SQL UPDATE in DOCS In reply to
Hi,

$result = $obj->update(
{ Title => \"REPLACE('Title', 'Dogs', 'Cats')", col2 => $val2 },
$condition
);

You pass in a hash of what you want to set, and a hash/condition of the where clause. Remember, the right hand side of the set or where clause is escaped by default. So if you do:

Title => "REPLACE('Title', 'Dogs', 'Cats')"

the SQL will look like:

UPDATE Table SET Title = 'REPLACE(\'Title\',\'Dogs\',\'Cats\')'

not what you want. You backslash it to tell GT::SQL not to escape it.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] SQL UPDATE in DOCS In reply to
Very Clear.

I have added this to my notes.

Thanks AlexCool


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Alex] SQL UPDATE in DOCS In reply to
Hi Alex, back to the SQL table (excuse the pun):

$affected = $obj->update(
{
Title => \"REPLACE($option,'%', myfunction('%')"
}
);

Beacuse of the potention damage such a function could have on someones table, I thought I would run this one past you....

I am carrying on from the replace you helped me with. I want to replace the content of every coloumn ($option: which could contain Title or Description), with its contents run through a function (myfunciton).

I understand the % is the wildcard for unlimited characters. The syntax is what worries me (as usual).


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] SQL UPDATE in DOCS In reply to
Hmm, I'm not sure this is doing what you think it is doing. What is myfunction()? Is that a perl function, or an SQL function?

What are you trying to do exactly?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] SQL UPDATE in DOCS In reply to
I have an HTML stripping function: untag() which returns the string passed to it, minus the HTML tags. I wish to pass all the Titles or Descriptions (depending on what the user has selected) through my html stripper function.

I was hoping this could be done with a single update function. But if not, I guess it would have to be a loop of every record.... select, then update.

Code:
if ($option eq 'Title') {
$affected = $ct->update(
{
Title => \"REPLACE('Title','%', untag('%')"
}
);}


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 17, 2002, 8:33 PM