 /*
 * Copyright (C) 17-sept.-2003  Jean-Yves Beaujean 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,  59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * 
 */
package jxtray.util;


import java.util.StringTokenizer;

/** This is a class that contains only static methods for SQL use.
 */


public class SQLUtilities
{
	
	/** 
	 * Add slashes to the query whene it contains quote.
	 * This method is similar to the PHP method.
	 * @param oldQuery Query to parse
	 * @param spaceChar Escape delimtor. With MySQL = \ with ORACLE = '
	 * @param targetChar Char to replace
	 * @return String
	 */
	public static String addSlashes( String oldQuery, String spaceChar, String targetChar )
	{
		String newQuery = new String();
		try
		{ 
			StringTokenizer stoken = new StringTokenizer(oldQuery,targetChar);
			while ( true )
			{
				 newQuery += (String) stoken.nextElement();
				 if ( stoken.hasMoreElements() )
					newQuery += spaceChar+targetChar;
				 else
					break;
			}
		}
		catch( Exception e) {	}
			
		return newQuery;
	}
	
}
