I actually decided to work within the framework of WP itself, and applied this (better) fix than my above fix. WordPress provides SQL sterilization natively if the right commands are use, so here it is, with no warranties:
In the WP plugins directory, in custom-permalinks, in custom-permalinks.php find the following lines:
$sql = “SELECT $wpdb->posts.ID, $wpdb->postmeta.meta_value, $wpdb->posts.post_type FROM $wpdb->posts “.
“LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE “.
” meta_key = ‘custom_permalink’ AND “.
” meta_value != ” AND “.
” ( LOWER(meta_value) = LEFT(LOWER(‘”.mysql_real_escape_string($request_noslash).”‘), LENGTH(meta_value)) OR “.
” LOWER(meta_value) = LEFT(LOWER(‘”.mysql_real_escape_string($request_noslash.”/”).”‘), LENGTH(meta_value)) ) “.
” AND post_status != ‘trash’ AND post_type != ‘nav_menu_item'”.
” ORDER BY LENGTH(meta_value) DESC, “.
” FIELD(post_status,’publish’,’private’,’draft’,’auto-draft’,’inherit’),”.
” FIELD(post_type,’post’,’page’),”.
“$wpdb->posts.ID ASC LIMIT 1”;
Replace them with:
$sql = $wpdb->prepare(“SELECT $wpdb->posts.ID, $wpdb->postmeta.meta_value, $wpdb->posts.post_type FROM $wpdb->posts “.
“LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE “.
” meta_key = ‘custom_permalink’ AND “.
” meta_value != ” AND “.
” ( LOWER(meta_value) = LEFT(LOWER(‘%s’), LENGTH(meta_value)) OR “.
” LOWER(meta_value) = LEFT(LOWER(‘%s’), LENGTH(meta_value)) ) “.
” AND post_status != ‘trash’ AND post_type != ‘nav_menu_item'”.
” ORDER BY LENGTH(meta_value) DESC, “.
” FIELD(post_status,’publish’,’private’,’draft’,’auto-draft’,’inherit’),”.
” FIELD(post_type,’post’,’page’),”.
“$wpdb->posts.ID ASC LIMIT 1”,$request_noslash,$request_noslash . “/”);
This restored my permalinks to working order. As always, make a backup of the custom-permalinks.php file before modifying it in case something goes horribly wrong. Good luck!