Help - Search - Members - Calendar
Full Version: MySQL partial replace query
Invision Power Services > Community Forums > Community Web Design and Coding
Chucker
In finally(!) migrating from IPB 1.3.1 to 2.1.7, there's quite a few things I have to manually change around. One of them is the emoticons; I used to implement two different emoticon sets manually, whereas now that IPB allows this per-skin, I can do it based on skin choice.

So, I would like to get rid of the user profile field for the emoticon set, but I also need to make a few database changes.

So first of all:

I have a lot of posts with contents like this (in the posts table's post column):
CODE
<!--emo&:achysan:--><img
src='emoteURL/achysan.gif' alt='achysan.gif' /><!--endemo-->


Which should now look like this:
CODE
<img
src="style_emoticons/<#EMO_DIR#>/achysan.gif" style="vertical-align:middle"
emoid=":achysan:" border="0" alt="achysan.gif" />


A select query will return results:
CODE
SELECT * from ibfmain_posts WHERE post LIKE "%<!--emo&:achysan:--><img src='emoteURL/achysan.gif' alt='achysan.gif' /><!--endemo-->%" LIMIT 25;


will give me 25.

But an update query like this:
CODE
UPDATE ibfmain_posts SET post = replace(post, "%<!--emo&:achysan:--><img
src='emoteURL/achysan.gif' alt='achysan.gif' /><!--endemo-->%", '<img
src="style_emoticons/<#EMO_DIR#>/achysan.gif" style="vertical-align:middle"
emoid=":achysan:" border="0" alt="achysan.gif" />');


will just give me "Query OK, 0 rows affected", leading me to believe that it failed to retrieve any matching rows and thus didn't even try to do any replacements. I'm assuming I need to escape some of the first argument's value, but how/what?

Any help greatly appreciated.
bfarber
Why not just do this:

update ibf_posts set post=replace(post, 'emoteURL/', 'style_emoticons/<#EMO_DIR#>/')

OR, even better, just run the rebuild post content tool in the ACP, which will unparse and then reparse emoticons wink.gif
Chucker
QUOTE(bfarber @ Aug 6 2006, 02:06 PM) *
Why not just do this:

update ibf_posts set post=replace(post, 'emoteURL/', 'style_emoticons/<#EMO_DIR#>/')


I guess I'm afraid it'll affect some unrelated posts.

QUOTE
OR, even better, just run the rebuild post content tool in the ACP, which will unparse and then reparse emoticons wink.gif


But won't that also unparse and reparse tags? (Many of which were custom and implemented differently, so it probably won't recognize them and will balk.)

I'll backup and try. Thanks original.gif
Phil Mossop
QUOTE(Chucker @ Aug 6 2006, 02:46 PM) *
I guess I'm afraid it'll affect some unrelated posts.


It's unlikely it'll effect anything other than emoticons; I'd try the query Brandon posted after backing up.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.