Opened 3 years ago

Closed 3 years ago

#2153 closed Bug (fixed)

Piwik Tracker throws SQL exceptions when using a boolean value for a tinyint(1) field

Reported by: JulienM Owned by:
Priority: normal Milestone: Piwik 1.2.1
Component: Core Keywords:
Cc: Sensitive: no

Description (last modified by JulienM)

/core/Tracker/Db/Pdo/Mysql.php#L170 with out of the box MySQL 5.5.9 throws

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'visitor_returning' at row 1

This happens because $parameters(3) is a bool variable and 'visitor_returning' is a tinyint(1) field.

One of the places this value is set is in /core/Tracker/Visit.php#L437.

Updating

'visitor_returning' 		=> $visitCount > 1 || $this->isVisitorKnown(),

to

'visitor_returning' 		=> $visitCount > 1 || $this->isVisitorKnown() ? 1 : 0,

suppresses the exception and confirms the issue.

What is the best way to go from here ?

Change History (5)

comment:1 Changed 3 years ago by JulienM (JulienMoumne)

  • Description modified (diff)

comment:2 Changed 3 years ago by vipsoft (robocoder)

  • Milestone set to 1.3 - Piwik 1.3

This is a weird regression. The MySQL docs says BOOL/BOOLEAN is a synonym for TINYINT(1), and TRUE and FALSE are aliases for 1 and 0, respectively. Also, looking at Piwik's schema, visitor returning is "TINYINT(1) NOT NULL". I would have expected PHP's type conversion to yield 1 for true.

<?php  var_dump( true == 1);

Well... I'm ok with the change. I assume other TINYINT columns are affected?

comment:3 Changed 3 years ago by matt (mattab)

+1 for patch

comment:4 Changed 3 years ago by JulienM (JulienMoumne)

With /ticket/2154 all my integration tests are now resolved on PHP 5.3.5, MySQL 5.5.9 x64.

comment:5 Changed 3 years ago by JulienM (JulienMoumne)

  • Resolution set to fixed
  • Status changed from new to closed

(In [4052]) fixes #2153

Note: See TracTickets for help on using tickets.