FIX: GetNextValue() adding regexsql() function
This commit is contained in:
parent
026404657d
commit
c12a6bd4d1
@ -80,6 +80,25 @@ abstract class DoliDB implements Database
|
|||||||
return 'IF('.$test.','.$resok.','.$resko.')';
|
return 'IF('.$test.','.$resok.','.$resko.')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a SQL REGEXP
|
||||||
|
*
|
||||||
|
* @param string $subject string tested
|
||||||
|
* @param string $pattern SQL pattern to match
|
||||||
|
* @param string $sqlstring whether or not the string being tested is an SQL expression
|
||||||
|
* @return string SQL string
|
||||||
|
*/
|
||||||
|
public function regexpsql($subject, $pattern, $sqlstring = false)
|
||||||
|
{
|
||||||
|
if ($sqlstring) {
|
||||||
|
return "(". $subject ." REGEXP '" . $pattern . "')";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "('". $subject ."' REGEXP '" . $pattern . "')";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
|
* Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
|
||||||
* Function to use to build INSERT, UPDATE or WHERE predica
|
* Function to use to build INSERT, UPDATE or WHERE predica
|
||||||
|
|||||||
@ -724,6 +724,24 @@ class DoliDBPgsql extends DoliDB
|
|||||||
return '(CASE WHEN '.$test.' THEN '.$resok.' ELSE '.$resko.' END)';
|
return '(CASE WHEN '.$test.' THEN '.$resok.' ELSE '.$resko.' END)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a SQL REGEXP
|
||||||
|
*
|
||||||
|
* @param string $subject string tested
|
||||||
|
* @param string $pattern SQL pattern to match
|
||||||
|
* @param string $sqlstring whether or not the string being tested is an SQL expression
|
||||||
|
* @return string SQL string
|
||||||
|
*/
|
||||||
|
public function regexpsql($subject, $pattern, $sqlstring = false)
|
||||||
|
{
|
||||||
|
if ($sqlstring) {
|
||||||
|
return "(". $subject ." ~ '" . $pattern . "')";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "('". $subject ."' ~ '" . $pattern . "')";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renvoie le code erreur generique de l'operation precedente.
|
* Renvoie le code erreur generique de l'operation precedente.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1282,6 +1282,11 @@ function get_next_value($db, $mask, $table, $field, $where = '', $objsoc = '', $
|
|||||||
$sql .= " FROM ".MAIN_DB_PREFIX.$table;
|
$sql .= " FROM ".MAIN_DB_PREFIX.$table;
|
||||||
$sql .= " WHERE ".$field." LIKE '".$db->escape($maskLike)."'";
|
$sql .= " WHERE ".$field." LIKE '".$db->escape($maskLike)."'";
|
||||||
$sql .= " AND ".$field." NOT LIKE '(PROV%)'";
|
$sql .= " AND ".$field." NOT LIKE '(PROV%)'";
|
||||||
|
|
||||||
|
// To ensure that all variables within the MAX() brackets are integers
|
||||||
|
$sql .= " AND ". $db->regexpsql($sqlstring, '^[0-9]+$', true);
|
||||||
|
|
||||||
|
|
||||||
if ($bentityon) { // only if entity enable
|
if ($bentityon) { // only if entity enable
|
||||||
$sql .= " AND entity IN (".getEntity($sharetable).")";
|
$sql .= " AND entity IN (".getEntity($sharetable).")";
|
||||||
} elseif (!empty($forceentity)) {
|
} elseif (!empty($forceentity)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user