Skip to content

Commit

Permalink
Fixed varchar length verification in update(). Improved some debug me…
Browse files Browse the repository at this point in the history
…ssages.

git-svn-id: http://voip.null.ro/svn/ansql/trunk@297 dbfed7de-b0aa-0410-b6a1-c7e608b77fc9
  • Loading branch information
monica committed Mar 15, 2017
1 parent 724497d commit 005643f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -1520,11 +1520,11 @@ protected function buildInsertParts($with_serials=false)
$res = $this->isValidVarchar($var->_type, $value);
if (!$res[0])
{
$error .= " "._("Field ")." '"._($var_name)."' "._("must be at most ".$res[1]." characters long").".";
$error .= " "._("Field ")." '"._($var_name)."' "._("must be at most ".$res[1]." characters long but has '").$res[2]."'.";
$error_fields[] = $var_name;
continue;
}
}
}
if ($columns != "")
{
$columns .= ",";
Expand Down Expand Up @@ -1554,8 +1554,9 @@ private function isValidVarchar($type, $value)
$var_length = strlen($value);
$allowed_length = explode("(", $type);
$allowed_length = substr($allowed_length[1],0,-1);
if ($var_length > (int)$allowed_length)
return array(false,$allowed_length);
$allowed_length = (int)$allowed_length;
if ($var_length > $allowed_length)
return array(false,$allowed_length,$var_length);
return array(true);
}

Expand Down Expand Up @@ -1638,15 +1639,16 @@ public function update($conditions = array(), $verifications = array())
$error_fields[] = $var_name;
continue;
}
$value = $var->escape($this->{$var_name});
$value = $this->{$var_name};
if (substr($var->_type,0,7) == "varchar") {
$res = $this->isValidVarchar($var->_type,$value);
if (!$res[0]) {
$error .= " "._("Field ")." '"._($var_name)."' "._("must be at most ".$res[1]." characters long").".";
$error .= " "._("Field ")." '"._($var_name)."' "._("must be at most ".$res[1]." characters long but has '").$res[2]."'.";
$error_fields[] = $var_name;
continue;
}
}
}
$value = $var->escape($value);

$variables .= esc($var_name)."=".$value."";
if ($var_name!="password")
Expand Down Expand Up @@ -1738,7 +1740,7 @@ public function fieldUpdate($conditions = array(), $fields = array(), $verificat
if (substr($var->_type,0,7) == "varchar") {
$res = $this->isValidVarchar($var->_type,$value);
if (!$res[0]) {
$error .= " "._("Field ")." '"._($var_name)."' "._("must be at most ".$res[1]." characters long").".";
$error .= " "._("Field ")." '"._($var_name)."' "._("must be at most ".$res[1]." characters long but has '").$res[2]."'.";
$error_fields[] = $var_name;
continue;
}
Expand Down

0 comments on commit 005643f

Please sign in to comment.