MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 29th, 2013, 01:07 AM
Jakes79 Jakes79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 Jakes79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 48 sec
Reputation Power: 0
Replace values between brackets

Good day,

I am busy trying to port over a BBforum to another system, and everything ported over well, except for the images. The images are in [img] brackets, while the new system use simple html. In the db, the img brackets are encoded with random magic quotes, for example [img:2it3n9tl]. with the magic quotes being random, I will have to find and replace every one of over 3000 posts. I am looking for a SQL query I can run that will replace the values in square brackets with something else. Is there a way one can use a SQL query that will replace everything between the brackets? I will really appreciate all the help.

Best Regards,

Jakes

Reply With Quote
  #2  
Old January 29th, 2013, 05:06 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 32 m 18 sec
Reputation Power: 4140
Quote:
Originally Posted by Jakes79
In the db, the img brackets are encoded with random magic quotes, for example [img:2it3n9tl].
what magic quotes? i don't see no magic quotes

but to answer your question, no there is no sql that will replace everything between the brackets
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old January 29th, 2013, 07:24 AM
bobert123 bobert123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 43 bobert123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 15 sec
Reputation Power: 2
Hi,

I'm also not sure what you mean by magic quotes, but if you are referring to the square brackets you can use find_in_set() or locate() to find the starting bracket and ending bracket and then change the substring in between.

for that, this may help:
https://launchpad.net/mysql-udf-regexp

if you don't want to do that, you'd probably have to do something like:
Quote:
update img_nameline
set img_nameline = concat( left(img_nameline, locate('[',img_nameline)), whatever, right(img_nameline,locate(']',img_nameline)) )

Last edited by bobert123 : January 30th, 2013 at 01:44 AM.

Reply With Quote
  #4  
Old January 30th, 2013, 04:45 AM
Jakes79 Jakes79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 Jakes79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 48 sec
Reputation Power: 0
Hi all, thanks for replying. Ok, my apologies,
refering to magic quotes, I am refering to the values following the [img tags. They do not show up when viewed on the forum, but only in the database. My understanding is that it is magic quotes, randomely coded for security reasons? My apologies if I am wrong.

@bobert, I will test out your suggestions, and give feedback. Thanks a million!

Reply With Quote
  #5  
Old January 30th, 2013, 06:48 AM
Jakes79 Jakes79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 Jakes79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 48 sec
Reputation Power: 0
Ok, tested your method, with no luck. It simply places the existing text in brackets (unless I am doing something wrong)

To start with: My table name is forum_post and the column name is text

Here is how I've tried it:
Quote:
update ow_forum_post set text = concat( left(text, locate('[',text)), text, right(text,locate(']',text)) )


I also did some research, and tried this:

Quote:
update ow_forum_post set columnName = (SELECT REPLACE(STUFF([ColumnName],1,text('[',[columnName]),''),']','')) where [columnName] like '%@%' select * Table"]update ow_forum_post set columnName = (SELECT REPLACE(STUFF([ColumnName],1,text('[',[columnName]),''),']','')) where [columnName] like '%@%' select * Table


The thing is, I have very limited knowledge on SQL, and by trying and asking,I am learning. If someone can help me I will greatly appreciate it!

Reply With Quote
  #6  
Old January 30th, 2013, 08:20 AM
bobert123 bobert123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 43 bobert123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 15 sec
Reputation Power: 2
Hi Jakes,
what is it that you'd like there to be between the brackets?

Reply With Quote
  #7  
Old January 30th, 2013, 08:48 AM
Jakes79 Jakes79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 Jakes79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 48 sec
Reputation Power: 0
Well, just the word image. so it must be [image] instead of [img- and the various numbers]

Reply With Quote
  #8  
Old January 30th, 2013, 08:57 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 32 m 18 sec
Reputation Power: 4140
STUFF is microsoft sql server, not mysql

please confirm which database engine you're using

Reply With Quote
  #9  
Old January 30th, 2013, 09:01 AM
Jakes79 Jakes79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 Jakes79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 48 sec
Reputation Power: 0
I am using MySQL
Thanks!

Reply With Quote
  #10  
Old February 3rd, 2013, 08:45 AM
bobert123 bobert123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 43 bobert123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 15 sec
Reputation Power: 2
Quote:
Originally Posted by Jakes79
Well, just the word image. so it must be [image] instead of [img- and the various numbers]


in that case, try running your query with this:
Quote:
update ow_forum_post set text = concat( left(text, locate('[',text)), "image", right(text,locate(']',text)) )

Reply With Quote
  #11  
Old February 4th, 2013, 02:33 AM
Jakes79 Jakes79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 Jakes79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 48 sec
Reputation Power: 0
Hi there,
Thanks for the reply. It work, but now I have the issue, when I have other square brackets too, it replaces everything between the first and last bracket.

for example, I have [img:8787] imagepath1[/img]
the result is {image} instead of {image} imagepath1{image}

here is the query I've used:
Quote:
update ow_forum_post set text = concat( left(text, locate('[',text)), "{image}", right(text,locate(']',text)) )

Reply With Quote
  #12  
Old February 10th, 2013, 03:30 AM
bobert123 bobert123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 43 bobert123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 15 sec
Reputation Power: 2
Quote:
Originally Posted by Jakes79
Hi there,
Thanks for the reply. It work, but now I have the issue, when I have other square brackets too, it replaces everything between the first and last bracket.

for example, I have [img:8787] imagepath1[/img]
the result is {image} instead of {image} imagepath1{image}

here is the query I've used:


what would you prefer that this become?
[img:8787] imagepath1[/img]

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Replace values between brackets

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap