2013-03-23, 03:33 PM
While I was testing mybb by adding post / delete thread and etc, mybb keeps throwing out "Integrity constraint violation: 19 column dateline is not unique". What causes this issue?
$db->replace_query("stats", $todays_stats, "dateline");
to$db->replace_query("stats", $todays_stats);
if(is_array($default_field) && !empty($default_field))
{
$search_bit = array();
foreach($default_field as $field)
{
$search_bit[] = "{$field} = '".$replacements[$field]."'";
}
$search_bit = implode(" AND ", $search_bit);
$query = $this->write_query("SELECT COUNT(".$default_field[0].") as count FROM {$this->table_prefix}{$table} WHERE {$search_bit} LIMIT 1");
if($this->fetch_field($query, "count") == 1)
{
$update = true;
}
}
else
{
$query = $this->write_query("SELECT {$default_field} FROM {$this->table_prefix}{$table}");
while($column = $this->fetch_array($query))
{
if($column[$default_field] == $replacements[$default_field])
{
$update = true;
break;
}
}
}
if($default_field)
{
$search_bit = array();
foreach((array)$default_field as $field)
{
$search_bit[] = "{$field} = '".$replacements[$field]."'";
}
$search_bit = implode(" AND ", $search_bit);
$query = $this->write_query("SELECT COUNT(".$default_field[0].") as count FROM {$this->table_prefix}{$table} WHERE {$search_bit} LIMIT 1");
if($this->fetch_field($query, "count") == 1)
{
$update = true;
}
}
(2013-03-23, 03:46 PM)Euan T. Wrote: [ -> ]SQlite support is severely lacking I'm afraid. The only fully supported databases are MySQL/MySQLi really.
(2013-03-23, 03:49 PM)frostschutz Wrote: [ -> ]It's a bug in MyBB's inc/db_sqlite.php::replace_query() function.
MyBB only works with MySQL, the other DB drivers are all buggy.
Workaround: in inc/functions.php change
to$db->replace_query("stats", $todays_stats, "dateline");
$db->replace_query("stats", $todays_stats);
Or if that does not work either, try in inc/db_sqlite.php
if(is_array($default_field) && !empty($default_field)) { $search_bit = array(); foreach($default_field as $field) { $search_bit[] = "{$field} = '".$replacements[$field]."'"; } $search_bit = implode(" AND ", $search_bit); $query = $this->write_query("SELECT COUNT(".$default_field[0].") as count FROM {$this->table_prefix}{$table} WHERE {$search_bit} LIMIT 1"); if($this->fetch_field($query, "count") == 1) { $update = true; } } else { $query = $this->write_query("SELECT {$default_field} FROM {$this->table_prefix}{$table}"); while($column = $this->fetch_array($query)) { if($column[$default_field] == $replacements[$default_field]) { $update = true; break; } } }
It doesn't set $search_bit in the else tree, that's why it fails. You should remove the else tree entirely and just cast $default_field to array instead.
if($default_field) { $search_bit = array(); foreach((array)$default_field as $field) { $search_bit[] = "{$field} = '".$replacements[$field]."'"; } $search_bit = implode(" AND ", $search_bit); $query = $this->write_query("SELECT COUNT(".$default_field[0].") as count FROM {$this->table_prefix}{$table} WHERE {$search_bit} LIMIT 1"); if($this->fetch_field($query, "count") == 1) { $update = true; } }
and then cross your fingers and hope for the best
Seriously, you don't want to use this. For MyBB, go with MySQL.
(2013-03-23, 04:12 PM)Daniel Hyuuga Wrote: [ -> ]Sorry forgot to update the thread. This issue has been resolved. I just changed field "mybb_stats" > dateline [bigint(30) INTEGER PRIMARY] to dateline bigint(30), then the error goes away.
./admin/modules/home/preferences.php:40: $db->replace_query("adminoptions", $sqlarray, "uid");
./inc/class_session.php:525: $db->replace_query("sessions", $onlinedata, "sid", false);
./inc/functions.php:1909: $db->replace_query("stats", $todays_stats, "dateline"); # that's yours
./install/upgrade.php:748: $db->replace_query("upgrade_data", $replace_array, "title");
(2013-03-23, 04:53 PM)frostschutz Wrote: [ -> ](2013-03-23, 04:12 PM)Daniel Hyuuga Wrote: [ -> ]Sorry forgot to update the thread. This issue has been resolved. I just changed field "mybb_stats" > dateline [bigint(30) INTEGER PRIMARY] to dateline bigint(30), then the error goes away.
Yo dawg I see you have an error so let's make an error so you can hide your error with an error.
By the way, there are several other calls to $db->replace_query() which will cause more of the same issues.
./admin/modules/home/preferences.php:40: $db->replace_query("adminoptions", $sqlarray, "uid"); ./inc/class_session.php:525: $db->replace_query("sessions", $onlinedata, "sid", false); ./inc/functions.php:1909: $db->replace_query("stats", $todays_stats, "dateline"); # that's yours ./install/upgrade.php:748: $db->replace_query("upgrade_data", $replace_array, "title");
...they will all not do what they're supposed to. You have to fix db_sqlite::replace_query() for that, fix above might work or might not work, I didn't test it.
Anyway: use MySQL.
(2013-03-23, 05:56 PM)frostschutz Wrote: [ -> ]Why do I even try to help ...