Code Duplication    Length = 19-20 lines in 2 locations

ecrire/req/sqlite_generique.php 1 location

@@ 1237-1255 (lines=19) @@
1234
1235
// renvoie les bonnes parentheses pour des where imbriquees
1236
// http://doc.spip.org/@_sqlite_calculer_where
1237
function _sqlite_calculer_where($v){
1238
	if (!is_array($v))
1239
	  return $v ;
1240
1241
	$op = array_shift($v);
1242
	if (!($n=count($v)))
1243
		return $op;
1244
	else {
1245
		$arg = _sqlite_calculer_where(array_shift($v));
1246
		if ($n==1) {
1247
			  return "$op($arg)";
1248
		} else {
1249
			$arg2 = _sqlite_calculer_where(array_shift($v));
1250
			if ($n==2) {
1251
				return "($arg $op $arg2)";
1252
			} else return "($arg $op ($arg2) : $v[0])";
1253
		}
1254
	}
1255
}
1256
1257
1258

ecrire/req/mysql.php 1 location

@@ 389-408 (lines=20) @@
386
 * @return string
387
 *     Contrainte pour clause WHERE
388
 */
389
function calculer_mysql_where($v)
390
{
391
	if (!is_array($v))
392
	  return $v ;
393
394
	$op = array_shift($v);
395
	if (!($n=count($v)))
396
		return $op;
397
	else {
398
		$arg = calculer_mysql_where(array_shift($v));
399
		if ($n==1) {
400
			  return "$op($arg)";
401
		} else {
402
			$arg2 = calculer_mysql_where(array_shift($v));
403
			if ($n==2) {
404
				return "($arg $op $arg2)";
405
			} else return "($arg $op ($arg2) : $v[0])";
406
		}
407
	}
408
}
409
410
/**
411
 * Calcule un expression pour une requête, en cumulant chaque élément