From c99078c6f4b56579a5a73ec887bc47f4724707d1 Mon Sep 17 00:00:00 2001
From: Matthieu Marcillaud <marcimat@rezo.net>
Date: Mon, 10 Nov 2008 22:10:23 +0000
Subject: [PATCH] report de [13136]

---
 ecrire/req/sqlite_fonctions.php |  4 +++-
 ecrire/req/sqlite_generique.php | 15 ++++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/ecrire/req/sqlite_fonctions.php b/ecrire/req/sqlite_fonctions.php
index 95bc7ef70b..8626001e7c 100644
--- a/ecrire/req/sqlite_fonctions.php
+++ b/ecrire/req/sqlite_fonctions.php
@@ -30,13 +30,14 @@ function _sqlite_init_functions(&$sqlite){
 		'DATE_FORMAT'	=> array( '_sqlite_func_strftime'		,2),
 		'DAYOFMONTH'	=> array( '_sqlite_func_dayofmonth'		,1),
 		
+		'EXP'			=> array( 'exp'							,1),//exponentielle
 		'FIND_IN_SET'	=> array( '_sqlite_func_find_in_set'	,2),
 
 		'IF'			=> array( '_sqlite_func_if' 			,3),
 		'INSERT'		=> array( '_sqlite_func_insert'			,4),		
 		'INSTR'			=> array( '_sqlite_func_instr'			,2),
 
-		'LEAST'			=> array( '_sqlite_func_least'			,3), // nb d'arguments ?
+		'LEAST'			=> array( '_sqlite_func_least'			,3),
 		'LEFT'			=> array( '_sqlite_func_left'			,2),
 #		'LENGTH'		=> array( 'strlen'						,1), // present v1.0.4
 #		'LOWER'			=> array( 'strtolower'					,1), // present v2.4
@@ -57,6 +58,7 @@ function _sqlite_init_functions(&$sqlite){
 #		'RTRIM'			=> array( 'rtrim'						,1), // present en theorie
 
 		'SETTYPE'		=> array( 'settype'						,2), // CAST present en v3.2.3
+		'SQRT'			=> array( 'sqrt'						,1), 
 		'SUBSTRING'		=> array( 'substr'						,3), 
 		
 		'TO_DAYS'		=> array( '_sqlite_func_to_days'		,1),
diff --git a/ecrire/req/sqlite_generique.php b/ecrire/req/sqlite_generique.php
index 3ef8ea6a7f..9e2f246c83 100644
--- a/ecrire/req/sqlite_generique.php
+++ b/ecrire/req/sqlite_generique.php
@@ -1687,7 +1687,20 @@ class sqlite_traiter_requete{
 				$this->query .= $suite;
 			}
 		}
-		
+
+		// Correction possible des divisions entieres
+		// Le standard SQL (lequel? ou?) semble indiquer que
+		// a/b=c doit donner c entier si a et b sont entiers 4/3=1.
+		// C'est ce que retournent effectivement SQL Server et SQLite
+		// Ce n'est pas ce qu'applique MySQL qui retourne un reel : 4/3=1.333...
+		// 
+		// On peut forcer la conversion en multipliant par 1.0 avant la division
+		// /!\ SQLite 3.5.9 Debian/Ubuntu est victime d'un bug en plus ! 
+		// cf. https://bugs.launchpad.net/ubuntu/+source/sqlite3/+bug/254228
+		//     http://www.sqlite.org/cvstrac/tktview?tn=3202
+		// (4*1.0/3) n'est pas rendu dans ce cas !
+		# $this->query = str_replace('/','* 1.00 / ',$this->query);
+			
 		// Correction Antiquotes
 		// ` => rien
 		$this->query = str_replace('`','',$this->query);
-- 
GitLab