Precise Similar Topics

SQL error with float in french - Precise Similar Topics

SQL error with float in french

by Aurelienazerty » Fri May 25, 2018 10:31 pm

With my server configuration all float are 2,5 and not 2.5

So, the

Code: Select all

'WHERE'		=> "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= " . (float) $sensitivity . '
make an SQL error.

A way to prevent is to replace

Code: Select all

'WHERE'		=> "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= " . str_replace(',', '.', (float) $sensitivity) . '
it's quick and dirty
User avatar
Aurelienazerty
Registered User
Posts: 226
Joined: Sat Jan 08, 2005 8:21 pm

Re: SQL error with float in french

by MattF » Sat May 26, 2018 4:08 pm

Aurelienazerty wrote:With my server configuration all float are 2,5 and not 2.5

So, the

Code: Select all

'WHERE'		=> "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= " . (float) $sensitivity . '
make an SQL error.

A way to prevent is to replace

Code: Select all

'WHERE'		=> "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= " . str_replace(',', '.', (float) $sensitivity) . '
it's quick and dirty
What happens if you don't do that, and instead change this:

Code: Select all

// Get stored sensitivity value and divide by 10. In query it should be a number between 0.0 to 1.0.
$sensitivity = $this->config->offsetExists('similar_topics_sense') ? $this->config['similar_topics_sense'] / 10 : '0.5';
to

Code: Select all

// Get stored sensitivity value and divide by 10. In query it should be a number between 0.0 to 1.0.
$sensitivity = $this->config->offsetExists('similar_topics_sense') ? number_format($this->config['similar_topics_sense'] / 10, 1, '.', '') : '0.5';
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 6097
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

Re: SQL error with float in french

by Aurelienazerty » Tue Aug 27, 2019 3:11 pm

It's still dosent work.

We had to change

Code: Select all

'WHERE'		=> "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= " . (float) $sensitivity . '
to

Code: Select all

'WHERE'		=> "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= " . str_replace(',', '.', (float) $sensitivity) . '
In similartopics/driver/mysqli.php (line 68)
User avatar
Aurelienazerty
Registered User
Posts: 226
Joined: Sat Jan 08, 2005 8:21 pm

Re: SQL error with float in french

by MattF » Tue Aug 27, 2019 6:31 pm

Since your SQL server expects mathematical numbers to use decimals (and not commas) you should consider fixing your server configuration to use the expected decimal standard then.
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 6097
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman