mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-18 23:41:28 +01:00
Revert was not complete
This commit is contained in:
@@ -66,7 +66,8 @@ else if ($conf->db->type == 'mssql')
|
|||||||
//$sqls[0] = "";
|
//$sqls[0] = "";
|
||||||
//$base=3;
|
//$base=3;
|
||||||
}
|
}
|
||||||
else if ($conf->db->type == 'sqlite3') {
|
else if ($conf->db->type == 'sqlite' || $conf->db->type == 'sqlite3')
|
||||||
|
{
|
||||||
//$sql = "SELECT name, type FROM sqlite_master";
|
//$sql = "SELECT name, type FROM sqlite_master";
|
||||||
$base = 4;
|
$base = 4;
|
||||||
}
|
}
|
||||||
@@ -176,7 +177,7 @@ else
|
|||||||
|
|
||||||
if ($base == 4)
|
if ($base == 4)
|
||||||
{
|
{
|
||||||
// Sqlite3
|
// Sqlite by PDO or by Sqlite3
|
||||||
print '<table class="noborder">';
|
print '<table class="noborder">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print '<td>'.$langs->trans("TableName").'</td>';
|
print '<td>'.$langs->trans("TableName").'</td>';
|
||||||
|
|||||||
@@ -40,12 +40,6 @@ class DoliDBSqlite extends DoliDB
|
|||||||
//! Resultset of last query
|
//! Resultset of last query
|
||||||
private $_results;
|
private $_results;
|
||||||
|
|
||||||
/**
|
|
||||||
* Indique que les fonctions personnalisées sont définies
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
private static $customFunctionsDefined = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* This create an opened connexion to a database server and eventually to a database
|
* This create an opened connexion to a database server and eventually to a database
|
||||||
@@ -56,6 +50,7 @@ class DoliDBSqlite extends DoliDB
|
|||||||
* @param string $pass Mot de passe
|
* @param string $pass Mot de passe
|
||||||
* @param string $name Nom de la database
|
* @param string $name Nom de la database
|
||||||
* @param int $port Port of database server
|
* @param int $port Port of database server
|
||||||
|
* @return int 1 if OK, 0 if not
|
||||||
*/
|
*/
|
||||||
function __construct($type, $host, $user, $pass, $name='', $port=0)
|
function __construct($type, $host, $user, $pass, $name='', $port=0)
|
||||||
{
|
{
|
||||||
@@ -159,7 +154,7 @@ class DoliDBSqlite extends DoliDB
|
|||||||
|
|
||||||
// Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..."
|
// 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)) {
|
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 integer PRIMARY KEY AUTOINCREMENT',$line);
|
$newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 SERIAL PRIMARY KEY',$line);
|
||||||
//$line = "-- ".$line." replaced by --\n".$newline;
|
//$line = "-- ".$line." replaced by --\n".$newline;
|
||||||
$line=$newline;
|
$line=$newline;
|
||||||
}
|
}
|
||||||
@@ -248,17 +243,10 @@ class DoliDBSqlite extends DoliDB
|
|||||||
$line = "-- ".$line." replaced by --\n";
|
$line = "-- ".$line." replaced by --\n";
|
||||||
$line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")";
|
$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;';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (preg_match('/rowid\s+.*\s+PRIMARY\s+KEY,/i', $line)) {
|
// To have postgresql case sensitive
|
||||||
//preg_replace('/(rowid\s+.*\s+PRIMARY\s+KEY\s*,)/i', '/* \\1 */', $line);
|
$line=str_replace(' LIKE \'',' ILIKE \'',$line);
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete using criteria on other table must not declare twice the deleted table
|
// Delete using criteria on other table must not declare twice the deleted table
|
||||||
// DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable
|
// DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable
|
||||||
@@ -400,53 +388,7 @@ class DoliDBSqlite extends DoliDB
|
|||||||
$this->error = 0;
|
$this->error = 0;
|
||||||
|
|
||||||
// Convert MySQL syntax to SQLite syntax
|
// Convert MySQL syntax to SQLite syntax
|
||||||
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);
|
$query=$this->convertSQLFromMysql($query,$type);
|
||||||
}
|
|
||||||
//print "After convertSQLFromMysql:\n".$query."<br>\n";
|
//print "After convertSQLFromMysql:\n".$query."<br>\n";
|
||||||
|
|
||||||
dol_syslog('sql='.$query, LOG_DEBUG);
|
dol_syslog('sql='.$query, LOG_DEBUG);
|
||||||
@@ -546,10 +488,6 @@ class DoliDBSqlite extends DoliDB
|
|||||||
{
|
{
|
||||||
// If resultset not provided, we take the last used by connexion
|
// If resultset not provided, we take the last used by connexion
|
||||||
if (! is_object($resultset)) { $resultset=$this->_results; }
|
if (! is_object($resultset)) { $resultset=$this->_results; }
|
||||||
if (preg_match("/^SELECT/i", $resultset->queryString)) {
|
|
||||||
$res = $this->db->query("SELECT count(*) FROM (" . $resultset->queryString . ") q");
|
|
||||||
return $res->fetchColumn();
|
|
||||||
}
|
|
||||||
return $resultset->rowCount();
|
return $resultset->rowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,12 +530,7 @@ class DoliDBSqlite extends DoliDB
|
|||||||
*/
|
*/
|
||||||
function escape($stringtoencode)
|
function escape($stringtoencode)
|
||||||
{
|
{
|
||||||
$ret = $this->db->quote($stringtoencode);
|
return $this->db->quote($stringtoencode);
|
||||||
$l = strlen($ret);
|
|
||||||
if ($l >= 2) {
|
|
||||||
return substr($ret, 1, $l -2);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1203,6 +1136,5 @@ class DoliDBSqlite extends DoliDB
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -354,7 +354,8 @@ class DoliDBSqlite3 extends DoliDB
|
|||||||
*/
|
*/
|
||||||
function getVersion()
|
function getVersion()
|
||||||
{
|
{
|
||||||
return $this->db->version()['versionString'];
|
$tmp=$this->db->version();
|
||||||
|
return $tmp['versionString'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ if ($dolibarr_main_db_type == "mysql") $choix=1;
|
|||||||
if ($dolibarr_main_db_type == "mysqli") $choix=1;
|
if ($dolibarr_main_db_type == "mysqli") $choix=1;
|
||||||
if ($dolibarr_main_db_type == "pgsql") $choix=2;
|
if ($dolibarr_main_db_type == "pgsql") $choix=2;
|
||||||
if ($dolibarr_main_db_type == "mssql") $choix=3;
|
if ($dolibarr_main_db_type == "mssql") $choix=3;
|
||||||
if ($dolibarr_main_db_type == "sqlite3") $choix=4;
|
if ($dolibarr_main_db_type == "sqlite") $choix=4;
|
||||||
|
if ($dolibarr_main_db_type == "sqlite3") $choix=5;
|
||||||
|
|
||||||
//if (empty($choix)) dol_print_error('','Database type '.$dolibarr_main_db_type.' not supported into etape2.php page');
|
//if (empty($choix)) dol_print_error('','Database type '.$dolibarr_main_db_type.' not supported into etape2.php page');
|
||||||
|
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ if (! empty($force_install_message))
|
|||||||
$class='DoliDB'.ucfirst($type);
|
$class='DoliDB'.ucfirst($type);
|
||||||
include_once $dir."/".$file;
|
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 until sqlite does not manage foreign key creation after table creation
|
||||||
|
|
||||||
// Version min of database
|
// Version min of database
|
||||||
$versionbasemin=explode('.',$class::VERSIONMIN);
|
$versionbasemin=explode('.',$class::VERSIONMIN);
|
||||||
@@ -320,6 +320,7 @@ if (! empty($force_install_message))
|
|||||||
if ($type=='mysqli') { $testfunction='mysqli_connect'; $testclass=''; }
|
if ($type=='mysqli') { $testfunction='mysqli_connect'; $testclass=''; }
|
||||||
if ($type=='pgsql') { $testfunction='pg_connect'; $testclass=''; }
|
if ($type=='pgsql') { $testfunction='pg_connect'; $testclass=''; }
|
||||||
if ($type=='mssql') { $testfunction='mssql_connect'; $testclass=''; }
|
if ($type=='mssql') { $testfunction='mssql_connect'; $testclass=''; }
|
||||||
|
if ($type=='sqlite') { $testfunction=''; $testclass='PDO'; }
|
||||||
if ($type=='sqlite3') { $testfunction=''; $testclass='SQLite3'; }
|
if ($type=='sqlite3') { $testfunction=''; $testclass='SQLite3'; }
|
||||||
$option.='<option value="'.$type.'"'.($defaultype == $type?' selected="selected"':'');
|
$option.='<option value="'.$type.'"'.($defaultype == $type?' selected="selected"':'');
|
||||||
if ($testfunction && ! function_exists($testfunction)) $option.=' disabled="disabled"';
|
if ($testfunction && ! function_exists($testfunction)) $option.=' disabled="disabled"';
|
||||||
|
|||||||
Reference in New Issue
Block a user