Please could someone help me understand why the following SQL doesn't work:
UPDATE `v2rns_content_new`
SET `images`= REPLACE(`images`, 'images\/news_images', 'images\/news_images\/legacy');
I am trying to find and replace the bold part of the following string (there are multiple records in the database with similar strings but the filenames e.g. example.png are different):
{"image_intro":"images\ /news_images\ /example.png","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}
Please note: I asked a related question yesterday (which will provide some background) but I feel that this question is best asked separately - Updating all rows within a single column using phpMyAdmin
I have managed to solve the issue by changing the already escaped \ to \
e.g. UPDATE v2rns_content_new SET images = REPLACE(images, 'images\\/news_images, 'images\\/news_images\/legacy')
Thanks to #GeolezTrol for pointing me in the right direction.
Related
I'm beginner in MySQL and I want to make a request to find all tables with this word "Ostéotomie", it works only if I write "%Ost%" and not "%Ostéotomie%"
The fact is that it shows me only 4 results instead of the 9 I need.
Here is a SQL Fiddle to show what I mean : SQL Fiddle
The table wasn't created by me, I'm working on a search bar from a project which isn't mine.
I don't know if you can help me, if I've putted enough information.
Thanks in advance.
I tried replacing é with % and the query gave me expected results.
https://dev.mysql.com/doc/refman/8.0/en/charset-binary-collations.html
Maybe this solved your Problem.
and thanks in advance for any help. I'm working on fixing all broken links in a massive WordPress multisite database and need some help writing an SQL query to run via PHP MyAdmin. I've searched, but can't the perfect solution...
PROBLEM: We have more than a thousand broken links that start with http:/ instead of http://
CHALLENGE: The following would result in numerous links starting with http:///
UPDATE wp_1_posts
SET post_content = replace (post_content,
'http:/',
'http://');
PROCESS: I want to write a query to SELECT all these links first, so I can review them to ensure I don't do any damage when replacing the text string. Downloading a db dump and doing a manual S&R is not an option since we're talking about a multi-gigabyte database.
I thought something like this would work...
SELECT * FROM wp_1_posts
WHERE post_content LIKE '%http:/%'
AND WHERE post_content NOT LIKE '%http://%'
But that just throws a syntax error. Am I even close?
QUESTION #1: How can I find all instances of "http:/" without returning all "http://" instances in the query results.
QUESTION #2: How might I safely fix all instances of "http:/" without affecting any "http://" strings.
FYI: I'll admit I know just enough about this to be dangerous, and I am not familiar with regular expressions. at. all. That's why I'm turning to you for help. Thanks again!
This should work, in MYSQL:
UPDATE wp_1_posts SET post_content = replace(post_content,'http:/', 'http://')
WHERE post_content REGEXP 'http:/[^/]'
I just want to say sorry if this is a really easy question but I'm overworked with this site to the point where parts of the code that are working aren't making sense, any help in telling me why this MYSQL UPDATE isn't working would be greatly appreciated
mysql_query("UPDATE setlist SET song_artist='$song_artist1' AND song_name='$song_name1' WHERE song_id='$song_id'");
When it does work the value is being entered as a 0 (which I believe would mean NULL but all of the variables are working correctly as I have used a die statement with the variables inputted into it, I am also not generating any errors from mysql_error, any help would be appreciated, thanks!
This is my MYSQL table setout.
song_id
song_artist
song_name
Replace AND with a comma,should work.
'$song_id'
remove the quotes.
I am looking for recovering from my local mysql.log file the changes to perform to the production server and I already got the changes using:
^.*(ALTER TABLE).*(ADD|DROP|CHANGE|^AUTO_INCREMENT).*$
.. and I would also catch the CREATE TABLE statement excluding SHOW CREATE TABLE and CREATE TABLE IF NOT EXISTS. So I tried to firstly only avoid the SHOW but I am not succeding using the more intuitive ways in my mind:
^.*(^SHOW)*(CREATE TABLE).*$
^.*(^SHOW CREATE TABLE|CREATE TABLE).*$
Any help is appreciated,
Carmine Iaciofano
Seems negative look aheads and behinds could be used to solve your problem. The following regex should do the job in this case.
(?<!SHOW )(CREATE TABLE)(?! IF)
In this case, it finds any instances of "CREATE TABLE" that is not preceded by "SHOW " or followed by " IF". Note the spaces in the groups.
You can then use
^.*(?<!SHOW )(CREATE TABLE)(?! IF).*
to match the whole line.
You can read up on look aheads and look behinds here.
I'm trying to create a text file that contains the value of a custom field I added on redmine. I tried to get it from an SQL query in the create method of the project_controller.rb (at line 80 on redmine 1.2.0) as follows :
sql = Mysql.new('localhost','root','pass','bitnami_redmine')
rq = sql.query("SELECT value
FROM custom_values
INNER JOIN projects
ON custom_values.customized_id=projects.id
WHERE custom_values.custom_field_id=7
AND projects.name='#{#project.name}'")
rq.each_hash { |h|
File.open('pleasework.txt', 'w') { |myfile|
myfile.write(h['value'])
}
}
sql.close
This works fine if I test it in a separate file (with an existing project name instead of #project.name) so it may be a syntax issue but I can't find what it is. I'd also be glad to hear any other solution to get that value.
Thanks !
(there's a very similar post here but none of the solutions actually worked)
First, you could use Project.connection.query instead of your own Mysql instance. Second, I would try to log the SQL RAILS_DEFAULT_LOGGER.info "SELECT ..." and check if it's ok... And the third, I would use identifier instead of name.
I ended up simply using params["project"]["custom_field_values"]["x"] where x is the custom field's id. I still don't know why the sql query didn't work but well, this is much simpler and faster.