@@ -45,7 +45,7 @@ |
||
45 | 45 | * |
46 | 46 | * @param DoliDB $db Database handler |
47 | 47 | * @param int $socid Id third party |
48 | - * @param mixed $userid Id user for filter or array of user ids |
|
48 | + * @param integer $userid Id user for filter or array of user ids |
|
49 | 49 | * @return void |
50 | 50 | */ |
51 | 51 | function __construct($db, $socid=0, $userid=0) |
@@ -31,21 +31,21 @@ discard block |
||
31 | 31 | */ |
32 | 32 | class DeplacementStats extends Stats |
33 | 33 | { |
34 | - public $table_element; |
|
34 | + public $table_element; |
|
35 | 35 | |
36 | - var $socid; |
|
37 | - var $userid; |
|
36 | + var $socid; |
|
37 | + var $userid; |
|
38 | 38 | |
39 | - var $from; |
|
40 | - var $field; |
|
41 | - var $where; |
|
39 | + var $from; |
|
40 | + var $field; |
|
41 | + var $where; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Constructor |
45 | 45 | * |
46 | 46 | * @param DoliDB $db Database handler |
47 | 47 | * @param int $socid Id third party |
48 | - * @param mixed $userid Id user for filter or array of user ids |
|
48 | + * @param mixed $userid Id user for filter or array of user ids |
|
49 | 49 | * @return void |
50 | 50 | */ |
51 | 51 | function __construct($db, $socid=0, $userid=0) |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | global $conf; |
54 | 54 | |
55 | 55 | $this->db = $db; |
56 | - $this->socid = $socid; |
|
57 | - $this->userid = $userid; |
|
56 | + $this->socid = $socid; |
|
57 | + $this->userid = $userid; |
|
58 | 58 | |
59 | 59 | $object=new Deplacement($this->db); |
60 | 60 | $this->from = MAIN_DB_PREFIX.$object->table_element; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $this->where.=" AND fk_soc = ".$this->socid; |
68 | 68 | } |
69 | 69 | if (is_array($this->userid) && count($this->userid) > 0) $this->where.=' AND fk_user IN ('.join(',',$this->userid).')'; |
70 | - else if ($this->userid > 0) $this->where.=' AND fk_user = '.$this->userid; |
|
70 | + else if ($this->userid > 0) $this->where.=' AND fk_user = '.$this->userid; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | $sql.= " WHERE YEAR(dated) = ".$year; |
101 | 101 | $sql.= " AND ".$this->where; |
102 | 102 | $sql.= " GROUP BY dm"; |
103 | - $sql.= $this->db->order('dm','DESC'); |
|
103 | + $sql.= $this->db->order('dm','DESC'); |
|
104 | 104 | |
105 | 105 | $res=$this->_getNbByMonth($year, $sql); |
106 | 106 | //var_dump($res);print '<br>'; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $sql.= " WHERE date_format(dated,'%Y') = '".$year."'"; |
142 | 142 | $sql.= " AND ".$this->where; |
143 | 143 | $sql.= " GROUP BY dm"; |
144 | - $sql.= $this->db->order('dm','DESC'); |
|
144 | + $sql.= $this->db->order('dm','DESC'); |
|
145 | 145 | |
146 | 146 | return $this->_getAverageByMonth($year, $sql); |
147 | 147 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $sql.= " FROM ".$this->from; |
158 | 158 | $sql.= " WHERE ".$this->where; |
159 | 159 | $sql.= " GROUP BY year"; |
160 | - $sql.= $this->db->order('year','DESC'); |
|
160 | + $sql.= $this->db->order('year','DESC'); |
|
161 | 161 | |
162 | 162 | return $this->_getAllByYear($sql); |
163 | 163 | } |
@@ -1285,7 +1285,7 @@ discard block |
||
1285 | 1285 | * @param int $info_bits Bits de type de lignes |
1286 | 1286 | * @param int $fk_fournprice Fourn price id |
1287 | 1287 | * @param int $pa_ht Buying price HT |
1288 | - * @param array $array_options extrafields array |
|
1288 | + * @param integer $array_options extrafields array |
|
1289 | 1289 | * @param string $fk_unit Code of the unit to use. Null to use the default one |
1290 | 1290 | * @return int <0 si erreur, >0 si ok |
1291 | 1291 | */ |
@@ -1474,7 +1474,7 @@ discard block |
||
1474 | 1474 | * @param int $info_bits Bits de type de lignes |
1475 | 1475 | * @param int $fk_fournprice Fourn price id |
1476 | 1476 | * @param int $pa_ht Buying price HT |
1477 | - * @param array $array_options extrafields array |
|
1477 | + * @param integer $array_options extrafields array |
|
1478 | 1478 | * @param string $fk_unit Code of the unit to use. Null to use the default one |
1479 | 1479 | * @return int < 0 si erreur, > 0 si ok |
1480 | 1480 | */ |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public $table_element_line='contratdet'; |
46 | 46 | public $fk_element='fk_contrat'; |
47 | 47 | protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
48 | - public $picto='contract'; |
|
48 | + public $picto='contract'; |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * {@inheritdoc} |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | foreach($this->lines as $contratline) |
315 | 315 | { |
316 | 316 | // Close lines not already closed |
317 | - if ($contratline->statut != 5) |
|
318 | - { |
|
317 | + if ($contratline->statut != 5) |
|
318 | + { |
|
319 | 319 | $contratline->date_cloture=dol_now(); |
320 | 320 | $contratline->fk_user_cloture=$user->id; |
321 | 321 | $contratline->statut='5'; |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $ok=false; |
326 | 326 | break; |
327 | 327 | } |
328 | - } |
|
328 | + } |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | if ($this->statut == 0) |
@@ -334,17 +334,17 @@ discard block |
||
334 | 334 | if ($result < 0) $ok=false; |
335 | 335 | } |
336 | 336 | |
337 | - if ($ok) |
|
338 | - { |
|
339 | - $this->db->commit(); |
|
340 | - return 1; |
|
341 | - } |
|
342 | - else |
|
343 | - { |
|
344 | - dol_print_error($this->db,'Error in closeAll function'); |
|
345 | - $this->db->rollback(); |
|
346 | - return -1; |
|
347 | - } |
|
337 | + if ($ok) |
|
338 | + { |
|
339 | + $this->db->commit(); |
|
340 | + return 1; |
|
341 | + } |
|
342 | + else |
|
343 | + { |
|
344 | + dol_print_error($this->db,'Error in closeAll function'); |
|
345 | + $this->db->rollback(); |
|
346 | + return -1; |
|
347 | + } |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @param User $user Objet User |
354 | 354 | * @param string $force_number Reference to force on contract (not implemented yet) |
355 | - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers |
|
355 | + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers |
|
356 | 356 | * @return int <0 if KO, >0 if OK |
357 | 357 | */ |
358 | 358 | function validate($user, $force_number='', $notrigger=0) |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | { |
383 | 383 | $num = $this->ref; |
384 | 384 | } |
385 | - $this->newref = $num; |
|
385 | + $this->newref = $num; |
|
386 | 386 | |
387 | 387 | if ($num) |
388 | 388 | { |
@@ -402,15 +402,15 @@ discard block |
||
402 | 402 | // Trigger calls |
403 | 403 | if (! $error && ! $notrigger) |
404 | 404 | { |
405 | - // Call trigger |
|
406 | - $result=$this->call_trigger('CONTRACT_VALIDATE',$user); |
|
407 | - if ($result < 0) { $error++; } |
|
408 | - // End call triggers |
|
405 | + // Call trigger |
|
406 | + $result=$this->call_trigger('CONTRACT_VALIDATE',$user); |
|
407 | + if ($result < 0) { $error++; } |
|
408 | + // End call triggers |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | if (! $error) |
412 | 412 | { |
413 | - $this->oldref = $this->ref; |
|
413 | + $this->oldref = $this->ref; |
|
414 | 414 | |
415 | 415 | // Rename directory if dir was a temporary ref |
416 | 416 | if (preg_match('/^[\(]?PROV/i', $this->ref)) |
@@ -428,16 +428,16 @@ discard block |
||
428 | 428 | if (@rename($dirsource, $dirdest)) |
429 | 429 | { |
430 | 430 | dol_syslog("Rename ok"); |
431 | - // Rename docs starting with $oldref with $newref |
|
432 | - $listoffiles=dol_dir_list($conf->contract->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/')); |
|
433 | - foreach($listoffiles as $fileentry) |
|
434 | - { |
|
435 | - $dirsource=$fileentry['name']; |
|
436 | - $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); |
|
437 | - $dirsource=$fileentry['path'].'/'.$dirsource; |
|
438 | - $dirdest=$fileentry['path'].'/'.$dirdest; |
|
439 | - @rename($dirsource, $dirdest); |
|
440 | - } |
|
431 | + // Rename docs starting with $oldref with $newref |
|
432 | + $listoffiles=dol_dir_list($conf->contract->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/')); |
|
433 | + foreach($listoffiles as $fileentry) |
|
434 | + { |
|
435 | + $dirsource=$fileentry['name']; |
|
436 | + $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); |
|
437 | + $dirsource=$fileentry['path'].'/'.$dirsource; |
|
438 | + $dirdest=$fileentry['path'].'/'.$dirdest; |
|
439 | + @rename($dirsource, $dirdest); |
|
440 | + } |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | * Unvalidate a contract |
475 | 475 | * |
476 | 476 | * @param User $user Objet User |
477 | - * @param int $notrigger 1=Does not execute triggers, 0=execute triggers |
|
477 | + * @param int $notrigger 1=Does not execute triggers, 0=execute triggers |
|
478 | 478 | * @return int <0 if KO, >0 if OK |
479 | 479 | */ |
480 | 480 | function reopen($user, $notrigger=0) |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | $extralabelsline=$extrafieldsline->fetch_name_optionals_label($line->table_element,true); |
675 | 675 | |
676 | 676 | $this->lines=array(); |
677 | - $pos = 0; |
|
677 | + $pos = 0; |
|
678 | 678 | |
679 | 679 | // Selectionne les lignes contrats liees a un produit |
680 | 680 | $sql = "SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref,"; |
@@ -775,8 +775,8 @@ discard block |
||
775 | 775 | if ($line->statut == 5) $this->nbofservicesclosed++; |
776 | 776 | |
777 | 777 | $total_ttc+=$objp->total_ttc; // TODO Not saved into database |
778 | - $total_vat+=$objp->total_tva; |
|
779 | - $total_ht+=$objp->total_ht; |
|
778 | + $total_vat+=$objp->total_tva; |
|
779 | + $total_ht+=$objp->total_ht; |
|
780 | 780 | |
781 | 781 | $i++; |
782 | 782 | $pos++; |
@@ -875,11 +875,11 @@ discard block |
||
875 | 875 | $this->lines_id_index_mapper[$line->id] = $pos; |
876 | 876 | |
877 | 877 | $total_ttc+=$objp->total_ttc; |
878 | - $total_vat+=$objp->total_tva; |
|
879 | - $total_ht+=$objp->total_ht; |
|
878 | + $total_vat+=$objp->total_tva; |
|
879 | + $total_ht+=$objp->total_ht; |
|
880 | 880 | |
881 | - $i++; |
|
882 | - $pos++; |
|
881 | + $i++; |
|
882 | + $pos++; |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | $this->db->free($result); |
@@ -892,9 +892,9 @@ discard block |
||
892 | 892 | } |
893 | 893 | |
894 | 894 | $this->nbofservices=count($this->lines); |
895 | - $this->total_ttc = price2num($total_ttc); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
896 | - $this->total_vat = price2num($total_vat); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
897 | - $this->total_ht = price2num($total_ht); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
895 | + $this->total_ttc = price2num($total_ttc); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
896 | + $this->total_vat = price2num($total_vat); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
897 | + $this->total_ht = price2num($total_ht); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
898 | 898 | |
899 | 899 | return $this->lines; |
900 | 900 | } |
@@ -982,107 +982,107 @@ discard block |
||
982 | 982 | |
983 | 983 | if (! $error) |
984 | 984 | { |
985 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
|
986 | - { |
|
987 | - $result=$this->insertExtraFields(); |
|
988 | - if ($result < 0) |
|
989 | - { |
|
990 | - $error++; |
|
991 | - } |
|
992 | - } |
|
985 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
|
986 | + { |
|
987 | + $result=$this->insertExtraFields(); |
|
988 | + if ($result < 0) |
|
989 | + { |
|
990 | + $error++; |
|
991 | + } |
|
992 | + } |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | // Insert contacts commerciaux ('SALESREPSIGN','contrat') |
996 | 996 | if (! $error) |
997 | 997 | { |
998 | - $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal'); |
|
999 | - if ($result < 0) $error++; |
|
998 | + $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal'); |
|
999 | + if ($result < 0) $error++; |
|
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | // Insert contacts commerciaux ('SALESREPFOLL','contrat') |
1003 | 1003 | if (! $error) |
1004 | 1004 | { |
1005 | - $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); |
|
1006 | - if ($result < 0) $error++; |
|
1005 | + $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); |
|
1006 | + if ($result < 0) $error++; |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | if (! $error) |
1010 | 1010 | { |
1011 | - // Add object linked |
|
1012 | - if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) |
|
1013 | - { |
|
1014 | - foreach($this->linked_objects as $origin => $tmp_origin_id) |
|
1015 | - { |
|
1016 | - if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) |
|
1017 | - { |
|
1018 | - foreach($tmp_origin_id as $origin_id) |
|
1019 | - { |
|
1020 | - $ret = $this->add_object_linked($origin, $origin_id); |
|
1021 | - if (! $ret) |
|
1022 | - { |
|
1023 | - dol_print_error($this->db); |
|
1024 | - $error++; |
|
1025 | - } |
|
1026 | - } |
|
1027 | - } |
|
1028 | - else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) |
|
1029 | - { |
|
1030 | - $origin_id = $tmp_origin_id; |
|
1031 | - $ret = $this->add_object_linked($origin, $origin_id); |
|
1032 | - if (! $ret) |
|
1033 | - { |
|
1034 | - dol_print_error($this->db); |
|
1035 | - $error++; |
|
1036 | - } |
|
1037 | - } |
|
1038 | - } |
|
1039 | - } |
|
1040 | - |
|
1041 | - if (! $error && $this->id && ! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && ! empty($this->origin) && ! empty($this->origin_id)) // Get contact from origin object |
|
1042 | - { |
|
1043 | - $originforcontact = $this->origin; |
|
1044 | - $originidforcontact = $this->origin_id; |
|
1045 | - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order |
|
1046 | - { |
|
1047 | - require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; |
|
1048 | - $exp = new Expedition($db); |
|
1049 | - $exp->fetch($this->origin_id); |
|
1050 | - $exp->fetchObjectLinked(); |
|
1051 | - if (count($exp->linkedObjectsIds['commande']) > 0) |
|
1052 | - { |
|
1053 | - foreach ($exp->linkedObjectsIds['commande'] as $key => $value) |
|
1054 | - { |
|
1055 | - $originforcontact = 'commande'; |
|
1056 | - $originidforcontact = $value->id; |
|
1057 | - break; // We take first one |
|
1058 | - } |
|
1059 | - } |
|
1060 | - } |
|
1061 | - |
|
1062 | - $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; |
|
1063 | - $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; |
|
1064 | - |
|
1065 | - $resqlcontact = $this->db->query($sqlcontact); |
|
1066 | - if ($resqlcontact) |
|
1067 | - { |
|
1068 | - while($objcontact = $this->db->fetch_object($resqlcontact)) |
|
1069 | - { |
|
1070 | - if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously |
|
1071 | - |
|
1072 | - //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; |
|
1073 | - $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object |
|
1074 | - } |
|
1075 | - } |
|
1076 | - else dol_print_error($resqlcontact); |
|
1077 | - } |
|
1011 | + // Add object linked |
|
1012 | + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) |
|
1013 | + { |
|
1014 | + foreach($this->linked_objects as $origin => $tmp_origin_id) |
|
1015 | + { |
|
1016 | + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) |
|
1017 | + { |
|
1018 | + foreach($tmp_origin_id as $origin_id) |
|
1019 | + { |
|
1020 | + $ret = $this->add_object_linked($origin, $origin_id); |
|
1021 | + if (! $ret) |
|
1022 | + { |
|
1023 | + dol_print_error($this->db); |
|
1024 | + $error++; |
|
1025 | + } |
|
1026 | + } |
|
1027 | + } |
|
1028 | + else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) |
|
1029 | + { |
|
1030 | + $origin_id = $tmp_origin_id; |
|
1031 | + $ret = $this->add_object_linked($origin, $origin_id); |
|
1032 | + if (! $ret) |
|
1033 | + { |
|
1034 | + dol_print_error($this->db); |
|
1035 | + $error++; |
|
1036 | + } |
|
1037 | + } |
|
1038 | + } |
|
1039 | + } |
|
1040 | + |
|
1041 | + if (! $error && $this->id && ! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && ! empty($this->origin) && ! empty($this->origin_id)) // Get contact from origin object |
|
1042 | + { |
|
1043 | + $originforcontact = $this->origin; |
|
1044 | + $originidforcontact = $this->origin_id; |
|
1045 | + if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order |
|
1046 | + { |
|
1047 | + require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; |
|
1048 | + $exp = new Expedition($db); |
|
1049 | + $exp->fetch($this->origin_id); |
|
1050 | + $exp->fetchObjectLinked(); |
|
1051 | + if (count($exp->linkedObjectsIds['commande']) > 0) |
|
1052 | + { |
|
1053 | + foreach ($exp->linkedObjectsIds['commande'] as $key => $value) |
|
1054 | + { |
|
1055 | + $originforcontact = 'commande'; |
|
1056 | + $originidforcontact = $value->id; |
|
1057 | + break; // We take first one |
|
1058 | + } |
|
1059 | + } |
|
1060 | + } |
|
1061 | + |
|
1062 | + $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; |
|
1063 | + $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; |
|
1064 | + |
|
1065 | + $resqlcontact = $this->db->query($sqlcontact); |
|
1066 | + if ($resqlcontact) |
|
1067 | + { |
|
1068 | + while($objcontact = $this->db->fetch_object($resqlcontact)) |
|
1069 | + { |
|
1070 | + if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously |
|
1071 | + |
|
1072 | + //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; |
|
1073 | + $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object |
|
1074 | + } |
|
1075 | + } |
|
1076 | + else dol_print_error($resqlcontact); |
|
1077 | + } |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | if (! $error) |
1081 | 1081 | { |
1082 | - // Call trigger |
|
1083 | - $result=$this->call_trigger('CONTRACT_CREATE',$user); |
|
1084 | - if ($result < 0) { $error++; } |
|
1085 | - // End call triggers |
|
1082 | + // Call trigger |
|
1083 | + $result=$this->call_trigger('CONTRACT_CREATE',$user); |
|
1084 | + if ($result < 0) { $error++; } |
|
1085 | + // End call triggers |
|
1086 | 1086 | |
1087 | 1087 | if (! $error) |
1088 | 1088 | { |
@@ -1129,10 +1129,10 @@ discard block |
||
1129 | 1129 | |
1130 | 1130 | $this->db->begin(); |
1131 | 1131 | |
1132 | - // Call trigger |
|
1133 | - $result=$this->call_trigger('CONTRACT_DELETE',$user); |
|
1134 | - if ($result < 0) { $error++; } |
|
1135 | - // End call triggers |
|
1132 | + // Call trigger |
|
1133 | + $result=$this->call_trigger('CONTRACT_DELETE',$user); |
|
1134 | + if ($result < 0) { $error++; } |
|
1135 | + // End call triggers |
|
1136 | 1136 | |
1137 | 1137 | if (! $error) |
1138 | 1138 | { |
@@ -1301,7 +1301,7 @@ discard block |
||
1301 | 1301 | // Put here code to add a control on parameters values |
1302 | 1302 | |
1303 | 1303 | // Update request |
1304 | - $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET"; |
|
1304 | + $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET"; |
|
1305 | 1305 | $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; |
1306 | 1306 | $sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").","; |
1307 | 1307 | $sql.= " ref_supplier=".(isset($this->ref_supplier)?"'".$this->db->escape($this->ref_supplier)."'":"null").","; |
@@ -1427,7 +1427,7 @@ discard block |
||
1427 | 1427 | if (empty($pu_ttc)) $pu_ttc=0; |
1428 | 1428 | if (empty($txtva) || ! is_numeric($txtva)) $txtva=0; |
1429 | 1429 | if (empty($txlocaltax1) || ! is_numeric($txlocaltax1)) $txlocaltax1=0; |
1430 | - if (empty($txlocaltax2) || ! is_numeric($txlocaltax2)) $txlocaltax2=0; |
|
1430 | + if (empty($txlocaltax2) || ! is_numeric($txlocaltax2)) $txlocaltax2=0; |
|
1431 | 1431 | |
1432 | 1432 | if ($price_base_type=='HT') |
1433 | 1433 | { |
@@ -1448,13 +1448,13 @@ discard block |
||
1448 | 1448 | |
1449 | 1449 | $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc); |
1450 | 1450 | |
1451 | - // Clean vat code |
|
1452 | - $vat_src_code=''; |
|
1453 | - if (preg_match('/\((.*)\)/', $txtva, $reg)) |
|
1454 | - { |
|
1455 | - $vat_src_code = $reg[1]; |
|
1456 | - $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. |
|
1457 | - } |
|
1451 | + // Clean vat code |
|
1452 | + $vat_src_code=''; |
|
1453 | + if (preg_match('/\((.*)\)/', $txtva, $reg)) |
|
1454 | + { |
|
1455 | + $vat_src_code = $reg[1]; |
|
1456 | + $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. |
|
1457 | + } |
|
1458 | 1458 | |
1459 | 1459 | $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,$mysoc, $localtaxes_type); |
1460 | 1460 | $total_ht = $tabprice[0]; |
@@ -1476,7 +1476,7 @@ discard block |
||
1476 | 1476 | $price = $pu_ht - $remise; |
1477 | 1477 | } |
1478 | 1478 | |
1479 | - if (empty($pa_ht)) $pa_ht=0; |
|
1479 | + if (empty($pa_ht)) $pa_ht=0; |
|
1480 | 1480 | |
1481 | 1481 | |
1482 | 1482 | // if buy price not defined, define buyprice as configured in margin admin |
@@ -1549,13 +1549,13 @@ discard block |
||
1549 | 1549 | } |
1550 | 1550 | |
1551 | 1551 | if (empty($error)) { |
1552 | - // Call trigger |
|
1553 | - $result=$this->call_trigger('LINECONTRACT_INSERT',$user); |
|
1554 | - if ($result < 0) |
|
1555 | - { |
|
1556 | - $error++; |
|
1557 | - } |
|
1558 | - // End call triggers |
|
1552 | + // Call trigger |
|
1553 | + $result=$this->call_trigger('LINECONTRACT_INSERT',$user); |
|
1554 | + if ($result < 0) |
|
1555 | + { |
|
1556 | + $error++; |
|
1557 | + } |
|
1558 | + // End call triggers |
|
1559 | 1559 | } |
1560 | 1560 | |
1561 | 1561 | if ($error) |
@@ -1666,11 +1666,11 @@ discard block |
||
1666 | 1666 | $price = price2num(round($pu, 2)); |
1667 | 1667 | if (dol_strlen($remise_percent) > 0) |
1668 | 1668 | { |
1669 | - $remise = round(($pu * $remise_percent / 100), 2); |
|
1670 | - $price = $pu - $remise; |
|
1669 | + $remise = round(($pu * $remise_percent / 100), 2); |
|
1670 | + $price = $pu - $remise; |
|
1671 | 1671 | } |
1672 | 1672 | |
1673 | - if (empty($pa_ht)) $pa_ht=0; |
|
1673 | + if (empty($pa_ht)) $pa_ht=0; |
|
1674 | 1674 | |
1675 | 1675 | // if buy price not defined, define buyprice as configured in margin admin |
1676 | 1676 | if ($this->pa_ht == 0) |
@@ -1736,14 +1736,14 @@ discard block |
||
1736 | 1736 | } |
1737 | 1737 | |
1738 | 1738 | if (empty($error)) { |
1739 | - // Call trigger |
|
1740 | - $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
1741 | - if ($result < 0) |
|
1742 | - { |
|
1743 | - $this->db->rollback(); |
|
1744 | - return -3; |
|
1745 | - } |
|
1746 | - // End call triggers |
|
1739 | + // Call trigger |
|
1740 | + $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
1741 | + if ($result < 0) |
|
1742 | + { |
|
1743 | + $this->db->rollback(); |
|
1744 | + return -3; |
|
1745 | + } |
|
1746 | + // End call triggers |
|
1747 | 1747 | |
1748 | 1748 | $this->db->commit(); |
1749 | 1749 | return 1; |
@@ -1781,12 +1781,12 @@ discard block |
||
1781 | 1781 | if ($this->statut >= 0) |
1782 | 1782 | { |
1783 | 1783 | |
1784 | - // Call trigger |
|
1785 | - $result=$this->call_trigger('LINECONTRACT_DELETE',$user); |
|
1786 | - if ($result < 0) return -1; |
|
1787 | - // End call triggers |
|
1784 | + // Call trigger |
|
1785 | + $result=$this->call_trigger('LINECONTRACT_DELETE',$user); |
|
1786 | + if ($result < 0) return -1; |
|
1787 | + // End call triggers |
|
1788 | 1788 | |
1789 | - $this->db->begin(); |
|
1789 | + $this->db->begin(); |
|
1790 | 1790 | |
1791 | 1791 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet"; |
1792 | 1792 | $sql.= " WHERE rowid=".$idline; |
@@ -1940,8 +1940,8 @@ discard block |
||
1940 | 1940 | * |
1941 | 1941 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
1942 | 1942 | * @param int $maxlength Max length of ref |
1943 | - * @param int $notooltip 1=Disable tooltip |
|
1944 | - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
|
1943 | + * @param int $notooltip 1=Disable tooltip |
|
1944 | + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
|
1945 | 1945 | * @return string Chaine avec URL |
1946 | 1946 | */ |
1947 | 1947 | function getNomUrl($withpicto=0, $maxlength=0, $notooltip=0, $save_lastsearch_value=-1) |
@@ -1961,35 +1961,35 @@ discard block |
||
1961 | 1961 | //} |
1962 | 1962 | |
1963 | 1963 | $picto = 'contract'; |
1964 | - $label = ''; |
|
1965 | - |
|
1966 | - if ($user->rights->contrat->lire) { |
|
1967 | - $label = '<u>'.$langs->trans("ShowContract").'</u>'; |
|
1968 | - $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref; |
|
1969 | - $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client); |
|
1970 | - $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_supplier; |
|
1971 | - if (!empty($this->total_ht)) { |
|
1972 | - $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); |
|
1973 | - } |
|
1974 | - if (!empty($this->total_tva)) { |
|
1975 | - $label .= '<br><b>'.$langs->trans('VAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); |
|
1976 | - } |
|
1977 | - if (!empty($this->total_ttc)) { |
|
1978 | - $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); |
|
1979 | - } |
|
1980 | - } |
|
1981 | - |
|
1982 | - $linkclose=''; |
|
1983 | - if (empty($notooltip) && $user->rights->contrat->lire) |
|
1984 | - { |
|
1985 | - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
1986 | - { |
|
1987 | - $label=$langs->trans("ShowOrder"); |
|
1988 | - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
1989 | - } |
|
1990 | - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
1991 | - $linkclose.=' class="classfortooltip"'; |
|
1992 | - } |
|
1964 | + $label = ''; |
|
1965 | + |
|
1966 | + if ($user->rights->contrat->lire) { |
|
1967 | + $label = '<u>'.$langs->trans("ShowContract").'</u>'; |
|
1968 | + $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref; |
|
1969 | + $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client); |
|
1970 | + $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_supplier; |
|
1971 | + if (!empty($this->total_ht)) { |
|
1972 | + $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); |
|
1973 | + } |
|
1974 | + if (!empty($this->total_tva)) { |
|
1975 | + $label .= '<br><b>'.$langs->trans('VAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); |
|
1976 | + } |
|
1977 | + if (!empty($this->total_ttc)) { |
|
1978 | + $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); |
|
1979 | + } |
|
1980 | + } |
|
1981 | + |
|
1982 | + $linkclose=''; |
|
1983 | + if (empty($notooltip) && $user->rights->contrat->lire) |
|
1984 | + { |
|
1985 | + if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
1986 | + { |
|
1987 | + $label=$langs->trans("ShowOrder"); |
|
1988 | + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
1989 | + } |
|
1990 | + $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
1991 | + $linkclose.=' class="classfortooltip"'; |
|
1992 | + } |
|
1993 | 1993 | |
1994 | 1994 | $linkstart = '<a href="'.$url.'"'; |
1995 | 1995 | $linkstart.=$linkclose.'>'; |
@@ -2126,11 +2126,11 @@ discard block |
||
2126 | 2126 | |
2127 | 2127 | |
2128 | 2128 | /** |
2129 | - * Load indicators for dashboard (this->nbtodo and this->nbtodolate) |
|
2130 | - * |
|
2131 | - * @param User $user Objet user |
|
2132 | - * @param string $mode "inactive" pour services a activer, "expired" pour services expires |
|
2133 | - * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK |
|
2129 | + * Load indicators for dashboard (this->nbtodo and this->nbtodolate) |
|
2130 | + * |
|
2131 | + * @param User $user Objet user |
|
2132 | + * @param string $mode "inactive" pour services a activer, "expired" pour services expires |
|
2133 | + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK |
|
2134 | 2134 | */ |
2135 | 2135 | function load_board($user,$mode) |
2136 | 2136 | { |
@@ -2233,7 +2233,7 @@ discard block |
||
2233 | 2233 | { |
2234 | 2234 | $this->nb["Contracts"]=$obj->nb; |
2235 | 2235 | } |
2236 | - $this->db->free($resql); |
|
2236 | + $this->db->free($resql); |
|
2237 | 2237 | return 1; |
2238 | 2238 | } |
2239 | 2239 | else |
@@ -2269,17 +2269,17 @@ discard block |
||
2269 | 2269 | |
2270 | 2270 | |
2271 | 2271 | /** |
2272 | - * Initialise an instance with random values. |
|
2273 | - * Used to build previews or test instances. |
|
2274 | - * id must be 0 if object instance is a specimen. |
|
2275 | - * |
|
2276 | - * @return void |
|
2272 | + * Initialise an instance with random values. |
|
2273 | + * Used to build previews or test instances. |
|
2274 | + * id must be 0 if object instance is a specimen. |
|
2275 | + * |
|
2276 | + * @return void |
|
2277 | 2277 | */ |
2278 | 2278 | function initAsSpecimen() |
2279 | 2279 | { |
2280 | 2280 | global $user,$langs,$conf; |
2281 | 2281 | |
2282 | - // Load array of products prodids |
|
2282 | + // Load array of products prodids |
|
2283 | 2283 | $num_prods = 0; |
2284 | 2284 | $prodids = array(); |
2285 | 2285 | $sql = "SELECT rowid"; |
@@ -2334,10 +2334,10 @@ discard block |
||
2334 | 2334 | $line->date_fin_validite = dol_now() + 500000; |
2335 | 2335 | $line->date_cloture = dol_now() - 100000; |
2336 | 2336 | if ($num_prods > 0) |
2337 | - { |
|
2337 | + { |
|
2338 | 2338 | $prodid = mt_rand(1, $num_prods); |
2339 | 2339 | $line->fk_product=$prodids[$prodid]; |
2340 | - } |
|
2340 | + } |
|
2341 | 2341 | $this->lines[$xnbp]=$line; |
2342 | 2342 | $xnbp++; |
2343 | 2343 | } |
@@ -2411,7 +2411,7 @@ discard block |
||
2411 | 2411 | $this->fetch($this->id); |
2412 | 2412 | // Load dest object |
2413 | 2413 | $clonedObj = clone $this; |
2414 | - $clonedObj->socid = $socid; |
|
2414 | + $clonedObj->socid = $socid; |
|
2415 | 2415 | |
2416 | 2416 | $this->db->begin(); |
2417 | 2417 | |
@@ -2446,13 +2446,13 @@ discard block |
||
2446 | 2446 | $this->error = $clonedObj->error; |
2447 | 2447 | $this->errors[] = $clonedObj->error; |
2448 | 2448 | } else { |
2449 | - // copy external contacts if same company |
|
2450 | - if ($this->socid == $clonedObj->socid) { |
|
2451 | - if ($clonedObj->copy_linked_contact($this, 'external') < 0) { |
|
2452 | - $error++; |
|
2453 | - } |
|
2454 | - } |
|
2455 | - } |
|
2449 | + // copy external contacts if same company |
|
2450 | + if ($this->socid == $clonedObj->socid) { |
|
2451 | + if ($clonedObj->copy_linked_contact($this, 'external') < 0) { |
|
2452 | + $error++; |
|
2453 | + } |
|
2454 | + } |
|
2455 | + } |
|
2456 | 2456 | |
2457 | 2457 | if (! $error) { |
2458 | 2458 | foreach ( $this->lines as $line ) { |
@@ -2510,8 +2510,8 @@ discard block |
||
2510 | 2510 | */ |
2511 | 2511 | class ContratLigne extends CommonObjectLine |
2512 | 2512 | { |
2513 | - public $element='contratdet'; |
|
2514 | - public $table_element='contratdet'; |
|
2513 | + public $element='contratdet'; |
|
2514 | + public $table_element='contratdet'; |
|
2515 | 2515 | |
2516 | 2516 | var $id; |
2517 | 2517 | var $ref; |
@@ -2577,9 +2577,9 @@ discard block |
||
2577 | 2577 | |
2578 | 2578 | |
2579 | 2579 | /** |
2580 | - * Constructor |
|
2581 | - * |
|
2582 | - * @param DoliDb $db Database handler |
|
2580 | + * Constructor |
|
2581 | + * |
|
2582 | + * @param DoliDb $db Database handler |
|
2583 | 2583 | */ |
2584 | 2584 | function __construct($db) |
2585 | 2585 | { |
@@ -2667,22 +2667,22 @@ discard block |
||
2667 | 2667 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
2668 | 2668 | * @param int $maxlength Max length |
2669 | 2669 | * @return string Chaine avec URL |
2670 | - */ |
|
2670 | + */ |
|
2671 | 2671 | function getNomUrl($withpicto=0,$maxlength=0) |
2672 | 2672 | { |
2673 | 2673 | global $langs; |
2674 | 2674 | |
2675 | 2675 | $result=''; |
2676 | - $label=$langs->trans("ShowContractOfService").': '.$this->label; |
|
2677 | - if (empty($label)) $label=$this->description; |
|
2676 | + $label=$langs->trans("ShowContractOfService").': '.$this->label; |
|
2677 | + if (empty($label)) $label=$this->description; |
|
2678 | 2678 | |
2679 | - $link = '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$this->fk_contrat.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
2679 | + $link = '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$this->fk_contrat.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
2680 | 2680 | $linkend='</a>'; |
2681 | 2681 | |
2682 | 2682 | $picto='service'; |
2683 | 2683 | if ($this->type == 0) $picto='product'; |
2684 | 2684 | |
2685 | - if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
2685 | + if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
2686 | 2686 | if ($withpicto && $withpicto != 2) $result.=' '; |
2687 | 2687 | if ($withpicto != 2) $result.=$link.($this->product_ref?$this->product_ref.' ':'').($this->label?$this->label:$this->description).$linkend; |
2688 | 2688 | return $result; |
@@ -2878,7 +2878,7 @@ discard block |
||
2878 | 2878 | $this->total_localtax1= $tabprice[9]; |
2879 | 2879 | $this->total_localtax2= $tabprice[10]; |
2880 | 2880 | |
2881 | - if (empty($this->pa_ht)) $this->pa_ht=0; |
|
2881 | + if (empty($this->pa_ht)) $this->pa_ht=0; |
|
2882 | 2882 | |
2883 | 2883 | // if buy price not defined, define buyprice as configured in margin admin |
2884 | 2884 | if ($this->pa_ht == 0) |
@@ -2961,15 +2961,15 @@ discard block |
||
2961 | 2961 | if (empty($error)) { |
2962 | 2962 | if (! $notrigger) |
2963 | 2963 | { |
2964 | - // Call trigger |
|
2965 | - $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
2966 | - if ($result < 0) { $error++; $this->db->rollback(); return -1; } |
|
2967 | - // End call triggers |
|
2964 | + // Call trigger |
|
2965 | + $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
2966 | + if ($result < 0) { $error++; $this->db->rollback(); return -1; } |
|
2967 | + // End call triggers |
|
2968 | 2968 | } |
2969 | 2969 | } |
2970 | 2970 | |
2971 | 2971 | if (empty($error)) { |
2972 | - $this->db->commit(); |
|
2972 | + $this->db->commit(); |
|
2973 | 2973 | return 1; |
2974 | 2974 | } else { |
2975 | 2975 | $this->db->rollback(); |
@@ -50,7 +50,7 @@ |
||
50 | 50 | * @param string $htmlname Nom de la zone html |
51 | 51 | * @param int $maxlength Maximum length of label |
52 | 52 | * @param int $showempty Show empty line |
53 | - * @return int Nbre of project if OK, <0 if KO |
|
53 | + * @return string Nbre of project if OK, <0 if KO |
|
54 | 54 | */ |
55 | 55 | function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1) |
56 | 56 | { |
@@ -27,19 +27,19 @@ |
||
27 | 27 | */ |
28 | 28 | class FormIntervention |
29 | 29 | { |
30 | - var $db; |
|
31 | - var $error; |
|
30 | + var $db; |
|
31 | + var $error; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Constructor |
|
36 | - * |
|
37 | - * @param DoliDB $db Database handler |
|
38 | - */ |
|
39 | - public function __construct($db) |
|
40 | - { |
|
41 | - $this->db = $db; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Constructor |
|
36 | + * |
|
37 | + * @param DoliDB $db Database handler |
|
38 | + */ |
|
39 | + public function __construct($db) |
|
40 | + { |
|
41 | + $this->db = $db; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | 45 | /** |
@@ -51,7 +51,7 @@ |
||
51 | 51 | * |
52 | 52 | * @param CommonObject $object Object we want to get margin information for |
53 | 53 | * @param boolean $force_price True of not |
54 | - * @return array Array with info |
|
54 | + * @return integer Array with info |
|
55 | 55 | */ |
56 | 56 | function getMarginInfosArray($object, $force_price=false) |
57 | 57 | { |
@@ -28,21 +28,21 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class FormMargin |
30 | 30 | { |
31 | - var $db; |
|
32 | - var $error; |
|
31 | + var $db; |
|
32 | + var $error; |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Constructor |
|
37 | - * |
|
38 | - * @param DoliDB $db Database handler |
|
39 | - */ |
|
40 | - function __construct($db) |
|
41 | - { |
|
42 | - $this->db = $db; |
|
35 | + /** |
|
36 | + * Constructor |
|
37 | + * |
|
38 | + * @param DoliDB $db Database handler |
|
39 | + */ |
|
40 | + function __construct($db) |
|
41 | + { |
|
42 | + $this->db = $db; |
|
43 | 43 | |
44 | - return 1; |
|
45 | - } |
|
44 | + return 1; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | 48 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | //} |
143 | 143 | //else |
144 | 144 | //{ |
145 | - $marginInfos['margin_on_products'] += $pv - $pa; |
|
145 | + $marginInfos['margin_on_products'] += $pv - $pa; |
|
146 | 146 | //} |
147 | 147 | } |
148 | 148 | elseif ($type == 1) { // service |
@@ -192,26 +192,26 @@ discard block |
||
192 | 192 | { |
193 | 193 | global $langs, $conf, $user; |
194 | 194 | |
195 | - if (! empty($user->societe_id)) return; |
|
195 | + if (! empty($user->societe_id)) return; |
|
196 | 196 | |
197 | - if (! $user->rights->margins->liretous) return; |
|
197 | + if (! $user->rights->margins->liretous) return; |
|
198 | 198 | |
199 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
|
199 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
|
200 | 200 | |
201 | 201 | $marginInfo = $this->getMarginInfosArray($object, $force_price); |
202 | 202 | |
203 | 203 | if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better |
204 | 204 | { |
205 | 205 | print $langs->trans('ShowMarginInfos').' : '; |
206 | - $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']; |
|
207 | - print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'':'hideobject').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>'; |
|
208 | - print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'hideobject':'').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>'; |
|
206 | + $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']; |
|
207 | + print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'':'hideobject').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>'; |
|
208 | + print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'hideobject':'').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>'; |
|
209 | 209 | |
210 | - print '<script>$(document).ready(function() { |
|
210 | + print '<script>$(document).ready(function() { |
|
211 | 211 | $("span#showMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 0); $(".margininfos").show(); $("span#showMarginInfos").addClass("hideobject"); $("span#hideMarginInfos").removeClass("hideobject");})}); |
212 | 212 | $("span#hideMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 1); $(".margininfos").hide(); $("span#hideMarginInfos").addClass("hideobject"); $("span#showMarginInfos").removeClass("hideobject");})}); |
213 | 213 | });</script>'; |
214 | - if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>'; |
|
214 | + if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>'; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | print '<!-- Margin table -->'."\n"; |
@@ -95,7 +95,7 @@ |
||
95 | 95 | /** |
96 | 96 | * Return last error code |
97 | 97 | * |
98 | - * @return string lasterrno |
|
98 | + * @return integer lasterrno |
|
99 | 99 | */ |
100 | 100 | function lasterrno() |
101 | 101 | { |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
320 | 320 | * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
321 | 321 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
322 | - * @return false|resource|true Resultset of answer |
|
322 | + * @return resource Resultset of answer |
|
323 | 323 | */ |
324 | 324 | function query($query,$usesavepoint=0,$type='auto') |
325 | 325 | { |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | * Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE |
517 | 517 | * |
518 | 518 | * @param resource $resultset Curseur de la requete voulue |
519 | - * @return int Nombre de lignes |
|
519 | + * @return string Nombre de lignes |
|
520 | 520 | * @see num_rows |
521 | 521 | */ |
522 | 522 | function affected_rows($resultset) |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * Free last resultset used. |
536 | 536 | * |
537 | 537 | * @param resource $resultset Curseur de la requete voulue |
538 | - * @return bool |
|
538 | + * @return boolean|null |
|
539 | 539 | */ |
540 | 540 | function free($resultset=null) |
541 | 541 | { |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | /** |
1016 | 1016 | * Return list of available charset that can be used to store data in database |
1017 | 1017 | * |
1018 | - * @return array List of Charset |
|
1018 | + * @return string List of Charset |
|
1019 | 1019 | */ |
1020 | 1020 | function getListOfCharacterSet() |
1021 | 1021 | { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | /** @var resource Resultset of last query */ |
45 | 45 | private $_results; |
46 | 46 | |
47 | - /** |
|
47 | + /** |
|
48 | 48 | * Constructor. |
49 | 49 | * This create an opened connexion to a database server and eventually to a database |
50 | 50 | * |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | * @param string $pass Mot de passe |
55 | 55 | * @param string $name Nom de la database |
56 | 56 | * @param int $port Port of database server |
57 | - */ |
|
57 | + */ |
|
58 | 58 | function __construct($type, $host, $user, $pass, $name='', $port=0) |
59 | 59 | { |
60 | 60 | global $langs; |
61 | 61 | |
62 | 62 | $this->database_user=$user; |
63 | - $this->database_host=$host; |
|
64 | - $this->database_port=$port; |
|
63 | + $this->database_host=$host; |
|
64 | + $this->database_port=$port; |
|
65 | 65 | $this->transaction_opened=0; |
66 | 66 | |
67 | 67 | if (! function_exists("mssql_connect")) |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | return $this->ok; |
128 | 128 | } |
129 | 129 | |
130 | - /** |
|
131 | - * Convert a SQL request in Mysql syntax to native syntax |
|
132 | - * |
|
133 | - * @param string $line SQL request line to convert |
|
134 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
135 | - * @return string SQL request line converted |
|
136 | - */ |
|
130 | + /** |
|
131 | + * Convert a SQL request in Mysql syntax to native syntax |
|
132 | + * |
|
133 | + * @param string $line SQL request line to convert |
|
134 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
135 | + * @return string SQL request line converted |
|
136 | + */ |
|
137 | 137 | static function convertSQLFromMysql($line,$type='ddl') |
138 | 138 | { |
139 | 139 | return $line; |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | //$this->query('SET NAMES '.$this->forcecharset); |
174 | 174 | //print "Resultat fonction connect: ".$this->db; |
175 | 175 | $set_options=array('SET ANSI_PADDING ON;', |
176 | - "SET ANSI_NULLS ON;", |
|
177 | - "SET ANSI_WARNINGS ON;", |
|
178 | - "SET ARITHABORT ON;", |
|
179 | - "SET CONCAT_NULL_YIELDS_NULL ON;", |
|
180 | - "SET QUOTED_IDENTIFIER ON;" |
|
176 | + "SET ANSI_NULLS ON;", |
|
177 | + "SET ANSI_WARNINGS ON;", |
|
178 | + "SET ARITHABORT ON;", |
|
179 | + "SET CONCAT_NULL_YIELDS_NULL ON;", |
|
180 | + "SET QUOTED_IDENTIFIER ON;" |
|
181 | 181 | ); |
182 | 182 | mssql_query(implode(' ',$set_options),$this->db); |
183 | 183 | |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | $resql=$this->query("SELECT @@VERSION"); |
195 | 195 | if ($resql) |
196 | 196 | { |
197 | - $version=$this->fetch_array($resql); |
|
198 | - return $version['computed']; |
|
197 | + $version=$this->fetch_array($resql); |
|
198 | + return $version['computed']; |
|
199 | 199 | } |
200 | 200 | else return ''; |
201 | 201 | } |
@@ -210,22 +210,22 @@ discard block |
||
210 | 210 | return 'php mssql driver'; |
211 | 211 | } |
212 | 212 | |
213 | - /** |
|
214 | - * Close database connexion |
|
215 | - * |
|
216 | - * @return bool True if disconnect successfull, false otherwise |
|
217 | - * @see connect |
|
218 | - */ |
|
219 | - function close() |
|
220 | - { |
|
221 | - if ($this->db) |
|
222 | - { |
|
223 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
224 | - $this->connected=false; |
|
225 | - return mssql_close($this->db); |
|
226 | - } |
|
227 | - return false; |
|
228 | - } |
|
213 | + /** |
|
214 | + * Close database connexion |
|
215 | + * |
|
216 | + * @return bool True if disconnect successfull, false otherwise |
|
217 | + * @see connect |
|
218 | + */ |
|
219 | + function close() |
|
220 | + { |
|
221 | + if ($this->db) |
|
222 | + { |
|
223 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
224 | + $this->connected=false; |
|
225 | + return mssql_close($this->db); |
|
226 | + } |
|
227 | + return false; |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | 231 | /** |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | function begin() |
237 | 237 | { |
238 | 238 | |
239 | - $res=mssql_query('select @@TRANCOUNT'); |
|
240 | - $this->transaction_opened=mssql_result($res, 0, 0); |
|
239 | + $res=mssql_query('select @@TRANCOUNT'); |
|
240 | + $this->transaction_opened=mssql_result($res, 0, 0); |
|
241 | 241 | |
242 | - if ($this->transaction_opened == 0) |
|
242 | + if ($this->transaction_opened == 0) |
|
243 | 243 | { |
244 | - //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTIONS ON' generate also a mess |
|
244 | + //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTIONS ON' generate also a mess |
|
245 | 245 | $ret=mssql_query("SET IMPLICIT_TRANSACTIONS OFF;BEGIN TRANSACTION;",$this->db); |
246 | 246 | if ($ret) |
247 | 247 | { |
@@ -256,19 +256,19 @@ discard block |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | - * Validate a database transaction |
|
260 | - * |
|
261 | - * @param string $log Add more log to default log line |
|
262 | - * @return bool true if validation is OK or transaction level no started, false if ERROR |
|
259 | + * Validate a database transaction |
|
260 | + * |
|
261 | + * @param string $log Add more log to default log line |
|
262 | + * @return bool true if validation is OK or transaction level no started, false if ERROR |
|
263 | 263 | */ |
264 | 264 | function commit($log='') |
265 | 265 | { |
266 | - $res=mssql_query('select @@TRANCOUNT'); |
|
267 | - $this->transaction_opened=mssql_result($res, 0, 0); |
|
266 | + $res=mssql_query('select @@TRANCOUNT'); |
|
267 | + $this->transaction_opened=mssql_result($res, 0, 0); |
|
268 | 268 | |
269 | 269 | if ($this->transaction_opened == 1) |
270 | 270 | { |
271 | - //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTION ON' generate also a mess |
|
271 | + //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTION ON' generate also a mess |
|
272 | 272 | $ret=mssql_query("COMMIT TRANSACTION",$this->db); |
273 | 273 | if ($ret) |
274 | 274 | { |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | */ |
297 | 297 | function rollback($log='') |
298 | 298 | { |
299 | - $res=mssql_query('select @@TRANCOUNT'); |
|
300 | - $this->transaction_opened=mssql_result($res, 0, 0); |
|
299 | + $res=mssql_query('select @@TRANCOUNT'); |
|
300 | + $this->transaction_opened=mssql_result($res, 0, 0); |
|
301 | 301 | |
302 | 302 | if ($this->transaction_opened == 1) |
303 | 303 | { |
@@ -314,13 +314,13 @@ discard block |
||
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
317 | - * Execute a SQL request and return the resultset |
|
318 | - * |
|
319 | - * @param string $query SQL query string |
|
320 | - * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
|
321 | - * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
|
322 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
323 | - * @return false|resource|true Resultset of answer |
|
317 | + * Execute a SQL request and return the resultset |
|
318 | + * |
|
319 | + * @param string $query SQL query string |
|
320 | + * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
|
321 | + * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
|
322 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
323 | + * @return false|resource|true Resultset of answer |
|
324 | 324 | */ |
325 | 325 | function query($query,$usesavepoint=0,$type='auto') |
326 | 326 | { |
@@ -337,85 +337,85 @@ discard block |
||
337 | 337 | |
338 | 338 | if ($type=="auto" || $type='dml') |
339 | 339 | { |
340 | - $query=preg_replace('/AUTO_INCREMENT/i','IDENTITY',$query); |
|
341 | - $query=preg_replace('/double/i','float',$query); |
|
342 | - $query=preg_replace('/float\((.*)\)/','numeric($1)',$query); |
|
343 | - $query=preg_replace('/([ \t])unsigned|IF NOT EXISTS[ \t]/i','$1',$query); |
|
344 | - $query=preg_replace('/([ \t])(MEDIUM|TINY|LONG){0,1}TEXT([ \t,])/i',"$1VARCHAR(MAX)$3",$query); |
|
345 | - |
|
346 | - $matches=array(); |
|
347 | - $original_query=''; |
|
348 | - if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+(?:(UNIQUE)|INDEX)\h+(?:INDEX)?\h*(\w+?)\h*\((.+)\)/is', $query,$matches)) |
|
349 | - { |
|
350 | - $original_query=$query; |
|
351 | - $query="CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")"; |
|
352 | - if ($matches[2]) { |
|
353 | - //check if columun is nullable cause Sql server only allow 1 null value if unique index. |
|
354 | - $fields=explode(",",trim($matches[4])); |
|
355 | - $fields_clear=array_map('trim',$fields); |
|
356 | - $infos=$this->GetFieldInformation(trim($matches[1]), $fields_clear); |
|
357 | - $query_comp=array(); |
|
358 | - foreach($infos as $fld) { |
|
359 | - if ($fld->IS_NULLABLE == 'YES') { |
|
360 | - $query_comp[]=$fld->COLUMN_NAME." IS NOT NULL"; |
|
361 | - } |
|
362 | - } |
|
363 | - if (! empty($query_comp)) |
|
364 | - $query.=" WHERE ".implode(" AND ",$query_comp); |
|
365 | - } |
|
366 | - } |
|
367 | - else |
|
368 | - { |
|
369 | - if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+PRIMARY\h+KEY\h+(\w+?)\h*\((.+)\)/is', $query, $matches)) |
|
370 | - { |
|
371 | - $original_query=$query; |
|
372 | - $query="ALTER TABLE [".$matches[1]."] ADD CONSTRAINT [".$matches[2]."] PRIMARY KEY CLUSTERED (".$matches[3].")"; |
|
373 | - } |
|
374 | - } |
|
340 | + $query=preg_replace('/AUTO_INCREMENT/i','IDENTITY',$query); |
|
341 | + $query=preg_replace('/double/i','float',$query); |
|
342 | + $query=preg_replace('/float\((.*)\)/','numeric($1)',$query); |
|
343 | + $query=preg_replace('/([ \t])unsigned|IF NOT EXISTS[ \t]/i','$1',$query); |
|
344 | + $query=preg_replace('/([ \t])(MEDIUM|TINY|LONG){0,1}TEXT([ \t,])/i',"$1VARCHAR(MAX)$3",$query); |
|
345 | + |
|
346 | + $matches=array(); |
|
347 | + $original_query=''; |
|
348 | + if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+(?:(UNIQUE)|INDEX)\h+(?:INDEX)?\h*(\w+?)\h*\((.+)\)/is', $query,$matches)) |
|
349 | + { |
|
350 | + $original_query=$query; |
|
351 | + $query="CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")"; |
|
352 | + if ($matches[2]) { |
|
353 | + //check if columun is nullable cause Sql server only allow 1 null value if unique index. |
|
354 | + $fields=explode(",",trim($matches[4])); |
|
355 | + $fields_clear=array_map('trim',$fields); |
|
356 | + $infos=$this->GetFieldInformation(trim($matches[1]), $fields_clear); |
|
357 | + $query_comp=array(); |
|
358 | + foreach($infos as $fld) { |
|
359 | + if ($fld->IS_NULLABLE == 'YES') { |
|
360 | + $query_comp[]=$fld->COLUMN_NAME." IS NOT NULL"; |
|
361 | + } |
|
362 | + } |
|
363 | + if (! empty($query_comp)) |
|
364 | + $query.=" WHERE ".implode(" AND ",$query_comp); |
|
365 | + } |
|
366 | + } |
|
367 | + else |
|
368 | + { |
|
369 | + if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+PRIMARY\h+KEY\h+(\w+?)\h*\((.+)\)/is', $query, $matches)) |
|
370 | + { |
|
371 | + $original_query=$query; |
|
372 | + $query="ALTER TABLE [".$matches[1]."] ADD CONSTRAINT [".$matches[2]."] PRIMARY KEY CLUSTERED (".$matches[3].")"; |
|
373 | + } |
|
374 | + } |
|
375 | 375 | |
376 | 376 | } |
377 | 377 | |
378 | 378 | if ($type=="auto" || $type='ddl') |
379 | 379 | { |
380 | - $itemfound = stripos($query, " limit "); |
|
381 | - if ($itemfound !== false) { |
|
382 | - // Extraire le nombre limite |
|
383 | - $number = stristr($query, " limit "); |
|
384 | - $number = substr($number, 7); |
|
385 | - // Inserer l'instruction TOP et le nombre limite |
|
386 | - $query = str_ireplace("select ", "select top ".$number." ", $query); |
|
387 | - // Supprimer l'instruction MySql |
|
388 | - $query = str_ireplace(" limit ".$number, "", $query); |
|
389 | - } |
|
390 | - |
|
391 | - $itemfound = stripos($query, " week("); |
|
392 | - if ($itemfound !== false) { |
|
393 | - // Recreer une requete sans instruction Mysql |
|
394 | - $positionMySql = stripos($query, " week("); |
|
395 | - $newquery = substr($query, 0, $positionMySql); |
|
396 | - |
|
397 | - // Recuperer la date passee en parametre |
|
398 | - $extractvalue = stristr($query, " week("); |
|
399 | - $extractvalue = substr($extractvalue, 6); |
|
400 | - $positionMySql = stripos($extractvalue, ")"); |
|
401 | - // Conserver la fin de la requete |
|
402 | - $endofquery = substr($extractvalue, $positionMySql); |
|
403 | - $extractvalue = substr($extractvalue, 0, $positionMySql); |
|
404 | - |
|
405 | - // Remplacer l'instruction MySql en Sql Server |
|
406 | - // Inserer la date en parametre et le reste de la requete |
|
407 | - $query = $newquery." DATEPART(week, ".$extractvalue.$endofquery; |
|
408 | - } |
|
409 | - if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i',$query,$matches)) |
|
410 | - { |
|
411 | - //var_dump($query); |
|
412 | - //var_dump($matches); |
|
413 | - //if (stripos($query,'llx_c_departements') !== false) var_dump($query); |
|
414 | - $sql='SET IDENTITY_INSERT ['.trim($matches[1]).'] ON;'; |
|
415 | - @mssql_query($sql, $this->db); |
|
416 | - $post_query='SET IDENTITY_INSERT ['.trim($matches[1]).'] OFF;'; |
|
417 | - |
|
418 | - } |
|
380 | + $itemfound = stripos($query, " limit "); |
|
381 | + if ($itemfound !== false) { |
|
382 | + // Extraire le nombre limite |
|
383 | + $number = stristr($query, " limit "); |
|
384 | + $number = substr($number, 7); |
|
385 | + // Inserer l'instruction TOP et le nombre limite |
|
386 | + $query = str_ireplace("select ", "select top ".$number." ", $query); |
|
387 | + // Supprimer l'instruction MySql |
|
388 | + $query = str_ireplace(" limit ".$number, "", $query); |
|
389 | + } |
|
390 | + |
|
391 | + $itemfound = stripos($query, " week("); |
|
392 | + if ($itemfound !== false) { |
|
393 | + // Recreer une requete sans instruction Mysql |
|
394 | + $positionMySql = stripos($query, " week("); |
|
395 | + $newquery = substr($query, 0, $positionMySql); |
|
396 | + |
|
397 | + // Recuperer la date passee en parametre |
|
398 | + $extractvalue = stristr($query, " week("); |
|
399 | + $extractvalue = substr($extractvalue, 6); |
|
400 | + $positionMySql = stripos($extractvalue, ")"); |
|
401 | + // Conserver la fin de la requete |
|
402 | + $endofquery = substr($extractvalue, $positionMySql); |
|
403 | + $extractvalue = substr($extractvalue, 0, $positionMySql); |
|
404 | + |
|
405 | + // Remplacer l'instruction MySql en Sql Server |
|
406 | + // Inserer la date en parametre et le reste de la requete |
|
407 | + $query = $newquery." DATEPART(week, ".$extractvalue.$endofquery; |
|
408 | + } |
|
409 | + if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i',$query,$matches)) |
|
410 | + { |
|
411 | + //var_dump($query); |
|
412 | + //var_dump($matches); |
|
413 | + //if (stripos($query,'llx_c_departements') !== false) var_dump($query); |
|
414 | + $sql='SET IDENTITY_INSERT ['.trim($matches[1]).'] ON;'; |
|
415 | + @mssql_query($sql, $this->db); |
|
416 | + $post_query='SET IDENTITY_INSERT ['.trim($matches[1]).'] OFF;'; |
|
417 | + |
|
418 | + } |
|
419 | 419 | } |
420 | 420 | //print "<!--".$query."-->"; |
421 | 421 | |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | |
434 | 434 | if (!empty($post_query)) |
435 | 435 | { |
436 | - @mssql_query($post_query, $this->db); |
|
436 | + @mssql_query($post_query, $this->db); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | $result = mssql_query("SELECT @@ERROR as code", $this->db); |
445 | 445 | $row = mssql_fetch_array($result); |
446 | 446 | |
447 | - $this->lastqueryerror = $query; |
|
447 | + $this->lastqueryerror = $query; |
|
448 | 448 | $this->lasterror = $this->error(); |
449 | 449 | $this->lasterrno = $row["code"]; |
450 | 450 | |
@@ -473,10 +473,10 @@ discard block |
||
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
476 | - * Return datas as an array |
|
477 | - * |
|
478 | - * @param resource $resultset Resultset of request |
|
479 | - * @return array|false Array or false if KO or end of cursor |
|
476 | + * Return datas as an array |
|
477 | + * |
|
478 | + * @param resource $resultset Resultset of request |
|
479 | + * @return array|false Array or false if KO or end of cursor |
|
480 | 480 | */ |
481 | 481 | function fetch_array($resultset) |
482 | 482 | { |
@@ -487,10 +487,10 @@ discard block |
||
487 | 487 | |
488 | 488 | |
489 | 489 | /** |
490 | - * Return datas as an array |
|
491 | - * |
|
492 | - * @param resource $resultset Resultset of request |
|
493 | - * @return array|false Array or false if KO or end of cursor |
|
490 | + * Return datas as an array |
|
491 | + * |
|
492 | + * @param resource $resultset Resultset of request |
|
493 | + * @return array|false Array or false if KO or end of cursor |
|
494 | 494 | */ |
495 | 495 | function fetch_row($resultset) |
496 | 496 | { |
@@ -500,11 +500,11 @@ discard block |
||
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
503 | - * Return number of lines for result of a SELECT |
|
504 | - * |
|
505 | - * @param resource $resultset Resulset of requests |
|
506 | - * @return int Nb of lines |
|
507 | - * @see affected_rows |
|
503 | + * Return number of lines for result of a SELECT |
|
504 | + * |
|
505 | + * @param resource $resultset Resulset of requests |
|
506 | + * @return int Nb of lines |
|
507 | + * @see affected_rows |
|
508 | 508 | */ |
509 | 509 | function num_rows($resultset) |
510 | 510 | { |
@@ -571,9 +571,9 @@ discard block |
||
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
574 | - * Return generic error code of last operation. |
|
575 | - * |
|
576 | - * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
574 | + * Return generic error code of last operation. |
|
575 | + * |
|
576 | + * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
577 | 577 | */ |
578 | 578 | function errno() |
579 | 579 | { |
@@ -660,12 +660,12 @@ discard block |
||
660 | 660 | } |
661 | 661 | |
662 | 662 | /** |
663 | - * Encrypt sensitive data in database |
|
664 | - * Warning: This function includes the escape, so it must use direct value |
|
665 | - * |
|
666 | - * @param string $fieldorvalue Field name or value to encrypt |
|
667 | - * @param int $withQuotes Return string with quotes |
|
668 | - * @return string XXX(field) or XXX('value') or field or 'value' |
|
663 | + * Encrypt sensitive data in database |
|
664 | + * Warning: This function includes the escape, so it must use direct value |
|
665 | + * |
|
666 | + * @param string $fieldorvalue Field name or value to encrypt |
|
667 | + * @param int $withQuotes Return string with quotes |
|
668 | + * @return string XXX(field) or XXX('value') or field or 'value' |
|
669 | 669 | */ |
670 | 670 | function encrypt($fieldorvalue, $withQuotes=0) |
671 | 671 | { |
@@ -682,10 +682,10 @@ discard block |
||
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
685 | - * Decrypt sensitive data in database |
|
686 | - * |
|
687 | - * @param string $value Value to decrypt |
|
688 | - * @return string Decrypted value if used |
|
685 | + * Decrypt sensitive data in database |
|
686 | + * |
|
687 | + * @param string $value Value to decrypt |
|
688 | + * @return string Decrypted value if used |
|
689 | 689 | */ |
690 | 690 | function decrypt($value) |
691 | 691 | { |
@@ -712,8 +712,8 @@ discard block |
||
712 | 712 | $resql=$this->query('SELECT CONNECTION_ID()'); |
713 | 713 | if ($resql) |
714 | 714 | { |
715 | - $row=$this->fetch_row($resql); |
|
716 | - return $row[0]; |
|
715 | + $row=$this->fetch_row($resql); |
|
716 | + return $row[0]; |
|
717 | 717 | } |
718 | 718 | else return '?'; |
719 | 719 | } |
@@ -731,12 +731,12 @@ discard block |
||
731 | 731 | */ |
732 | 732 | function DDLCreateDb($database,$charset='',$collation='',$owner='') |
733 | 733 | { |
734 | - /*if (empty($charset)) $charset=$this->forcecharset; |
|
734 | + /*if (empty($charset)) $charset=$this->forcecharset; |
|
735 | 735 | if (empty($collation)) $collation=$this->forcecollate; |
736 | 736 | */ |
737 | 737 | |
738 | 738 | $sql = 'CREATE DATABASE '.$this->EscapeFieldName($database); |
739 | - //TODO: Check if we need to force a charset |
|
739 | + //TODO: Check if we need to force a charset |
|
740 | 740 | //$sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
741 | 741 | $ret=$this->query($sql); |
742 | 742 | |
@@ -747,11 +747,11 @@ discard block |
||
747 | 747 | mssql_query($sql,$this->db); |
748 | 748 | |
749 | 749 | $sql="ALTER DATABASE [$database] SET ANSI_NULL_DEFAULT ON;"; |
750 | - @mssql_query($sql,$this->db); |
|
751 | - $sql="ALTER DATABASE [$database] SET ANSI_NULL ON;"; |
|
752 | - @mssql_query($sql,$this->db); |
|
750 | + @mssql_query($sql,$this->db); |
|
751 | + $sql="ALTER DATABASE [$database] SET ANSI_NULL ON;"; |
|
752 | + @mssql_query($sql,$this->db); |
|
753 | 753 | |
754 | - return $ret; |
|
754 | + return $ret; |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * |
760 | 760 | * @param string $database Name of database |
761 | 761 | * @param string $table Nmae of table filter ('xxx%') |
762 | - * @return array List of tables in an array |
|
762 | + * @return array List of tables in an array |
|
763 | 763 | */ |
764 | 764 | function DDLListTables($database,$table='') |
765 | 765 | { |
@@ -968,48 +968,48 @@ discard block |
||
968 | 968 | */ |
969 | 969 | function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
970 | 970 | { |
971 | - $sql = "CREATE LOGIN ".$this->EscapeFieldName($dolibarr_main_db_user)." WITH PASSWORD='$dolibarr_main_db_pass'"; |
|
972 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
973 | - $resql=$this->query($sql); |
|
974 | - if (! $resql) |
|
975 | - { |
|
976 | - if ($this->lasterrno != '15025') |
|
977 | - { |
|
978 | - return -1; |
|
979 | - } |
|
980 | - else |
|
971 | + $sql = "CREATE LOGIN ".$this->EscapeFieldName($dolibarr_main_db_user)." WITH PASSWORD='$dolibarr_main_db_pass'"; |
|
972 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
973 | + $resql=$this->query($sql); |
|
974 | + if (! $resql) |
|
975 | + { |
|
976 | + if ($this->lasterrno != '15025') |
|
981 | 977 | { |
982 | - // If user already exists, we continue to set permissions |
|
983 | - dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
984 | - } |
|
985 | - } |
|
986 | - $sql="SELECT name from sys.databases where name='".$dolibarr_main_db_name."'"; |
|
987 | - $ressql=$this->query($sql); |
|
988 | - if (! $ressql) |
|
989 | - { |
|
990 | - dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
991 | - return -1; |
|
992 | - } |
|
993 | - else |
|
994 | - { |
|
995 | - if ($num) |
|
996 | - { |
|
997 | - $this->select_db($dolibarr_main_db_name); |
|
998 | - $sql="CREATE USER [$dolibarr_main_db_user] FOR LOGIN [$dolibarr_main_db_user]"; |
|
999 | - $this->query($sql); |
|
1000 | - $sql="ALTER ROLE [db_owner] ADD MEMBER [$dolibarr_main_db_user]"; |
|
1001 | - $this->query($sql); |
|
1002 | - } |
|
1003 | - } |
|
1004 | - return 1; |
|
978 | + return -1; |
|
979 | + } |
|
980 | + else |
|
981 | + { |
|
982 | + // If user already exists, we continue to set permissions |
|
983 | + dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
984 | + } |
|
985 | + } |
|
986 | + $sql="SELECT name from sys.databases where name='".$dolibarr_main_db_name."'"; |
|
987 | + $ressql=$this->query($sql); |
|
988 | + if (! $ressql) |
|
989 | + { |
|
990 | + dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
991 | + return -1; |
|
992 | + } |
|
993 | + else |
|
994 | + { |
|
995 | + if ($num) |
|
996 | + { |
|
997 | + $this->select_db($dolibarr_main_db_name); |
|
998 | + $sql="CREATE USER [$dolibarr_main_db_user] FOR LOGIN [$dolibarr_main_db_user]"; |
|
999 | + $this->query($sql); |
|
1000 | + $sql="ALTER ROLE [db_owner] ADD MEMBER [$dolibarr_main_db_user]"; |
|
1001 | + $this->query($sql); |
|
1002 | + } |
|
1003 | + } |
|
1004 | + return 1; |
|
1005 | 1005 | } |
1006 | 1006 | |
1007 | - /** |
|
1008 | - * Return charset used to store data in database |
|
1009 | - * |
|
1010 | - * @return string Charset |
|
1011 | - */ |
|
1012 | - function getDefaultCharacterSetDatabase() |
|
1007 | + /** |
|
1008 | + * Return charset used to store data in database |
|
1009 | + * |
|
1010 | + * @return string Charset |
|
1011 | + */ |
|
1012 | + function getDefaultCharacterSetDatabase() |
|
1013 | 1013 | { |
1014 | 1014 | // FIXME: Dummy method |
1015 | 1015 | // TODO: Implement |
@@ -1069,7 +1069,7 @@ discard block |
||
1069 | 1069 | // FIXME: Dummy method |
1070 | 1070 | // TODO: Implement |
1071 | 1071 | |
1072 | - return ''; |
|
1072 | + return ''; |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | /** |
@@ -1082,7 +1082,7 @@ discard block |
||
1082 | 1082 | // FIXME: Dummy method |
1083 | 1083 | // TODO: Implement |
1084 | 1084 | |
1085 | - return ''; |
|
1085 | + return ''; |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | /** |
@@ -1123,7 +1123,7 @@ discard block |
||
1123 | 1123 | * @return string field's name escaped |
1124 | 1124 | */ |
1125 | 1125 | function EscapeFieldName($fieldname) { |
1126 | - return "[".$fieldname."]"; |
|
1126 | + return "[".$fieldname."]"; |
|
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | |
@@ -1135,28 +1135,28 @@ discard block |
||
1135 | 1135 | * @return false|object |
1136 | 1136 | */ |
1137 | 1137 | function GetFieldInformation($table,$fields) { |
1138 | - $sql="SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$this->escape($table)."' AND COLUMN_NAME"; |
|
1139 | - if (is_array($fields)) |
|
1140 | - { |
|
1141 | - $where=" IN ('".implode("','",$fields)."')"; |
|
1142 | - } |
|
1143 | - else |
|
1144 | - { |
|
1145 | - $where="='".$this->escape($fields)."'"; |
|
1146 | - } |
|
1147 | - $result=array(); |
|
1148 | - $ret=mssql_query($sql.$where,$this->db); |
|
1149 | - if ($ret) |
|
1150 | - { |
|
1151 | - while($obj=mssql_fetch_object($ret)) |
|
1152 | - { |
|
1153 | - $result[]=$obj; |
|
1154 | - } |
|
1155 | - } |
|
1156 | - else |
|
1157 | - return false; |
|
1158 | - |
|
1159 | - return $result; |
|
1138 | + $sql="SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$this->escape($table)."' AND COLUMN_NAME"; |
|
1139 | + if (is_array($fields)) |
|
1140 | + { |
|
1141 | + $where=" IN ('".implode("','",$fields)."')"; |
|
1142 | + } |
|
1143 | + else |
|
1144 | + { |
|
1145 | + $where="='".$this->escape($fields)."'"; |
|
1146 | + } |
|
1147 | + $result=array(); |
|
1148 | + $ret=mssql_query($sql.$where,$this->db); |
|
1149 | + if ($ret) |
|
1150 | + { |
|
1151 | + while($obj=mssql_fetch_object($ret)) |
|
1152 | + { |
|
1153 | + $result[]=$obj; |
|
1154 | + } |
|
1155 | + } |
|
1156 | + else |
|
1157 | + return false; |
|
1158 | + |
|
1159 | + return $result; |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | } |
@@ -233,7 +233,7 @@ |
||
233 | 233 | * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
234 | 234 | * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
235 | 235 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
236 | - * @return bool|mysqli_result Resultset of answer |
|
236 | + * @return mysqli_result|null Resultset of answer |
|
237 | 237 | */ |
238 | 238 | function query($query,$usesavepoint=0,$type='auto') |
239 | 239 | { |
@@ -34,16 +34,16 @@ discard block |
||
34 | 34 | { |
35 | 35 | /** @var mysqli Database object */ |
36 | 36 | public $db; |
37 | - //! Database type |
|
38 | - public $type='mysqli'; |
|
39 | - //! Database label |
|
40 | - const LABEL='MySQL or MariaDB'; |
|
41 | - //! Version min database |
|
42 | - const VERSIONMIN='5.0.3'; |
|
37 | + //! Database type |
|
38 | + public $type='mysqli'; |
|
39 | + //! Database label |
|
40 | + const LABEL='MySQL or MariaDB'; |
|
41 | + //! Version min database |
|
42 | + const VERSIONMIN='5.0.3'; |
|
43 | 43 | /** @var mysqli_result Resultset of last query */ |
44 | 44 | private $_results; |
45 | 45 | |
46 | - /** |
|
46 | + /** |
|
47 | 47 | * Constructor. |
48 | 48 | * This create an opened connexion to a database server and eventually to a database |
49 | 49 | * |
@@ -53,38 +53,38 @@ discard block |
||
53 | 53 | * @param string $pass Mot de passe |
54 | 54 | * @param string $name Nom de la database |
55 | 55 | * @param int $port Port of database server |
56 | - */ |
|
57 | - function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
58 | - { |
|
59 | - global $conf,$langs; |
|
60 | - |
|
61 | - // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
|
62 | - if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; |
|
63 | - if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
|
64 | - |
|
65 | - $this->database_user=$user; |
|
66 | - $this->database_host=$host; |
|
67 | - $this->database_port=$port; |
|
68 | - |
|
69 | - $this->transaction_opened=0; |
|
70 | - |
|
71 | - //print "Name DB: $host,$user,$pass,$name<br>"; |
|
72 | - |
|
73 | - if (! class_exists('mysqli')) |
|
74 | - { |
|
75 | - $this->connected = false; |
|
76 | - $this->ok = false; |
|
77 | - $this->error="Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver."; |
|
78 | - dol_syslog(get_class($this)."::DoliDBMysqli : Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.",LOG_ERR); |
|
79 | - } |
|
80 | - |
|
81 | - if (! $host) |
|
82 | - { |
|
83 | - $this->connected = false; |
|
84 | - $this->ok = false; |
|
85 | - $this->error=$langs->trans("ErrorWrongHostParameter"); |
|
86 | - dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters",LOG_ERR); |
|
87 | - } |
|
56 | + */ |
|
57 | + function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
58 | + { |
|
59 | + global $conf,$langs; |
|
60 | + |
|
61 | + // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
|
62 | + if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; |
|
63 | + if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
|
64 | + |
|
65 | + $this->database_user=$user; |
|
66 | + $this->database_host=$host; |
|
67 | + $this->database_port=$port; |
|
68 | + |
|
69 | + $this->transaction_opened=0; |
|
70 | + |
|
71 | + //print "Name DB: $host,$user,$pass,$name<br>"; |
|
72 | + |
|
73 | + if (! class_exists('mysqli')) |
|
74 | + { |
|
75 | + $this->connected = false; |
|
76 | + $this->ok = false; |
|
77 | + $this->error="Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver."; |
|
78 | + dol_syslog(get_class($this)."::DoliDBMysqli : Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.",LOG_ERR); |
|
79 | + } |
|
80 | + |
|
81 | + if (! $host) |
|
82 | + { |
|
83 | + $this->connected = false; |
|
84 | + $this->ok = false; |
|
85 | + $this->error=$langs->trans("ErrorWrongHostParameter"); |
|
86 | + dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters",LOG_ERR); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | // Try server connection |
90 | 90 | // We do not try to connect to database, only to server. Connect to database is done later in constrcutor |
@@ -101,61 +101,61 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | // If server connection is ok, we try to connect to the database |
104 | - if ($this->connected && $name) |
|
105 | - { |
|
106 | - if ($this->select_db($name)) |
|
107 | - { |
|
108 | - $this->database_selected = true; |
|
109 | - $this->database_name = $name; |
|
110 | - $this->ok = true; |
|
111 | - |
|
112 | - // If client connected with different charset than Dolibarr HTML output |
|
113 | - $clientmustbe=''; |
|
114 | - if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8'; |
|
115 | - if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1'; |
|
104 | + if ($this->connected && $name) |
|
105 | + { |
|
106 | + if ($this->select_db($name)) |
|
107 | + { |
|
108 | + $this->database_selected = true; |
|
109 | + $this->database_name = $name; |
|
110 | + $this->ok = true; |
|
111 | + |
|
112 | + // If client connected with different charset than Dolibarr HTML output |
|
113 | + $clientmustbe=''; |
|
114 | + if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8'; |
|
115 | + if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1'; |
|
116 | 116 | if ($this->db->character_set_name() != $clientmustbe) { |
117 | 117 | $this->db->set_charset($clientmustbe); |
118 | 118 | } |
119 | - } |
|
120 | - else |
|
121 | - { |
|
122 | - $this->database_selected = false; |
|
123 | - $this->database_name = ''; |
|
124 | - $this->ok = false; |
|
125 | - $this->error=$this->error(); |
|
126 | - dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR); |
|
127 | - } |
|
128 | - } |
|
129 | - else |
|
130 | - { |
|
131 | - // Pas de selection de base demandee, ok ou ko |
|
132 | - $this->database_selected = false; |
|
133 | - |
|
134 | - if ($this->connected) |
|
135 | - { |
|
136 | - // If client connected with different charset than Dolibarr HTML output |
|
137 | - $clientmustbe=''; |
|
138 | - if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8'; |
|
139 | - if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1'; |
|
119 | + } |
|
120 | + else |
|
121 | + { |
|
122 | + $this->database_selected = false; |
|
123 | + $this->database_name = ''; |
|
124 | + $this->ok = false; |
|
125 | + $this->error=$this->error(); |
|
126 | + dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR); |
|
127 | + } |
|
128 | + } |
|
129 | + else |
|
130 | + { |
|
131 | + // Pas de selection de base demandee, ok ou ko |
|
132 | + $this->database_selected = false; |
|
133 | + |
|
134 | + if ($this->connected) |
|
135 | + { |
|
136 | + // If client connected with different charset than Dolibarr HTML output |
|
137 | + $clientmustbe=''; |
|
138 | + if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8'; |
|
139 | + if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1'; |
|
140 | 140 | if ($this->db->character_set_name() != $clientmustbe) { |
141 | 141 | $this->db->set_charset($clientmustbe); |
142 | 142 | } |
143 | - } |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Convert a SQL request in Mysql syntax to native syntax |
|
150 | - * |
|
151 | - * @param string $line SQL request line to convert |
|
152 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
153 | - * @return string SQL request line converted |
|
154 | - */ |
|
155 | - static function convertSQLFromMysql($line,$type='ddl') |
|
156 | - { |
|
157 | - return $line; |
|
158 | - } |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Convert a SQL request in Mysql syntax to native syntax |
|
150 | + * |
|
151 | + * @param string $line SQL request line to convert |
|
152 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
153 | + * @return string SQL request line converted |
|
154 | + */ |
|
155 | + static function convertSQLFromMysql($line,$type='ddl') |
|
156 | + { |
|
157 | + return $line; |
|
158 | + } |
|
159 | 159 | |
160 | 160 | /** |
161 | 161 | * Select a database |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | * @param string $database Name of database |
164 | 164 | * @return boolean true if OK, false if KO |
165 | 165 | */ |
166 | - function select_db($database) |
|
167 | - { |
|
168 | - dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); |
|
169 | - return $this->db->select_db($database); |
|
170 | - } |
|
166 | + function select_db($database) |
|
167 | + { |
|
168 | + dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); |
|
169 | + return $this->db->select_db($database); |
|
170 | + } |
|
171 | 171 | |
172 | 172 | |
173 | 173 | /** |
@@ -188,360 +188,360 @@ discard block |
||
188 | 188 | return new mysqli($host, $login, $passwd, $name, $port); |
189 | 189 | } |
190 | 190 | |
191 | - /** |
|
191 | + /** |
|
192 | 192 | * Return version of database server |
193 | 193 | * |
194 | 194 | * @return string Version string |
195 | - */ |
|
196 | - function getVersion() |
|
197 | - { |
|
198 | - return $this->db->server_info; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Return version of database client driver |
|
203 | - * |
|
204 | - * @return string Version string |
|
205 | - */ |
|
195 | + */ |
|
196 | + function getVersion() |
|
197 | + { |
|
198 | + return $this->db->server_info; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Return version of database client driver |
|
203 | + * |
|
204 | + * @return string Version string |
|
205 | + */ |
|
206 | 206 | function getDriverInfo() |
207 | 207 | { |
208 | 208 | return $this->db->client_info; |
209 | 209 | } |
210 | 210 | |
211 | 211 | |
212 | - /** |
|
213 | - * Close database connexion |
|
214 | - * |
|
215 | - * @return bool True if disconnect successfull, false otherwise |
|
216 | - * @see connect |
|
217 | - */ |
|
218 | - function close() |
|
219 | - { |
|
220 | - if ($this->db) |
|
221 | - { |
|
222 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
223 | - $this->connected=false; |
|
224 | - return $this->db->close(); |
|
225 | - } |
|
226 | - return false; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Execute a SQL request and return the resultset |
|
231 | - * |
|
232 | - * @param string $query SQL query string |
|
233 | - * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
|
234 | - * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
|
235 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
236 | - * @return bool|mysqli_result Resultset of answer |
|
237 | - */ |
|
238 | - function query($query,$usesavepoint=0,$type='auto') |
|
239 | - { |
|
240 | - global $conf; |
|
241 | - |
|
242 | - $query = trim($query); |
|
243 | - |
|
244 | - if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
245 | - |
|
246 | - if (! $this->database_name) |
|
247 | - { |
|
248 | - // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
|
249 | - $ret = $this->db->query($query); |
|
250 | - } |
|
251 | - else |
|
252 | - { |
|
253 | - $ret = $this->db->query($query); |
|
254 | - } |
|
255 | - |
|
256 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
257 | - { |
|
258 | - // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
259 | - if (! $ret) |
|
260 | - { |
|
261 | - $this->lastqueryerror = $query; |
|
262 | - $this->lasterror = $this->error(); |
|
263 | - $this->lasterrno = $this->errno(); |
|
212 | + /** |
|
213 | + * Close database connexion |
|
214 | + * |
|
215 | + * @return bool True if disconnect successfull, false otherwise |
|
216 | + * @see connect |
|
217 | + */ |
|
218 | + function close() |
|
219 | + { |
|
220 | + if ($this->db) |
|
221 | + { |
|
222 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
223 | + $this->connected=false; |
|
224 | + return $this->db->close(); |
|
225 | + } |
|
226 | + return false; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Execute a SQL request and return the resultset |
|
231 | + * |
|
232 | + * @param string $query SQL query string |
|
233 | + * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
|
234 | + * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
|
235 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
236 | + * @return bool|mysqli_result Resultset of answer |
|
237 | + */ |
|
238 | + function query($query,$usesavepoint=0,$type='auto') |
|
239 | + { |
|
240 | + global $conf; |
|
241 | + |
|
242 | + $query = trim($query); |
|
243 | + |
|
244 | + if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
245 | + |
|
246 | + if (! $this->database_name) |
|
247 | + { |
|
248 | + // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
|
249 | + $ret = $this->db->query($query); |
|
250 | + } |
|
251 | + else |
|
252 | + { |
|
253 | + $ret = $this->db->query($query); |
|
254 | + } |
|
255 | + |
|
256 | + if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
257 | + { |
|
258 | + // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
259 | + if (! $ret) |
|
260 | + { |
|
261 | + $this->lastqueryerror = $query; |
|
262 | + $this->lasterror = $this->error(); |
|
263 | + $this->lasterrno = $this->errno(); |
|
264 | 264 | |
265 | 265 | if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); // Log of request was not yet done previously |
266 | - dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterrno." ".$this->lasterror, LOG_ERR); |
|
267 | - } |
|
268 | - $this->lastquery=$query; |
|
269 | - $this->_results = $ret; |
|
270 | - } |
|
271 | - |
|
272 | - return $ret; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Renvoie la ligne courante (comme un objet) pour le curseur resultset |
|
277 | - * |
|
278 | - * @param mysqli_result $resultset Curseur de la requete voulue |
|
279 | - * @return object|null Object result line or null if KO or end of cursor |
|
280 | - */ |
|
281 | - function fetch_object($resultset) |
|
282 | - { |
|
283 | - // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
|
284 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
266 | + dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterrno." ".$this->lasterror, LOG_ERR); |
|
267 | + } |
|
268 | + $this->lastquery=$query; |
|
269 | + $this->_results = $ret; |
|
270 | + } |
|
271 | + |
|
272 | + return $ret; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Renvoie la ligne courante (comme un objet) pour le curseur resultset |
|
277 | + * |
|
278 | + * @param mysqli_result $resultset Curseur de la requete voulue |
|
279 | + * @return object|null Object result line or null if KO or end of cursor |
|
280 | + */ |
|
281 | + function fetch_object($resultset) |
|
282 | + { |
|
283 | + // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
|
284 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
285 | 285 | return $resultset->fetch_object(); |
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Return datas as an array |
|
291 | - * |
|
292 | - * @param mysqli_result $resultset Resultset of request |
|
293 | - * @return array|null Array or null if KO or end of cursor |
|
294 | - */ |
|
295 | - function fetch_array($resultset) |
|
296 | - { |
|
297 | - // If resultset not provided, we take the last used by connexion |
|
298 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
299 | - return $resultset->fetch_array(); |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Return datas as an array |
|
304 | - * |
|
305 | - * @param mysqli_result $resultset Resultset of request |
|
306 | - * @return array|null|0 Array or null if KO or end of cursor or 0 if resultset is bool |
|
307 | - */ |
|
308 | - function fetch_row($resultset) |
|
309 | - { |
|
310 | - // If resultset not provided, we take the last used by connexion |
|
311 | - if (! is_bool($resultset)) |
|
312 | - { |
|
313 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
314 | - return $resultset->fetch_row(); |
|
315 | - } |
|
316 | - else |
|
317 | - { |
|
318 | - // si le curseur est un booleen on retourne la valeur 0 |
|
319 | - return 0; |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Return number of lines for result of a SELECT |
|
325 | - * |
|
326 | - * @param mysqli_result $resultset Resulset of requests |
|
327 | - * @return int Nb of lines |
|
328 | - * @see affected_rows |
|
329 | - */ |
|
330 | - function num_rows($resultset) |
|
331 | - { |
|
332 | - // If resultset not provided, we take the last used by connexion |
|
333 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
334 | - return $resultset->num_rows; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE |
|
339 | - * |
|
340 | - * @param mysqli_result $resultset Curseur de la requete voulue |
|
341 | - * @return int Nombre de lignes |
|
342 | - * @see num_rows |
|
343 | - */ |
|
344 | - function affected_rows($resultset) |
|
345 | - { |
|
346 | - // If resultset not provided, we take the last used by connexion |
|
347 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
348 | - // mysql necessite un link de base pour cette fonction contrairement |
|
349 | - // a pqsql qui prend un resultset |
|
350 | - return $this->db->affected_rows; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * Libere le dernier resultset utilise sur cette connexion |
|
356 | - * |
|
357 | - * @param mysqli_result $resultset Curseur de la requete voulue |
|
358 | - * @return void |
|
359 | - */ |
|
360 | - function free($resultset=null) |
|
361 | - { |
|
362 | - // If resultset not provided, we take the last used by connexion |
|
363 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
364 | - // Si resultset en est un, on libere la memoire |
|
365 | - if (is_object($resultset)) $resultset->free_result(); |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Escape a string to insert data |
|
370 | - * |
|
371 | - * @param string $stringtoencode String to escape |
|
372 | - * @return string String escaped |
|
373 | - */ |
|
374 | - function escape($stringtoencode) |
|
375 | - { |
|
376 | - return $this->db->real_escape_string($stringtoencode); |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Return generic error code of last operation. |
|
381 | - * |
|
382 | - * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
383 | - */ |
|
384 | - function errno() |
|
385 | - { |
|
386 | - if (! $this->connected) { |
|
387 | - // Si il y a eu echec de connexion, $this->db n'est pas valide. |
|
388 | - return 'DB_ERROR_FAILED_TO_CONNECT'; |
|
389 | - } else { |
|
390 | - // Constants to convert a MySql error code to a generic Dolibarr error code |
|
391 | - $errorcode_map = array( |
|
392 | - 1004 => 'DB_ERROR_CANNOT_CREATE', |
|
393 | - 1005 => 'DB_ERROR_CANNOT_CREATE', |
|
394 | - 1006 => 'DB_ERROR_CANNOT_CREATE', |
|
395 | - 1007 => 'DB_ERROR_ALREADY_EXISTS', |
|
396 | - 1008 => 'DB_ERROR_CANNOT_DROP', |
|
397 | - 1022 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
|
398 | - 1025 => 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP', |
|
399 | - 1044 => 'DB_ERROR_ACCESSDENIED', |
|
400 | - 1046 => 'DB_ERROR_NODBSELECTED', |
|
401 | - 1048 => 'DB_ERROR_CONSTRAINT', |
|
402 | - 1050 => 'DB_ERROR_TABLE_ALREADY_EXISTS', |
|
403 | - 1051 => 'DB_ERROR_NOSUCHTABLE', |
|
404 | - 1054 => 'DB_ERROR_NOSUCHFIELD', |
|
405 | - 1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS', |
|
406 | - 1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
|
407 | - 1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS', |
|
408 | - 1064 => 'DB_ERROR_SYNTAX', |
|
409 | - 1068 => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS', |
|
410 | - 1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY', |
|
411 | - 1091 => 'DB_ERROR_NOSUCHFIELD', |
|
412 | - 1100 => 'DB_ERROR_NOT_LOCKED', |
|
413 | - 1136 => 'DB_ERROR_VALUE_COUNT_ON_ROW', |
|
414 | - 1146 => 'DB_ERROR_NOSUCHTABLE', |
|
415 | - 1215 => 'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT', |
|
416 | - 1216 => 'DB_ERROR_NO_PARENT', |
|
417 | - 1217 => 'DB_ERROR_CHILD_EXISTS', |
|
418 | - 1396 => 'DB_ERROR_USER_ALREADY_EXISTS', // When creating user already existing |
|
419 | - 1451 => 'DB_ERROR_CHILD_EXISTS' |
|
420 | - ); |
|
421 | - |
|
422 | - if (isset($errorcode_map[$this->db->errno])) { |
|
423 | - return $errorcode_map[$this->db->errno]; |
|
424 | - } |
|
425 | - $errno=$this->db->errno; |
|
426 | - return ($errno?'DB_ERROR_'.$errno:'0'); |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Return datas as an array |
|
291 | + * |
|
292 | + * @param mysqli_result $resultset Resultset of request |
|
293 | + * @return array|null Array or null if KO or end of cursor |
|
294 | + */ |
|
295 | + function fetch_array($resultset) |
|
296 | + { |
|
297 | + // If resultset not provided, we take the last used by connexion |
|
298 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
299 | + return $resultset->fetch_array(); |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Return datas as an array |
|
304 | + * |
|
305 | + * @param mysqli_result $resultset Resultset of request |
|
306 | + * @return array|null|0 Array or null if KO or end of cursor or 0 if resultset is bool |
|
307 | + */ |
|
308 | + function fetch_row($resultset) |
|
309 | + { |
|
310 | + // If resultset not provided, we take the last used by connexion |
|
311 | + if (! is_bool($resultset)) |
|
312 | + { |
|
313 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
314 | + return $resultset->fetch_row(); |
|
315 | + } |
|
316 | + else |
|
317 | + { |
|
318 | + // si le curseur est un booleen on retourne la valeur 0 |
|
319 | + return 0; |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Return number of lines for result of a SELECT |
|
325 | + * |
|
326 | + * @param mysqli_result $resultset Resulset of requests |
|
327 | + * @return int Nb of lines |
|
328 | + * @see affected_rows |
|
329 | + */ |
|
330 | + function num_rows($resultset) |
|
331 | + { |
|
332 | + // If resultset not provided, we take the last used by connexion |
|
333 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
334 | + return $resultset->num_rows; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE |
|
339 | + * |
|
340 | + * @param mysqli_result $resultset Curseur de la requete voulue |
|
341 | + * @return int Nombre de lignes |
|
342 | + * @see num_rows |
|
343 | + */ |
|
344 | + function affected_rows($resultset) |
|
345 | + { |
|
346 | + // If resultset not provided, we take the last used by connexion |
|
347 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
348 | + // mysql necessite un link de base pour cette fonction contrairement |
|
349 | + // a pqsql qui prend un resultset |
|
350 | + return $this->db->affected_rows; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * Libere le dernier resultset utilise sur cette connexion |
|
356 | + * |
|
357 | + * @param mysqli_result $resultset Curseur de la requete voulue |
|
358 | + * @return void |
|
359 | + */ |
|
360 | + function free($resultset=null) |
|
361 | + { |
|
362 | + // If resultset not provided, we take the last used by connexion |
|
363 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
364 | + // Si resultset en est un, on libere la memoire |
|
365 | + if (is_object($resultset)) $resultset->free_result(); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Escape a string to insert data |
|
370 | + * |
|
371 | + * @param string $stringtoencode String to escape |
|
372 | + * @return string String escaped |
|
373 | + */ |
|
374 | + function escape($stringtoencode) |
|
375 | + { |
|
376 | + return $this->db->real_escape_string($stringtoencode); |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Return generic error code of last operation. |
|
381 | + * |
|
382 | + * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
383 | + */ |
|
384 | + function errno() |
|
385 | + { |
|
386 | + if (! $this->connected) { |
|
387 | + // Si il y a eu echec de connexion, $this->db n'est pas valide. |
|
388 | + return 'DB_ERROR_FAILED_TO_CONNECT'; |
|
389 | + } else { |
|
390 | + // Constants to convert a MySql error code to a generic Dolibarr error code |
|
391 | + $errorcode_map = array( |
|
392 | + 1004 => 'DB_ERROR_CANNOT_CREATE', |
|
393 | + 1005 => 'DB_ERROR_CANNOT_CREATE', |
|
394 | + 1006 => 'DB_ERROR_CANNOT_CREATE', |
|
395 | + 1007 => 'DB_ERROR_ALREADY_EXISTS', |
|
396 | + 1008 => 'DB_ERROR_CANNOT_DROP', |
|
397 | + 1022 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
|
398 | + 1025 => 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP', |
|
399 | + 1044 => 'DB_ERROR_ACCESSDENIED', |
|
400 | + 1046 => 'DB_ERROR_NODBSELECTED', |
|
401 | + 1048 => 'DB_ERROR_CONSTRAINT', |
|
402 | + 1050 => 'DB_ERROR_TABLE_ALREADY_EXISTS', |
|
403 | + 1051 => 'DB_ERROR_NOSUCHTABLE', |
|
404 | + 1054 => 'DB_ERROR_NOSUCHFIELD', |
|
405 | + 1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS', |
|
406 | + 1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
|
407 | + 1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS', |
|
408 | + 1064 => 'DB_ERROR_SYNTAX', |
|
409 | + 1068 => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS', |
|
410 | + 1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY', |
|
411 | + 1091 => 'DB_ERROR_NOSUCHFIELD', |
|
412 | + 1100 => 'DB_ERROR_NOT_LOCKED', |
|
413 | + 1136 => 'DB_ERROR_VALUE_COUNT_ON_ROW', |
|
414 | + 1146 => 'DB_ERROR_NOSUCHTABLE', |
|
415 | + 1215 => 'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT', |
|
416 | + 1216 => 'DB_ERROR_NO_PARENT', |
|
417 | + 1217 => 'DB_ERROR_CHILD_EXISTS', |
|
418 | + 1396 => 'DB_ERROR_USER_ALREADY_EXISTS', // When creating user already existing |
|
419 | + 1451 => 'DB_ERROR_CHILD_EXISTS' |
|
420 | + ); |
|
421 | + |
|
422 | + if (isset($errorcode_map[$this->db->errno])) { |
|
423 | + return $errorcode_map[$this->db->errno]; |
|
424 | + } |
|
425 | + $errno=$this->db->errno; |
|
426 | + return ($errno?'DB_ERROR_'.$errno:'0'); |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | 431 | * Return description of last error |
432 | 432 | * |
433 | 433 | * @return string Error text |
434 | - */ |
|
435 | - function error() |
|
436 | - { |
|
437 | - if (! $this->connected) { |
|
438 | - // Si il y a eu echec de connexion, $this->db n'est pas valide pour mysqli_error. |
|
439 | - return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions'; |
|
440 | - } |
|
441 | - else { |
|
442 | - return $this->db->error; |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
434 | + */ |
|
435 | + function error() |
|
436 | + { |
|
437 | + if (! $this->connected) { |
|
438 | + // Si il y a eu echec de connexion, $this->db n'est pas valide pour mysqli_error. |
|
439 | + return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions'; |
|
440 | + } |
|
441 | + else { |
|
442 | + return $this->db->error; |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | 447 | * Get last ID after an insert INSERT |
448 | 448 | * |
449 | 449 | * @param string $tab Table name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql |
450 | 450 | * @param string $fieldid Field name |
451 | 451 | * @return int|string Id of row |
452 | - */ |
|
453 | - function last_insert_id($tab,$fieldid='rowid') |
|
454 | - { |
|
455 | - return $this->db->insert_id; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Encrypt sensitive data in database |
|
460 | - * Warning: This function includes the escape, so it must use direct value |
|
461 | - * |
|
462 | - * @param string $fieldorvalue Field name or value to encrypt |
|
463 | - * @param int $withQuotes Return string with quotes |
|
464 | - * @return string XXX(field) or XXX('value') or field or 'value' |
|
465 | - * |
|
466 | - */ |
|
467 | - function encrypt($fieldorvalue, $withQuotes=0) |
|
468 | - { |
|
469 | - global $conf; |
|
470 | - |
|
471 | - // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
472 | - $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
473 | - |
|
474 | - //Encryption key |
|
475 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
476 | - |
|
477 | - $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
478 | - |
|
479 | - if ($cryptType && !empty($cryptKey)) |
|
480 | - { |
|
481 | - if ($cryptType == 2) |
|
482 | - { |
|
483 | - $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
484 | - } |
|
485 | - else if ($cryptType == 1) |
|
486 | - { |
|
487 | - $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
488 | - } |
|
489 | - } |
|
490 | - |
|
491 | - return $return; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * Decrypt sensitive data in database |
|
496 | - * |
|
497 | - * @param string $value Value to decrypt |
|
498 | - * @return string Decrypted value if used |
|
499 | - */ |
|
500 | - function decrypt($value) |
|
501 | - { |
|
502 | - global $conf; |
|
503 | - |
|
504 | - // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
505 | - $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
506 | - |
|
507 | - //Encryption key |
|
508 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
509 | - |
|
510 | - $return = $value; |
|
511 | - |
|
512 | - if ($cryptType && !empty($cryptKey)) |
|
513 | - { |
|
514 | - if ($cryptType == 2) |
|
515 | - { |
|
516 | - $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
517 | - } |
|
518 | - else if ($cryptType == 1) |
|
519 | - { |
|
520 | - $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - return $return; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
452 | + */ |
|
453 | + function last_insert_id($tab,$fieldid='rowid') |
|
454 | + { |
|
455 | + return $this->db->insert_id; |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * Encrypt sensitive data in database |
|
460 | + * Warning: This function includes the escape, so it must use direct value |
|
461 | + * |
|
462 | + * @param string $fieldorvalue Field name or value to encrypt |
|
463 | + * @param int $withQuotes Return string with quotes |
|
464 | + * @return string XXX(field) or XXX('value') or field or 'value' |
|
465 | + * |
|
466 | + */ |
|
467 | + function encrypt($fieldorvalue, $withQuotes=0) |
|
468 | + { |
|
469 | + global $conf; |
|
470 | + |
|
471 | + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
472 | + $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
473 | + |
|
474 | + //Encryption key |
|
475 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
476 | + |
|
477 | + $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
478 | + |
|
479 | + if ($cryptType && !empty($cryptKey)) |
|
480 | + { |
|
481 | + if ($cryptType == 2) |
|
482 | + { |
|
483 | + $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
484 | + } |
|
485 | + else if ($cryptType == 1) |
|
486 | + { |
|
487 | + $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
488 | + } |
|
489 | + } |
|
490 | + |
|
491 | + return $return; |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * Decrypt sensitive data in database |
|
496 | + * |
|
497 | + * @param string $value Value to decrypt |
|
498 | + * @return string Decrypted value if used |
|
499 | + */ |
|
500 | + function decrypt($value) |
|
501 | + { |
|
502 | + global $conf; |
|
503 | + |
|
504 | + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
505 | + $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
506 | + |
|
507 | + //Encryption key |
|
508 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
509 | + |
|
510 | + $return = $value; |
|
511 | + |
|
512 | + if ($cryptType && !empty($cryptKey)) |
|
513 | + { |
|
514 | + if ($cryptType == 2) |
|
515 | + { |
|
516 | + $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
517 | + } |
|
518 | + else if ($cryptType == 1) |
|
519 | + { |
|
520 | + $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + return $return; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | 529 | * Return connexion ID |
530 | 530 | * |
531 | 531 | * @return string Id connexion |
532 | - */ |
|
533 | - function DDLGetConnectId() |
|
534 | - { |
|
535 | - $resql=$this->query('SELECT CONNECTION_ID()'); |
|
536 | - if ($resql) |
|
537 | - { |
|
538 | - $row=$this->fetch_row($resql); |
|
539 | - return $row[0]; |
|
540 | - } |
|
541 | - else return '?'; |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
532 | + */ |
|
533 | + function DDLGetConnectId() |
|
534 | + { |
|
535 | + $resql=$this->query('SELECT CONNECTION_ID()'); |
|
536 | + if ($resql) |
|
537 | + { |
|
538 | + $row=$this->fetch_row($resql); |
|
539 | + return $row[0]; |
|
540 | + } |
|
541 | + else return '?'; |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | 545 | * Create a new database |
546 | 546 | * Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated |
547 | 547 | * We force to create database with charset this->forcecharset and collate this->forcecollate |
@@ -551,79 +551,79 @@ discard block |
||
551 | 551 | * @param string $collation Charset used to sort data |
552 | 552 | * @param string $owner Username of database owner |
553 | 553 | * @return bool|mysqli_result resource defined if OK, null if KO |
554 | - */ |
|
555 | - function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
556 | - { |
|
557 | - if (empty($charset)) $charset=$this->forcecharset; |
|
558 | - if (empty($collation)) $collation=$this->forcecollate; |
|
554 | + */ |
|
555 | + function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
556 | + { |
|
557 | + if (empty($charset)) $charset=$this->forcecharset; |
|
558 | + if (empty($collation)) $collation=$this->forcecollate; |
|
559 | 559 | |
560 | - // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
|
560 | + // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
|
561 | 561 | $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
562 | 562 | $sql.= " DEFAULT CHARACTER SET `".$this->escape($charset)."` DEFAULT COLLATE `".$this->escape($collation)."`"; |
563 | 563 | |
564 | - dol_syslog($sql,LOG_DEBUG); |
|
565 | - $ret=$this->query($sql); |
|
566 | - if (! $ret) |
|
567 | - { |
|
568 | - // We try again for compatibility with Mysql < 4.1.1 |
|
569 | - $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
|
570 | - dol_syslog($sql,LOG_DEBUG); |
|
571 | - $ret=$this->query($sql); |
|
572 | - } |
|
573 | - return $ret; |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
564 | + dol_syslog($sql,LOG_DEBUG); |
|
565 | + $ret=$this->query($sql); |
|
566 | + if (! $ret) |
|
567 | + { |
|
568 | + // We try again for compatibility with Mysql < 4.1.1 |
|
569 | + $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
|
570 | + dol_syslog($sql,LOG_DEBUG); |
|
571 | + $ret=$this->query($sql); |
|
572 | + } |
|
573 | + return $ret; |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | 577 | * List tables into a database |
578 | 578 | * |
579 | 579 | * @param string $database Name of database |
580 | 580 | * @param string $table Nmae of table filter ('xxx%') |
581 | 581 | * @return array List of tables in an array |
582 | - */ |
|
583 | - function DDLListTables($database, $table='') |
|
584 | - { |
|
585 | - $listtables=array(); |
|
586 | - |
|
587 | - $like = ''; |
|
588 | - if ($table) $like = "LIKE '".$table."'"; |
|
589 | - $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
590 | - //print $sql; |
|
591 | - $result = $this->query($sql); |
|
592 | - if ($result) |
|
593 | - { |
|
594 | - while($row = $this->fetch_row($result)) |
|
595 | - { |
|
596 | - $listtables[] = $row[0]; |
|
597 | - } |
|
598 | - } |
|
599 | - return $listtables; |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
582 | + */ |
|
583 | + function DDLListTables($database, $table='') |
|
584 | + { |
|
585 | + $listtables=array(); |
|
586 | + |
|
587 | + $like = ''; |
|
588 | + if ($table) $like = "LIKE '".$table."'"; |
|
589 | + $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
590 | + //print $sql; |
|
591 | + $result = $this->query($sql); |
|
592 | + if ($result) |
|
593 | + { |
|
594 | + while($row = $this->fetch_row($result)) |
|
595 | + { |
|
596 | + $listtables[] = $row[0]; |
|
597 | + } |
|
598 | + } |
|
599 | + return $listtables; |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | 603 | * List information of columns into a table. |
604 | 604 | * |
605 | 605 | * @param string $table Name of table |
606 | 606 | * @return array Tableau des informations des champs de la table |
607 | - */ |
|
608 | - function DDLInfoTable($table) |
|
609 | - { |
|
610 | - $infotables=array(); |
|
611 | - |
|
612 | - $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
613 | - |
|
614 | - dol_syslog($sql,LOG_DEBUG); |
|
615 | - $result = $this->query($sql); |
|
616 | - if ($result) |
|
617 | - { |
|
618 | - while($row = $this->fetch_row($result)) |
|
619 | - { |
|
620 | - $infotables[] = $row; |
|
621 | - } |
|
622 | - } |
|
623 | - return $infotables; |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
607 | + */ |
|
608 | + function DDLInfoTable($table) |
|
609 | + { |
|
610 | + $infotables=array(); |
|
611 | + |
|
612 | + $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
613 | + |
|
614 | + dol_syslog($sql,LOG_DEBUG); |
|
615 | + $result = $this->query($sql); |
|
616 | + if ($result) |
|
617 | + { |
|
618 | + while($row = $this->fetch_row($result)) |
|
619 | + { |
|
620 | + $infotables[] = $row; |
|
621 | + } |
|
622 | + } |
|
623 | + return $infotables; |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | 627 | * Create a table into database |
628 | 628 | * |
629 | 629 | * @param string $table Nom de la table |
@@ -634,18 +634,18 @@ discard block |
||
634 | 634 | * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext |
635 | 635 | * @param array $keys Tableau des champs cles noms => valeur |
636 | 636 | * @return int <0 if KO, >=0 if OK |
637 | - */ |
|
638 | - function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
639 | - { |
|
640 | - // FIXME: $fulltext_keys parameter is unused |
|
641 | - |
|
642 | - // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
|
643 | - // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
644 | - $sql = "CREATE TABLE ".$table."("; |
|
645 | - $i=0; |
|
646 | - foreach($fields as $field_name => $field_desc) |
|
647 | - { |
|
648 | - $sqlfields[$i] = $field_name." "; |
|
637 | + */ |
|
638 | + function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
639 | + { |
|
640 | + // FIXME: $fulltext_keys parameter is unused |
|
641 | + |
|
642 | + // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
|
643 | + // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
644 | + $sql = "CREATE TABLE ".$table."("; |
|
645 | + $i=0; |
|
646 | + foreach($fields as $field_name => $field_desc) |
|
647 | + { |
|
648 | + $sqlfields[$i] = $field_name." "; |
|
649 | 649 | $sqlfields[$i] .= $field_desc['type']; |
650 | 650 | if( preg_match("/^[^\s]/i",$field_desc['value'])) { |
651 | 651 | $sqlfields[$i] .= "(".$field_desc['value'].")"; |
@@ -668,61 +668,61 @@ discard block |
||
668 | 668 | if( preg_match("/^[^\s]/i",$field_desc['extra'])) { |
669 | 669 | $sqlfields[$i] .= " ".$field_desc['extra']; |
670 | 670 | } |
671 | - $i++; |
|
672 | - } |
|
673 | - if($primary_key != "") |
|
674 | - $pk = "primary key(".$primary_key.")"; |
|
675 | - |
|
676 | - if(is_array($unique_keys)) { |
|
677 | - $i = 0; |
|
678 | - foreach($unique_keys as $key => $value) |
|
679 | - { |
|
680 | - $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
|
681 | - $i++; |
|
682 | - } |
|
683 | - } |
|
684 | - if(is_array($keys)) |
|
685 | - { |
|
686 | - $i = 0; |
|
687 | - foreach($keys as $key => $value) |
|
688 | - { |
|
689 | - $sqlk[$i] = "KEY ".$key." (".$value.")"; |
|
690 | - $i++; |
|
691 | - } |
|
692 | - } |
|
693 | - $sql .= implode(',',$sqlfields); |
|
694 | - if($primary_key != "") |
|
695 | - $sql .= ",".$pk; |
|
696 | - if($unique_keys != "") |
|
697 | - $sql .= ",".implode(',',$sqluq); |
|
698 | - if(is_array($keys)) |
|
699 | - $sql .= ",".implode(',',$sqlk); |
|
700 | - $sql .=") engine=".$type; |
|
701 | - |
|
702 | - dol_syslog($sql,LOG_DEBUG); |
|
703 | - if(! $this -> query($sql)) |
|
704 | - return -1; |
|
705 | - else |
|
706 | - return 1; |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
671 | + $i++; |
|
672 | + } |
|
673 | + if($primary_key != "") |
|
674 | + $pk = "primary key(".$primary_key.")"; |
|
675 | + |
|
676 | + if(is_array($unique_keys)) { |
|
677 | + $i = 0; |
|
678 | + foreach($unique_keys as $key => $value) |
|
679 | + { |
|
680 | + $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
|
681 | + $i++; |
|
682 | + } |
|
683 | + } |
|
684 | + if(is_array($keys)) |
|
685 | + { |
|
686 | + $i = 0; |
|
687 | + foreach($keys as $key => $value) |
|
688 | + { |
|
689 | + $sqlk[$i] = "KEY ".$key." (".$value.")"; |
|
690 | + $i++; |
|
691 | + } |
|
692 | + } |
|
693 | + $sql .= implode(',',$sqlfields); |
|
694 | + if($primary_key != "") |
|
695 | + $sql .= ",".$pk; |
|
696 | + if($unique_keys != "") |
|
697 | + $sql .= ",".implode(',',$sqluq); |
|
698 | + if(is_array($keys)) |
|
699 | + $sql .= ",".implode(',',$sqlk); |
|
700 | + $sql .=") engine=".$type; |
|
701 | + |
|
702 | + dol_syslog($sql,LOG_DEBUG); |
|
703 | + if(! $this -> query($sql)) |
|
704 | + return -1; |
|
705 | + else |
|
706 | + return 1; |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | 710 | * Return a pointer of line with description of a table or field |
711 | 711 | * |
712 | 712 | * @param string $table Name of table |
713 | 713 | * @param string $field Optionnel : Name of field if we want description of field |
714 | 714 | * @return bool|mysqli_result Resultset x (x->Field, x->Type, ...) |
715 | - */ |
|
716 | - function DDLDescTable($table,$field="") |
|
717 | - { |
|
718 | - $sql="DESC ".$table." ".$field; |
|
715 | + */ |
|
716 | + function DDLDescTable($table,$field="") |
|
717 | + { |
|
718 | + $sql="DESC ".$table." ".$field; |
|
719 | 719 | |
720 | - dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
721 | - $this->_results = $this->query($sql); |
|
722 | - return $this->_results; |
|
723 | - } |
|
720 | + dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
721 | + $this->_results = $this->query($sql); |
|
722 | + return $this->_results; |
|
723 | + } |
|
724 | 724 | |
725 | - /** |
|
725 | + /** |
|
726 | 726 | * Create a new field into table |
727 | 727 | * |
728 | 728 | * @param string $table Name of table |
@@ -730,105 +730,105 @@ discard block |
||
730 | 730 | * @param string $field_desc Tableau associatif de description du champ a inserer[nom du parametre][valeur du parametre] |
731 | 731 | * @param string $field_position Optionnel ex.: "after champtruc" |
732 | 732 | * @return int <0 if KO, >0 if OK |
733 | - */ |
|
734 | - function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
735 | - { |
|
736 | - // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
|
737 | - // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
738 | - $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
739 | - $sql.= $field_desc['type']; |
|
740 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
741 | - if (! in_array($field_desc['type'],array('date','datetime'))) |
|
742 | - { |
|
743 | - $sql.= "(".$field_desc['value'].")"; |
|
744 | - } |
|
745 | - if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
746 | - $sql.= " ".$field_desc['attribute']; |
|
747 | - if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
748 | - $sql.= " ".$field_desc['null']; |
|
749 | - if(preg_match("/^[^\s]/i",$field_desc['default'])) |
|
750 | - { |
|
751 | - if(preg_match("/null/i",$field_desc['default'])) |
|
752 | - $sql.= " default ".$field_desc['default']; |
|
753 | - else |
|
754 | - $sql.= " default '".$field_desc['default']."'"; |
|
755 | - } |
|
756 | - if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
757 | - $sql.= " ".$field_desc['extra']; |
|
758 | - $sql.= " ".$field_position; |
|
759 | - |
|
760 | - dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
761 | - if($this->query($sql)) { |
|
762 | - return 1; |
|
763 | - } |
|
764 | - return -1; |
|
765 | - } |
|
766 | - |
|
767 | - /** |
|
733 | + */ |
|
734 | + function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
735 | + { |
|
736 | + // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
|
737 | + // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
738 | + $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
739 | + $sql.= $field_desc['type']; |
|
740 | + if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
741 | + if (! in_array($field_desc['type'],array('date','datetime'))) |
|
742 | + { |
|
743 | + $sql.= "(".$field_desc['value'].")"; |
|
744 | + } |
|
745 | + if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
746 | + $sql.= " ".$field_desc['attribute']; |
|
747 | + if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
748 | + $sql.= " ".$field_desc['null']; |
|
749 | + if(preg_match("/^[^\s]/i",$field_desc['default'])) |
|
750 | + { |
|
751 | + if(preg_match("/null/i",$field_desc['default'])) |
|
752 | + $sql.= " default ".$field_desc['default']; |
|
753 | + else |
|
754 | + $sql.= " default '".$field_desc['default']."'"; |
|
755 | + } |
|
756 | + if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
757 | + $sql.= " ".$field_desc['extra']; |
|
758 | + $sql.= " ".$field_position; |
|
759 | + |
|
760 | + dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
761 | + if($this->query($sql)) { |
|
762 | + return 1; |
|
763 | + } |
|
764 | + return -1; |
|
765 | + } |
|
766 | + |
|
767 | + /** |
|
768 | 768 | * Update format of a field into a table |
769 | 769 | * |
770 | 770 | * @param string $table Name of table |
771 | 771 | * @param string $field_name Name of field to modify |
772 | 772 | * @param string $field_desc Array with description of field format |
773 | 773 | * @return int <0 if KO, >0 if OK |
774 | - */ |
|
775 | - function DDLUpdateField($table,$field_name,$field_desc) |
|
776 | - { |
|
777 | - $sql = "ALTER TABLE ".$table; |
|
778 | - $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
|
779 | - if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
|
780 | - $sql.="(".$field_desc['value'].")"; |
|
781 | - } |
|
782 | - if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') |
|
783 | - { |
|
784 | - // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL |
|
785 | - if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
|
786 | - { |
|
787 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
788 | - $this->query($sqlbis); |
|
789 | - } |
|
790 | - elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
791 | - { |
|
792 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
793 | - $this->query($sqlbis); |
|
794 | - } |
|
795 | - |
|
796 | - $sql.=" NOT NULL"; |
|
797 | - } |
|
798 | - |
|
799 | - if ($field_desc['default'] != '') |
|
800 | - { |
|
774 | + */ |
|
775 | + function DDLUpdateField($table,$field_name,$field_desc) |
|
776 | + { |
|
777 | + $sql = "ALTER TABLE ".$table; |
|
778 | + $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
|
779 | + if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
|
780 | + $sql.="(".$field_desc['value'].")"; |
|
781 | + } |
|
782 | + if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') |
|
783 | + { |
|
784 | + // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL |
|
785 | + if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
|
786 | + { |
|
787 | + $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
788 | + $this->query($sqlbis); |
|
789 | + } |
|
790 | + elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
791 | + { |
|
792 | + $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
793 | + $this->query($sqlbis); |
|
794 | + } |
|
795 | + |
|
796 | + $sql.=" NOT NULL"; |
|
797 | + } |
|
798 | + |
|
799 | + if ($field_desc['default'] != '') |
|
800 | + { |
|
801 | 801 | if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']); |
802 | - elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
803 | - } |
|
802 | + elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
803 | + } |
|
804 | 804 | |
805 | - dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
806 | - if (! $this->query($sql)) |
|
807 | - return -1; |
|
808 | - else |
|
809 | - return 1; |
|
810 | - } |
|
805 | + dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
806 | + if (! $this->query($sql)) |
|
807 | + return -1; |
|
808 | + else |
|
809 | + return 1; |
|
810 | + } |
|
811 | 811 | |
812 | - /** |
|
812 | + /** |
|
813 | 813 | * Drop a field from table |
814 | 814 | * |
815 | 815 | * @param string $table Name of table |
816 | 816 | * @param string $field_name Name of field to drop |
817 | 817 | * @return int <0 if KO, >0 if OK |
818 | - */ |
|
819 | - function DDLDropField($table,$field_name) |
|
820 | - { |
|
821 | - $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
822 | - dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG); |
|
823 | - if ($this->query($sql)) { |
|
824 | - return 1; |
|
825 | - } |
|
826 | - $this->error=$this->lasterror(); |
|
827 | - return -1; |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - /** |
|
818 | + */ |
|
819 | + function DDLDropField($table,$field_name) |
|
820 | + { |
|
821 | + $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
822 | + dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG); |
|
823 | + if ($this->query($sql)) { |
|
824 | + return 1; |
|
825 | + } |
|
826 | + $this->error=$this->lasterror(); |
|
827 | + return -1; |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + /** |
|
832 | 832 | * Create a user and privileges to connect to database (even if database does not exists yet) |
833 | 833 | * |
834 | 834 | * @param string $dolibarr_main_db_host Ip server or '%' |
@@ -836,213 +836,213 @@ discard block |
||
836 | 836 | * @param string $dolibarr_main_db_pass Mot de passe user a creer |
837 | 837 | * @param string $dolibarr_main_db_name Database name where user must be granted |
838 | 838 | * @return int <0 if KO, >=0 if OK |
839 | - */ |
|
840 | - function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
841 | - { |
|
842 | - $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'"; |
|
843 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
844 | - $resql=$this->query($sql); |
|
845 | - if (! $resql) |
|
846 | - { |
|
847 | - if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS') |
|
848 | - { |
|
849 | - return -1; |
|
850 | - } |
|
851 | - else |
|
839 | + */ |
|
840 | + function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
841 | + { |
|
842 | + $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'"; |
|
843 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
844 | + $resql=$this->query($sql); |
|
845 | + if (! $resql) |
|
846 | + { |
|
847 | + if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS') |
|
848 | + { |
|
849 | + return -1; |
|
850 | + } |
|
851 | + else |
|
852 | + { |
|
853 | + // If user already exists, we continue to set permissions |
|
854 | + dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
855 | + } |
|
856 | + } |
|
857 | + $sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'"; |
|
858 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
859 | + $resql=$this->query($sql); |
|
860 | + if (! $resql) |
|
861 | + { |
|
862 | + return -1; |
|
863 | + } |
|
864 | + |
|
865 | + $sql="FLUSH Privileges"; |
|
866 | + |
|
867 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
868 | + $resql=$this->query($sql); |
|
869 | + if (! $resql) |
|
870 | + { |
|
871 | + return -1; |
|
872 | + } |
|
873 | + |
|
874 | + return 1; |
|
875 | + } |
|
876 | + |
|
877 | + /** |
|
878 | + * Return charset used to store data in current database (same result than using SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = "databasename";) |
|
879 | + * |
|
880 | + * @return string Charset |
|
881 | + * @see getDefaultCollationDatabase |
|
882 | + */ |
|
883 | + function getDefaultCharacterSetDatabase() |
|
884 | + { |
|
885 | + $resql=$this->query('SHOW VARIABLES LIKE \'character_set_database\''); |
|
886 | + if (!$resql) |
|
887 | + { |
|
888 | + // version Mysql < 4.1.1 |
|
889 | + return $this->forcecharset; |
|
890 | + } |
|
891 | + $liste=$this->fetch_array($resql); |
|
892 | + $tmpval = $liste['Value']; |
|
893 | + |
|
894 | + return $tmpval; |
|
895 | + } |
|
896 | + |
|
897 | + /** |
|
898 | + * Return list of available charset that can be used to store data in database |
|
899 | + * |
|
900 | + * @return array|null List of Charset |
|
901 | + */ |
|
902 | + function getListOfCharacterSet() |
|
903 | + { |
|
904 | + $resql=$this->query('SHOW CHARSET'); |
|
905 | + $liste = array(); |
|
906 | + if ($resql) |
|
907 | + { |
|
908 | + $i = 0; |
|
909 | + while ($obj = $this->fetch_object($resql) ) |
|
910 | + { |
|
911 | + $liste[$i]['charset'] = $obj->Charset; |
|
912 | + $liste[$i]['description'] = $obj->Description; |
|
913 | + $i++; |
|
914 | + } |
|
915 | + $this->free($resql); |
|
916 | + } else { |
|
917 | + // version Mysql < 4.1.1 |
|
918 | + return null; |
|
919 | + } |
|
920 | + return $liste; |
|
921 | + } |
|
922 | + |
|
923 | + /** |
|
924 | + * Return collation used in current database |
|
925 | + * |
|
926 | + * @return string Collation value |
|
927 | + * @see getDefaultCharacterSetDatabase |
|
928 | + */ |
|
929 | + function getDefaultCollationDatabase() |
|
930 | + { |
|
931 | + $resql=$this->query('SHOW VARIABLES LIKE \'collation_database\''); |
|
932 | + if (!$resql) |
|
933 | + { |
|
934 | + // version Mysql < 4.1.1 |
|
935 | + return $this->forcecollate; |
|
936 | + } |
|
937 | + $liste=$this->fetch_array($resql); |
|
938 | + $tmpval = $liste['Value']; |
|
939 | + |
|
940 | + return $tmpval; |
|
941 | + } |
|
942 | + |
|
943 | + /** |
|
944 | + * Return list of available collation that can be used for database |
|
945 | + * |
|
946 | + * @return array|null Liste of Collation |
|
947 | + */ |
|
948 | + function getListOfCollation() |
|
949 | + { |
|
950 | + $resql=$this->query('SHOW COLLATION'); |
|
951 | + $liste = array(); |
|
952 | + if ($resql) |
|
953 | + { |
|
954 | + $i = 0; |
|
955 | + while ($obj = $this->fetch_object($resql) ) |
|
852 | 956 | { |
853 | - // If user already exists, we continue to set permissions |
|
854 | - dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
855 | - } |
|
856 | - } |
|
857 | - $sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'"; |
|
858 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
859 | - $resql=$this->query($sql); |
|
860 | - if (! $resql) |
|
861 | - { |
|
862 | - return -1; |
|
863 | - } |
|
864 | - |
|
865 | - $sql="FLUSH Privileges"; |
|
866 | - |
|
867 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
868 | - $resql=$this->query($sql); |
|
869 | - if (! $resql) |
|
870 | - { |
|
871 | - return -1; |
|
872 | - } |
|
873 | - |
|
874 | - return 1; |
|
875 | - } |
|
876 | - |
|
877 | - /** |
|
878 | - * Return charset used to store data in current database (same result than using SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = "databasename";) |
|
879 | - * |
|
880 | - * @return string Charset |
|
881 | - * @see getDefaultCollationDatabase |
|
882 | - */ |
|
883 | - function getDefaultCharacterSetDatabase() |
|
884 | - { |
|
885 | - $resql=$this->query('SHOW VARIABLES LIKE \'character_set_database\''); |
|
886 | - if (!$resql) |
|
887 | - { |
|
888 | - // version Mysql < 4.1.1 |
|
889 | - return $this->forcecharset; |
|
890 | - } |
|
891 | - $liste=$this->fetch_array($resql); |
|
892 | - $tmpval = $liste['Value']; |
|
893 | - |
|
894 | - return $tmpval; |
|
895 | - } |
|
896 | - |
|
897 | - /** |
|
898 | - * Return list of available charset that can be used to store data in database |
|
899 | - * |
|
900 | - * @return array|null List of Charset |
|
901 | - */ |
|
902 | - function getListOfCharacterSet() |
|
903 | - { |
|
904 | - $resql=$this->query('SHOW CHARSET'); |
|
905 | - $liste = array(); |
|
906 | - if ($resql) |
|
907 | - { |
|
908 | - $i = 0; |
|
909 | - while ($obj = $this->fetch_object($resql) ) |
|
910 | - { |
|
911 | - $liste[$i]['charset'] = $obj->Charset; |
|
912 | - $liste[$i]['description'] = $obj->Description; |
|
913 | - $i++; |
|
914 | - } |
|
915 | - $this->free($resql); |
|
916 | - } else { |
|
917 | - // version Mysql < 4.1.1 |
|
918 | - return null; |
|
919 | - } |
|
920 | - return $liste; |
|
921 | - } |
|
922 | - |
|
923 | - /** |
|
924 | - * Return collation used in current database |
|
925 | - * |
|
926 | - * @return string Collation value |
|
927 | - * @see getDefaultCharacterSetDatabase |
|
928 | - */ |
|
929 | - function getDefaultCollationDatabase() |
|
930 | - { |
|
931 | - $resql=$this->query('SHOW VARIABLES LIKE \'collation_database\''); |
|
932 | - if (!$resql) |
|
933 | - { |
|
934 | - // version Mysql < 4.1.1 |
|
935 | - return $this->forcecollate; |
|
936 | - } |
|
937 | - $liste=$this->fetch_array($resql); |
|
938 | - $tmpval = $liste['Value']; |
|
939 | - |
|
940 | - return $tmpval; |
|
941 | - } |
|
942 | - |
|
943 | - /** |
|
944 | - * Return list of available collation that can be used for database |
|
945 | - * |
|
946 | - * @return array|null Liste of Collation |
|
947 | - */ |
|
948 | - function getListOfCollation() |
|
949 | - { |
|
950 | - $resql=$this->query('SHOW COLLATION'); |
|
951 | - $liste = array(); |
|
952 | - if ($resql) |
|
953 | - { |
|
954 | - $i = 0; |
|
955 | - while ($obj = $this->fetch_object($resql) ) |
|
956 | - { |
|
957 | - $liste[$i]['collation'] = $obj->Collation; |
|
958 | - $i++; |
|
959 | - } |
|
960 | - $this->free($resql); |
|
961 | - } else { |
|
962 | - // version Mysql < 4.1.1 |
|
963 | - return null; |
|
964 | - } |
|
965 | - return $liste; |
|
966 | - } |
|
967 | - |
|
968 | - /** |
|
957 | + $liste[$i]['collation'] = $obj->Collation; |
|
958 | + $i++; |
|
959 | + } |
|
960 | + $this->free($resql); |
|
961 | + } else { |
|
962 | + // version Mysql < 4.1.1 |
|
963 | + return null; |
|
964 | + } |
|
965 | + return $liste; |
|
966 | + } |
|
967 | + |
|
968 | + /** |
|
969 | 969 | * Return full path of dump program |
970 | 970 | * |
971 | 971 | * @return string Full path of dump program |
972 | - */ |
|
973 | - function getPathOfDump() |
|
974 | - { |
|
975 | - $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
976 | - |
|
977 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
978 | - if ($resql) |
|
979 | - { |
|
980 | - $liste=$this->fetch_array($resql); |
|
981 | - $basedir=$liste['Value']; |
|
982 | - $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
983 | - } |
|
984 | - return $fullpathofdump; |
|
985 | - } |
|
986 | - |
|
987 | - /** |
|
988 | - * Return full path of restore program |
|
989 | - * |
|
990 | - * @return string Full path of restore program |
|
991 | - */ |
|
992 | - function getPathOfRestore() |
|
993 | - { |
|
994 | - $fullpathofimport='/pathtomysql/mysql'; |
|
995 | - |
|
996 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
997 | - if ($resql) |
|
998 | - { |
|
999 | - $liste=$this->fetch_array($resql); |
|
1000 | - $basedir=$liste['Value']; |
|
1001 | - $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
1002 | - } |
|
1003 | - return $fullpathofimport; |
|
1004 | - } |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * Return value of server parameters |
|
1008 | - * |
|
1009 | - * @param string $filter Filter list on a particular value |
|
972 | + */ |
|
973 | + function getPathOfDump() |
|
974 | + { |
|
975 | + $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
976 | + |
|
977 | + $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
978 | + if ($resql) |
|
979 | + { |
|
980 | + $liste=$this->fetch_array($resql); |
|
981 | + $basedir=$liste['Value']; |
|
982 | + $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
983 | + } |
|
984 | + return $fullpathofdump; |
|
985 | + } |
|
986 | + |
|
987 | + /** |
|
988 | + * Return full path of restore program |
|
989 | + * |
|
990 | + * @return string Full path of restore program |
|
991 | + */ |
|
992 | + function getPathOfRestore() |
|
993 | + { |
|
994 | + $fullpathofimport='/pathtomysql/mysql'; |
|
995 | + |
|
996 | + $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
997 | + if ($resql) |
|
998 | + { |
|
999 | + $liste=$this->fetch_array($resql); |
|
1000 | + $basedir=$liste['Value']; |
|
1001 | + $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
1002 | + } |
|
1003 | + return $fullpathofimport; |
|
1004 | + } |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * Return value of server parameters |
|
1008 | + * |
|
1009 | + * @param string $filter Filter list on a particular value |
|
1010 | 1010 | * @return array Array of key-values (key=>value) |
1011 | - */ |
|
1012 | - function getServerParametersValues($filter='') |
|
1013 | - { |
|
1014 | - $result=array(); |
|
1015 | - |
|
1016 | - $sql='SHOW VARIABLES'; |
|
1017 | - if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
1018 | - $resql=$this->query($sql); |
|
1019 | - if ($resql) |
|
1020 | - { |
|
1021 | - while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
1022 | - } |
|
1023 | - |
|
1024 | - return $result; |
|
1025 | - } |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * Return value of server status (current indicators on memory, cache...) |
|
1029 | - * |
|
1030 | - * @param string $filter Filter list on a particular value |
|
1011 | + */ |
|
1012 | + function getServerParametersValues($filter='') |
|
1013 | + { |
|
1014 | + $result=array(); |
|
1015 | + |
|
1016 | + $sql='SHOW VARIABLES'; |
|
1017 | + if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
1018 | + $resql=$this->query($sql); |
|
1019 | + if ($resql) |
|
1020 | + { |
|
1021 | + while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
1022 | + } |
|
1023 | + |
|
1024 | + return $result; |
|
1025 | + } |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * Return value of server status (current indicators on memory, cache...) |
|
1029 | + * |
|
1030 | + * @param string $filter Filter list on a particular value |
|
1031 | 1031 | * @return array Array of key-values (key=>value) |
1032 | - */ |
|
1033 | - function getServerStatusValues($filter='') |
|
1034 | - { |
|
1035 | - $result=array(); |
|
1036 | - |
|
1037 | - $sql='SHOW STATUS'; |
|
1038 | - if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
1039 | - $resql=$this->query($sql); |
|
1040 | - if ($resql) |
|
1041 | - { |
|
1042 | - while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
1043 | - } |
|
1044 | - |
|
1045 | - return $result; |
|
1046 | - } |
|
1032 | + */ |
|
1033 | + function getServerStatusValues($filter='') |
|
1034 | + { |
|
1035 | + $result=array(); |
|
1036 | + |
|
1037 | + $sql='SHOW STATUS'; |
|
1038 | + if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
1039 | + $resql=$this->query($sql); |
|
1040 | + if ($resql) |
|
1041 | + { |
|
1042 | + while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
1043 | + } |
|
1044 | + |
|
1045 | + return $result; |
|
1046 | + } |
|
1047 | 1047 | } |
1048 | 1048 |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @param string $query SQL query string |
465 | 465 | * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollback to savepoint if error (this allow to have some request with errors inside global transactions). |
466 | 466 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
467 | - * @return false|resource Resultset of answer |
|
467 | + * @return resource|null Resultset of answer |
|
468 | 468 | */ |
469 | 469 | function query($query,$usesavepoint=0,$type='auto') |
470 | 470 | { |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | * Decrypt sensitive data in database |
791 | 791 | * |
792 | 792 | * @param int $value Value to decrypt |
793 | - * @return string Decrypted value if used |
|
793 | + * @return integer Decrypted value if used |
|
794 | 794 | */ |
795 | 795 | function decrypt($value) |
796 | 796 | { |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | */ |
36 | 36 | class DoliDBPgsql extends DoliDB |
37 | 37 | { |
38 | - //! Database type |
|
38 | + //! Database type |
|
39 | 39 | public $type='pgsql'; // Name of manager |
40 | - //! Database label |
|
40 | + //! Database label |
|
41 | 41 | const LABEL='PostgreSQL'; // Label of manager |
42 | 42 | //! Charset |
43 | 43 | var $forcecharset='UTF8'; // Can't be static as it may be forced with a dynamic value |
44 | - //! Collate used to force collate when creating database |
|
45 | - var $forcecollate=''; // Can't be static as it may be forced with a dynamic value |
|
44 | + //! Collate used to force collate when creating database |
|
45 | + var $forcecollate=''; // Can't be static as it may be forced with a dynamic value |
|
46 | 46 | //! Version min database |
47 | 47 | const VERSIONMIN='9.0.0'; // Version min database |
48 | 48 | /** @var resource Resultset of last query */ |
@@ -66,13 +66,13 @@ discard block |
||
66 | 66 | { |
67 | 67 | global $conf,$langs; |
68 | 68 | |
69 | - // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
|
69 | + // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
|
70 | 70 | if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; |
71 | 71 | if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
72 | 72 | |
73 | 73 | $this->database_user=$user; |
74 | - $this->database_host=$host; |
|
75 | - $this->database_port=$port; |
|
74 | + $this->database_host=$host; |
|
75 | + $this->database_port=$port; |
|
76 | 76 | |
77 | 77 | $this->transaction_opened=0; |
78 | 78 | |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | |
145 | - /** |
|
146 | - * Convert a SQL request in Mysql syntax to native syntax |
|
147 | - * |
|
148 | - * @param string $line SQL request line to convert |
|
149 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
150 | - * @param bool $unescapeslashquot Unescape slash quote with quote quote |
|
151 | - * @return string SQL request line converted |
|
152 | - */ |
|
145 | + /** |
|
146 | + * Convert a SQL request in Mysql syntax to native syntax |
|
147 | + * |
|
148 | + * @param string $line SQL request line to convert |
|
149 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
150 | + * @param bool $unescapeslashquot Unescape slash quote with quote quote |
|
151 | + * @return string SQL request line converted |
|
152 | + */ |
|
153 | 153 | static function convertSQLFromMysql($line,$type='auto',$unescapeslashquot=false) |
154 | 154 | { |
155 | 155 | // Removed empty line if this is a comment line for SVN tagging |
@@ -165,149 +165,149 @@ discard block |
||
165 | 165 | { |
166 | 166 | // group_concat support (PgSQL >= 9.0) |
167 | 167 | // Replace group_concat(x) or group_concat(x SEPARATOR ',') with string_agg(x, ',') |
168 | - $line = preg_replace('/GROUP_CONCAT/i', 'STRING_AGG', $line); |
|
168 | + $line = preg_replace('/GROUP_CONCAT/i', 'STRING_AGG', $line); |
|
169 | 169 | $line = preg_replace('/ SEPARATOR/i', ',', $line); |
170 | 170 | $line = preg_replace('/STRING_AGG\(([^,\)]+)\)/i', 'STRING_AGG(\\1, \',\')', $line); |
171 | 171 | //print $line."\n"; |
172 | 172 | |
173 | - if ($type == 'auto') |
|
174 | - { |
|
175 | - if (preg_match('/ALTER TABLE/i',$line)) $type='dml'; |
|
176 | - else if (preg_match('/CREATE TABLE/i',$line)) $type='dml'; |
|
177 | - else if (preg_match('/DROP TABLE/i',$line)) $type='dml'; |
|
178 | - } |
|
179 | - |
|
180 | - $line=preg_replace('/ as signed\)/i',' as integer)',$line); |
|
181 | - |
|
182 | - if ($type == 'dml') |
|
183 | - { |
|
184 | - $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
185 | - |
|
186 | - // we are inside create table statement so lets process datatypes |
|
187 | - if (preg_match('/(ISAM|innodb)/i',$line)) { // end of create table sequence |
|
188 | - $line=preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i',');',$line); |
|
189 | - $line=preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i',');',$line); |
|
190 | - $line=preg_replace('/,$/','',$line); |
|
191 | - } |
|
192 | - |
|
193 | - // Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..." |
|
194 | - if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) { |
|
195 | - $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 SERIAL PRIMARY KEY',$line); |
|
196 | - //$line = "-- ".$line." replaced by --\n".$newline; |
|
197 | - $line=$newline; |
|
198 | - } |
|
199 | - |
|
200 | - // tinyint type conversion |
|
201 | - $line=preg_replace('/tinyint\(?[0-9]*\)?/','smallint',$line); |
|
202 | - $line=preg_replace('/tinyint/i','smallint',$line); |
|
203 | - |
|
204 | - // nuke unsigned |
|
205 | - $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
206 | - |
|
207 | - // blob -> text |
|
208 | - $line=preg_replace('/\w*blob/i','text',$line); |
|
209 | - |
|
210 | - // tinytext/mediumtext -> text |
|
211 | - $line=preg_replace('/tinytext/i','text',$line); |
|
212 | - $line=preg_replace('/mediumtext/i','text',$line); |
|
213 | - $line=preg_replace('/longtext/i','text',$line); |
|
214 | - |
|
215 | - $line=preg_replace('/text\([0-9]+\)/i','text',$line); |
|
216 | - |
|
217 | - // change not null datetime field to null valid ones |
|
218 | - // (to support remapping of "zero time" to null |
|
219 | - $line=preg_replace('/datetime not null/i','datetime',$line); |
|
220 | - $line=preg_replace('/datetime/i','timestamp',$line); |
|
221 | - |
|
222 | - // double -> numeric |
|
223 | - $line=preg_replace('/^double/i','numeric',$line); |
|
224 | - $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
225 | - // float -> numeric |
|
226 | - $line=preg_replace('/^float/i','numeric',$line); |
|
227 | - $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
228 | - |
|
229 | - //Check tms timestamp field case (in Mysql this field is defautled to now and |
|
230 | - // on update defaulted by now |
|
231 | - $line=preg_replace('/(\s*)tms(\s*)timestamp/i','\\1tms timestamp without time zone DEFAULT now() NOT NULL',$line); |
|
232 | - |
|
233 | - // nuke ON UPDATE CURRENT_TIMESTAMP |
|
234 | - $line=preg_replace('/(\s*)on(\s*)update(\s*)CURRENT_TIMESTAMP/i','\\1',$line); |
|
235 | - |
|
236 | - // unique index(field1,field2) |
|
237 | - if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
238 | - { |
|
239 | - $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
240 | - } |
|
241 | - |
|
242 | - // We remove end of requests "AFTER fieldxxx" |
|
243 | - $line=preg_replace('/\sAFTER [a-z0-9_]+/i','',$line); |
|
244 | - |
|
245 | - // We remove start of requests "ALTER TABLE tablexxx" if this is a DROP INDEX |
|
246 | - $line=preg_replace('/ALTER TABLE [a-z0-9_]+\s+DROP INDEX/i','DROP INDEX',$line); |
|
247 | - |
|
248 | - // Translate order to rename fields |
|
249 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg)) |
|
250 | - { |
|
251 | - $line = "-- ".$line." replaced by --\n"; |
|
252 | - $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
253 | - } |
|
254 | - |
|
255 | - // Translate order to modify field format |
|
256 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg)) |
|
257 | - { |
|
258 | - $line = "-- ".$line." replaced by --\n"; |
|
259 | - $newreg3=$reg[3]; |
|
260 | - $newreg3=preg_replace('/ DEFAULT NULL/i','',$newreg3); |
|
261 | - $newreg3=preg_replace('/ NOT NULL/i','',$newreg3); |
|
262 | - $newreg3=preg_replace('/ NULL/i','',$newreg3); |
|
263 | - $newreg3=preg_replace('/ DEFAULT 0/i','',$newreg3); |
|
264 | - $newreg3=preg_replace('/ DEFAULT \'?[0-9a-zA-Z_@]*\'?/i','',$newreg3); |
|
265 | - $line.= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3; |
|
266 | - // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
|
267 | - } |
|
268 | - |
|
269 | - // alter table add primary key (field1, field2 ...) -> We remove the primary key name not accepted by PostGreSQL |
|
270 | - // ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity) |
|
271 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i',$line,$reg)) |
|
272 | - { |
|
273 | - $line = "-- ".$line." replaced by --\n"; |
|
274 | - $line.= "ALTER TABLE ".$reg[1]." ADD PRIMARY KEY (".$reg[3]; |
|
275 | - } |
|
276 | - |
|
277 | - // Translate order to drop foreign keys |
|
278 | - // ALTER TABLE llx_dolibarr_modules DROP FOREIGN KEY fk_xxx |
|
279 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
280 | - { |
|
281 | - $line = "-- ".$line." replaced by --\n"; |
|
282 | - $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
283 | - } |
|
284 | - |
|
285 | - // Translate order to add foreign keys |
|
286 | - // ALTER TABLE llx_tablechild ADD CONSTRAINT fk_tablechild_fk_fieldparent FOREIGN KEY (fk_fieldparent) REFERENCES llx_tableparent (rowid) |
|
287 | - if (preg_match('/ALTER\s+TABLE\s+(.*)\s*ADD CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
288 | - { |
|
289 | - $line=preg_replace('/;$/','',$line); |
|
290 | - $line.=" DEFERRABLE INITIALLY IMMEDIATE;"; |
|
291 | - } |
|
292 | - |
|
293 | - // alter table add [unique] [index] (field1, field2 ...) |
|
294 | - // ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version) |
|
295 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i',$line,$reg)) |
|
296 | - { |
|
297 | - $fieldlist=$reg[4]; |
|
298 | - $idxname=$reg[3]; |
|
299 | - $tablename=$reg[1]; |
|
300 | - $line = "-- ".$line." replaced by --\n"; |
|
301 | - $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - // To have postgresql case sensitive |
|
306 | - $line=str_replace(' LIKE \'',' ILIKE \'',$line); |
|
307 | - $line=str_replace(' LIKE BINARY \'',' LIKE \'',$line); |
|
308 | - |
|
309 | - // Replace INSERT IGNORE into INSERT |
|
310 | - $line=preg_replace('/^INSERT IGNORE/','INSERT',$line); |
|
173 | + if ($type == 'auto') |
|
174 | + { |
|
175 | + if (preg_match('/ALTER TABLE/i',$line)) $type='dml'; |
|
176 | + else if (preg_match('/CREATE TABLE/i',$line)) $type='dml'; |
|
177 | + else if (preg_match('/DROP TABLE/i',$line)) $type='dml'; |
|
178 | + } |
|
179 | + |
|
180 | + $line=preg_replace('/ as signed\)/i',' as integer)',$line); |
|
181 | + |
|
182 | + if ($type == 'dml') |
|
183 | + { |
|
184 | + $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
185 | + |
|
186 | + // we are inside create table statement so lets process datatypes |
|
187 | + if (preg_match('/(ISAM|innodb)/i',$line)) { // end of create table sequence |
|
188 | + $line=preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i',');',$line); |
|
189 | + $line=preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i',');',$line); |
|
190 | + $line=preg_replace('/,$/','',$line); |
|
191 | + } |
|
192 | + |
|
193 | + // Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..." |
|
194 | + if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) { |
|
195 | + $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 SERIAL PRIMARY KEY',$line); |
|
196 | + //$line = "-- ".$line." replaced by --\n".$newline; |
|
197 | + $line=$newline; |
|
198 | + } |
|
199 | + |
|
200 | + // tinyint type conversion |
|
201 | + $line=preg_replace('/tinyint\(?[0-9]*\)?/','smallint',$line); |
|
202 | + $line=preg_replace('/tinyint/i','smallint',$line); |
|
203 | + |
|
204 | + // nuke unsigned |
|
205 | + $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
206 | + |
|
207 | + // blob -> text |
|
208 | + $line=preg_replace('/\w*blob/i','text',$line); |
|
209 | + |
|
210 | + // tinytext/mediumtext -> text |
|
211 | + $line=preg_replace('/tinytext/i','text',$line); |
|
212 | + $line=preg_replace('/mediumtext/i','text',$line); |
|
213 | + $line=preg_replace('/longtext/i','text',$line); |
|
214 | + |
|
215 | + $line=preg_replace('/text\([0-9]+\)/i','text',$line); |
|
216 | + |
|
217 | + // change not null datetime field to null valid ones |
|
218 | + // (to support remapping of "zero time" to null |
|
219 | + $line=preg_replace('/datetime not null/i','datetime',$line); |
|
220 | + $line=preg_replace('/datetime/i','timestamp',$line); |
|
221 | + |
|
222 | + // double -> numeric |
|
223 | + $line=preg_replace('/^double/i','numeric',$line); |
|
224 | + $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
225 | + // float -> numeric |
|
226 | + $line=preg_replace('/^float/i','numeric',$line); |
|
227 | + $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
228 | + |
|
229 | + //Check tms timestamp field case (in Mysql this field is defautled to now and |
|
230 | + // on update defaulted by now |
|
231 | + $line=preg_replace('/(\s*)tms(\s*)timestamp/i','\\1tms timestamp without time zone DEFAULT now() NOT NULL',$line); |
|
232 | + |
|
233 | + // nuke ON UPDATE CURRENT_TIMESTAMP |
|
234 | + $line=preg_replace('/(\s*)on(\s*)update(\s*)CURRENT_TIMESTAMP/i','\\1',$line); |
|
235 | + |
|
236 | + // unique index(field1,field2) |
|
237 | + if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
238 | + { |
|
239 | + $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
240 | + } |
|
241 | + |
|
242 | + // We remove end of requests "AFTER fieldxxx" |
|
243 | + $line=preg_replace('/\sAFTER [a-z0-9_]+/i','',$line); |
|
244 | + |
|
245 | + // We remove start of requests "ALTER TABLE tablexxx" if this is a DROP INDEX |
|
246 | + $line=preg_replace('/ALTER TABLE [a-z0-9_]+\s+DROP INDEX/i','DROP INDEX',$line); |
|
247 | + |
|
248 | + // Translate order to rename fields |
|
249 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg)) |
|
250 | + { |
|
251 | + $line = "-- ".$line." replaced by --\n"; |
|
252 | + $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
253 | + } |
|
254 | + |
|
255 | + // Translate order to modify field format |
|
256 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg)) |
|
257 | + { |
|
258 | + $line = "-- ".$line." replaced by --\n"; |
|
259 | + $newreg3=$reg[3]; |
|
260 | + $newreg3=preg_replace('/ DEFAULT NULL/i','',$newreg3); |
|
261 | + $newreg3=preg_replace('/ NOT NULL/i','',$newreg3); |
|
262 | + $newreg3=preg_replace('/ NULL/i','',$newreg3); |
|
263 | + $newreg3=preg_replace('/ DEFAULT 0/i','',$newreg3); |
|
264 | + $newreg3=preg_replace('/ DEFAULT \'?[0-9a-zA-Z_@]*\'?/i','',$newreg3); |
|
265 | + $line.= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3; |
|
266 | + // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
|
267 | + } |
|
268 | + |
|
269 | + // alter table add primary key (field1, field2 ...) -> We remove the primary key name not accepted by PostGreSQL |
|
270 | + // ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity) |
|
271 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i',$line,$reg)) |
|
272 | + { |
|
273 | + $line = "-- ".$line." replaced by --\n"; |
|
274 | + $line.= "ALTER TABLE ".$reg[1]." ADD PRIMARY KEY (".$reg[3]; |
|
275 | + } |
|
276 | + |
|
277 | + // Translate order to drop foreign keys |
|
278 | + // ALTER TABLE llx_dolibarr_modules DROP FOREIGN KEY fk_xxx |
|
279 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
280 | + { |
|
281 | + $line = "-- ".$line." replaced by --\n"; |
|
282 | + $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
283 | + } |
|
284 | + |
|
285 | + // Translate order to add foreign keys |
|
286 | + // ALTER TABLE llx_tablechild ADD CONSTRAINT fk_tablechild_fk_fieldparent FOREIGN KEY (fk_fieldparent) REFERENCES llx_tableparent (rowid) |
|
287 | + if (preg_match('/ALTER\s+TABLE\s+(.*)\s*ADD CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
288 | + { |
|
289 | + $line=preg_replace('/;$/','',$line); |
|
290 | + $line.=" DEFERRABLE INITIALLY IMMEDIATE;"; |
|
291 | + } |
|
292 | + |
|
293 | + // alter table add [unique] [index] (field1, field2 ...) |
|
294 | + // ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version) |
|
295 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i',$line,$reg)) |
|
296 | + { |
|
297 | + $fieldlist=$reg[4]; |
|
298 | + $idxname=$reg[3]; |
|
299 | + $tablename=$reg[1]; |
|
300 | + $line = "-- ".$line." replaced by --\n"; |
|
301 | + $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + // To have postgresql case sensitive |
|
306 | + $line=str_replace(' LIKE \'',' ILIKE \'',$line); |
|
307 | + $line=str_replace(' LIKE BINARY \'',' LIKE \'',$line); |
|
308 | + |
|
309 | + // Replace INSERT IGNORE into INSERT |
|
310 | + $line=preg_replace('/^INSERT IGNORE/','INSERT',$line); |
|
311 | 311 | |
312 | 312 | // Delete using criteria on other table must not declare twice the deleted table |
313 | 313 | // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable |
@@ -353,8 +353,8 @@ discard block |
||
353 | 353 | |
354 | 354 | /** |
355 | 355 | * Select a database |
356 | - * Ici postgresql n'a aucune fonction equivalente de mysql_select_db |
|
357 | - * On compare juste manuellement si la database choisie est bien celle activee par la connexion |
|
356 | + * Ici postgresql n'a aucune fonction equivalente de mysql_select_db |
|
357 | + * On compare juste manuellement si la database choisie est bien celle activee par la connexion |
|
358 | 358 | * |
359 | 359 | * @param string $database Name of database |
360 | 360 | * @return bool true if OK, false if KO |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | // if local connection failed or not requested, use TCP/IP |
402 | 402 | if (! $this->db) |
403 | 403 | { |
404 | - if (! $host) $host = "localhost"; |
|
404 | + if (! $host) $host = "localhost"; |
|
405 | 405 | if (! $port) $port = 5432; |
406 | 406 | |
407 | 407 | $con_string = "host='".$host."' port='".$port."' dbname='".$name."' user='".$login."' password='".$passwd."'"; |
@@ -445,29 +445,29 @@ discard block |
||
445 | 445 | return 'pgsql php driver'; |
446 | 446 | } |
447 | 447 | |
448 | - /** |
|
449 | - * Close database connexion |
|
450 | - * |
|
451 | - * @return boolean True if disconnect successfull, false otherwise |
|
452 | - * @see connect |
|
453 | - */ |
|
454 | - function close() |
|
455 | - { |
|
456 | - if ($this->db) |
|
457 | - { |
|
458 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
459 | - $this->connected=false; |
|
460 | - return pg_close($this->db); |
|
461 | - } |
|
462 | - return false; |
|
463 | - } |
|
448 | + /** |
|
449 | + * Close database connexion |
|
450 | + * |
|
451 | + * @return boolean True if disconnect successfull, false otherwise |
|
452 | + * @see connect |
|
453 | + */ |
|
454 | + function close() |
|
455 | + { |
|
456 | + if ($this->db) |
|
457 | + { |
|
458 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
459 | + $this->connected=false; |
|
460 | + return pg_close($this->db); |
|
461 | + } |
|
462 | + return false; |
|
463 | + } |
|
464 | 464 | |
465 | 465 | /** |
466 | 466 | * Convert request to PostgreSQL syntax, execute it and return the resultset |
467 | 467 | * |
468 | 468 | * @param string $query SQL query string |
469 | 469 | * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollback to savepoint if error (this allow to have some request with errors inside global transactions). |
470 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
470 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
471 | 471 | * @return false|resource Resultset of answer |
472 | 472 | */ |
473 | 473 | function query($query,$usesavepoint=0,$type='auto') |
@@ -509,16 +509,16 @@ discard block |
||
509 | 509 | { |
510 | 510 | if (! $ret) |
511 | 511 | { |
512 | - if ($this->errno() != 'DB_ERROR_25P02') // Do not overwrite errors if this is a consecutive error |
|
513 | - { |
|
514 | - $this->lastqueryerror = $query; |
|
515 | - $this->lasterror = $this->error(); |
|
516 | - $this->lasterrno = $this->errno(); |
|
512 | + if ($this->errno() != 'DB_ERROR_25P02') // Do not overwrite errors if this is a consecutive error |
|
513 | + { |
|
514 | + $this->lastqueryerror = $query; |
|
515 | + $this->lasterror = $this->error(); |
|
516 | + $this->lasterrno = $this->errno(); |
|
517 | 517 | |
518 | - if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); // Log of request was not yet done previously |
|
518 | + if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); // Log of request was not yet done previously |
|
519 | 519 | dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR); |
520 | 520 | dol_syslog(get_class($this)."::query SQL Error usesavepoint = ".$usesavepoint, LOG_ERR); |
521 | - } |
|
521 | + } |
|
522 | 522 | |
523 | 523 | if ($usesavepoint && $this->transaction_opened) // Warning, after that errno will be erased |
524 | 524 | { |
@@ -540,29 +540,29 @@ discard block |
||
540 | 540 | */ |
541 | 541 | function fetch_object($resultset) |
542 | 542 | { |
543 | - // If resultset not provided, we take the last used by connexion |
|
543 | + // If resultset not provided, we take the last used by connexion |
|
544 | 544 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
545 | 545 | return pg_fetch_object($resultset); |
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
549 | - * Return datas as an array |
|
550 | - * |
|
551 | - * @param resource $resultset Resultset of request |
|
552 | - * @return false|array Array |
|
549 | + * Return datas as an array |
|
550 | + * |
|
551 | + * @param resource $resultset Resultset of request |
|
552 | + * @return false|array Array |
|
553 | 553 | */ |
554 | 554 | function fetch_array($resultset) |
555 | 555 | { |
556 | - // If resultset not provided, we take the last used by connexion |
|
556 | + // If resultset not provided, we take the last used by connexion |
|
557 | 557 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
558 | 558 | return pg_fetch_array($resultset); |
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
562 | - * Return datas as an array |
|
563 | - * |
|
564 | - * @param resource $resultset Resultset of request |
|
565 | - * @return false|array Array |
|
562 | + * Return datas as an array |
|
563 | + * |
|
564 | + * @param resource $resultset Resultset of request |
|
565 | + * @return false|array Array |
|
566 | 566 | */ |
567 | 567 | function fetch_row($resultset) |
568 | 568 | { |
@@ -572,15 +572,15 @@ discard block |
||
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
575 | - * Return number of lines for result of a SELECT |
|
576 | - * |
|
577 | - * @param resourse $resultset Resulset of requests |
|
578 | - * @return int Nb of lines, -1 on error |
|
579 | - * @see affected_rows |
|
575 | + * Return number of lines for result of a SELECT |
|
576 | + * |
|
577 | + * @param resourse $resultset Resulset of requests |
|
578 | + * @return int Nb of lines, -1 on error |
|
579 | + * @see affected_rows |
|
580 | 580 | */ |
581 | 581 | function num_rows($resultset) |
582 | 582 | { |
583 | - // If resultset not provided, we take the last used by connexion |
|
583 | + // If resultset not provided, we take the last used by connexion |
|
584 | 584 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
585 | 585 | return pg_num_rows($resultset); |
586 | 586 | } |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | */ |
595 | 595 | function affected_rows($resultset) |
596 | 596 | { |
597 | - // If resultset not provided, we take the last used by connexion |
|
597 | + // If resultset not provided, we take the last used by connexion |
|
598 | 598 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
599 | 599 | // pgsql necessite un resultset pour cette fonction contrairement |
600 | 600 | // a mysql qui prend un link de base |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | */ |
611 | 611 | function free($resultset=null) |
612 | 612 | { |
613 | - // If resultset not provided, we take the last used by connexion |
|
613 | + // If resultset not provided, we take the last used by connexion |
|
614 | 614 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
615 | 615 | // Si resultset en est un, on libere la memoire |
616 | 616 | if (is_resource($resultset)) pg_free_result($resultset); |
@@ -618,16 +618,16 @@ discard block |
||
618 | 618 | |
619 | 619 | |
620 | 620 | /** |
621 | - * Define limits and offset of request |
|
622 | - * |
|
623 | - * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) |
|
624 | - * @param int $offset Numero of line from where starting fetch |
|
625 | - * @return string String with SQL syntax to add a limit and offset |
|
621 | + * Define limits and offset of request |
|
622 | + * |
|
623 | + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) |
|
624 | + * @param int $offset Numero of line from where starting fetch |
|
625 | + * @return string String with SQL syntax to add a limit and offset |
|
626 | 626 | */ |
627 | 627 | function plimit($limit=0,$offset=0) |
628 | 628 | { |
629 | 629 | global $conf; |
630 | - if (empty($limit)) return ""; |
|
630 | + if (empty($limit)) return ""; |
|
631 | 631 | if ($limit < 0) $limit=$conf->liste_limit; |
632 | 632 | if ($offset > 0) return " LIMIT ".$limit." OFFSET ".$offset." "; |
633 | 633 | else return " LIMIT $limit "; |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | return pg_escape_string($stringtoencode); |
646 | 646 | } |
647 | 647 | |
648 | - /** |
|
648 | + /** |
|
649 | 649 | * Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. |
650 | 650 | * Function to use to build INSERT, UPDATE or WHERE predica |
651 | 651 | * |
@@ -658,8 +658,8 @@ discard block |
||
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
661 | - * Format a SQL IF |
|
662 | - * |
|
661 | + * Format a SQL IF |
|
662 | + * |
|
663 | 663 | * @param string $test Test string (example: 'cd.statut=0', 'field IS NULL') |
664 | 664 | * @param string $resok resultat si test egal |
665 | 665 | * @param string $resko resultat si test non egal |
@@ -768,12 +768,12 @@ discard block |
||
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
771 | - * Encrypt sensitive data in database |
|
772 | - * Warning: This function includes the escape, so it must use direct value |
|
773 | - * |
|
774 | - * @param string $fieldorvalue Field name or value to encrypt |
|
775 | - * @param int $withQuotes Return string with quotes |
|
776 | - * @return string XXX(field) or XXX('value') or field or 'value' |
|
771 | + * Encrypt sensitive data in database |
|
772 | + * Warning: This function includes the escape, so it must use direct value |
|
773 | + * |
|
774 | + * @param string $fieldorvalue Field name or value to encrypt |
|
775 | + * @param int $withQuotes Return string with quotes |
|
776 | + * @return string XXX(field) or XXX('value') or field or 'value' |
|
777 | 777 | */ |
778 | 778 | function encrypt($fieldorvalue, $withQuotes=0) |
779 | 779 | { |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | */ |
837 | 837 | function DDLCreateDb($database,$charset='',$collation='',$owner='') |
838 | 838 | { |
839 | - if (empty($charset)) $charset=$this->forcecharset; |
|
839 | + if (empty($charset)) $charset=$this->forcecharset; |
|
840 | 840 | if (empty($collation)) $collation=$this->forcecollate; |
841 | 841 | |
842 | 842 | // Test charset match LC_TYPE (pgsql error otherwise) |
@@ -862,13 +862,13 @@ discard block |
||
862 | 862 | $like = ''; |
863 | 863 | if ($table) $like = " AND table_name LIKE '".$table."'"; |
864 | 864 | $result = pg_query($this->db, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'".$like." ORDER BY table_name"); |
865 | - if ($result) |
|
866 | - { |
|
867 | - while($row = $this->fetch_row($result)) |
|
868 | - { |
|
869 | - $listtables[] = $row[0]; |
|
870 | - } |
|
871 | - } |
|
865 | + if ($result) |
|
866 | + { |
|
867 | + while($row = $this->fetch_row($result)) |
|
868 | + { |
|
869 | + $listtables[] = $row[0]; |
|
870 | + } |
|
871 | + } |
|
872 | 872 | return $listtables; |
873 | 873 | } |
874 | 874 | |
@@ -903,12 +903,12 @@ discard block |
||
903 | 903 | $result = $this->query($sql); |
904 | 904 | if ($result) |
905 | 905 | { |
906 | - while($row = $this->fetch_row($result)) |
|
907 | - { |
|
908 | - $infotables[] = $row; |
|
909 | - } |
|
906 | + while($row = $this->fetch_row($result)) |
|
907 | + { |
|
908 | + $infotables[] = $row; |
|
909 | + } |
|
910 | 910 | } |
911 | - return $infotables; |
|
911 | + return $infotables; |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | |
@@ -1049,10 +1049,10 @@ discard block |
||
1049 | 1049 | $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
1050 | 1050 | $sql .= $field_desc['type']; |
1051 | 1051 | if(preg_match("/^[^\s]/i",$field_desc['value'])) |
1052 | - if (! in_array($field_desc['type'],array('int','date','datetime'))) |
|
1053 | - { |
|
1054 | - $sql.= "(".$field_desc['value'].")"; |
|
1055 | - } |
|
1052 | + if (! in_array($field_desc['type'],array('int','date','datetime'))) |
|
1053 | + { |
|
1054 | + $sql.= "(".$field_desc['value'].")"; |
|
1055 | + } |
|
1056 | 1056 | if (preg_match("/^[^\s]/i",$field_desc['attribute'])) |
1057 | 1057 | $sql .= " ".$field_desc['attribute']; |
1058 | 1058 | if (preg_match("/^[^\s]/i",$field_desc['null'])) |
@@ -1090,23 +1090,23 @@ discard block |
||
1090 | 1090 | |
1091 | 1091 | if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') |
1092 | 1092 | { |
1093 | - // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL |
|
1094 | - if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
|
1095 | - { |
|
1096 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
1097 | - $this->query($sqlbis); |
|
1098 | - } |
|
1099 | - elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
1100 | - { |
|
1101 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
1102 | - $this->query($sqlbis); |
|
1103 | - } |
|
1093 | + // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL |
|
1094 | + if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
|
1095 | + { |
|
1096 | + $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
1097 | + $this->query($sqlbis); |
|
1098 | + } |
|
1099 | + elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
1100 | + { |
|
1101 | + $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
1102 | + $this->query($sqlbis); |
|
1103 | + } |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | if ($field_desc['default'] != '') |
1107 | 1107 | { |
1108 | 1108 | if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']); |
1109 | - elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
1109 | + elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
1110 | 1110 | } |
1111 | 1111 | |
1112 | 1112 | dol_syslog($sql,LOG_DEBUG); |
@@ -1144,8 +1144,8 @@ discard block |
||
1144 | 1144 | $resql=$this->query('SHOW SERVER_ENCODING'); |
1145 | 1145 | if ($resql) |
1146 | 1146 | { |
1147 | - $liste=$this->fetch_array($resql); |
|
1148 | - return $liste['server_encoding']; |
|
1147 | + $liste=$this->fetch_array($resql); |
|
1148 | + return $liste['server_encoding']; |
|
1149 | 1149 | } |
1150 | 1150 | else return ''; |
1151 | 1151 | } |
@@ -1185,7 +1185,7 @@ discard block |
||
1185 | 1185 | $resql=$this->query('SHOW LC_COLLATE'); |
1186 | 1186 | if ($resql) |
1187 | 1187 | { |
1188 | - $liste=$this->fetch_array($resql); |
|
1188 | + $liste=$this->fetch_array($resql); |
|
1189 | 1189 | return $liste['lc_collate']; |
1190 | 1190 | } |
1191 | 1191 | else return ''; |
@@ -1226,28 +1226,28 @@ discard block |
||
1226 | 1226 | |
1227 | 1227 | if (file_exists('/usr/bin/pg_dump')) |
1228 | 1228 | { |
1229 | - $fullpathofdump='/usr/bin/pg_dump'; |
|
1229 | + $fullpathofdump='/usr/bin/pg_dump'; |
|
1230 | 1230 | } |
1231 | 1231 | else |
1232 | 1232 | { |
1233 | - // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
|
1234 | - $resql=$this->query('SHOW data_directory'); |
|
1235 | - if ($resql) |
|
1236 | - { |
|
1237 | - $liste=$this->fetch_array($resql); |
|
1238 | - $basedir=$liste['data_directory']; |
|
1239 | - $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_dump'; |
|
1240 | - } |
|
1233 | + // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
|
1234 | + $resql=$this->query('SHOW data_directory'); |
|
1235 | + if ($resql) |
|
1236 | + { |
|
1237 | + $liste=$this->fetch_array($resql); |
|
1238 | + $basedir=$liste['data_directory']; |
|
1239 | + $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_dump'; |
|
1240 | + } |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | return $fullpathofdump; |
1244 | 1244 | } |
1245 | 1245 | |
1246 | - /** |
|
1247 | - * Return full path of restore program |
|
1248 | - * |
|
1249 | - * @return string Full path of restore program |
|
1250 | - */ |
|
1246 | + /** |
|
1247 | + * Return full path of restore program |
|
1248 | + * |
|
1249 | + * @return string Full path of restore program |
|
1250 | + */ |
|
1251 | 1251 | function getPathOfRestore() |
1252 | 1252 | { |
1253 | 1253 | //$tool='pg_restore'; |
@@ -1255,21 +1255,21 @@ discard block |
||
1255 | 1255 | |
1256 | 1256 | $fullpathofdump='/pathtopgrestore/'.$tool; |
1257 | 1257 | |
1258 | - if (file_exists('/usr/bin/'.$tool)) |
|
1259 | - { |
|
1260 | - $fullpathofdump='/usr/bin/'.$tool; |
|
1261 | - } |
|
1262 | - else |
|
1263 | - { |
|
1264 | - // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
|
1265 | - $resql=$this->query('SHOW data_directory'); |
|
1266 | - if ($resql) |
|
1267 | - { |
|
1268 | - $liste=$this->fetch_array($resql); |
|
1269 | - $basedir=$liste['data_directory']; |
|
1270 | - $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/'.$tool; |
|
1271 | - } |
|
1272 | - } |
|
1258 | + if (file_exists('/usr/bin/'.$tool)) |
|
1259 | + { |
|
1260 | + $fullpathofdump='/usr/bin/'.$tool; |
|
1261 | + } |
|
1262 | + else |
|
1263 | + { |
|
1264 | + // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
|
1265 | + $resql=$this->query('SHOW data_directory'); |
|
1266 | + if ($resql) |
|
1267 | + { |
|
1268 | + $liste=$this->fetch_array($resql); |
|
1269 | + $basedir=$liste['data_directory']; |
|
1270 | + $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/'.$tool; |
|
1271 | + } |
|
1272 | + } |
|
1273 | 1273 | |
1274 | 1274 | return $fullpathofdump; |
1275 | 1275 | } |
@@ -1449,7 +1449,7 @@ |
||
1449 | 1449 | * |
1450 | 1450 | * @param int $daynr ??? |
1451 | 1451 | * @param bool $sunday_first_day_of_week ??? |
1452 | - * @return int |
|
1452 | + * @return double |
|
1453 | 1453 | */ |
1454 | 1454 | private static function calc_weekday($daynr, $sunday_first_day_of_week) { |
1455 | 1455 | $ret = floor(($daynr + 5 + ($sunday_first_day_of_week ? 1 : 0)) % 7); |
@@ -32,48 +32,48 @@ discard block |
||
32 | 32 | */ |
33 | 33 | class DoliDBSqlite3 extends DoliDB |
34 | 34 | { |
35 | - //! Database type |
|
36 | - public $type='sqlite3'; |
|
37 | - //! Database label |
|
38 | - const LABEL='Sqlite3'; |
|
39 | - //! Version min database |
|
40 | - const VERSIONMIN='3.0.0'; |
|
35 | + //! Database type |
|
36 | + public $type='sqlite3'; |
|
37 | + //! Database label |
|
38 | + const LABEL='Sqlite3'; |
|
39 | + //! Version min database |
|
40 | + const VERSIONMIN='3.0.0'; |
|
41 | 41 | /** @var SQLite3Result Resultset of last query */ |
42 | 42 | private $_results; |
43 | 43 | |
44 | - const WEEK_MONDAY_FIRST=1; |
|
45 | - const WEEK_YEAR = 2; |
|
46 | - const WEEK_FIRST_WEEKDAY=4; |
|
44 | + const WEEK_MONDAY_FIRST=1; |
|
45 | + const WEEK_YEAR = 2; |
|
46 | + const WEEK_FIRST_WEEKDAY=4; |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
49 | + /** |
|
50 | 50 | * Constructor. |
51 | 51 | * This create an opened connexion to a database server and eventually to a database |
52 | - * |
|
52 | + * |
|
53 | 53 | * @param string $type Type of database (mysql, pgsql...) |
54 | 54 | * @param string $host Address of database server |
55 | 55 | * @param string $user Nom de l'utilisateur autorise |
56 | 56 | * @param string $pass Mot de passe |
57 | 57 | * @param string $name Nom de la database |
58 | 58 | * @param int $port Port of database server |
59 | - */ |
|
60 | - function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
61 | - { |
|
62 | - global $conf; |
|
59 | + */ |
|
60 | + function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
61 | + { |
|
62 | + global $conf; |
|
63 | 63 | |
64 | - // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
|
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; |
|
64 | + // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
|
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; |
|
67 | 67 | |
68 | - $this->database_user=$user; |
|
69 | - $this->database_host=$host; |
|
70 | - $this->database_port=$port; |
|
68 | + $this->database_user=$user; |
|
69 | + $this->database_host=$host; |
|
70 | + $this->database_port=$port; |
|
71 | 71 | |
72 | - $this->transaction_opened=0; |
|
72 | + $this->transaction_opened=0; |
|
73 | 73 | |
74 | - //print "Name DB: $host,$user,$pass,$name<br>"; |
|
74 | + //print "Name DB: $host,$user,$pass,$name<br>"; |
|
75 | 75 | |
76 | - /*if (! function_exists("sqlite_query")) |
|
76 | + /*if (! function_exists("sqlite_query")) |
|
77 | 77 | { |
78 | 78 | $this->connected = false; |
79 | 79 | $this->ok = false; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | return $this->ok; |
83 | 83 | }*/ |
84 | 84 | |
85 | - /*if (! $host) |
|
85 | + /*if (! $host) |
|
86 | 86 | { |
87 | 87 | $this->connected = false; |
88 | 88 | $this->ok = false; |
@@ -91,229 +91,229 @@ discard block |
||
91 | 91 | return $this->ok; |
92 | 92 | }*/ |
93 | 93 | |
94 | - // Essai connexion serveur |
|
95 | - // We do not try to connect to database, only to server. Connect to database is done later in constrcutor |
|
96 | - $this->db = $this->connect($host, $user, $pass, $name, $port); |
|
94 | + // Essai connexion serveur |
|
95 | + // We do not try to connect to database, only to server. Connect to database is done later in constrcutor |
|
96 | + $this->db = $this->connect($host, $user, $pass, $name, $port); |
|
97 | + |
|
98 | + if ($this->db) |
|
99 | + { |
|
100 | + $this->connected = true; |
|
101 | + $this->ok = true; |
|
102 | + $this->database_selected = true; |
|
103 | + $this->database_name = $name; |
|
104 | + |
|
105 | + $this->addCustomFunction('IF'); |
|
106 | + $this->addCustomFunction('MONTH'); |
|
107 | + $this->addCustomFunction('CURTIME'); |
|
108 | + $this->addCustomFunction('CURDATE'); |
|
109 | + $this->addCustomFunction('WEEK', 1); |
|
110 | + $this->addCustomFunction('WEEK', 2); |
|
111 | + $this->addCustomFunction('WEEKDAY'); |
|
112 | + $this->addCustomFunction('date_format'); |
|
113 | + //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
114 | + } |
|
115 | + else |
|
116 | + { |
|
117 | + // host, login ou password incorrect |
|
118 | + $this->connected = false; |
|
119 | + $this->ok = false; |
|
120 | + $this->database_selected = false; |
|
121 | + $this->database_name = ''; |
|
122 | + //$this->error=sqlite_connect_error(); |
|
123 | + dol_syslog(get_class($this)."::DoliDBSqlite3 : Error Connect ".$this->error,LOG_ERR); |
|
124 | + } |
|
125 | + |
|
126 | + return $this->ok; |
|
127 | + } |
|
97 | 128 | |
98 | - if ($this->db) |
|
99 | - { |
|
100 | - $this->connected = true; |
|
101 | - $this->ok = true; |
|
102 | - $this->database_selected = true; |
|
103 | - $this->database_name = $name; |
|
104 | - |
|
105 | - $this->addCustomFunction('IF'); |
|
106 | - $this->addCustomFunction('MONTH'); |
|
107 | - $this->addCustomFunction('CURTIME'); |
|
108 | - $this->addCustomFunction('CURDATE'); |
|
109 | - $this->addCustomFunction('WEEK', 1); |
|
110 | - $this->addCustomFunction('WEEK', 2); |
|
111 | - $this->addCustomFunction('WEEKDAY'); |
|
112 | - $this->addCustomFunction('date_format'); |
|
113 | - //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
114 | - } |
|
115 | - else |
|
116 | - { |
|
117 | - // host, login ou password incorrect |
|
118 | - $this->connected = false; |
|
119 | - $this->ok = false; |
|
120 | - $this->database_selected = false; |
|
121 | - $this->database_name = ''; |
|
122 | - //$this->error=sqlite_connect_error(); |
|
123 | - dol_syslog(get_class($this)."::DoliDBSqlite3 : Error Connect ".$this->error,LOG_ERR); |
|
124 | - } |
|
125 | 129 | |
126 | - return $this->ok; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Convert a SQL request in Mysql syntax to native syntax |
|
132 | - * |
|
133 | - * @param string $line SQL request line to convert |
|
134 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
135 | - * @return string SQL request line converted |
|
136 | - */ |
|
137 | - static function convertSQLFromMysql($line,$type='ddl') |
|
138 | - { |
|
139 | - // Removed empty line if this is a comment line for SVN tagging |
|
140 | - if (preg_match('/^--\s\$Id/i',$line)) { |
|
141 | - return ''; |
|
142 | - } |
|
143 | - // Return line if this is a comment |
|
144 | - if (preg_match('/^#/i',$line) || preg_match('/^$/i',$line) || preg_match('/^--/i',$line)) |
|
145 | - { |
|
146 | - return $line; |
|
147 | - } |
|
148 | - if ($line != "") |
|
149 | - { |
|
150 | - if ($type == 'auto') |
|
151 | - { |
|
152 | - if (preg_match('/ALTER TABLE/i',$line)) $type='dml'; |
|
153 | - else if (preg_match('/CREATE TABLE/i',$line)) $type='dml'; |
|
154 | - else if (preg_match('/DROP TABLE/i',$line)) $type='dml'; |
|
155 | - } |
|
156 | - |
|
157 | - if ($type == 'dml') |
|
158 | - { |
|
159 | - $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
160 | - |
|
161 | - // we are inside create table statement so lets process datatypes |
|
162 | - if (preg_match('/(ISAM|innodb)/i',$line)) { // end of create table sequence |
|
163 | - $line=preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb);/i',');',$line); |
|
164 | - $line=preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb);/i',');',$line); |
|
165 | - $line=preg_replace('/,$/','',$line); |
|
166 | - } |
|
167 | - |
|
168 | - // Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..." |
|
169 | - if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) { |
|
170 | - $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 integer PRIMARY KEY AUTOINCREMENT',$line); |
|
171 | - //$line = "-- ".$line." replaced by --\n".$newline; |
|
172 | - $line=$newline; |
|
173 | - } |
|
174 | - |
|
175 | - // tinyint type conversion |
|
176 | - $line=str_replace('tinyint','smallint',$line); |
|
177 | - |
|
178 | - // nuke unsigned |
|
179 | - $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
180 | - |
|
181 | - // blob -> text |
|
182 | - $line=preg_replace('/\w*blob/i','text',$line); |
|
183 | - |
|
184 | - // tinytext/mediumtext -> text |
|
185 | - $line=preg_replace('/tinytext/i','text',$line); |
|
186 | - $line=preg_replace('/mediumtext/i','text',$line); |
|
187 | - |
|
188 | - // change not null datetime field to null valid ones |
|
189 | - // (to support remapping of "zero time" to null |
|
190 | - $line=preg_replace('/datetime not null/i','datetime',$line); |
|
191 | - $line=preg_replace('/datetime/i','timestamp',$line); |
|
192 | - |
|
193 | - // double -> numeric |
|
194 | - $line=preg_replace('/^double/i','numeric',$line); |
|
195 | - $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
196 | - // float -> numeric |
|
197 | - $line=preg_replace('/^float/i','numeric',$line); |
|
198 | - $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
199 | - |
|
200 | - // unique index(field1,field2) |
|
201 | - if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
202 | - { |
|
203 | - $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
204 | - } |
|
205 | - |
|
206 | - // We remove end of requests "AFTER fieldxxx" |
|
207 | - $line=preg_replace('/AFTER [a-z0-9_]+/i','',$line); |
|
208 | - |
|
209 | - // We remove start of requests "ALTER TABLE tablexxx" if this is a DROP INDEX |
|
210 | - $line=preg_replace('/ALTER TABLE [a-z0-9_]+ DROP INDEX/i','DROP INDEX',$line); |
|
211 | - |
|
212 | - // Translate order to rename fields |
|
213 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+) CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg)) |
|
214 | - { |
|
215 | - $line = "-- ".$line." replaced by --\n"; |
|
216 | - $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
217 | - } |
|
218 | - |
|
219 | - // Translate order to modify field format |
|
220 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+) MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg)) |
|
221 | - { |
|
222 | - $line = "-- ".$line." replaced by --\n"; |
|
223 | - $newreg3=$reg[3]; |
|
224 | - $newreg3=preg_replace('/ DEFAULT NULL/i','',$newreg3); |
|
225 | - $newreg3=preg_replace('/ NOT NULL/i','',$newreg3); |
|
226 | - $newreg3=preg_replace('/ NULL/i','',$newreg3); |
|
227 | - $newreg3=preg_replace('/ DEFAULT 0/i','',$newreg3); |
|
228 | - $newreg3=preg_replace('/ DEFAULT \'[0-9a-zA-Z_@]*\'/i','',$newreg3); |
|
229 | - $line.= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3; |
|
230 | - // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
|
231 | - } |
|
232 | - |
|
233 | - // alter table add primary key (field1, field2 ...) -> We create a unique index instead as dynamic creation of primary key is not supported |
|
234 | - // ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity); |
|
235 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i',$line,$reg)) |
|
236 | - { |
|
237 | - $line = "-- ".$line." replaced by --\n"; |
|
238 | - $line.= "CREATE UNIQUE INDEX ".$reg[2]." ON ".$reg[1]."(".$reg[3]; |
|
239 | - } |
|
240 | - |
|
241 | - // Translate order to drop foreign keys |
|
242 | - // ALTER TABLE llx_dolibarr_modules DROP FOREIGN KEY fk_xxx; |
|
243 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
244 | - { |
|
245 | - $line = "-- ".$line." replaced by --\n"; |
|
246 | - $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
247 | - } |
|
248 | - |
|
249 | - // alter table add [unique] [index] (field1, field2 ...) |
|
250 | - // ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version) |
|
251 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i',$line,$reg)) |
|
252 | - { |
|
253 | - $fieldlist=$reg[4]; |
|
254 | - $idxname=$reg[3]; |
|
255 | - $tablename=$reg[1]; |
|
256 | - $line = "-- ".$line." replaced by --\n"; |
|
257 | - $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
258 | - } |
|
259 | - 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)) { |
|
260 | - // Pour l'instant les contraintes ne sont pas créées |
|
261 | - dol_syslog(get_class().'::query line emptied'); |
|
262 | - $line = 'SELECT 0;'; |
|
263 | - |
|
264 | - } |
|
265 | - |
|
266 | - //if (preg_match('/rowid\s+.*\s+PRIMARY\s+KEY,/i', $line)) { |
|
267 | - //preg_replace('/(rowid\s+.*\s+PRIMARY\s+KEY\s*,)/i', '/* \\1 */', $line); |
|
268 | - //} |
|
269 | - } |
|
270 | - |
|
271 | - // Delete using criteria on other table must not declare twice the deleted table |
|
272 | - // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable |
|
273 | - if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg)) |
|
274 | - { |
|
130 | + /** |
|
131 | + * Convert a SQL request in Mysql syntax to native syntax |
|
132 | + * |
|
133 | + * @param string $line SQL request line to convert |
|
134 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
135 | + * @return string SQL request line converted |
|
136 | + */ |
|
137 | + static function convertSQLFromMysql($line,$type='ddl') |
|
138 | + { |
|
139 | + // Removed empty line if this is a comment line for SVN tagging |
|
140 | + if (preg_match('/^--\s\$Id/i',$line)) { |
|
141 | + return ''; |
|
142 | + } |
|
143 | + // Return line if this is a comment |
|
144 | + if (preg_match('/^#/i',$line) || preg_match('/^$/i',$line) || preg_match('/^--/i',$line)) |
|
145 | + { |
|
146 | + return $line; |
|
147 | + } |
|
148 | + if ($line != "") |
|
149 | + { |
|
150 | + if ($type == 'auto') |
|
151 | + { |
|
152 | + if (preg_match('/ALTER TABLE/i',$line)) $type='dml'; |
|
153 | + else if (preg_match('/CREATE TABLE/i',$line)) $type='dml'; |
|
154 | + else if (preg_match('/DROP TABLE/i',$line)) $type='dml'; |
|
155 | + } |
|
156 | + |
|
157 | + if ($type == 'dml') |
|
158 | + { |
|
159 | + $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
160 | + |
|
161 | + // we are inside create table statement so lets process datatypes |
|
162 | + if (preg_match('/(ISAM|innodb)/i',$line)) { // end of create table sequence |
|
163 | + $line=preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb);/i',');',$line); |
|
164 | + $line=preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb);/i',');',$line); |
|
165 | + $line=preg_replace('/,$/','',$line); |
|
166 | + } |
|
167 | + |
|
168 | + // Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..." |
|
169 | + if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) { |
|
170 | + $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 integer PRIMARY KEY AUTOINCREMENT',$line); |
|
171 | + //$line = "-- ".$line." replaced by --\n".$newline; |
|
172 | + $line=$newline; |
|
173 | + } |
|
174 | + |
|
175 | + // tinyint type conversion |
|
176 | + $line=str_replace('tinyint','smallint',$line); |
|
177 | + |
|
178 | + // nuke unsigned |
|
179 | + $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
180 | + |
|
181 | + // blob -> text |
|
182 | + $line=preg_replace('/\w*blob/i','text',$line); |
|
183 | + |
|
184 | + // tinytext/mediumtext -> text |
|
185 | + $line=preg_replace('/tinytext/i','text',$line); |
|
186 | + $line=preg_replace('/mediumtext/i','text',$line); |
|
187 | + |
|
188 | + // change not null datetime field to null valid ones |
|
189 | + // (to support remapping of "zero time" to null |
|
190 | + $line=preg_replace('/datetime not null/i','datetime',$line); |
|
191 | + $line=preg_replace('/datetime/i','timestamp',$line); |
|
192 | + |
|
193 | + // double -> numeric |
|
194 | + $line=preg_replace('/^double/i','numeric',$line); |
|
195 | + $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
196 | + // float -> numeric |
|
197 | + $line=preg_replace('/^float/i','numeric',$line); |
|
198 | + $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
199 | + |
|
200 | + // unique index(field1,field2) |
|
201 | + if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
202 | + { |
|
203 | + $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
204 | + } |
|
205 | + |
|
206 | + // We remove end of requests "AFTER fieldxxx" |
|
207 | + $line=preg_replace('/AFTER [a-z0-9_]+/i','',$line); |
|
208 | + |
|
209 | + // We remove start of requests "ALTER TABLE tablexxx" if this is a DROP INDEX |
|
210 | + $line=preg_replace('/ALTER TABLE [a-z0-9_]+ DROP INDEX/i','DROP INDEX',$line); |
|
211 | + |
|
212 | + // Translate order to rename fields |
|
213 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+) CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg)) |
|
214 | + { |
|
215 | + $line = "-- ".$line." replaced by --\n"; |
|
216 | + $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
217 | + } |
|
218 | + |
|
219 | + // Translate order to modify field format |
|
220 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+) MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg)) |
|
221 | + { |
|
222 | + $line = "-- ".$line." replaced by --\n"; |
|
223 | + $newreg3=$reg[3]; |
|
224 | + $newreg3=preg_replace('/ DEFAULT NULL/i','',$newreg3); |
|
225 | + $newreg3=preg_replace('/ NOT NULL/i','',$newreg3); |
|
226 | + $newreg3=preg_replace('/ NULL/i','',$newreg3); |
|
227 | + $newreg3=preg_replace('/ DEFAULT 0/i','',$newreg3); |
|
228 | + $newreg3=preg_replace('/ DEFAULT \'[0-9a-zA-Z_@]*\'/i','',$newreg3); |
|
229 | + $line.= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3; |
|
230 | + // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
|
231 | + } |
|
232 | + |
|
233 | + // alter table add primary key (field1, field2 ...) -> We create a unique index instead as dynamic creation of primary key is not supported |
|
234 | + // ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity); |
|
235 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i',$line,$reg)) |
|
236 | + { |
|
237 | + $line = "-- ".$line." replaced by --\n"; |
|
238 | + $line.= "CREATE UNIQUE INDEX ".$reg[2]." ON ".$reg[1]."(".$reg[3]; |
|
239 | + } |
|
240 | + |
|
241 | + // Translate order to drop foreign keys |
|
242 | + // ALTER TABLE llx_dolibarr_modules DROP FOREIGN KEY fk_xxx; |
|
243 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
244 | + { |
|
245 | + $line = "-- ".$line." replaced by --\n"; |
|
246 | + $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
247 | + } |
|
248 | + |
|
249 | + // alter table add [unique] [index] (field1, field2 ...) |
|
250 | + // ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version) |
|
251 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i',$line,$reg)) |
|
252 | + { |
|
253 | + $fieldlist=$reg[4]; |
|
254 | + $idxname=$reg[3]; |
|
255 | + $tablename=$reg[1]; |
|
256 | + $line = "-- ".$line." replaced by --\n"; |
|
257 | + $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
258 | + } |
|
259 | + 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)) { |
|
260 | + // Pour l'instant les contraintes ne sont pas créées |
|
261 | + dol_syslog(get_class().'::query line emptied'); |
|
262 | + $line = 'SELECT 0;'; |
|
263 | + |
|
264 | + } |
|
265 | + |
|
266 | + //if (preg_match('/rowid\s+.*\s+PRIMARY\s+KEY,/i', $line)) { |
|
267 | + //preg_replace('/(rowid\s+.*\s+PRIMARY\s+KEY\s*,)/i', '/* \\1 */', $line); |
|
268 | + //} |
|
269 | + } |
|
270 | + |
|
271 | + // Delete using criteria on other table must not declare twice the deleted table |
|
272 | + // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable |
|
273 | + if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg)) |
|
274 | + { |
|
275 | 275 | if ($reg[1] == $reg[2]) // If same table, we remove second one |
276 | - { |
|
277 | - $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line); |
|
278 | - } |
|
279 | - } |
|
276 | + { |
|
277 | + $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line); |
|
278 | + } |
|
279 | + } |
|
280 | 280 | |
281 | - // Remove () in the tables in FROM if one table |
|
282 | - $line=preg_replace('/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i','FROM \\1',$line); |
|
283 | - //print $line."\n"; |
|
281 | + // Remove () in the tables in FROM if one table |
|
282 | + $line=preg_replace('/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i','FROM \\1',$line); |
|
283 | + //print $line."\n"; |
|
284 | 284 | |
285 | - // Remove () in the tables in FROM if two table |
|
286 | - $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 | - //print $line."\n"; |
|
285 | + // Remove () in the tables in FROM if two table |
|
286 | + $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 | + //print $line."\n"; |
|
288 | 288 | |
289 | - // Remove () in the tables in FROM if two table |
|
290 | - $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); |
|
291 | - //print $line."\n"; |
|
289 | + // Remove () in the tables in FROM if two table |
|
290 | + $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); |
|
291 | + //print $line."\n"; |
|
292 | 292 | |
293 | - //print "type=".$type." newline=".$line."<br>\n"; |
|
294 | - } |
|
293 | + //print "type=".$type." newline=".$line."<br>\n"; |
|
294 | + } |
|
295 | 295 | |
296 | - return $line; |
|
297 | - } |
|
296 | + return $line; |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
299 | + /** |
|
300 | 300 | * Select a database |
301 | - * |
|
301 | + * |
|
302 | 302 | * @param string $database Name of database |
303 | 303 | * @return boolean true if OK, false if KO |
304 | - */ |
|
305 | - function select_db($database) |
|
306 | - { |
|
307 | - dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); |
|
308 | - // sqlite_select_db() does not exist |
|
309 | - //return sqlite_select_db($this->db,$database); |
|
310 | - return true; |
|
311 | - } |
|
304 | + */ |
|
305 | + function select_db($database) |
|
306 | + { |
|
307 | + dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); |
|
308 | + // sqlite_select_db() does not exist |
|
309 | + //return sqlite_select_db($this->db,$database); |
|
310 | + return true; |
|
311 | + } |
|
312 | 312 | |
313 | 313 | |
314 | - /** |
|
314 | + /** |
|
315 | 315 | * Connexion to server |
316 | - * |
|
316 | + * |
|
317 | 317 | * @param string $host database server host |
318 | 318 | * @param string $login login |
319 | 319 | * @param string $passwd password |
@@ -321,310 +321,310 @@ discard block |
||
321 | 321 | * @param integer $port Port of database server |
322 | 322 | * @return SQLite3 Database access handler |
323 | 323 | * @see close |
324 | - */ |
|
325 | - function connect($host, $login, $passwd, $name, $port=0) |
|
326 | - { |
|
327 | - global $main_data_dir; |
|
328 | - |
|
329 | - dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG); |
|
330 | - |
|
331 | - $dir=$main_data_dir; |
|
332 | - if (empty($dir)) $dir=DOL_DATA_ROOT; |
|
333 | - // With sqlite, port must be in connect parameters |
|
334 | - //if (! $newport) $newport=3306; |
|
335 | - $database_name = $dir.'/database_'.$name.'.sdb'; |
|
336 | - try { |
|
337 | - /*** connect to SQLite database ***/ |
|
338 | - //$this->db = new PDO("sqlite:".$dir.'/database_'.$name.'.sdb'); |
|
324 | + */ |
|
325 | + function connect($host, $login, $passwd, $name, $port=0) |
|
326 | + { |
|
327 | + global $main_data_dir; |
|
328 | + |
|
329 | + dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG); |
|
330 | + |
|
331 | + $dir=$main_data_dir; |
|
332 | + if (empty($dir)) $dir=DOL_DATA_ROOT; |
|
333 | + // With sqlite, port must be in connect parameters |
|
334 | + //if (! $newport) $newport=3306; |
|
335 | + $database_name = $dir.'/database_'.$name.'.sdb'; |
|
336 | + try { |
|
337 | + /*** connect to SQLite database ***/ |
|
338 | + //$this->db = new PDO("sqlite:".$dir.'/database_'.$name.'.sdb'); |
|
339 | 339 | $this->db = new SQLite3($database_name); |
340 | - //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
341 | - } |
|
342 | - catch(Exception $e) |
|
343 | - { |
|
344 | - $this->error= self::LABEL.' '.$e->getMessage().' current dir='.$database_name; |
|
345 | - return ''; |
|
346 | - } |
|
340 | + //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
341 | + } |
|
342 | + catch(Exception $e) |
|
343 | + { |
|
344 | + $this->error= self::LABEL.' '.$e->getMessage().' current dir='.$database_name; |
|
345 | + return ''; |
|
346 | + } |
|
347 | 347 | |
348 | - //print "Resultat fonction connect: ".$this->db; |
|
349 | - return $this->db; |
|
350 | - } |
|
348 | + //print "Resultat fonction connect: ".$this->db; |
|
349 | + return $this->db; |
|
350 | + } |
|
351 | 351 | |
352 | 352 | |
353 | - /** |
|
353 | + /** |
|
354 | 354 | * Return version of database server |
355 | - * |
|
355 | + * |
|
356 | 356 | * @return string Version string |
357 | - */ |
|
358 | - function getVersion() |
|
359 | - { |
|
360 | - $tmp=$this->db->version(); |
|
361 | - return $tmp['versionString']; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Return version of database client driver |
|
366 | - * |
|
367 | - * @return string Version string |
|
368 | - */ |
|
369 | - function getDriverInfo() |
|
370 | - { |
|
371 | - return 'sqlite3 php driver'; |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Close database connexion |
|
377 | - * |
|
378 | - * @return bool True if disconnect successfull, false otherwise |
|
379 | - * @see connect |
|
380 | - */ |
|
381 | - function close() |
|
382 | - { |
|
383 | - if ($this->db) |
|
384 | - { |
|
385 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
386 | - $this->connected=false; |
|
387 | - $this->db->close(); |
|
388 | - unset($this->db); // Clean this->db |
|
389 | - return true; |
|
390 | - } |
|
391 | - return false; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Execute a SQL request and return the resultset |
|
396 | - * |
|
397 | - * @param string $query SQL query string |
|
398 | - * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
|
399 | - * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
|
400 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
401 | - * @return SQLite3Result Resultset of answer |
|
402 | - */ |
|
403 | - function query($query,$usesavepoint=0,$type='auto') |
|
404 | - { |
|
405 | - $ret=null; |
|
406 | - $query = trim($query); |
|
407 | - $this->error = 0; |
|
408 | - |
|
409 | - // Convert MySQL syntax to SQLite syntax |
|
410 | - 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)) { |
|
411 | - // Ajout d'une clef étrangère à la table |
|
412 | - // procédure de remplacement de la table pour ajouter la contrainte |
|
413 | - // Exemple : ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid) |
|
414 | - // -> CREATE TABLE ( ... ,CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid)) |
|
415 | - $foreignFields = $reg[5]; |
|
416 | - $foreignTable = $reg[4]; |
|
417 | - $localfields = $reg[3]; |
|
418 | - $constraintname=trim($reg[2]); |
|
419 | - $tablename=trim($reg[1]); |
|
420 | - |
|
421 | - $descTable = $this->db->querySingle("SELECT sql FROM sqlite_master WHERE name='" . $tablename . "'"); |
|
422 | - |
|
423 | - // 1- Renommer la table avec un nom temporaire |
|
424 | - $this->query('ALTER TABLE ' . $tablename . ' RENAME TO tmp_' . $tablename); |
|
425 | - |
|
426 | - // 2- Recréer la table avec la contrainte ajoutée |
|
427 | - |
|
428 | - // on bricole la requete pour ajouter la contrainte |
|
429 | - $descTable = substr($descTable, 0, strlen($descTable) - 1); |
|
430 | - $descTable .= ", CONSTRAINT " . $constraintname . " FOREIGN KEY (" . $localfields . ") REFERENCES " .$foreignTable . "(" . $foreignFields . ")"; |
|
431 | - |
|
432 | - // fermeture de l'instruction |
|
433 | - $descTable .= ')'; |
|
434 | - |
|
435 | - // Création proprement dite de la table |
|
436 | - $this->query($descTable); |
|
437 | - |
|
438 | - // 3- Transférer les données |
|
439 | - $this->query('INSERT INTO ' . $tablename . ' SELECT * FROM tmp_' . $tablename); |
|
440 | - |
|
441 | - // 4- Supprimer la table temporaire |
|
442 | - $this->query('DROP TABLE tmp_' . $tablename); |
|
443 | - |
|
444 | - // dummy statement |
|
445 | - $query="SELECT 0"; |
|
446 | - |
|
447 | - } else { |
|
448 | - $query=$this->convertSQLFromMysql($query,$type); |
|
449 | - } |
|
450 | - //print "After convertSQLFromMysql:\n".$query."<br>\n"; |
|
357 | + */ |
|
358 | + function getVersion() |
|
359 | + { |
|
360 | + $tmp=$this->db->version(); |
|
361 | + return $tmp['versionString']; |
|
362 | + } |
|
451 | 363 | |
452 | - dol_syslog('sql='.$query, LOG_DEBUG); |
|
364 | + /** |
|
365 | + * Return version of database client driver |
|
366 | + * |
|
367 | + * @return string Version string |
|
368 | + */ |
|
369 | + function getDriverInfo() |
|
370 | + { |
|
371 | + return 'sqlite3 php driver'; |
|
372 | + } |
|
453 | 373 | |
454 | - // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
|
455 | - try { |
|
456 | - //$ret = $this->db->exec($query); |
|
457 | - $ret = $this->db->query($query); // $ret is a Sqlite3Result |
|
458 | - if ($ret) { |
|
459 | - $ret->queryString = $query; |
|
460 | - } |
|
461 | - } |
|
462 | - catch(Exception $e) |
|
463 | - { |
|
464 | - $this->error=$this->db->lastErrorMsg(); |
|
465 | - } |
|
466 | 374 | |
467 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
468 | - { |
|
469 | - // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
470 | - if (! is_object($ret) || $this->error) |
|
471 | - { |
|
472 | - $this->lastqueryerror = $query; |
|
473 | - $this->lasterror = $this->error(); |
|
474 | - $this->lasterrno = $this->errno(); |
|
375 | + /** |
|
376 | + * Close database connexion |
|
377 | + * |
|
378 | + * @return bool True if disconnect successfull, false otherwise |
|
379 | + * @see connect |
|
380 | + */ |
|
381 | + function close() |
|
382 | + { |
|
383 | + if ($this->db) |
|
384 | + { |
|
385 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
386 | + $this->connected=false; |
|
387 | + $this->db->close(); |
|
388 | + unset($this->db); // Clean this->db |
|
389 | + return true; |
|
390 | + } |
|
391 | + return false; |
|
392 | + } |
|
475 | 393 | |
476 | - dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); |
|
394 | + /** |
|
395 | + * Execute a SQL request and return the resultset |
|
396 | + * |
|
397 | + * @param string $query SQL query string |
|
398 | + * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
|
399 | + * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
|
400 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
401 | + * @return SQLite3Result Resultset of answer |
|
402 | + */ |
|
403 | + function query($query,$usesavepoint=0,$type='auto') |
|
404 | + { |
|
405 | + $ret=null; |
|
406 | + $query = trim($query); |
|
407 | + $this->error = 0; |
|
408 | + |
|
409 | + // Convert MySQL syntax to SQLite syntax |
|
410 | + 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)) { |
|
411 | + // Ajout d'une clef étrangère à la table |
|
412 | + // procédure de remplacement de la table pour ajouter la contrainte |
|
413 | + // Exemple : ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid) |
|
414 | + // -> CREATE TABLE ( ... ,CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid)) |
|
415 | + $foreignFields = $reg[5]; |
|
416 | + $foreignTable = $reg[4]; |
|
417 | + $localfields = $reg[3]; |
|
418 | + $constraintname=trim($reg[2]); |
|
419 | + $tablename=trim($reg[1]); |
|
420 | + |
|
421 | + $descTable = $this->db->querySingle("SELECT sql FROM sqlite_master WHERE name='" . $tablename . "'"); |
|
422 | + |
|
423 | + // 1- Renommer la table avec un nom temporaire |
|
424 | + $this->query('ALTER TABLE ' . $tablename . ' RENAME TO tmp_' . $tablename); |
|
425 | + |
|
426 | + // 2- Recréer la table avec la contrainte ajoutée |
|
427 | + |
|
428 | + // on bricole la requete pour ajouter la contrainte |
|
429 | + $descTable = substr($descTable, 0, strlen($descTable) - 1); |
|
430 | + $descTable .= ", CONSTRAINT " . $constraintname . " FOREIGN KEY (" . $localfields . ") REFERENCES " .$foreignTable . "(" . $foreignFields . ")"; |
|
431 | + |
|
432 | + // fermeture de l'instruction |
|
433 | + $descTable .= ')'; |
|
434 | + |
|
435 | + // Création proprement dite de la table |
|
436 | + $this->query($descTable); |
|
437 | + |
|
438 | + // 3- Transférer les données |
|
439 | + $this->query('INSERT INTO ' . $tablename . ' SELECT * FROM tmp_' . $tablename); |
|
440 | + |
|
441 | + // 4- Supprimer la table temporaire |
|
442 | + $this->query('DROP TABLE tmp_' . $tablename); |
|
443 | + |
|
444 | + // dummy statement |
|
445 | + $query="SELECT 0"; |
|
446 | + |
|
447 | + } else { |
|
448 | + $query=$this->convertSQLFromMysql($query,$type); |
|
449 | + } |
|
450 | + //print "After convertSQLFromMysql:\n".$query."<br>\n"; |
|
451 | + |
|
452 | + dol_syslog('sql='.$query, LOG_DEBUG); |
|
453 | + |
|
454 | + // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
|
455 | + try { |
|
456 | + //$ret = $this->db->exec($query); |
|
457 | + $ret = $this->db->query($query); // $ret is a Sqlite3Result |
|
458 | + if ($ret) { |
|
459 | + $ret->queryString = $query; |
|
460 | + } |
|
461 | + } |
|
462 | + catch(Exception $e) |
|
463 | + { |
|
464 | + $this->error=$this->db->lastErrorMsg(); |
|
465 | + } |
|
466 | + |
|
467 | + if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
468 | + { |
|
469 | + // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
470 | + if (! is_object($ret) || $this->error) |
|
471 | + { |
|
472 | + $this->lastqueryerror = $query; |
|
473 | + $this->lasterror = $this->error(); |
|
474 | + $this->lasterrno = $this->errno(); |
|
475 | + |
|
476 | + dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); |
|
477 | + |
|
478 | + $errormsg = get_class($this)."::query SQL Error message: ".$this->lasterror; |
|
479 | + |
|
480 | + if (preg_match('/[0-9]/',$this->lasterrno)) { |
|
481 | + $errormsg .= ' ('.$this->lasterrno.')'; |
|
482 | + } |
|
483 | + |
|
484 | + dol_syslog($errormsg, LOG_ERR); |
|
485 | + } |
|
486 | + $this->lastquery=$query; |
|
487 | + $this->_results = $ret; |
|
488 | + } |
|
489 | + |
|
490 | + return $ret; |
|
491 | + } |
|
477 | 492 | |
478 | - $errormsg = get_class($this)."::query SQL Error message: ".$this->lasterror; |
|
493 | + /** |
|
494 | + * Renvoie la ligne courante (comme un objet) pour le curseur resultset |
|
495 | + * |
|
496 | + * @param SQLite3Result $resultset Curseur de la requete voulue |
|
497 | + * @return false|object Object result line or false if KO or end of cursor |
|
498 | + */ |
|
499 | + function fetch_object($resultset) |
|
500 | + { |
|
501 | + // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
|
502 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
503 | + //return $resultset->fetch(PDO::FETCH_OBJ); |
|
504 | + $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
|
505 | + if ($ret) { |
|
506 | + return (object) $ret; |
|
507 | + } |
|
508 | + return false; |
|
509 | + } |
|
479 | 510 | |
480 | - if (preg_match('/[0-9]/',$this->lasterrno)) { |
|
481 | - $errormsg .= ' ('.$this->lasterrno.')'; |
|
482 | - } |
|
483 | 511 | |
484 | - dol_syslog($errormsg, LOG_ERR); |
|
485 | - } |
|
486 | - $this->lastquery=$query; |
|
487 | - $this->_results = $ret; |
|
488 | - } |
|
512 | + /** |
|
513 | + * Return datas as an array |
|
514 | + * |
|
515 | + * @param SQLite3Result $resultset Resultset of request |
|
516 | + * @return false|array Array or false if KO or end of cursor |
|
517 | + */ |
|
518 | + function fetch_array($resultset) |
|
519 | + { |
|
520 | + // If resultset not provided, we take the last used by connexion |
|
521 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
522 | + //return $resultset->fetch(PDO::FETCH_ASSOC); |
|
523 | + $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
|
524 | + return $ret; |
|
525 | + } |
|
489 | 526 | |
490 | - return $ret; |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Renvoie la ligne courante (comme un objet) pour le curseur resultset |
|
495 | - * |
|
496 | - * @param SQLite3Result $resultset Curseur de la requete voulue |
|
497 | - * @return false|object Object result line or false if KO or end of cursor |
|
498 | - */ |
|
499 | - function fetch_object($resultset) |
|
500 | - { |
|
501 | - // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
|
502 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
503 | - //return $resultset->fetch(PDO::FETCH_OBJ); |
|
504 | - $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
|
505 | - if ($ret) { |
|
506 | - return (object) $ret; |
|
507 | - } |
|
508 | - return false; |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Return datas as an array |
|
514 | - * |
|
515 | - * @param SQLite3Result $resultset Resultset of request |
|
516 | - * @return false|array Array or false if KO or end of cursor |
|
517 | - */ |
|
518 | - function fetch_array($resultset) |
|
519 | - { |
|
520 | - // If resultset not provided, we take the last used by connexion |
|
521 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
522 | - //return $resultset->fetch(PDO::FETCH_ASSOC); |
|
523 | - $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
|
524 | - return $ret; |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Return datas as an array |
|
529 | - * |
|
530 | - * @param SQLite3Result $resultset Resultset of request |
|
531 | - * @return false|array Array or false if KO or end of cursor |
|
532 | - */ |
|
533 | - function fetch_row($resultset) |
|
534 | - { |
|
535 | - // If resultset not provided, we take the last used by connexion |
|
536 | - if (! is_bool($resultset)) |
|
537 | - { |
|
538 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
539 | - return $resultset->fetchArray(SQLITE3_NUM); |
|
540 | - } |
|
541 | - else |
|
542 | - { |
|
543 | - // si le curseur est un booleen on retourne la valeur 0 |
|
544 | - return false; |
|
545 | - } |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Return number of lines for result of a SELECT |
|
550 | - * |
|
551 | - * @param SQLite3Result $resultset Resulset of requests |
|
552 | - * @return int Nb of lines |
|
553 | - * @see affected_rows |
|
554 | - */ |
|
555 | - function num_rows($resultset) |
|
556 | - { |
|
557 | - // FIXME: SQLite3Result does not have a queryString member |
|
558 | - |
|
559 | - // If resultset not provided, we take the last used by connexion |
|
560 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
561 | - if (preg_match("/^SELECT/i", $resultset->queryString)) { |
|
562 | - return $this->db->querySingle("SELECT count(*) FROM (" . $resultset->queryString . ") q"); |
|
563 | - } |
|
564 | - return 0; |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * Return number of lines for result of a SELECT |
|
569 | - * |
|
570 | - * @param SQLite3Result $resultset Resulset of requests |
|
571 | - * @return int Nb of lines |
|
572 | - * @see affected_rows |
|
573 | - */ |
|
574 | - function affected_rows($resultset) |
|
575 | - { |
|
576 | - // FIXME: SQLite3Result does not have a queryString member |
|
577 | - |
|
578 | - // If resultset not provided, we take the last used by connexion |
|
579 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
580 | - if (preg_match("/^SELECT/i", $resultset->queryString)) { |
|
581 | - return $this->num_rows($resultset); |
|
582 | - } |
|
583 | - // mysql necessite un link de base pour cette fonction contrairement |
|
584 | - // a pqsql qui prend un resultset |
|
585 | - return $this->db->changes(); |
|
586 | - } |
|
527 | + /** |
|
528 | + * Return datas as an array |
|
529 | + * |
|
530 | + * @param SQLite3Result $resultset Resultset of request |
|
531 | + * @return false|array Array or false if KO or end of cursor |
|
532 | + */ |
|
533 | + function fetch_row($resultset) |
|
534 | + { |
|
535 | + // If resultset not provided, we take the last used by connexion |
|
536 | + if (! is_bool($resultset)) |
|
537 | + { |
|
538 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
539 | + return $resultset->fetchArray(SQLITE3_NUM); |
|
540 | + } |
|
541 | + else |
|
542 | + { |
|
543 | + // si le curseur est un booleen on retourne la valeur 0 |
|
544 | + return false; |
|
545 | + } |
|
546 | + } |
|
587 | 547 | |
548 | + /** |
|
549 | + * Return number of lines for result of a SELECT |
|
550 | + * |
|
551 | + * @param SQLite3Result $resultset Resulset of requests |
|
552 | + * @return int Nb of lines |
|
553 | + * @see affected_rows |
|
554 | + */ |
|
555 | + function num_rows($resultset) |
|
556 | + { |
|
557 | + // FIXME: SQLite3Result does not have a queryString member |
|
558 | + |
|
559 | + // If resultset not provided, we take the last used by connexion |
|
560 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
561 | + if (preg_match("/^SELECT/i", $resultset->queryString)) { |
|
562 | + return $this->db->querySingle("SELECT count(*) FROM (" . $resultset->queryString . ") q"); |
|
563 | + } |
|
564 | + return 0; |
|
565 | + } |
|
588 | 566 | |
589 | - /** |
|
567 | + /** |
|
568 | + * Return number of lines for result of a SELECT |
|
569 | + * |
|
570 | + * @param SQLite3Result $resultset Resulset of requests |
|
571 | + * @return int Nb of lines |
|
572 | + * @see affected_rows |
|
573 | + */ |
|
574 | + function affected_rows($resultset) |
|
575 | + { |
|
576 | + // FIXME: SQLite3Result does not have a queryString member |
|
577 | + |
|
578 | + // If resultset not provided, we take the last used by connexion |
|
579 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
580 | + if (preg_match("/^SELECT/i", $resultset->queryString)) { |
|
581 | + return $this->num_rows($resultset); |
|
582 | + } |
|
583 | + // mysql necessite un link de base pour cette fonction contrairement |
|
584 | + // a pqsql qui prend un resultset |
|
585 | + return $this->db->changes(); |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | 590 | * Free last resultset used. |
591 | - * |
|
591 | + * |
|
592 | 592 | * @param SQLite3Result $resultset Curseur de la requete voulue |
593 | 593 | * @return void |
594 | - */ |
|
595 | - function free($resultset=null) |
|
596 | - { |
|
597 | - // If resultset not provided, we take the last used by connexion |
|
598 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
599 | - // Si resultset en est un, on libere la memoire |
|
600 | - if ($resultset && is_object($resultset)) $resultset->finalize(); |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
594 | + */ |
|
595 | + function free($resultset=null) |
|
596 | + { |
|
597 | + // If resultset not provided, we take the last used by connexion |
|
598 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
599 | + // Si resultset en est un, on libere la memoire |
|
600 | + if ($resultset && is_object($resultset)) $resultset->finalize(); |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | 604 | * Escape a string to insert data |
605 | - * |
|
605 | + * |
|
606 | 606 | * @param string $stringtoencode String to escape |
607 | 607 | * @return string String escaped |
608 | - */ |
|
609 | - function escape($stringtoencode) |
|
610 | - { |
|
611 | - return Sqlite3::escapeString($stringtoencode); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Renvoie le code erreur generique de l'operation precedente. |
|
616 | - * |
|
617 | - * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
618 | - */ |
|
619 | - function errno() |
|
620 | - { |
|
621 | - if (! $this->connected) { |
|
622 | - // Si il y a eu echec de connexion, $this->db n'est pas valide. |
|
623 | - return 'DB_ERROR_FAILED_TO_CONNECT'; |
|
624 | - } |
|
625 | - else { |
|
626 | - // Constants to convert error code to a generic Dolibarr error code |
|
627 | - /*$errorcode_map = array( |
|
608 | + */ |
|
609 | + function escape($stringtoencode) |
|
610 | + { |
|
611 | + return Sqlite3::escapeString($stringtoencode); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Renvoie le code erreur generique de l'operation precedente. |
|
616 | + * |
|
617 | + * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
618 | + */ |
|
619 | + function errno() |
|
620 | + { |
|
621 | + if (! $this->connected) { |
|
622 | + // Si il y a eu echec de connexion, $this->db n'est pas valide. |
|
623 | + return 'DB_ERROR_FAILED_TO_CONNECT'; |
|
624 | + } |
|
625 | + else { |
|
626 | + // Constants to convert error code to a generic Dolibarr error code |
|
627 | + /*$errorcode_map = array( |
|
628 | 628 | 1004 => 'DB_ERROR_CANNOT_CREATE', |
629 | 629 | 1005 => 'DB_ERROR_CANNOT_CREATE', |
630 | 630 | 1006 => 'DB_ERROR_CANNOT_CREATE', |
@@ -656,220 +656,220 @@ discard block |
||
656 | 656 | { |
657 | 657 | return $errorcode_map[$this->db->errorCode()]; |
658 | 658 | }*/ |
659 | - $errno=$this->db->lastErrorCode(); |
|
659 | + $errno=$this->db->lastErrorCode(); |
|
660 | 660 | if ($errno=='HY000' || $errno == 0) |
661 | - { |
|
662 | - if (preg_match('/table.*already exists/i',$this->error)) return 'DB_ERROR_TABLE_ALREADY_EXISTS'; |
|
663 | - elseif (preg_match('/index.*already exists/i',$this->error)) return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'; |
|
664 | - elseif (preg_match('/syntax error/i',$this->error)) return 'DB_ERROR_SYNTAX'; |
|
665 | - } |
|
666 | - if ($errno=='23000') |
|
667 | - { |
|
668 | - if (preg_match('/column.* not unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
669 | - elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
670 | - } |
|
671 | - if ($errno > 1) { |
|
672 | - // TODO Voir la liste des messages d'erreur |
|
673 | - } |
|
674 | - |
|
675 | - return ($errno?'DB_ERROR_'.$errno:'0'); |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * Renvoie le texte de l'erreur mysql de l'operation precedente. |
|
681 | - * |
|
682 | - * @return string Error text |
|
683 | - */ |
|
684 | - function error() |
|
685 | - { |
|
686 | - if (! $this->connected) { |
|
687 | - // Si il y a eu echec de connexion, $this->db n'est pas valide pour sqlite_error. |
|
688 | - return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version'; |
|
689 | - } |
|
690 | - else { |
|
691 | - return $this->error; |
|
692 | - } |
|
693 | - } |
|
661 | + { |
|
662 | + if (preg_match('/table.*already exists/i',$this->error)) return 'DB_ERROR_TABLE_ALREADY_EXISTS'; |
|
663 | + elseif (preg_match('/index.*already exists/i',$this->error)) return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'; |
|
664 | + elseif (preg_match('/syntax error/i',$this->error)) return 'DB_ERROR_SYNTAX'; |
|
665 | + } |
|
666 | + if ($errno=='23000') |
|
667 | + { |
|
668 | + if (preg_match('/column.* not unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
669 | + elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
670 | + } |
|
671 | + if ($errno > 1) { |
|
672 | + // TODO Voir la liste des messages d'erreur |
|
673 | + } |
|
674 | + |
|
675 | + return ($errno?'DB_ERROR_'.$errno:'0'); |
|
676 | + } |
|
677 | + } |
|
694 | 678 | |
695 | - /** |
|
696 | - * Get last ID after an insert INSERT |
|
697 | - * |
|
679 | + /** |
|
680 | + * Renvoie le texte de l'erreur mysql de l'operation precedente. |
|
681 | + * |
|
682 | + * @return string Error text |
|
683 | + */ |
|
684 | + function error() |
|
685 | + { |
|
686 | + if (! $this->connected) { |
|
687 | + // Si il y a eu echec de connexion, $this->db n'est pas valide pour sqlite_error. |
|
688 | + return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version'; |
|
689 | + } |
|
690 | + else { |
|
691 | + return $this->error; |
|
692 | + } |
|
693 | + } |
|
694 | + |
|
695 | + /** |
|
696 | + * Get last ID after an insert INSERT |
|
697 | + * |
|
698 | 698 | * @param string $tab Table name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql |
699 | 699 | * @param string $fieldid Field name |
700 | 700 | * @return int Id of row |
701 | - */ |
|
702 | - function last_insert_id($tab,$fieldid='rowid') |
|
703 | - { |
|
704 | - return $this->db->lastInsertRowId(); |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * Encrypt sensitive data in database |
|
709 | - * Warning: This function includes the escape, so it must use direct value |
|
710 | - * |
|
711 | - * @param string $fieldorvalue Field name or value to encrypt |
|
712 | - * @param int $withQuotes Return string with quotes |
|
713 | - * @return string XXX(field) or XXX('value') or field or 'value' |
|
714 | - */ |
|
715 | - function encrypt($fieldorvalue, $withQuotes=0) |
|
716 | - { |
|
717 | - global $conf; |
|
718 | - |
|
719 | - // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
720 | - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
721 | - |
|
722 | - //Encryption key |
|
723 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
724 | - |
|
725 | - $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
726 | - |
|
727 | - if ($cryptType && !empty($cryptKey)) |
|
728 | - { |
|
729 | - if ($cryptType == 2) |
|
730 | - { |
|
731 | - $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
732 | - } |
|
733 | - else if ($cryptType == 1) |
|
734 | - { |
|
735 | - $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
736 | - } |
|
737 | - } |
|
701 | + */ |
|
702 | + function last_insert_id($tab,$fieldid='rowid') |
|
703 | + { |
|
704 | + return $this->db->lastInsertRowId(); |
|
705 | + } |
|
738 | 706 | |
739 | - return $return; |
|
740 | - } |
|
707 | + /** |
|
708 | + * Encrypt sensitive data in database |
|
709 | + * Warning: This function includes the escape, so it must use direct value |
|
710 | + * |
|
711 | + * @param string $fieldorvalue Field name or value to encrypt |
|
712 | + * @param int $withQuotes Return string with quotes |
|
713 | + * @return string XXX(field) or XXX('value') or field or 'value' |
|
714 | + */ |
|
715 | + function encrypt($fieldorvalue, $withQuotes=0) |
|
716 | + { |
|
717 | + global $conf; |
|
741 | 718 | |
742 | - /** |
|
743 | - * Decrypt sensitive data in database |
|
744 | - * |
|
745 | - * @param string $value Value to decrypt |
|
746 | - * @return string Decrypted value if used |
|
747 | - */ |
|
748 | - function decrypt($value) |
|
749 | - { |
|
750 | - global $conf; |
|
719 | + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
720 | + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
751 | 721 | |
752 | - // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
753 | - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
722 | + //Encryption key |
|
723 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
754 | 724 | |
755 | - //Encryption key |
|
756 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
725 | + $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
757 | 726 | |
758 | - $return = $value; |
|
727 | + if ($cryptType && !empty($cryptKey)) |
|
728 | + { |
|
729 | + if ($cryptType == 2) |
|
730 | + { |
|
731 | + $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
732 | + } |
|
733 | + else if ($cryptType == 1) |
|
734 | + { |
|
735 | + $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
736 | + } |
|
737 | + } |
|
759 | 738 | |
760 | - if ($cryptType && !empty($cryptKey)) |
|
761 | - { |
|
762 | - if ($cryptType == 2) |
|
763 | - { |
|
764 | - $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
765 | - } |
|
766 | - else if ($cryptType == 1) |
|
767 | - { |
|
768 | - $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
769 | - } |
|
770 | - } |
|
739 | + return $return; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Decrypt sensitive data in database |
|
744 | + * |
|
745 | + * @param string $value Value to decrypt |
|
746 | + * @return string Decrypted value if used |
|
747 | + */ |
|
748 | + function decrypt($value) |
|
749 | + { |
|
750 | + global $conf; |
|
751 | + |
|
752 | + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
753 | + $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
754 | + |
|
755 | + //Encryption key |
|
756 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
757 | + |
|
758 | + $return = $value; |
|
771 | 759 | |
772 | - return $return; |
|
773 | - } |
|
760 | + if ($cryptType && !empty($cryptKey)) |
|
761 | + { |
|
762 | + if ($cryptType == 2) |
|
763 | + { |
|
764 | + $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
765 | + } |
|
766 | + else if ($cryptType == 1) |
|
767 | + { |
|
768 | + $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
769 | + } |
|
770 | + } |
|
774 | 771 | |
772 | + return $return; |
|
773 | + } |
|
775 | 774 | |
776 | - /** |
|
777 | - * Return connexion ID |
|
778 | - * |
|
775 | + |
|
776 | + /** |
|
777 | + * Return connexion ID |
|
778 | + * |
|
779 | 779 | * @return string Id connexion |
780 | - */ |
|
781 | - function DDLGetConnectId() |
|
782 | - { |
|
783 | - return '?'; |
|
784 | - } |
|
780 | + */ |
|
781 | + function DDLGetConnectId() |
|
782 | + { |
|
783 | + return '?'; |
|
784 | + } |
|
785 | 785 | |
786 | 786 | |
787 | - /** |
|
787 | + /** |
|
788 | 788 | * Create a new database |
789 | 789 | * Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated |
790 | 790 | * We force to create database with charset this->forcecharset and collate this->forcecollate |
791 | - * |
|
791 | + * |
|
792 | 792 | * @param string $database Database name to create |
793 | 793 | * @param string $charset Charset used to store data |
794 | 794 | * @param string $collation Charset used to sort data |
795 | 795 | * @param string $owner Username of database owner |
796 | 796 | * @return SQLite3Result resource defined if OK, null if KO |
797 | - */ |
|
798 | - function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
799 | - { |
|
800 | - if (empty($charset)) $charset=$this->forcecharset; |
|
801 | - if (empty($collation)) $collation=$this->forcecollate; |
|
802 | - |
|
803 | - // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
|
804 | - $sql = 'CREATE DATABASE '.$database; |
|
805 | - $sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
|
806 | - |
|
807 | - dol_syslog($sql,LOG_DEBUG); |
|
808 | - $ret=$this->query($sql); |
|
809 | - if (! $ret) |
|
810 | - { |
|
811 | - // We try again for compatibility with Mysql < 4.1.1 |
|
812 | - $sql = 'CREATE DATABASE '.$database; |
|
813 | - $ret=$this->query($sql); |
|
814 | - dol_syslog($sql,LOG_DEBUG); |
|
815 | - } |
|
816 | - return $ret; |
|
817 | - } |
|
797 | + */ |
|
798 | + function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
799 | + { |
|
800 | + if (empty($charset)) $charset=$this->forcecharset; |
|
801 | + if (empty($collation)) $collation=$this->forcecollate; |
|
802 | + |
|
803 | + // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
|
804 | + $sql = 'CREATE DATABASE '.$database; |
|
805 | + $sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
|
806 | + |
|
807 | + dol_syslog($sql,LOG_DEBUG); |
|
808 | + $ret=$this->query($sql); |
|
809 | + if (! $ret) |
|
810 | + { |
|
811 | + // We try again for compatibility with Mysql < 4.1.1 |
|
812 | + $sql = 'CREATE DATABASE '.$database; |
|
813 | + $ret=$this->query($sql); |
|
814 | + dol_syslog($sql,LOG_DEBUG); |
|
815 | + } |
|
816 | + return $ret; |
|
817 | + } |
|
818 | 818 | |
819 | - /** |
|
820 | - * List tables into a database |
|
821 | - * |
|
819 | + /** |
|
820 | + * List tables into a database |
|
821 | + * |
|
822 | 822 | * @param string $database Name of database |
823 | 823 | * @param string $table Name of table filter ('xxx%') |
824 | 824 | * @return array List of tables in an array |
825 | - */ |
|
826 | - function DDLListTables($database, $table='') |
|
827 | - { |
|
828 | - $listtables=array(); |
|
829 | - |
|
830 | - $like = ''; |
|
831 | - if ($table) $like = "LIKE '".$table."'"; |
|
832 | - $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
833 | - //print $sql; |
|
834 | - $result = $this->query($sql); |
|
835 | - if ($result) |
|
836 | - { |
|
837 | - while($row = $this->fetch_row($result)) |
|
838 | - { |
|
839 | - $listtables[] = $row[0]; |
|
840 | - } |
|
841 | - } |
|
842 | - return $listtables; |
|
843 | - } |
|
825 | + */ |
|
826 | + function DDLListTables($database, $table='') |
|
827 | + { |
|
828 | + $listtables=array(); |
|
829 | + |
|
830 | + $like = ''; |
|
831 | + if ($table) $like = "LIKE '".$table."'"; |
|
832 | + $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
833 | + //print $sql; |
|
834 | + $result = $this->query($sql); |
|
835 | + if ($result) |
|
836 | + { |
|
837 | + while($row = $this->fetch_row($result)) |
|
838 | + { |
|
839 | + $listtables[] = $row[0]; |
|
840 | + } |
|
841 | + } |
|
842 | + return $listtables; |
|
843 | + } |
|
844 | 844 | |
845 | - /** |
|
845 | + /** |
|
846 | 846 | * List information of columns into a table. |
847 | - * |
|
847 | + * |
|
848 | 848 | * @param string $table Name of table |
849 | 849 | * @return array Tableau des informations des champs de la table |
850 | 850 | * TODO modify for sqlite |
851 | - */ |
|
852 | - function DDLInfoTable($table) |
|
853 | - { |
|
854 | - $infotables=array(); |
|
855 | - |
|
856 | - $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
857 | - |
|
858 | - dol_syslog($sql,LOG_DEBUG); |
|
859 | - $result = $this->query($sql); |
|
860 | - if ($result) |
|
861 | - { |
|
862 | - while($row = $this->fetch_row($result)) |
|
863 | - { |
|
864 | - $infotables[] = $row; |
|
865 | - } |
|
866 | - } |
|
867 | - return $infotables; |
|
868 | - } |
|
851 | + */ |
|
852 | + function DDLInfoTable($table) |
|
853 | + { |
|
854 | + $infotables=array(); |
|
855 | + |
|
856 | + $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
857 | + |
|
858 | + dol_syslog($sql,LOG_DEBUG); |
|
859 | + $result = $this->query($sql); |
|
860 | + if ($result) |
|
861 | + { |
|
862 | + while($row = $this->fetch_row($result)) |
|
863 | + { |
|
864 | + $infotables[] = $row; |
|
865 | + } |
|
866 | + } |
|
867 | + return $infotables; |
|
868 | + } |
|
869 | 869 | |
870 | - /** |
|
870 | + /** |
|
871 | 871 | * Create a table into database |
872 | - * |
|
872 | + * |
|
873 | 873 | * @param string $table Nom de la table |
874 | 874 | * @param array $fields Tableau associatif [nom champ][tableau des descriptions] |
875 | 875 | * @param string $primary_key Nom du champ qui sera la clef primaire |
@@ -878,367 +878,367 @@ discard block |
||
878 | 878 | * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext |
879 | 879 | * @param array $keys Tableau des champs cles noms => valeur |
880 | 880 | * @return int <0 if KO, >=0 if OK |
881 | - */ |
|
882 | - function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
883 | - { |
|
884 | - // FIXME: $fulltext_keys parameter is unused |
|
885 | - |
|
886 | - // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
|
887 | - // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
888 | - $sql = "create table ".$table."("; |
|
889 | - $i=0; |
|
890 | - foreach($fields as $field_name => $field_desc) |
|
891 | - { |
|
892 | - $sqlfields[$i] = $field_name." "; |
|
893 | - $sqlfields[$i] .= $field_desc['type']; |
|
894 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
895 | - $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
896 | - else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
897 | - $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
898 | - else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
899 | - { |
|
900 | - if(preg_match("/null/i",$field_desc['default'])) |
|
901 | - $sqlfields[$i] .= " default ".$field_desc['default']; |
|
902 | - else |
|
903 | - $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
904 | - } |
|
905 | - else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
906 | - $sqlfields[$i] .= " ".$field_desc['null']; |
|
907 | - |
|
908 | - else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
909 | - $sqlfields[$i] .= " ".$field_desc['extra']; |
|
910 | - $i++; |
|
911 | - } |
|
912 | - if($primary_key != "") |
|
913 | - $pk = "primary key(".$primary_key.")"; |
|
881 | + */ |
|
882 | + function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
883 | + { |
|
884 | + // FIXME: $fulltext_keys parameter is unused |
|
885 | + |
|
886 | + // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
|
887 | + // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
888 | + $sql = "create table ".$table."("; |
|
889 | + $i=0; |
|
890 | + foreach($fields as $field_name => $field_desc) |
|
891 | + { |
|
892 | + $sqlfields[$i] = $field_name." "; |
|
893 | + $sqlfields[$i] .= $field_desc['type']; |
|
894 | + if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
895 | + $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
896 | + else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
897 | + $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
898 | + else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
899 | + { |
|
900 | + if(preg_match("/null/i",$field_desc['default'])) |
|
901 | + $sqlfields[$i] .= " default ".$field_desc['default']; |
|
902 | + else |
|
903 | + $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
904 | + } |
|
905 | + else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
906 | + $sqlfields[$i] .= " ".$field_desc['null']; |
|
907 | + |
|
908 | + else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
909 | + $sqlfields[$i] .= " ".$field_desc['extra']; |
|
910 | + $i++; |
|
911 | + } |
|
912 | + if($primary_key != "") |
|
913 | + $pk = "primary key(".$primary_key.")"; |
|
914 | + |
|
915 | + if(is_array($unique_keys)) |
|
916 | + { |
|
917 | + $i = 0; |
|
918 | + foreach($unique_keys as $key => $value) |
|
919 | + { |
|
920 | + $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
|
921 | + $i++; |
|
922 | + } |
|
923 | + } |
|
924 | + if(is_array($keys)) |
|
925 | + { |
|
926 | + $i = 0; |
|
927 | + foreach($keys as $key => $value) |
|
928 | + { |
|
929 | + $sqlk[$i] = "KEY ".$key." (".$value.")"; |
|
930 | + $i++; |
|
931 | + } |
|
932 | + } |
|
933 | + $sql .= implode(',',$sqlfields); |
|
934 | + if($primary_key != "") |
|
935 | + $sql .= ",".$pk; |
|
936 | + if(is_array($unique_keys)) |
|
937 | + $sql .= ",".implode(',',$sqluq); |
|
938 | + if(is_array($keys)) |
|
939 | + $sql .= ",".implode(',',$sqlk); |
|
940 | + $sql .=") type=".$type; |
|
941 | + |
|
942 | + dol_syslog($sql,LOG_DEBUG); |
|
943 | + if(! $this -> query($sql)) |
|
944 | + return -1; |
|
945 | + return 1; |
|
946 | + } |
|
914 | 947 | |
915 | - if(is_array($unique_keys)) |
|
916 | - { |
|
917 | - $i = 0; |
|
918 | - foreach($unique_keys as $key => $value) |
|
919 | - { |
|
920 | - $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
|
921 | - $i++; |
|
922 | - } |
|
923 | - } |
|
924 | - if(is_array($keys)) |
|
925 | - { |
|
926 | - $i = 0; |
|
927 | - foreach($keys as $key => $value) |
|
928 | - { |
|
929 | - $sqlk[$i] = "KEY ".$key." (".$value.")"; |
|
930 | - $i++; |
|
931 | - } |
|
932 | - } |
|
933 | - $sql .= implode(',',$sqlfields); |
|
934 | - if($primary_key != "") |
|
935 | - $sql .= ",".$pk; |
|
936 | - if(is_array($unique_keys)) |
|
937 | - $sql .= ",".implode(',',$sqluq); |
|
938 | - if(is_array($keys)) |
|
939 | - $sql .= ",".implode(',',$sqlk); |
|
940 | - $sql .=") type=".$type; |
|
941 | - |
|
942 | - dol_syslog($sql,LOG_DEBUG); |
|
943 | - if(! $this -> query($sql)) |
|
944 | - return -1; |
|
945 | - return 1; |
|
946 | - } |
|
947 | - |
|
948 | - /** |
|
948 | + /** |
|
949 | 949 | * Return a pointer of line with description of a table or field |
950 | - * |
|
950 | + * |
|
951 | 951 | * @param string $table Name of table |
952 | 952 | * @param string $field Optionnel : Name of field if we want description of field |
953 | 953 | * @return SQLite3Result Resource |
954 | - */ |
|
955 | - function DDLDescTable($table,$field="") |
|
956 | - { |
|
957 | - $sql="DESC ".$table." ".$field; |
|
954 | + */ |
|
955 | + function DDLDescTable($table,$field="") |
|
956 | + { |
|
957 | + $sql="DESC ".$table." ".$field; |
|
958 | 958 | |
959 | - dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
960 | - $this->_results = $this->query($sql); |
|
961 | - return $this->_results; |
|
962 | - } |
|
959 | + dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
960 | + $this->_results = $this->query($sql); |
|
961 | + return $this->_results; |
|
962 | + } |
|
963 | 963 | |
964 | - /** |
|
964 | + /** |
|
965 | 965 | * Create a new field into table |
966 | - * |
|
966 | + * |
|
967 | 967 | * @param string $table Name of table |
968 | 968 | * @param string $field_name Name of field to add |
969 | 969 | * @param string $field_desc Tableau associatif de description du champ a inserer[nom du parametre][valeur du parametre] |
970 | 970 | * @param string $field_position Optionnel ex.: "after champtruc" |
971 | 971 | * @return int <0 if KO, >0 if OK |
972 | - */ |
|
973 | - function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
974 | - { |
|
975 | - // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
|
976 | - // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
977 | - $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
978 | - $sql.= $field_desc['type']; |
|
979 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
980 | - if (! in_array($field_desc['type'],array('date','datetime'))) |
|
981 | - { |
|
982 | - $sql.= "(".$field_desc['value'].")"; |
|
983 | - } |
|
984 | - if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
985 | - $sql.= " ".$field_desc['attribute']; |
|
986 | - if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
987 | - $sql.= " ".$field_desc['null']; |
|
988 | - if(preg_match("/^[^\s]/i",$field_desc['default'])) |
|
989 | - { |
|
990 | - if(preg_match("/null/i",$field_desc['default'])) |
|
991 | - $sql.= " default ".$field_desc['default']; |
|
992 | - else |
|
993 | - $sql.= " default '".$field_desc['default']."'"; |
|
994 | - } |
|
995 | - if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
996 | - $sql.= " ".$field_desc['extra']; |
|
997 | - $sql.= " ".$field_position; |
|
998 | - |
|
999 | - dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
1000 | - if(! $this->query($sql)) |
|
1001 | - { |
|
1002 | - return -1; |
|
1003 | - } |
|
1004 | - return 1; |
|
1005 | - } |
|
972 | + */ |
|
973 | + function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
974 | + { |
|
975 | + // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
|
976 | + // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
977 | + $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
978 | + $sql.= $field_desc['type']; |
|
979 | + if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
980 | + if (! in_array($field_desc['type'],array('date','datetime'))) |
|
981 | + { |
|
982 | + $sql.= "(".$field_desc['value'].")"; |
|
983 | + } |
|
984 | + if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
985 | + $sql.= " ".$field_desc['attribute']; |
|
986 | + if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
987 | + $sql.= " ".$field_desc['null']; |
|
988 | + if(preg_match("/^[^\s]/i",$field_desc['default'])) |
|
989 | + { |
|
990 | + if(preg_match("/null/i",$field_desc['default'])) |
|
991 | + $sql.= " default ".$field_desc['default']; |
|
992 | + else |
|
993 | + $sql.= " default '".$field_desc['default']."'"; |
|
994 | + } |
|
995 | + if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
996 | + $sql.= " ".$field_desc['extra']; |
|
997 | + $sql.= " ".$field_position; |
|
998 | + |
|
999 | + dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
1000 | + if(! $this->query($sql)) |
|
1001 | + { |
|
1002 | + return -1; |
|
1003 | + } |
|
1004 | + return 1; |
|
1005 | + } |
|
1006 | 1006 | |
1007 | - /** |
|
1007 | + /** |
|
1008 | 1008 | * Update format of a field into a table |
1009 | - * |
|
1009 | + * |
|
1010 | 1010 | * @param string $table Name of table |
1011 | 1011 | * @param string $field_name Name of field to modify |
1012 | 1012 | * @param string $field_desc Array with description of field format |
1013 | 1013 | * @return int <0 if KO, >0 if OK |
1014 | - */ |
|
1015 | - function DDLUpdateField($table,$field_name,$field_desc) |
|
1016 | - { |
|
1017 | - $sql = "ALTER TABLE ".$table; |
|
1018 | - $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
|
1019 | - if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
|
1020 | - $sql.="(".$field_desc['value'].")"; |
|
1021 | - } |
|
1022 | - |
|
1023 | - dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
1024 | - if (! $this->query($sql)) |
|
1025 | - return -1; |
|
1026 | - return 1; |
|
1027 | - } |
|
1014 | + */ |
|
1015 | + function DDLUpdateField($table,$field_name,$field_desc) |
|
1016 | + { |
|
1017 | + $sql = "ALTER TABLE ".$table; |
|
1018 | + $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
|
1019 | + if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
|
1020 | + $sql.="(".$field_desc['value'].")"; |
|
1021 | + } |
|
1022 | + |
|
1023 | + dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
1024 | + if (! $this->query($sql)) |
|
1025 | + return -1; |
|
1026 | + return 1; |
|
1027 | + } |
|
1028 | 1028 | |
1029 | - /** |
|
1029 | + /** |
|
1030 | 1030 | * Drop a field from table |
1031 | - * |
|
1031 | + * |
|
1032 | 1032 | * @param string $table Name of table |
1033 | 1033 | * @param string $field_name Name of field to drop |
1034 | 1034 | * @return int <0 if KO, >0 if OK |
1035 | - */ |
|
1036 | - function DDLDropField($table,$field_name) |
|
1037 | - { |
|
1038 | - $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
1039 | - dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG); |
|
1040 | - if (! $this->query($sql)) |
|
1041 | - { |
|
1042 | - $this->error=$this->lasterror(); |
|
1043 | - return -1; |
|
1044 | - } |
|
1045 | - return 1; |
|
1046 | - } |
|
1035 | + */ |
|
1036 | + function DDLDropField($table,$field_name) |
|
1037 | + { |
|
1038 | + $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
1039 | + dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG); |
|
1040 | + if (! $this->query($sql)) |
|
1041 | + { |
|
1042 | + $this->error=$this->lasterror(); |
|
1043 | + return -1; |
|
1044 | + } |
|
1045 | + return 1; |
|
1046 | + } |
|
1047 | 1047 | |
1048 | 1048 | |
1049 | - /** |
|
1049 | + /** |
|
1050 | 1050 | * Create a user and privileges to connect to database (even if database does not exists yet) |
1051 | - * |
|
1051 | + * |
|
1052 | 1052 | * @param string $dolibarr_main_db_host Ip serveur |
1053 | 1053 | * @param string $dolibarr_main_db_user Nom user a creer |
1054 | 1054 | * @param string $dolibarr_main_db_pass Mot de passe user a creer |
1055 | 1055 | * @param string $dolibarr_main_db_name Database name where user must be granted |
1056 | 1056 | * @return int <0 if KO, >=0 if OK |
1057 | - */ |
|
1058 | - function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
1059 | - { |
|
1060 | - $sql = "INSERT INTO user "; |
|
1061 | - $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; |
|
1062 | - $sql.= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_user)."',password('".addslashes($dolibarr_main_db_pass)."')"; |
|
1063 | - $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; |
|
1064 | - |
|
1065 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
1066 | - $resql=$this->query($sql); |
|
1067 | - if (! $resql) |
|
1068 | - { |
|
1069 | - return -1; |
|
1070 | - } |
|
1071 | - |
|
1072 | - $sql = "INSERT INTO db "; |
|
1073 | - $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; |
|
1074 | - $sql.= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_name)."','".addslashes($dolibarr_main_db_user)."'"; |
|
1075 | - $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; |
|
1076 | - |
|
1077 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
1078 | - $resql=$this->query($sql); |
|
1079 | - if (! $resql) |
|
1080 | - { |
|
1081 | - return -1; |
|
1082 | - } |
|
1083 | - |
|
1084 | - $sql="FLUSH Privileges"; |
|
1085 | - |
|
1086 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
1087 | - $resql=$this->query($sql); |
|
1088 | - if (! $resql) |
|
1089 | - { |
|
1090 | - return -1; |
|
1091 | - } |
|
1092 | - return 1; |
|
1093 | - } |
|
1057 | + */ |
|
1058 | + function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
1059 | + { |
|
1060 | + $sql = "INSERT INTO user "; |
|
1061 | + $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; |
|
1062 | + $sql.= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_user)."',password('".addslashes($dolibarr_main_db_pass)."')"; |
|
1063 | + $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; |
|
1064 | + |
|
1065 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
1066 | + $resql=$this->query($sql); |
|
1067 | + if (! $resql) |
|
1068 | + { |
|
1069 | + return -1; |
|
1070 | + } |
|
1071 | + |
|
1072 | + $sql = "INSERT INTO db "; |
|
1073 | + $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; |
|
1074 | + $sql.= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_name)."','".addslashes($dolibarr_main_db_user)."'"; |
|
1075 | + $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; |
|
1076 | + |
|
1077 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
1078 | + $resql=$this->query($sql); |
|
1079 | + if (! $resql) |
|
1080 | + { |
|
1081 | + return -1; |
|
1082 | + } |
|
1083 | + |
|
1084 | + $sql="FLUSH Privileges"; |
|
1085 | + |
|
1086 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
1087 | + $resql=$this->query($sql); |
|
1088 | + if (! $resql) |
|
1089 | + { |
|
1090 | + return -1; |
|
1091 | + } |
|
1092 | + return 1; |
|
1093 | + } |
|
1094 | 1094 | |
1095 | - /** |
|
1095 | + /** |
|
1096 | 1096 | * Return charset used to store data in database |
1097 | - * |
|
1097 | + * |
|
1098 | 1098 | * @return string Charset |
1099 | - */ |
|
1100 | - function getDefaultCharacterSetDatabase() |
|
1101 | - { |
|
1102 | - return 'UTF-8'; |
|
1103 | - } |
|
1099 | + */ |
|
1100 | + function getDefaultCharacterSetDatabase() |
|
1101 | + { |
|
1102 | + return 'UTF-8'; |
|
1103 | + } |
|
1104 | 1104 | |
1105 | - /** |
|
1105 | + /** |
|
1106 | 1106 | * Return list of available charset that can be used to store data in database |
1107 | - * |
|
1107 | + * |
|
1108 | 1108 | * @return array List of Charset |
1109 | - */ |
|
1110 | - function getListOfCharacterSet() |
|
1111 | - { |
|
1112 | - $liste = array(); |
|
1113 | - $i=0; |
|
1114 | - $liste[$i]['charset'] = 'UTF-8'; |
|
1115 | - $liste[$i]['description'] = 'UTF-8'; |
|
1116 | - return $liste; |
|
1117 | - } |
|
1118 | - |
|
1119 | - /** |
|
1109 | + */ |
|
1110 | + function getListOfCharacterSet() |
|
1111 | + { |
|
1112 | + $liste = array(); |
|
1113 | + $i=0; |
|
1114 | + $liste[$i]['charset'] = 'UTF-8'; |
|
1115 | + $liste[$i]['description'] = 'UTF-8'; |
|
1116 | + return $liste; |
|
1117 | + } |
|
1118 | + |
|
1119 | + /** |
|
1120 | 1120 | * Return collation used in database |
1121 | - * |
|
1121 | + * |
|
1122 | 1122 | * @return string Collation value |
1123 | - */ |
|
1124 | - function getDefaultCollationDatabase() |
|
1125 | - { |
|
1126 | - return 'UTF-8'; |
|
1127 | - } |
|
1123 | + */ |
|
1124 | + function getDefaultCollationDatabase() |
|
1125 | + { |
|
1126 | + return 'UTF-8'; |
|
1127 | + } |
|
1128 | 1128 | |
1129 | - /** |
|
1129 | + /** |
|
1130 | 1130 | * Return list of available collation that can be used for database |
1131 | - * |
|
1131 | + * |
|
1132 | 1132 | * @return array List of Collation |
1133 | - */ |
|
1134 | - function getListOfCollation() |
|
1135 | - { |
|
1136 | - $liste = array(); |
|
1137 | - $i=0; |
|
1138 | - $liste[$i]['charset'] = 'UTF-8'; |
|
1139 | - $liste[$i]['description'] = 'UTF-8'; |
|
1140 | - return $liste; |
|
1141 | - } |
|
1142 | - |
|
1143 | - /** |
|
1133 | + */ |
|
1134 | + function getListOfCollation() |
|
1135 | + { |
|
1136 | + $liste = array(); |
|
1137 | + $i=0; |
|
1138 | + $liste[$i]['charset'] = 'UTF-8'; |
|
1139 | + $liste[$i]['description'] = 'UTF-8'; |
|
1140 | + return $liste; |
|
1141 | + } |
|
1142 | + |
|
1143 | + /** |
|
1144 | 1144 | * Return full path of dump program |
1145 | - * |
|
1145 | + * |
|
1146 | 1146 | * @return string Full path of dump program |
1147 | - */ |
|
1148 | - function getPathOfDump() |
|
1149 | - { |
|
1150 | - // FIXME: not for SQLite |
|
1151 | - $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
1152 | - |
|
1153 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1154 | - if ($resql) |
|
1155 | - { |
|
1156 | - $liste=$this->fetch_array($resql); |
|
1157 | - $basedir=$liste['Value']; |
|
1158 | - $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
1159 | - } |
|
1160 | - return $fullpathofdump; |
|
1161 | - } |
|
1147 | + */ |
|
1148 | + function getPathOfDump() |
|
1149 | + { |
|
1150 | + // FIXME: not for SQLite |
|
1151 | + $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
1152 | + |
|
1153 | + $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1154 | + if ($resql) |
|
1155 | + { |
|
1156 | + $liste=$this->fetch_array($resql); |
|
1157 | + $basedir=$liste['Value']; |
|
1158 | + $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
1159 | + } |
|
1160 | + return $fullpathofdump; |
|
1161 | + } |
|
1162 | 1162 | |
1163 | - /** |
|
1163 | + /** |
|
1164 | 1164 | * Return full path of restore program |
1165 | - * |
|
1165 | + * |
|
1166 | 1166 | * @return string Full path of restore program |
1167 | - */ |
|
1168 | - function getPathOfRestore() |
|
1169 | - { |
|
1170 | - // FIXME: not for SQLite |
|
1171 | - $fullpathofimport='/pathtomysql/mysql'; |
|
1172 | - |
|
1173 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1174 | - if ($resql) |
|
1175 | - { |
|
1176 | - $liste=$this->fetch_array($resql); |
|
1177 | - $basedir=$liste['Value']; |
|
1178 | - $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
1179 | - } |
|
1180 | - return $fullpathofimport; |
|
1181 | - } |
|
1167 | + */ |
|
1168 | + function getPathOfRestore() |
|
1169 | + { |
|
1170 | + // FIXME: not for SQLite |
|
1171 | + $fullpathofimport='/pathtomysql/mysql'; |
|
1172 | + |
|
1173 | + $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1174 | + if ($resql) |
|
1175 | + { |
|
1176 | + $liste=$this->fetch_array($resql); |
|
1177 | + $basedir=$liste['Value']; |
|
1178 | + $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
1179 | + } |
|
1180 | + return $fullpathofimport; |
|
1181 | + } |
|
1182 | 1182 | |
1183 | - /** |
|
1184 | - * Return value of server parameters |
|
1185 | - * |
|
1183 | + /** |
|
1184 | + * Return value of server parameters |
|
1185 | + * |
|
1186 | 1186 | * @param string $filter Filter list on a particular value |
1187 | 1187 | * @return array Array of key-values (key=>value) |
1188 | - */ |
|
1189 | - function getServerParametersValues($filter='') |
|
1190 | - { |
|
1191 | - $result=array(); |
|
1192 | - static $pragmas; |
|
1193 | - if (! isset($pragmas)) { |
|
1194 | - // Définition de la liste des pragmas utilisés qui ne retournent qu'une seule valeur |
|
1195 | - // indépendante de la base de données. |
|
1196 | - // cf. http://www.sqlite.org/pragma.html |
|
1197 | - $pragmas = array( |
|
1198 | - 'application_id', 'auto_vacuum', 'automatic_index', 'busy_timeout', 'cache_size', |
|
1199 | - 'cache_spill', 'case_sensitive_like', 'checkpoint_fullsync', 'collation_list', |
|
1188 | + */ |
|
1189 | + function getServerParametersValues($filter='') |
|
1190 | + { |
|
1191 | + $result=array(); |
|
1192 | + static $pragmas; |
|
1193 | + if (! isset($pragmas)) { |
|
1194 | + // Définition de la liste des pragmas utilisés qui ne retournent qu'une seule valeur |
|
1195 | + // indépendante de la base de données. |
|
1196 | + // cf. http://www.sqlite.org/pragma.html |
|
1197 | + $pragmas = array( |
|
1198 | + 'application_id', 'auto_vacuum', 'automatic_index', 'busy_timeout', 'cache_size', |
|
1199 | + 'cache_spill', 'case_sensitive_like', 'checkpoint_fullsync', 'collation_list', |
|
1200 | 1200 | 'compile_options', 'data_version', /*'database_list',*/ |
1201 | - 'defer_foreign_keys', 'encoding', 'foreign_key_check', 'freelist_count', |
|
1202 | - 'full_column_names', 'fullsync', 'ingore_check_constraints', 'integrity_check', |
|
1203 | - 'journal_mode', 'journal_size_limit', 'legacy_file_format', 'locking_mode', |
|
1204 | - 'max_page_count', 'page_count', 'page_size', 'parser_trace', |
|
1205 | - 'query_only', 'quick_check', 'read_uncommitted', 'recursive_triggers', |
|
1206 | - 'reverse_unordered_selects', 'schema_version', 'user_version', |
|
1207 | - 'secure_delete', 'short_column_names', 'shrink_memory', 'soft_heap_limit', |
|
1208 | - 'synchronous', 'temp_store', /*'temp_store_directory',*/ 'threads', |
|
1209 | - 'vdbe_addoptrace', 'vdbe_debug', 'vdbe_listing', 'vdbe_trace', |
|
1210 | - 'wal_autocheckpoint', |
|
1211 | - ); |
|
1212 | - } |
|
1213 | - |
|
1214 | - // TODO prendre en compte le filtre |
|
1215 | - foreach($pragmas as $var) { |
|
1216 | - $sql = "PRAGMA $var"; |
|
1217 | - $resql=$this->query($sql); |
|
1218 | - if ($resql) |
|
1219 | - { |
|
1220 | - $obj = $this->fetch_row($resql); |
|
1221 | - //dol_syslog(get_class($this)."::select_db getServerParametersValues $var=". print_r($obj, true), LOG_DEBUG); |
|
1222 | - $result[$var] = $obj[0]; |
|
1223 | - } |
|
1224 | - else { |
|
1225 | - // TODO Récupérer le message |
|
1226 | - $result[$var] = 'FAIL'; |
|
1227 | - } |
|
1228 | - } |
|
1229 | - return $result; |
|
1230 | - } |
|
1201 | + 'defer_foreign_keys', 'encoding', 'foreign_key_check', 'freelist_count', |
|
1202 | + 'full_column_names', 'fullsync', 'ingore_check_constraints', 'integrity_check', |
|
1203 | + 'journal_mode', 'journal_size_limit', 'legacy_file_format', 'locking_mode', |
|
1204 | + 'max_page_count', 'page_count', 'page_size', 'parser_trace', |
|
1205 | + 'query_only', 'quick_check', 'read_uncommitted', 'recursive_triggers', |
|
1206 | + 'reverse_unordered_selects', 'schema_version', 'user_version', |
|
1207 | + 'secure_delete', 'short_column_names', 'shrink_memory', 'soft_heap_limit', |
|
1208 | + 'synchronous', 'temp_store', /*'temp_store_directory',*/ 'threads', |
|
1209 | + 'vdbe_addoptrace', 'vdbe_debug', 'vdbe_listing', 'vdbe_trace', |
|
1210 | + 'wal_autocheckpoint', |
|
1211 | + ); |
|
1212 | + } |
|
1213 | + |
|
1214 | + // TODO prendre en compte le filtre |
|
1215 | + foreach($pragmas as $var) { |
|
1216 | + $sql = "PRAGMA $var"; |
|
1217 | + $resql=$this->query($sql); |
|
1218 | + if ($resql) |
|
1219 | + { |
|
1220 | + $obj = $this->fetch_row($resql); |
|
1221 | + //dol_syslog(get_class($this)."::select_db getServerParametersValues $var=". print_r($obj, true), LOG_DEBUG); |
|
1222 | + $result[$var] = $obj[0]; |
|
1223 | + } |
|
1224 | + else { |
|
1225 | + // TODO Récupérer le message |
|
1226 | + $result[$var] = 'FAIL'; |
|
1227 | + } |
|
1228 | + } |
|
1229 | + return $result; |
|
1230 | + } |
|
1231 | 1231 | |
1232 | - /** |
|
1233 | - * Return value of server status |
|
1234 | - * |
|
1232 | + /** |
|
1233 | + * Return value of server status |
|
1234 | + * |
|
1235 | 1235 | * @param string $filter Filter list on a particular value |
1236 | 1236 | * @return array Array of key-values (key=>value) |
1237 | - */ |
|
1238 | - function getServerStatusValues($filter='') |
|
1239 | - { |
|
1240 | - $result=array(); |
|
1241 | - /* |
|
1237 | + */ |
|
1238 | + function getServerStatusValues($filter='') |
|
1239 | + { |
|
1240 | + $result=array(); |
|
1241 | + /* |
|
1242 | 1242 | $sql='SHOW STATUS'; |
1243 | 1243 | if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
1244 | 1244 | $resql=$this->query($sql); |
@@ -1248,79 +1248,79 @@ discard block |
||
1248 | 1248 | } |
1249 | 1249 | */ |
1250 | 1250 | |
1251 | - return $result; |
|
1252 | - } |
|
1253 | - |
|
1254 | - /** |
|
1255 | - * Permet le chargement d'une fonction personnalisee dans le moteur de base de donnees. |
|
1256 | - * Note: le nom de la fonction personnalisee est prefixee par 'db'. La fonction doit être |
|
1257 | - * statique et publique. Le nombre de parametres est determine automatiquement. |
|
1258 | - * |
|
1259 | - * @param string $name Le nom de la fonction a definir dans Sqlite |
|
1260 | - * @param int $arg_count Arg count |
|
1261 | - * @return void |
|
1262 | - */ |
|
1263 | - private function addCustomFunction($name, $arg_count = -1) |
|
1264 | - { |
|
1265 | - if ($this->db) |
|
1266 | - { |
|
1267 | - $newname=preg_replace('/_/','',$name); |
|
1268 | - $localname = __CLASS__ . '::' . 'db' . $newname; |
|
1269 | - $reflectClass = new ReflectionClass(__CLASS__); |
|
1270 | - $reflectFunction = $reflectClass->getMethod('db' . $newname); |
|
1271 | - if ($arg_count < 0) { |
|
1272 | - $arg_count = $reflectFunction->getNumberOfParameters(); |
|
1273 | - } |
|
1274 | - if (!$this->db->createFunction($name, $localname, $arg_count)) |
|
1275 | - { |
|
1276 | - $this->error = "unable to create custom function '$name'"; |
|
1277 | - } |
|
1278 | - } |
|
1279 | - } |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * calc_daynr |
|
1283 | - * |
|
1284 | - * @param int $year Year |
|
1285 | - * @param int $month Month |
|
1286 | - * @param int $day Day |
|
1287 | - * @return int Formatted date |
|
1288 | - */ |
|
1289 | - private static function calc_daynr($year, $month, $day) { |
|
1290 | - $y = $year; |
|
1291 | - if ($y == 0 && $month == 0) return 0; |
|
1292 | - $num = (365* $y + 31 * ($month - 1) + $day); |
|
1293 | - if ($month <= 2) { |
|
1294 | - $y--; } |
|
1295 | - else { |
|
1296 | - $num -= floor(($month * 4 + 23) / 10); |
|
1297 | - } |
|
1298 | - $temp = floor(($y / 100 + 1) * 3 / 4); |
|
1299 | - return $num + floor($y / 4) - $temp; |
|
1300 | - } |
|
1301 | - |
|
1302 | - /** |
|
1303 | - * calc_weekday |
|
1304 | - * |
|
1305 | - * @param int $daynr ??? |
|
1306 | - * @param bool $sunday_first_day_of_week ??? |
|
1307 | - * @return int |
|
1308 | - */ |
|
1309 | - private static function calc_weekday($daynr, $sunday_first_day_of_week) { |
|
1310 | - $ret = floor(($daynr + 5 + ($sunday_first_day_of_week ? 1 : 0)) % 7); |
|
1311 | - return $ret; |
|
1312 | - } |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * calc_days_in_year |
|
1316 | - * |
|
1317 | - * @param string $year Year |
|
1318 | - * @return int Nb of days in year |
|
1319 | - */ |
|
1320 | - private static function calc_days_in_year($year) |
|
1321 | - { |
|
1322 | - return (($year & 3) == 0 && ($year%100 || ($year%400 == 0 && $year)) ? 366 : 365); |
|
1323 | - } |
|
1251 | + return $result; |
|
1252 | + } |
|
1253 | + |
|
1254 | + /** |
|
1255 | + * Permet le chargement d'une fonction personnalisee dans le moteur de base de donnees. |
|
1256 | + * Note: le nom de la fonction personnalisee est prefixee par 'db'. La fonction doit être |
|
1257 | + * statique et publique. Le nombre de parametres est determine automatiquement. |
|
1258 | + * |
|
1259 | + * @param string $name Le nom de la fonction a definir dans Sqlite |
|
1260 | + * @param int $arg_count Arg count |
|
1261 | + * @return void |
|
1262 | + */ |
|
1263 | + private function addCustomFunction($name, $arg_count = -1) |
|
1264 | + { |
|
1265 | + if ($this->db) |
|
1266 | + { |
|
1267 | + $newname=preg_replace('/_/','',$name); |
|
1268 | + $localname = __CLASS__ . '::' . 'db' . $newname; |
|
1269 | + $reflectClass = new ReflectionClass(__CLASS__); |
|
1270 | + $reflectFunction = $reflectClass->getMethod('db' . $newname); |
|
1271 | + if ($arg_count < 0) { |
|
1272 | + $arg_count = $reflectFunction->getNumberOfParameters(); |
|
1273 | + } |
|
1274 | + if (!$this->db->createFunction($name, $localname, $arg_count)) |
|
1275 | + { |
|
1276 | + $this->error = "unable to create custom function '$name'"; |
|
1277 | + } |
|
1278 | + } |
|
1279 | + } |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * calc_daynr |
|
1283 | + * |
|
1284 | + * @param int $year Year |
|
1285 | + * @param int $month Month |
|
1286 | + * @param int $day Day |
|
1287 | + * @return int Formatted date |
|
1288 | + */ |
|
1289 | + private static function calc_daynr($year, $month, $day) { |
|
1290 | + $y = $year; |
|
1291 | + if ($y == 0 && $month == 0) return 0; |
|
1292 | + $num = (365* $y + 31 * ($month - 1) + $day); |
|
1293 | + if ($month <= 2) { |
|
1294 | + $y--; } |
|
1295 | + else { |
|
1296 | + $num -= floor(($month * 4 + 23) / 10); |
|
1297 | + } |
|
1298 | + $temp = floor(($y / 100 + 1) * 3 / 4); |
|
1299 | + return $num + floor($y / 4) - $temp; |
|
1300 | + } |
|
1301 | + |
|
1302 | + /** |
|
1303 | + * calc_weekday |
|
1304 | + * |
|
1305 | + * @param int $daynr ??? |
|
1306 | + * @param bool $sunday_first_day_of_week ??? |
|
1307 | + * @return int |
|
1308 | + */ |
|
1309 | + private static function calc_weekday($daynr, $sunday_first_day_of_week) { |
|
1310 | + $ret = floor(($daynr + 5 + ($sunday_first_day_of_week ? 1 : 0)) % 7); |
|
1311 | + return $ret; |
|
1312 | + } |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * calc_days_in_year |
|
1316 | + * |
|
1317 | + * @param string $year Year |
|
1318 | + * @return int Nb of days in year |
|
1319 | + */ |
|
1320 | + private static function calc_days_in_year($year) |
|
1321 | + { |
|
1322 | + return (($year & 3) == 0 && ($year%100 || ($year%400 == 0 && $year)) ? 366 : 365); |
|
1323 | + } |
|
1324 | 1324 | |
1325 | 1325 | /** |
1326 | 1326 | * calc_week |
@@ -1332,44 +1332,44 @@ discard block |
||
1332 | 1332 | * @param string $calc_year ??? |
1333 | 1333 | * @return string ??? |
1334 | 1334 | */ |
1335 | - private static function calc_week($year, $month, $day, $week_behaviour, &$calc_year) { |
|
1336 | - $daynr=self::calc_daynr($year,$month,$day); |
|
1337 | - $first_daynr=self::calc_daynr($year,1,1); |
|
1338 | - $monday_first= ($week_behaviour & self::WEEK_MONDAY_FIRST) ? 1 : 0; |
|
1339 | - $week_year= ($week_behaviour & self::WEEK_YEAR) ? 1 : 0; |
|
1340 | - $first_weekday= ($week_behaviour & self::WEEK_FIRST_WEEKDAY) ? 1 : 0; |
|
1341 | - |
|
1342 | - $weekday=self::calc_weekday($first_daynr, !$monday_first); |
|
1343 | - $calc_year=$year; |
|
1344 | - |
|
1345 | - if ($month == 1 && $day <= 7-$weekday) |
|
1346 | - { |
|
1347 | - if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) |
|
1348 | - return 0; |
|
1349 | - $week_year= 1; |
|
1350 | - $calc_year--; |
|
1351 | - $first_daynr-= ($days=self::calc_days_in_year($calc_year)); |
|
1352 | - $weekday= ($weekday + 53*7- $days) % 7; |
|
1353 | - } |
|
1354 | - |
|
1355 | - if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) { |
|
1356 | - $days= $daynr - ($first_daynr+ (7-$weekday)); |
|
1357 | - } |
|
1358 | - else { |
|
1359 | - $days= $daynr - ($first_daynr - $weekday); |
|
1360 | - } |
|
1361 | - |
|
1362 | - if ($week_year && $days >= 52*7) |
|
1363 | - { |
|
1364 | - $weekday= ($weekday + self::calc_days_in_year($calc_year)) % 7; |
|
1365 | - if ((!$first_weekday && $weekday < 4) || ($first_weekday && $weekday == 0)) |
|
1366 | - { |
|
1367 | - $calc_year++; |
|
1368 | - return 1; |
|
1369 | - } |
|
1370 | - } |
|
1371 | - return floor($days/7+1); |
|
1372 | - } |
|
1335 | + private static function calc_week($year, $month, $day, $week_behaviour, &$calc_year) { |
|
1336 | + $daynr=self::calc_daynr($year,$month,$day); |
|
1337 | + $first_daynr=self::calc_daynr($year,1,1); |
|
1338 | + $monday_first= ($week_behaviour & self::WEEK_MONDAY_FIRST) ? 1 : 0; |
|
1339 | + $week_year= ($week_behaviour & self::WEEK_YEAR) ? 1 : 0; |
|
1340 | + $first_weekday= ($week_behaviour & self::WEEK_FIRST_WEEKDAY) ? 1 : 0; |
|
1341 | + |
|
1342 | + $weekday=self::calc_weekday($first_daynr, !$monday_first); |
|
1343 | + $calc_year=$year; |
|
1344 | + |
|
1345 | + if ($month == 1 && $day <= 7-$weekday) |
|
1346 | + { |
|
1347 | + if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) |
|
1348 | + return 0; |
|
1349 | + $week_year= 1; |
|
1350 | + $calc_year--; |
|
1351 | + $first_daynr-= ($days=self::calc_days_in_year($calc_year)); |
|
1352 | + $weekday= ($weekday + 53*7- $days) % 7; |
|
1353 | + } |
|
1354 | + |
|
1355 | + if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) { |
|
1356 | + $days= $daynr - ($first_daynr+ (7-$weekday)); |
|
1357 | + } |
|
1358 | + else { |
|
1359 | + $days= $daynr - ($first_daynr - $weekday); |
|
1360 | + } |
|
1361 | + |
|
1362 | + if ($week_year && $days >= 52*7) |
|
1363 | + { |
|
1364 | + $weekday= ($weekday + self::calc_days_in_year($calc_year)) % 7; |
|
1365 | + if ((!$first_weekday && $weekday < 4) || ($first_weekday && $weekday == 0)) |
|
1366 | + { |
|
1367 | + $calc_year++; |
|
1368 | + return 1; |
|
1369 | + } |
|
1370 | + } |
|
1371 | + return floor($days/7+1); |
|
1372 | + } |
|
1373 | 1373 | |
1374 | 1374 | } |
1375 | 1375 |