diff --git a/.gitattributes b/.gitattributes
index c5785ace780..0bea828e011 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,33 +1,33 @@
-# Set default behaviour, in case users don't have core.autocrlf set.
-# More info: https://help.github.com/articles/dealing-with-line-endings
-* text=auto
-
-
-# Explicitly declare text files we want to always be normalized and converted
-# to native line endings on checkout.
-*.php text eol=lf
-*.pl text eol=lf
-*.sql text eol=lf
-*.htm text eol=lf
-*.html text eol=lf
-*.js text eol=lf
-*.css text eol=lf
-*.lang text eol=lf
-*.txt text eol=lf
-*.md text eol=lf
-*.pp text eol=lf
-*.sh text eol=lf
-*.yaml text eol=lf
-
-.bash_aliases text eol=lf
-
-# Denote all files that are truly binary and should not be modified.
-*.bmp binary
-*.ico binary
-*.png binary
-*.jpg binary
-*.odt binary
-*.odf binary
-*.frm binary
-*.MYD binary
-*.MYI binary
+# Set default behaviour, in case users don't have core.autocrlf set.
+# More info: https://help.github.com/articles/dealing-with-line-endings
+* text=auto
+
+
+# Explicitly declare text files we want to always be normalized and converted
+# to native line endings on checkout.
+*.php text eol=lf
+*.pl text eol=lf
+*.sql text eol=lf
+*.htm text eol=lf
+*.html text eol=lf
+*.js text eol=lf
+*.css text eol=lf
+*.lang text eol=lf
+*.txt text eol=lf
+*.md text eol=lf
+*.pp text eol=lf
+*.sh text eol=lf
+*.yaml text eol=lf
+
+.bash_aliases text eol=lf
+
+# Denote all files that are truly binary and should not be modified.
+*.bmp binary
+*.ico binary
+*.png binary
+*.jpg binary
+*.odt binary
+*.odf binary
+*.frm binary
+*.MYD binary
+*.MYI binary
diff --git a/INSTALL b/INSTALL
index 584c3f04713..9f2fb214281 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,6 +1,6 @@
-INSTALL
--------
-
-English: See README.md file.
-
-French: Voir fichier README-FR.md.
+INSTALL
+-------
+
+English: See README.md file.
+
+French: Voir fichier README-FR.md.
diff --git a/htdocs/conf/phpinfo.php b/htdocs/conf/phpinfo.php
new file mode 100644
index 00000000000..179bd651458
--- /dev/null
+++ b/htdocs/conf/phpinfo.php
@@ -0,0 +1,5 @@
+Go back to index
+| ">Refresh
+
+
+
\ No newline at end of file
diff --git a/htdocs/core/db/sqlite.class.php b/htdocs/core/db/sqlite.class.php
index b16114a773f..786bf435fcf 100644
--- a/htdocs/core/db/sqlite.class.php
+++ b/htdocs/core/db/sqlite.class.php
@@ -40,6 +40,12 @@ class DoliDBSqlite extends DoliDB
//! Resultset of last query
private $_results;
+ /**
+ * Indique que les fonctions personnalisées sont définies
+ * @var boolean
+ */
+ private static $customFunctionsDefined = false;
+
/**
* Constructor.
* This create an opened connexion to a database server and eventually to a database
@@ -153,7 +159,7 @@ class DoliDBSqlite extends DoliDB
// Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..."
if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) {
- $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 SERIAL PRIMARY KEY',$line);
+ $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 integer PRIMARY KEY AUTOINCREMENT',$line);
//$line = "-- ".$line." replaced by --\n".$newline;
$line=$newline;
}
@@ -242,10 +248,17 @@ class DoliDBSqlite extends DoliDB
$line = "-- ".$line." replaced by --\n";
$line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")";
}
- }
+ if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i',$line, $reg)) {
+ // Pour l'instant les contraintes ne sont pas créées
+ dol_syslog(get_class().'::query line emptied');
+ $line = 'SELECT 0;';
- // To have postgresql case sensitive
- $line=str_replace(' LIKE \'',' ILIKE \'',$line);
+ }
+
+ //if (preg_match('/rowid\s+.*\s+PRIMARY\s+KEY,/i', $line)) {
+ //preg_replace('/(rowid\s+.*\s+PRIMARY\s+KEY\s*,)/i', '/* \\1 */', $line);
+ //}
+ }
// Delete using criteria on other table must not declare twice the deleted table
// DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable
@@ -387,7 +400,53 @@ class DoliDBSqlite extends DoliDB
$this->error = 0;
// Convert MySQL syntax to SQLite syntax
- $query=$this->convertSQLFromMysql($query,$type);
+ if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i',$query, $reg)) {
+ // Ajout d'une clef étrangère à la table
+ // procédure de remplacement de la table pour ajouter la contrainte
+ // Exemple : ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid)
+ // -> CREATE TABLE ( ... ,CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid))
+ $foreignFields = $reg[5];
+ $foreignTable = $reg[4];
+ $localfields = $reg[3];
+ $constraintname=trim($reg[2]);
+ $tablename=trim($reg[1]);
+
+ $res = $this->db->query("SELECT sql FROM sqlite_master WHERE name='" . $tablename . "'");
+ $descTable = $res->fetchColumn();
+ $res->closeCursor();
+
+ // 1- Renommer la table avec un nom temporaire
+ $res = $this->query('ALTER TABLE ' . $tablename . ' RENAME TO tmp_' . $tablename);
+ $res->closeCursor();
+
+ // 2- Recréer la table avec la contrainte ajoutée
+
+ // on bricole la requete pour ajouter la contrainte
+ $descTable = substr($descTable, 0, strlen($descTable) - 1);
+ $descTable .= ", CONSTRAINT " . $constraintname . " FOREIGN KEY (" . $localfields . ") REFERENCES " .$foreignTable . "(" . $foreignFields . ")";
+
+ // fermeture de l'instruction
+ $descTable .= ')';
+
+ // Création proprement dite de la table
+ $res = $this->query($descTable);
+ $res->closeCursor();
+
+ // 3- Transférer les données
+ $res = $this->query('INSERT INTO ' . $tablename . ' SELECT * FROM tmp_' . $tablename);
+ $res->closeCursor();
+
+
+ // 4- Supprimer la table temporaire
+ $res = $this->query('DROP TABLE tmp_' . $tablename);
+ $res->closeCursor();
+
+ // dummy statement
+ $query="SELECT 0";
+
+ } else {
+ $query=$this->convertSQLFromMysql($query,$type);
+ }
//print "After convertSQLFromMysql:\n".$query."
\n";
dol_syslog('sql='.$query, LOG_DEBUG);
@@ -487,7 +546,11 @@ class DoliDBSqlite extends DoliDB
{
// If resultset not provided, we take the last used by connexion
if (! is_object($resultset)) { $resultset=$this->_results; }
- return $resultset->rowCount();
+ if (preg_match("/^SELECT/i", $resultset->queryString)) {
+ $res = $this->db->query("SELECT count(*) FROM (" . $resultset->queryString . ") q");
+ return $res->fetchColumn();
+ }
+ return $resultset->rowCount();
}
/**
@@ -529,7 +592,12 @@ class DoliDBSqlite extends DoliDB
*/
function escape($stringtoencode)
{
- return $this->db->quote($stringtoencode);
+ $ret = $this->db->quote($stringtoencode);
+ $l = strlen($ret);
+ if ($l >= 2) {
+ return substr($ret, 1, $l -2);
+ }
+ return '';
}
/**
@@ -1135,5 +1203,6 @@ class DoliDBSqlite extends DoliDB
return $result;
}
+
}
diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php
index 17b8b8e8def..0b0ceb5460c 100644
--- a/htdocs/core/modules/DolibarrModules.class.php
+++ b/htdocs/core/modules/DolibarrModules.class.php
@@ -1012,7 +1012,7 @@ abstract class DolibarrModules
if ($resql)
{
$obj=$this->db->fetch_object($resql);
- if (! empty($obj->value) && ! empty($this->rights))
+ if ($obj !== null && ! empty($obj->value) && ! empty($this->rights))
{
// Si module actif
foreach ($this->rights as $key => $value)
diff --git a/htdocs/install/etape2.php b/htdocs/install/etape2.php
index 1f6c5244d84..d934f79f0af 100644
--- a/htdocs/install/etape2.php
+++ b/htdocs/install/etape2.php
@@ -51,6 +51,8 @@ if ($dolibarr_main_db_type == "mysql") $choix=1;
if ($dolibarr_main_db_type == "mysqli") $choix=1;
if ($dolibarr_main_db_type == "pgsql") $choix=2;
if ($dolibarr_main_db_type == "mssql") $choix=3;
+if ($dolibarr_main_db_type == "sqlite") $choix=4;
+
//if (empty($choix)) dol_print_error('','Database type '.$dolibarr_main_db_type.' not supported into etape2.php page');
// Now we load forced value from install.forced.php file.
@@ -411,6 +413,7 @@ if ($action == "set")
if ($choix==1) $dir = "mysql/functions/";
elseif ($choix==2) $dir = "pgsql/functions/";
elseif ($choix==3) $dir = "mssql/functions/";
+ elseif ($choix==4) { $dir = "sqlite/functions/"; }
// Creation donnees
$file = "functions.sql";
diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php
index 2c6a5730100..49b80eb1b6b 100644
--- a/htdocs/install/fileconf.php
+++ b/htdocs/install/fileconf.php
@@ -306,7 +306,7 @@ if (! empty($force_install_message))
$class='DoliDB'.ucfirst($type);
include_once $dir."/".$file;
- if ($type == 'sqlite') continue; // We hide sqlite because support can't be complete unti sqlit does not manage foreign key creation after table creation
+ //if ($type == 'sqlite') continue; // We hide sqlite because support can't be complete unti sqlit does not manage foreign key creation after table creation
// Version min of database
$versionbasemin=explode('.',$class::VERSIONMIN);
diff --git a/htdocs/install/sqlite/functions/functions.sql b/htdocs/install/sqlite/functions/functions.sql
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/htdocs/install/sqlite/index.html b/htdocs/install/sqlite/index.html
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/index.php b/index.php
new file mode 100644
index 00000000000..c59480bf4de
--- /dev/null
+++ b/index.php
@@ -0,0 +1,2 @@
+