Topic: Trying to change Printing Profiles

When I try to make changes to the Sales Department profile, I get this error:

DATABASE ERROR : could not update printing profile
error code : 1366
error message : Incorrect integer value: '' for column 'printer' at row 1
sql that failed was : REPLACE INTO 9_print_profiles (profile, report, printer) VALUES ('Sales Department','','')

2 (edited by apmuthu 09/18/2013 02:52:38 am)

Re: Trying to change Printing Profiles

Lines 1109-1123 of sql/en_US-new.sql:

CREATE TABLE IF NOT EXISTS `0_print_profiles` (
  `id` smallint(6) unsigned NOT NULL auto_increment,
  `profile` varchar(30) NOT NULL,
  `report` varchar(5) default NULL,
  `printer` tinyint(3) unsigned default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `profile` (`profile`,`report`)
) ENGINE=MyISAM  AUTO_INCREMENT=10 ;

--
-- Dumping data for table `0_print_profiles`
--

INSERT INTO `0_print_profiles` VALUES(1, 'Out of office', '', 0);
INSERT INTO `0_print_profiles` VALUES(2, 'Sales Department', '', 0);

Therefore an integer should be used and not a string. This was not an issue for older MySQL versions, but the later ones after Oracle took over seem to become more strict in such insert syntaxes. Wonder if NULL values would cause trouble (backward compatibility issues) or a mere 0 should suffice.

Lines 52-65 of admin/db/printers_db.inc:

function update_printer_profile($name, $dest)
{
    foreach( $dest as $rep => $printer) {
        if ($printer != '' || $rep == '') {
            $sql = "REPLACE INTO ".TB_PREF."print_profiles "
            ."(profile, report, printer) VALUES ("
            .db_escape($name).","
            .db_escape($rep).","
            .db_escape($printer).")";
        } else {
            $sql = "DELETE FROM ".TB_PREF."print_profiles WHERE ("
                ."report=" . db_escape($rep)
                ." AND profile=".db_escape($name).")";
        }

A prior integer cast for $printer may be in order here.

The offending line is line 60 in the above code:

            .db_escape($printer).")";

which may be replaced with:

            . ($printer + 0) .")";

Re: Trying to change Printing Profiles

Fixed in repo, thanks.
Janusz

Re: Trying to change Printing Profiles

Nice Fix.