Hey guys, I can't figure this one out. Sometimes when backing up an sql file using phpmyadmin (database stuff), for some reason it forgets to double up a single quote, resulting in an error when loading the sql file back into the database when required. A line in such an sql file looks like this;

(1, 'http://codex.wordpress.org/', 'Docu,ment,ation', '', '', '', 'Y', 1, 0, '27' LCD screen is for you if you''re a hip youngster who likes to boogeh', '', '', '')

As shown in the example, phpmyadmin did double up the quote in "you're" as it should, but it forgot to double up the one after "27", resulting in an error.

As you can see it's like this (*value*, *'value'*, (and so on) but beforehand I can;
A) Never know how many values are in such a string
B) Can't simply split the values by "," because the value itself can hold a comma aswel.

It would be easy if every value was like this; *'value'* because then I could split by " ', ' " but that's not the case, and I also never know what location the values not enclosed in single quotes are. I also can't simply double up all single quotes in the entire string because then it will also double up the ones that are enclosing the values, resulting in an error during upload again.

So yeah, what I need to get done is single out all the values with regex ($1, $2 etc.) and then string.replace single quotes in those values but *only* if said single quote is not preceeded or followed by another single quote, else it would become a tripple quote resulting in an error again.

This is so complicated it literally gave me a headache like you wouldn't believe so I hope there's someone here with a more competent brain for stuff like this because mine's about to explode :<

I think I *might* have got the general idea now but I can't check for a few hours.

The basic idea is;

>if line starts with (
for x as integer 0 to 3
x -= 1
>if character '
get value after it up to ', OR ')
>elseif character NOT '
get value up to , OR )
>check if next char is ) or ')
>yes? end for
>no? next

Would this work? Still don't know how to check if the single quote is already doubled up or not btw.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.