LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-29-2019, 09:59 PM   #31
xray55
Member
 
Registered: Aug 2019
Posts: 46

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by scasey View Post
Oh!
The data you're showing us now still has the .m3u8, in your OP you posted that the replace of the .m3u8 had worked.
Why is it still there?
I restored the db to leave it untouched. Was just saying it did work for update replace .m3u8



Code:
SELECT stream_source, replace(stream_source, 'live\/', '') FROM streams where stream_source like '%live%';
The output is messy in terminal windows but lined up better in ultraedit

Code:
| ["http:\/\/domain:25461\/live\/JayStevens\/kjafijq25251\/2056.m3u8"]                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | ["http:\/\/domain:25461\/live\/JayStevens\/kjafijq25251\/2056.m3u8"]                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ["http:\/\/domain:25461\/live\/JayStevens\/kjafijq25251\/2057.m3u8"]                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | ["http:\/\/domain:25461\/live\/JayStevens\/kjafijq25251\/2057.m3u8"]                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ["http:\/\/domain:25461\/live\/JayStevens\/kjafijq25251\/2058.m3u8"]                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | ["http:\/\/domain:25461\/live\/JayStevens\/kjafijq25251\/2058.m3u8"]                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
301 rows in set (0.00 sec)
 
Old 10-30-2019, 12:11 AM   #32
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,763

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Hmmmm.
Post without the long line of ----- perhaps.

Not sure why the output would be messy on the terminal...does it wrap? Why? Is there a longer entry you're not showing us? On my terminal, the space between the pipes appears to be set to the length of the longest entry.

Anyway,
So that didn't work. Is it possible that the data is not what it appears? Maybe the \ or the / are not what they appear to be...not sure how we'd check that. Is there a way to see the string in hexadecimal, I wonder?

Very strange.
I just tried it again, and it works as expected for me. The replace() sees and replaces \/ just fine.
Going to have to tinker with it a bit more.

Try this:
Code:
SELECT stream_source, replace(stream_source, 'live\/', '') FROM streams WHERE stream_source like '%live\/%';
to see if the \/ is a match...

Last edited by scasey; 10-30-2019 at 12:14 AM.
 
1 members found this post helpful.
Old 10-30-2019, 12:30 AM   #33
xray55
Member
 
Registered: Aug 2019
Posts: 46

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Hmmmm.
Post without the long line of ----- perhaps.

Not sure why the output would be messy on the terminal...does it wrap? Why? Is there a longer entry you're not showing us? On my terminal, the space between the pipes appears to be set to the length of the longest entry.
No, doesnt wrap


Quote:
Originally Posted by scasey View Post
Hmmmm.
Try this:
Code:
SELECT stream_source, replace(stream_source, 'live\/', '') FROM streams WHERE stream_source like '%live\/%';
to see if the \/ is a match...
Code:
mysql> SELECT stream_source, replace(stream_source, 'live\/', '') FROM streams WHERE stream_source like '%live\/%';
Empty set (0.00 sec)

The entire DB is only 25mb

I manually browsed a dump with Ultraedit and found double escapes

Code:
"http:\\/\\/domain.com\\/live\\/JayStevens\\/kjafijq25251\\/301.m3u8\"
 
Old 10-30-2019, 12:35 AM   #34
xray55
Member
 
Registered: Aug 2019
Posts: 46

Original Poster
Rep: Reputation: Disabled
which then suggested

Code:
update streams set stream_source = replace(stream_source, '\\/live\\/', '\\/');
or

Code:
update streams set stream_source = replace(stream_source, '\\/live', '');
or

Code:
update streams set stream_source = replace(stream_source, 'live\\/', '');


and bingo!

Code:
mysql> update streams set stream_source = replace(stream_source, '\\/live\\/', '\\/');
Query OK, 300 rows affected (0.02 sec)
Rows matched: 1317  Changed: 300  Warnings: 0
Code:
mysql> update streams set stream_source = replace(stream_source, '.m3u8', '');
Query OK, 214 rows affected (0.02 sec)
Rows matched: 1317  Changed: 214  Warnings: 0

Last edited by xray55; 10-30-2019 at 12:48 AM.
 
Old 10-30-2019, 01:08 AM   #35
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,763

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
TADA!!
Good job xray55. That was a good piece of detective work.
You can mark this thread SOLVED using the Thread Tools at the top of any page.

Hopefully our discussion will help others in the future. It was a strange situation/condition. Makes me wonder where those entries came from. It shouldn't be necessary to escape slashes when writing URLs to a database. It most certainly shouldn't be necessary to store the escape characters.

I do need to escape single quotes when writing names, so that the apostrophe in O'Casey doesn't mess up the insert statement...but the \ doesn't get stored in the database when I do that.

Doesn't matter. It is what it is. Now you know what the data really looks like, and you were able to make the changes you wanted, so task completed.

I was happy to help.

Last edited by scasey; 10-30-2019 at 01:09 AM.
 
Old 10-30-2019, 01:15 AM   #36
xray55
Member
 
Registered: Aug 2019
Posts: 46

Original Poster
Rep: Reputation: Disabled
Thanks pal for not giving up on me.

Like i said, I had easy solutions. I could have easily mass deleted from GUI and reuploaded a corrected list but i wanted to once and for all understand why in this type of DB I can never use the replace command on certain characters.

So to finalize my understanding of escapes? They wrap to ignore a special DB function of that character its wrapping?
 
Old 10-30-2019, 09:32 AM   #37
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,763

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by xray55 View Post
Thanks pal for not giving up on me.

Like i said, I had easy solutions. I could have easily mass deleted from GUI and reuploaded a corrected list but i wanted to once and for all understand why in this type of DB I can never use the replace command on certain characters.

So to finalize my understanding of escapes? They wrap to ignore a special DB function of that character its wrapping?
Not sure I understand your question. I can think of no reason to have escapes within the data as you do.
What complicated this was that the data contained an escaped backslash (\\), which rendered as a single backslash when queried, so you couldn't see what to match. So, again, it's not about "certain characters," it is because you didn't know what to match. Once you did, the replace function worked just fine, yes?

The only time I use an escape is when the VALUE of a column delimited by single quotes contains an apostrophe:
Code:
UPDATE table SET name='O\'Hara'
and in that case the backslash does not get written into the data. I do that when I'm creating the SQL statement programmatically. If I were typing it, I could just use double quotes:
Code:
UPDATE table SET name="O'Hara"
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Slackware vs simple Arch vs simple Frugalware punchy71 Linux - Distributions 2 08-28-2012 02:30 PM
mysql use output of one query in another query secretlydead Programming 2 11-19-2007 01:25 AM
non Recursive query and Recursive query prashsharma Linux - Server 1 06-27-2007 09:33 AM
Database Programming (database to database transaction) johncsl82 Programming 7 02-02-2007 08:20 AM
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 06:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration