Subversion Repositories eFlore/Applications.cel

Rev

Rev 3857 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2419 jpm 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Contient des méthodes utiles pour manipuler le SQL.
5
 *
6
 * @category   CEL
7
 * @package    Scripts
8
 * @subpackage Bibliotheque
9
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
10
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
12
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
15
 */
16
class SqlUtil {
17
 
18
	public static function extraireRequetes($contenuSql) {
2430 jpm 19
		$contenuSansCommentaire = self::supprimerCommentaires($contenuSql);
20
		$requetesExtraites = preg_split("/;\e*\t*\r*\n/", $contenuSansCommentaire);
2419 jpm 21
		if (count($requetesExtraites) == 0){
2430 jpm 22
			throw new Exception("Aucune requête n'a été trouvée dans le contenu SQL.");
2419 jpm 23
		}
24
 
25
		$requetes = array();
26
		foreach ($requetesExtraites as $requete) {
27
			if (trim($requete) != '') {
28
				$requetes[] = rtrim(trim($requete), ';');
29
			}
30
		}
31
		return $requetes;
32
	}
2430 jpm 33
 
34
	private static function supprimerCommentaires($contenuSql) {
35
		return preg_replace('/(## |--).*?\r*\n/', '', $contenuSql);
36
	}
2419 jpm 37
}