Skip to content

Commit

Permalink
Added option to add the serial fields in buildInsertParts. Report las…
Browse files Browse the repository at this point in the history
…t_db_error in logs when update/create table statements fail.

git-svn-id: http://voip.null.ro/svn/ansql/trunk@160 dbfed7de-b0aa-0410-b6a1-c7e608b77fc9
  • Loading branch information
monica committed Apr 9, 2015
1 parent 6527012 commit f42ca90
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public static function createTable($table,$vars)

$res = self::db_query($query) !== false;
if (!$res)
Debug::Output(_("Could not create table")." '$table'. "._("Query failed").": $query");
Debug::Output(_("Could not create table")." '$table'. "._("Query failed").": $query". " .Error: ".Database::get_last_db_error());

return $res;
}
Expand Down Expand Up @@ -679,7 +679,7 @@ public static function updateTable($table,$vars)
}
}
if (!self::queryRaw($query)) {
Debug::Output('critical', _("Could not update table")." '$table'. ".("Query failed").": '$query'");
Debug::Output('critical', _("Could not update table")." '$table'. ".("Query failed").": '$query'". " .Error: ".Database::get_last_db_error());
$error_sql_update = true;
continue;
}
Expand All @@ -688,7 +688,7 @@ public static function updateTable($table,$vars)
$val = $var->escape($var->_value);
$query = "UPDATE ".esc($table)." SET ".esc($name)."=$val";
if (!self::queryRaw($query)) {
Debug::Output('critical', _("Could not update table fields to default value for")." '$table'. "._("Query failed").": '$query'");
Debug::Output('critical', _("Could not update table fields to default value for")." '$table'. "._("Query failed").": '$query'". " .Error: ".Database::get_last_db_error());
$error_sql_update = true;
}
}
Expand Down Expand Up @@ -1430,9 +1430,11 @@ public function insert($retrieve_id = true, $keep_log = true)

/**
* Build various pieces necesary for building an INSERT query. Build error string, error_field array and insert log
* @param #with_serials Bool. Defaults to false. Whether to add the serial fields in the built parts or not.
* This is true only when the parts are used from outside the Model class
* @return array("columns"=>String, "values"=>String, "error"=>String, "error_fields"=>array(), "serials"=>array(), "insert_log"=>String, "update_fields"=>String)
*/
protected function buildInsertParts()
protected function buildInsertParts($with_serials=false)
{
Debug::func_start(__METHOD__,func_get_args(),"framework");

Expand All @@ -1446,7 +1448,7 @@ protected function buildInsertParts()
foreach ($this->_model as $var_name => $var)
{
$value = $this->$var_name;
if (!strlen($value))
if (!strlen($value) && !$with_serials)
{
// some types have defaults assigned by DB server so we don't set them
switch ($var->_type)
Expand Down

0 comments on commit f42ca90

Please sign in to comment.