28 require_once DOL_DOCUMENT_ROOT.
'/core/db/DoliDB.class.php';
44 const WEEK_MONDAY_FIRST = 1;
46 const WEEK_FIRST_WEEKDAY = 4;
65 if (!empty($conf->db->character_set)) $this->forcecharset = $conf->db->character_set;
66 if (!empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate = $conf->db->dolibarr_main_db_collation;
68 $this->database_user = $user;
69 $this->database_host = $host;
70 $this->database_port = $port;
72 $this->transaction_opened = 0;
96 $this->
db = $this->
connect($host, $user, $pass, $name, $port);
100 $this->connected =
true;
102 $this->database_selected =
true;
103 $this->database_name = $name;
116 $this->connected =
false;
118 $this->database_selected =
false;
119 $this->database_name =
'';
121 dol_syslog(get_class($this).
"::DoliDBSqlite3 : Error Connect ".$this->
error, LOG_ERR);
138 if (preg_match(
'/^--\s\$Id/i', $line)) {
142 if (preg_match(
'/^#/i', $line) || preg_match(
'/^$/i', $line) || preg_match(
'/^--/i', $line))
150 if (preg_match(
'/ALTER TABLE/i', $line))
$type =
'dml';
151 elseif (preg_match(
'/CREATE TABLE/i', $line))
$type =
'dml';
152 elseif (preg_match(
'/DROP TABLE/i', $line))
$type =
'dml';
157 $line = preg_replace(
'/\s/',
' ', $line);
160 if (preg_match(
'/(ISAM|innodb)/i', $line)) {
161 $line = preg_replace(
'/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb);/i',
');', $line);
162 $line = preg_replace(
'/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb);/i',
');', $line);
163 $line = preg_replace(
'/,$/',
'', $line);
167 if (preg_match(
'/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i', $line, $reg)) {
168 $newline = preg_replace(
'/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i',
'\\1 \\2 integer PRIMARY KEY AUTOINCREMENT', $line);
174 $line = str_replace(
'tinyint',
'smallint', $line);
177 $line = preg_replace(
'/(int\w+|smallint)\s+unsigned/i',
'\\1', $line);
180 $line = preg_replace(
'/\w*blob/i',
'text', $line);
183 $line = preg_replace(
'/tinytext/i',
'text', $line);
184 $line = preg_replace(
'/mediumtext/i',
'text', $line);
188 $line = preg_replace(
'/datetime not null/i',
'datetime', $line);
189 $line = preg_replace(
'/datetime/i',
'timestamp', $line);
192 $line = preg_replace(
'/^double/i',
'numeric', $line);
193 $line = preg_replace(
'/(\s*)double/i',
'\\1numeric', $line);
195 $line = preg_replace(
'/^float/i',
'numeric', $line);
196 $line = preg_replace(
'/(\s*)float/i',
'\\1numeric', $line);
199 if (preg_match(
'/unique index\s*\((\w+\s*,\s*\w+)\)/i', $line))
201 $line = preg_replace(
'/unique index\s*\((\w+\s*,\s*\w+)\)/i',
'UNIQUE\(\\1\)', $line);
205 $line = preg_replace(
'/AFTER [a-z0-9_]+/i',
'', $line);
208 $line = preg_replace(
'/ALTER TABLE [a-z0-9_]+ DROP INDEX/i',
'DROP INDEX', $line);
211 if (preg_match(
'/ALTER TABLE ([a-z0-9_]+) CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i', $line, $reg))
213 $line =
"-- ".$line.
" replaced by --\n";
214 $line .=
"ALTER TABLE ".$reg[1].
" RENAME COLUMN ".$reg[2].
" TO ".$reg[3];
218 if (preg_match(
'/ALTER TABLE ([a-z0-9_]+) MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i', $line, $reg))
220 $line =
"-- ".$line.
" replaced by --\n";
222 $newreg3 = preg_replace(
'/ DEFAULT NULL/i',
'', $newreg3);
223 $newreg3 = preg_replace(
'/ NOT NULL/i',
'', $newreg3);
224 $newreg3 = preg_replace(
'/ NULL/i',
'', $newreg3);
225 $newreg3 = preg_replace(
'/ DEFAULT 0/i',
'', $newreg3);
226 $newreg3 = preg_replace(
'/ DEFAULT \'[0-9a-zA-Z_@]*\'/i',
'', $newreg3);
227 $line .=
"ALTER TABLE ".$reg[1].
" ALTER COLUMN ".$reg[2].
" TYPE ".$newreg3;
233 if (preg_match(
'/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i', $line, $reg))
235 $line =
"-- ".$line.
" replaced by --\n";
236 $line .=
"CREATE UNIQUE INDEX ".$reg[2].
" ON ".$reg[1].
"(".$reg[3];
241 if (preg_match(
'/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i', $line, $reg))
243 $line =
"-- ".$line.
" replaced by --\n";
244 $line .=
"ALTER TABLE ".$reg[1].
" DROP CONSTRAINT ".$reg[2];
249 if (preg_match(
'/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i', $line, $reg))
251 $fieldlist = $reg[4];
253 $tablename = $reg[1];
254 $line =
"-- ".$line.
" replaced by --\n";
255 $line .=
"CREATE ".(preg_match(
'/UNIQUE/', $reg[2]) ?
'UNIQUE ' :
'').
"INDEX ".$idxname.
" ON ".$tablename.
" (".$fieldlist.
")";
257 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)) {
259 dol_syslog(get_class().
'::query line emptied');
270 if (preg_match(
'/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i', $line, $reg))
272 if ($reg[1] == $reg[2])
274 $line = preg_replace(
'/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',
'DELETE FROM \\1 USING \\3', $line);
279 $line = preg_replace(
'/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i',
'FROM \\1', $line);
283 $line = preg_replace(
'/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i',
'FROM \\1, \\2', $line);
287 $line = preg_replace(
'/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i',
'FROM \\1, \\2, \\3', $line);
306 dol_syslog(get_class($this).
"::select_db database=".$database, LOG_DEBUG);
324 public function connect($host, $login, $passwd, $name, $port = 0)
326 global $main_data_dir;
328 dol_syslog(get_class($this).
"::connect name=".$name, LOG_DEBUG);
330 $dir = $main_data_dir;
331 if (empty($dir)) $dir = DOL_DATA_ROOT;
334 $database_name = $dir.
'/database_'.$name.
'.sdb';
338 $this->
db =
new SQLite3($database_name);
342 $this->
error = self::LABEL.
' '.$e->getMessage().
' current dir='.$database_name;
358 $tmp = $this->
db->version();
359 return $tmp[
'versionString'];
369 return 'sqlite3 php driver';
383 if ($this->transaction_opened > 0)
dol_syslog(get_class($this).
"::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR);
384 $this->connected =
false;
401 public function query($query, $usesavepoint = 0,
$type =
'auto')
407 $query = trim($query);
412 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)) {
417 $foreignFields = $reg[5];
418 $foreignTable = $reg[4];
419 $localfields = $reg[3];
420 $constraintname = trim($reg[2]);
421 $tablename = trim($reg[1]);
423 $descTable = $this->
db->querySingle(
"SELECT sql FROM sqlite_master WHERE name='".$this->
escape($tablename).
"'");
426 $this->
query(
'ALTER TABLE '.$tablename.
' RENAME TO tmp_'.$tablename);
431 $descTable = substr($descTable, 0, strlen($descTable) - 1);
432 $descTable .=
", CONSTRAINT ".$constraintname.
" FOREIGN KEY (".$localfields.
") REFERENCES ".$foreignTable.
"(".$foreignFields.
")";
438 $this->
query($descTable);
441 $this->
query(
'INSERT INTO '.$tablename.
' SELECT * FROM tmp_'.$tablename);
444 $this->
query(
'DROP TABLE tmp_'.$tablename);
453 if (!in_array($query, array(
'BEGIN',
'COMMIT',
'ROLLBACK')))
455 $SYSLOG_SQL_LIMIT = 10000;
456 dol_syslog(
'sql='.substr($query, 0, $SYSLOG_SQL_LIMIT), LOG_DEBUG);
458 if (empty($query))
return false;
463 $ret = $this->
db->query($query);
465 $ret->queryString = $query;
469 $this->
error = $this->
db->lastErrorMsg();
472 if (!preg_match(
"/^COMMIT/i", $query) && !preg_match(
"/^ROLLBACK/i", $query))
475 if (!is_object($ret) || $this->
error)
481 dol_syslog(get_class($this).
"::query SQL Error query: ".$query, LOG_ERR);
483 $errormsg = get_class($this).
"::query SQL Error message: ".$this->lasterror;
485 if (preg_match(
'/[0-9]/', $this->
lasterrno)) {
486 $errormsg .=
' ('.$this->lasterrno.
')';
489 if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG)
dol_syslog(get_class($this).
"::query SQL Error query: ".$query, LOG_ERR);
490 dol_syslog(get_class($this).
"::query SQL Error message: ".$errormsg, LOG_ERR);
493 $this->_results = $ret;
510 if (!is_object($resultset)) { $resultset = $this->_results; }
512 $ret = $resultset->fetchArray(SQLITE3_ASSOC);
514 return (
object) $ret;
531 if (!is_object($resultset)) { $resultset = $this->_results; }
533 $ret = $resultset->fetchArray(SQLITE3_ASSOC);
548 if (!is_bool($resultset))
550 if (!is_object($resultset)) { $resultset = $this->_results; }
551 return $resultset->fetchArray(SQLITE3_NUM);
572 if (!is_object($resultset)) { $resultset = $this->_results; }
573 if (preg_match(
"/^SELECT/i", $resultset->queryString)) {
574 return $this->
db->querySingle(
"SELECT count(*) FROM (".$resultset->queryString.
") q");
593 if (!is_object($resultset)) { $resultset = $this->_results; }
594 if (preg_match(
"/^SELECT/i", $resultset->queryString)) {
599 return $this->
db->changes();
609 public function free($resultset = null)
612 if (!is_object($resultset)) { $resultset = $this->_results; }
614 if ($resultset && is_object($resultset)) $resultset->finalize();
625 return Sqlite3::escapeString($stringtoencode);
635 if (!$this->connected) {
637 return 'DB_ERROR_FAILED_TO_CONNECT';
672 $errno = $this->
db->lastErrorCode();
673 if ($errno ==
'HY000' || $errno == 0)
675 if (preg_match(
'/table.*already exists/i', $this->
error))
return 'DB_ERROR_TABLE_ALREADY_EXISTS';
676 elseif (preg_match(
'/index.*already exists/i', $this->
error))
return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS';
677 elseif (preg_match(
'/syntax error/i', $this->
error))
return 'DB_ERROR_SYNTAX';
679 if ($errno ==
'23000')
681 if (preg_match(
'/column.* not unique/i', $this->
error))
return 'DB_ERROR_RECORD_ALREADY_EXISTS';
682 elseif (preg_match(
'/PRIMARY KEY must be unique/i', $this->
error))
return 'DB_ERROR_RECORD_ALREADY_EXISTS';
688 return ($errno ?
'DB_ERROR_'.$errno :
'0');
699 if (!$this->connected) {
701 return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version';
718 return $this->
db->lastInsertRowId();
729 public function encrypt($fieldorvalue, $withQuotes = 0)
734 $cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0);
737 $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey :
'');
739 $return = ($withQuotes ?
"'" :
"").$this->
escape($fieldorvalue).($withQuotes ?
"'" :
"");
741 if ($cryptType && !empty($cryptKey))
745 $return =
'AES_ENCRYPT('.$return.
',\''.$cryptKey.
'\')
';
746 } elseif ($cryptType == 1)
748 $return = 'DES_ENCRYPT(
'.$return.',\
''.$cryptKey.
'\')
';
761 public function decrypt($value)
765 // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
766 $cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0);
769 $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : '');
773 if ($cryptType && !empty($cryptKey))
777 $return = 'AES_DECRYPT(
'.$value.',\
''.$cryptKey.
'\')
';
778 } elseif ($cryptType == 1)
780 $return = 'DES_DECRYPT(
'.$value.',\
''.$cryptKey.
'\')
';
788 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
794 public function DDLGetConnectId()
801 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
813 public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
816 if (empty($charset)) $charset = $this->forcecharset;
817 if (empty($collation)) $collation = $this->forcecollate;
819 // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
820 $sql = 'CREATE DATABASE
'.$database;
821 $sql .= ' DEFAULT CHARACTER SET
'.$charset.' DEFAULT COLLATE
'.$collation;
823 dol_syslog($sql, LOG_DEBUG);
824 $ret = $this->query($sql);
827 // We try again for compatibility with Mysql < 4.1.1
828 $sql = 'CREATE DATABASE
'.$database;
829 $ret = $this->query($sql);
830 dol_syslog($sql, LOG_DEBUG);
835 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
843 public function DDLListTables($database, $table = '')
846 $listtables = array();
849 if ($table) $like = "LIKE '".$table."'";
850 $sql = "SHOW TABLES FROM ".$database." ".$like.";";
852 $result = $this->query($sql);
855 while ($row = $this->fetch_row($result))
857 $listtables[] = $row[0];
863 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
871 public function DDLInfoTable($table)
874 $infotables = array();
876 $sql = "SHOW FULL COLUMNS FROM ".$table.";";
878 dol_syslog($sql, LOG_DEBUG);
879 $result = $this->query($sql);
882 while ($row = $this->fetch_row($result))
884 $infotables[] = $row;
890 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
903 public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null)
906 // FIXME: $fulltext_keys parameter is unused
908 // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra
909 // ex. : $fields['rowid'] = array('type'=>'int','value
'=>'11
','null
'=>'not null
','extra
'=> 'auto_increment
');
910 $sql = "create table ".$table."(";
912 foreach ($fields as $field_name => $field_desc)
914 $sqlfields[$i] = $field_name." ";
915 $sqlfields[$i] .= $field_desc['type'];
916 if (preg_match("/^[^\s]/i", $field_desc['value
']))
917 $sqlfields[$i] .= "(".$field_desc['value
'].")";
918 elseif (preg_match("/^[^\s]/i", $field_desc['attribute
']))
919 $sqlfields[$i] .= " ".$field_desc['attribute
'];
920 elseif (preg_match("/^[^\s]/i", $field_desc['default']))
922 if (preg_match("/null/i", $field_desc['default']))
923 $sqlfields[$i] .= " default ".$field_desc['default'];
924 else $sqlfields[$i] .= " default '".$this->escape($field_desc['default'])."'";
925 } elseif (preg_match("/^[^\s]/i", $field_desc['null
']))
926 $sqlfields[$i] .= " ".$field_desc['null
'];
928 elseif (preg_match("/^[^\s]/i", $field_desc['extra
']))
929 $sqlfields[$i] .= " ".$field_desc['extra
'];
932 if ($primary_key != "")
933 $pk = "primary key(".$primary_key.")";
935 if (is_array($unique_keys))
938 foreach ($unique_keys as $key => $value)
940 $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$this->escape($value)."')";
947 foreach ($keys as $key => $value)
949 $sqlk[$i] = "KEY ".$key." (".$value.")";
953 $sql .= implode(',
', $sqlfields);
954 if ($primary_key != "")
956 if (is_array($unique_keys))
957 $sql .= ",".implode(',
', $sqluq);
959 $sql .= ",".implode(',
', $sqlk);
960 $sql .= ") type=".$type;
962 dol_syslog($sql, LOG_DEBUG);
963 if (!$this -> query($sql))
968 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
975 public function DDLDropTable($table)
978 $sql = "DROP TABLE ".$table;
980 if (!$this->query($sql))
985 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
993 public function DDLDescTable($table, $field = "")
996 $sql = "DESC ".$table." ".$field;
998 dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG);
999 $this->_results = $this->query($sql);
1000 return $this->_results;
1003 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1013 public function DDLAddField($table, $field_name, $field_desc, $field_position = "")
1016 // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra
1017 // ex. : $field_desc = array('type'=>'int','value
'=>'11
','null
'=>'not null
','extra
'=> 'auto_increment
');
1018 $sql = "ALTER TABLE ".$table." ADD ".$field_name." ";
1019 $sql .= $field_desc['type'];
1020 if (preg_match("/^[^\s]/i", $field_desc['value
']))
1021 if (!in_array($field_desc['type'], array('date
', 'datetime
')))
1023 $sql .= "(".$field_desc['value
'].")";
1025 if (preg_match("/^[^\s]/i", $field_desc['attribute
']))
1026 $sql .= " ".$field_desc['attribute
'];
1027 if (preg_match("/^[^\s]/i", $field_desc['null
']))
1028 $sql .= " ".$field_desc['null
'];
1029 if (preg_match("/^[^\s]/i", $field_desc['default']))
1031 if (preg_match("/null/i", $field_desc['default']))
1032 $sql .= " default ".$field_desc['default'];
1033 else $sql .= " default '".$this->escape($field_desc['default'])."'";
1035 if (preg_match("/^[^\s]/i", $field_desc['extra
']))
1036 $sql .= " ".$field_desc['extra
'];
1037 $sql .= " ".$field_position;
1039 dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG);
1040 if (!$this->query($sql))
1047 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1056 public function DDLUpdateField($table, $field_name, $field_desc)
1059 $sql = "ALTER TABLE ".$table;
1060 $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type'];
1061 if ($field_desc['type'] == 'tinyint
' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar
') {
1062 $sql .= "(".$field_desc['value
'].")";
1065 dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG);
1066 if (!$this->query($sql))
1071 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1079 public function DDLDropField($table, $field_name)
1082 $sql = "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`";
1083 dol_syslog(get_class($this)."::DDLDropField ".$sql, LOG_DEBUG);
1084 if (!$this->query($sql))
1086 $this->error = $this->lasterror();
1093 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1103 public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
1106 $sql = "INSERT INTO user ";
1107 $sql .= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)";
1108 $sql .= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_user)."',password('".addslashes($dolibarr_main_db_pass)."')";
1109 $sql .= ",'Y
','Y
','Y
','Y
','Y
','Y
','Y
','Y
','Y
')";
1111 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
1112 $resql = $this->query($sql);
1118 $sql = "INSERT INTO db ";
1119 $sql .= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)";
1120 $sql .= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_name)."','".addslashes($dolibarr_main_db_user)."'";
1121 $sql .= ",'Y
','Y
','Y
','Y
','Y
','Y
','Y
','Y
','Y
')";
1123 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG);
1124 $resql = $this->query($sql);
1130 $sql = "FLUSH Privileges";
1132 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG);
1133 $resql = $this->query($sql);
1146 public function getDefaultCharacterSetDatabase()
1156 public function getListOfCharacterSet()
1160 $liste[$i]['charset
'] = 'UTF-8
';
1170 public function getDefaultCollationDatabase()
1180 public function getListOfCollation()
1184 $liste[$i]['charset
'] = 'UTF-8
';
1194 public function getPathOfDump()
1196 // FIXME: not for SQLite
1197 $fullpathofdump = '/pathtomysqldump/mysqldump
';
1199 $resql = $this->query('SHOW VARIABLES LIKE \
'basedir\'');
1203 $basedir = $liste[
'Value'];
1204 $fullpathofdump = $basedir.(preg_match(
'/\/$/', $basedir) ?
'' :
'/').
'bin/mysqldump';
1206 return $fullpathofdump;
1217 $fullpathofimport =
'/pathtomysql/mysql';
1219 $resql = $this->
query(
'SHOW VARIABLES LIKE \'basedir\'');
1223 $basedir = $liste[
'Value'];
1224 $fullpathofimport = $basedir.(preg_match(
'/\/$/', $basedir) ?
'' :
'/').
'bin/mysql';
1226 return $fullpathofimport;
1239 if (!isset($pragmas)) {
1244 'application_id',
'auto_vacuum',
'automatic_index',
'busy_timeout',
'cache_size',
1245 'cache_spill',
'case_sensitive_like',
'checkpoint_fullsync',
'collation_list',
1246 'compile_options',
'data_version',
1247 'defer_foreign_keys',
'encoding',
'foreign_key_check',
'freelist_count',
1248 'full_column_names',
'fullsync',
'ingore_check_constraints',
'integrity_check',
1249 'journal_mode',
'journal_size_limit',
'legacy_file_format',
'locking_mode',
1250 'max_page_count',
'page_count',
'page_size',
'parser_trace',
1251 'query_only',
'quick_check',
'read_uncommitted',
'recursive_triggers',
1252 'reverse_unordered_selects',
'schema_version',
'user_version',
1253 'secure_delete',
'short_column_names',
'shrink_memory',
'soft_heap_limit',
1254 'synchronous',
'temp_store',
'threads',
1255 'vdbe_addoptrace',
'vdbe_debug',
'vdbe_listing',
'vdbe_trace',
1256 'wal_autocheckpoint',
1261 foreach ($pragmas as $var) {
1262 $sql =
"PRAGMA $var";
1268 $result[$var] = $obj[0];
1271 $result[$var] =
'FAIL';
1312 $newname = preg_replace(
'/_/',
'', $name);
1313 $localname = __CLASS__.
'::db'.$newname;
1314 $reflectClass =
new ReflectionClass(__CLASS__);
1315 $reflectFunction = $reflectClass->getMethod(
'db'.$newname);
1316 if ($arg_count < 0) {
1317 $arg_count = $reflectFunction->getNumberOfParameters();
1319 if (!$this->
db->createFunction($name, $localname, $arg_count))
1321 $this->
error =
"unable to create custom function '$name'";
1339 if ($y == 0 && $month == 0)
return 0;
1340 $num = (365 * $y + 31 * ($month - 1) + $day);
1343 $num -= floor(($month * 4 + 23) / 10);
1345 $temp = floor(($y / 100 + 1) * 3 / 4);
1346 return $num + floor($y / 4) - $temp;
1360 $ret = floor(($daynr + 5 + ($sunday_first_day_of_week ? 1 : 0)) % 7);
1374 return (($year & 3) == 0 && ($year % 100 || ($year % 400 == 0 && $year)) ? 366 : 365);
1388 private static function calc_week($year, $month, $day, $week_behaviour, &$calc_year)
1391 $daynr = self::calc_daynr($year, $month, $day);
1392 $first_daynr = self::calc_daynr($year, 1, 1);
1393 $monday_first = ($week_behaviour & self::WEEK_MONDAY_FIRST) ? 1 : 0;
1394 $week_year = ($week_behaviour & self::WEEK_YEAR) ? 1 : 0;
1395 $first_weekday = ($week_behaviour & self::WEEK_FIRST_WEEKDAY) ? 1 : 0;
1397 $weekday = self::calc_weekday($first_daynr, !$monday_first);
1400 if ($month == 1 && $day <= 7 - $weekday) {
1401 if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)))
1405 $first_daynr -= ($days = self::calc_days_in_year($calc_year));
1406 $weekday = ($weekday + 53 * 7 - $days) % 7;
1409 if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) {
1410 $days = $daynr - ($first_daynr + (7 - $weekday));
1412 $days = $daynr - ($first_daynr - $weekday);
1415 if ($week_year && $days >= 52 * 7) {
1416 $weekday = ($weekday + self::calc_days_in_year($calc_year)) % 7;
1417 if ((!$first_weekday && $weekday < 4) || ($first_weekday && $weekday == 0)) {
1422 return floor($days / 7 + 1);
addCustomFunction($name, $arg_count=-1)
Permet le chargement d'une fonction personnalisee dans le moteur de base de donnees.
const LABEL
Database label.
lastqueryerror()
Return last query in error.
getDriverInfo()
Return version of database client driver.
select_db($database)
Select a database.
last_insert_id($tab, $fieldid= 'rowid')
Get last ID after an insert INSERT.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
error()
Renvoie le texte de l'erreur mysql de l'operation precedente.
escape($stringtoencode)
Escape a string to insert data.
lastquery()
Return last request executed with query()
encrypt($fieldorvalue, $withQuotes=0)
Encrypt sensitive data in database Warning: This function includes the escape, so it must use direct ...
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
Class to manage Dolibarr database access.
static calc_days_in_year($year)
calc_days_in_year
connect($host, $login, $passwd, $name, $port=0)
Connexion to server.
lasterror()
Return last error label.
$conf db
API class for accounts.
close()
Close database connexion.
free($resultset=null)
Free last resultset used.
getServerParametersValues($filter= '')
Return value of server parameters.
const VERSIONMIN
Version min database.
static calc_week($year, $month, $day, $week_behaviour, &$calc_year)
calc_week
fetch_array($resultset)
Return datas as an array.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getPathOfRestore()
Return full path of restore program.
fetch_row($resultset)
Return datas as an array.
fetch_object($resultset)
Renvoie la ligne courante (comme un objet) pour le curseur resultset.
num_rows($resultset)
Return number of lines for result of a SELECT.
affected_rows($resultset)
Return number of lines for result of a SELECT.
__construct($type, $host, $user, $pass, $name= '', $port=0)
Constructor.
query($query, $usesavepoint=0, $type= 'auto')
Execute a SQL request and return the resultset.
static calc_weekday($daynr, $sunday_first_day_of_week)
calc_weekday
static convertSQLFromMysql($line, $type= 'ddl')
Convert a SQL request in Mysql syntax to native syntax.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
lasterrno()
Return last error code.
Class to manage Dolibarr database access for a SQLite database.
getServerStatusValues($filter= '')
Return value of server status.
static calc_daynr($year, $month, $day)
calc_daynr
errno()
Renvoie le code erreur generique de l'operation precedente.
getVersion()
Return version of database server.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type