I'm trying not to write code that has already been written -- really I am :)
I've got a production MariaDB database that simply refuses to dump load to an earlier version of itself and I need to write a custom dump/load routine to handle this situation. None of the myriad of compatibility switches for mysqldump
do the trick sadly.
Effort to manually clean up the dump is too high and too dangerous to automate and I need to repeat the process precisely several times so I do can't afford any manual effort. I know there are tools that might help but easier to write code (I'm familiar with) than learn to trust yet another tool
I've written this code before in a previous platform/framework so I know what has to be done and how to do it.
All I'm asking this time is there an elegant way to use whatever Anorm uses to sanitize it's data to sanitize the data pre-dump?
This far I've not even been able to view the actual SQL query that Anorm generates (other than through MySQL query loggers) so I'm not holding up much hope but I'm asking in case anyone else has a way into the internal routines that I just haven't found yet.
Apparently from what I can see the answer is actually no.
However I hate leaving things at a dead end so here is a little routine that should do the trick. I'm pretty sure it could be optimized way better as I'm not too fond of the char.toString
having to be called on every character that is not replaced.
def escapeSQLDelimiters(dataToEscape: String) = {
dataToEscape flatMap { c =>
c match {
case '\\' => "\\\\"
case '\u0000' => "\\0"
case '\n' => "\\n"
case '\t' => "\\t"
case '\r' => "\\r"
case '\b' => "\\b"
case '\'' => "\\\'"
case '\"' => "\\\""
case _ => c.toString
}
}
}