Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Bug Reports » Semicolon in Strings within SQL Multi Query String
Re: Semicolon in Strings within SQL Multi Query String [message #4613 is a reply to message #4610] Mon, 27 October 2014 08:48 Go to previous messageGo to previous message
kong is currently offline  kong
Messages: 90
Registered: December 2011
Member
Noticed a bug in my previous solution, which did not take into account spaces followed by semicolon within strings inside sub-queries.
So, here is the updated version.
            if (!is_array($query)) {
                // split string into an array of individual queries
                $array = explode(';', $query); 
                $query = '';
                $sub_query = '';
                foreach ($array as $value) {            	
                	$sub_query .= $value;             
                	if (substr_count(str_replace("\'",'',$sub_query),"'")%2) 
                        {
                		// Odd number single quotes means semicolon was part of a string in one sub-query
                		// Must add back the semicolon and loop to restore the remainder of sub-query
                		$sub_query .= ';';
                	} // if
                	else 
                        {
                		$sub_query = trim($sub_query);              		
                       	        if (!empty($sub_query)) {
                        	        $query[] = $sub_query.';';   // replace query terminator
                			$sub_query = '';
                     	        } // if
                     	        // $sub_query is empty again ready for the next $value
                	} // else
                } // foreach                
            } // if
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Unexpected "Cannot extract token from" Error Due to Tabs / Newlines
Next Topic: Duplicated Messages on SUBMIT+Stay (File Upload pattern)
Goto Forum:
  


Current Time: Mon Dec 23 05:31:09 EST 2024

Total time taken to generate the page: 0.00977 seconds