Simple Machines Community Forum

SMF Development => Bug Reports => Fixed or Bogus Bugs => Topic started by: onepiece on April 22, 2009, 06:10:34 AM

Title: [3405] [2.0 RC1] No Errors and No Table
Post by: onepiece on April 22, 2009, 06:10:34 AM
When using $smcFunc['db_create_table'] if you have an incorrect table definition, like defining a size value for a TEXT field, the table is not created but there are no errors either -even when you are on debug mode-.

This gives mod authors a hard time debugging the issue and figuring out the problem. Here some examples of it.

http://www.simplemachines.org/community/index.php?topic=224166.msg1814902#msg1814902
http://www.simplemachines.org/community/index.php?topic=276008.0
http://www.simplemachines.org/community/index.php?topic=299177.0
Title: Re: [2.0 RC1] No Errors and No Table
Post by: SleePy on April 26, 2009, 11:56:33 AM
Thanks,
Bug #3405: Table creation does not return success of failure (http://dev.simplemachines.org/mantis/view.php?id=3405)

You can fix this by modifying DbPackages-mysq.php

Find:

    // Create the table!
    $smcFunc['db_query']('', $table_query,
        'security_override'
    );


Add After:

    // Does it exist?
    $request = $smcFunc['db_query']('', '
        SHOW TABLES LIKE {string:table}',
        array(
            'table' => $table_name,
    ));
    // Oh no!
    if ($smcFunc['db_num_rows']($request) < 1)
    {
        loadLanguage('Errors');
        log_error($txt['database_error'] . ':' . sprintf($txt['db_table_creation'], $table_name), $database, null, null);
        $smcFunc['db_free_result']($request);

        return false;
    }
    $smcFunc['db_free_result']($request);

    return true;


Then add to Errors.english.php

$txt['db_table_creation'] = 'Unable to create %1s table in database';
Title: Re: [2.0 RC1] No Errors and No Table
Post by: onepiece on May 04, 2009, 06:32:24 AM
I don't think that's a neat solution. In my opinion, it should return the real error occurring. Here is the actual problem:

Subs-Db-mysql.php

Code (Line:355-60) Select

if (empty($db_unbuffered))
$ret = @mysql_query($db_string, $connection);
else
$ret = @mysql_unbuffered_query($db_string, $connection);
if ($ret === false && empty($db_values['db_error_skip']))
$ret = smf_db_error($db_string, $connection);


It won't return an error for $smcFunc['db_query'] if $db_values['db_error_skip'] is not empty. When $db_values is set as the string 'security_override' (which is how it is done for most of the package functions) $db_values['db_error_skip'] will be equal to 's' and it won't return an error.

My suggested fixes: (just for MySQL as an example)

Sources/Subs-Db-mysql.php

Quick and easy way:

Code (Find) Select
if ($ret === false && empty($db_values['db_error_skip']))

Code (Replace) Select
if ($ret === false && (empty($db_values['db_error_skip']) || $db_values === 'security_override'))

Maybe a cleaner way:

Code (Find) Select
// Overriding security? This is evil!
$security_override = $db_values === 'security_override' || !empty($db_values['security_override']);


Code (Replace) Select
// It is better to have db values as an array here.
$db_values = $db_values === 'security_override' ? array('security_override' => true) : $db_values;

// Overriding security? This is evil!
$security_override = !empty($db_values['security_override']);
Title: Re: [2.0 RC1] No Errors and No Table
Post by: karlbenson on May 04, 2009, 07:11:55 AM
As i pointe out to sleepy,
We need to find out why security_override is used when creating the table.
For alot of things it has been used INTENTIONALLY.
Title: Re: [2.0 RC1] No Errors and No Table
Post by: onepiece on May 04, 2009, 12:14:18 PM
Well, I don't have a problem with security_override parameter. I just say that, regardless of the value of security_override parameter, it should return an error if there are any.
Title: Re: [2.0 RC1] No Errors and No Table
Post by: SleePy on May 04, 2009, 12:22:35 PM
I assumed that it was done that way on purpose to prevent SMF from trying to throw security measures at something we hand worked out ourselves.
In any case then. We just add => true, after 'security_override' and this should still work.
Title: Re: [2.0 RC1] No Errors and No Table
Post by: onepiece on May 04, 2009, 12:32:39 PM
Quote from: SleePy on May 04, 2009, 12:22:35 PM
I assumed that it was done that way on purpose to prevent SMF from trying to throw security measures at something we hand worked out ourselves.

I'm not sure if I got what you mean correctly, but SMF doesn't show the actual error to user, unless s/he has the 'admin_forum' permission.

Quote from: SleePy on May 04, 2009, 12:22:35 PM
In any case then. We just add => true, after 'security_override' and this should still work.

Yeah, with the array() it would work. However, there are quite a lot of queries using it as a string. Also, if that is to make only the desired queries to display errors, I don't think that's a clean way either.
Title: Re: [3405] [2.0 RC1] No Errors and No Table
Post by: [SiNaN] on May 12, 2010, 08:26:27 AM
Fixed with Revision 9883.