?
avatar vzenix
vzenix
21 Jan 2015

Steps to reproduce the issue

Installation of a module

Expected result

Installation of a module

Actual result

[Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot insert the value NULL into column 'path', table '*****.dbo._menu'; column does not allow nulls. INSERT fails.SQL=INSERT INTO *******_menu VALUES ('1','1','281','282','*','main','***','index.php?option=**','component','0','','1','class:component','0','1')

System information (as much as possible)

Joomla 3.3.6

Additional comments

I insert a code in insertObject() inside JDatabaseDriverSqlsrv

/**
 * Inserts a row into a table based on an object's properties.
 *
 * @param   string  $table    The name of the database table to insert into.
 * @param   object  &$object  A reference to an object whose public properties match the table fields.
 * @param   string  $key      The name of the primary key. If provided the object property is updated.
 *
 * @return  boolean    True on success.
 *
 * @since   12.1
 * @throws  RuntimeException
 */
public function insertObject($table, &$object, $key = null)
{
    $fields = array();
    $values = array();
    $statement = 'INSERT INTO ' . $this->quoteName($table) . ' (%s) VALUES (%s)';

    foreach (get_object_vars($object) as $k => $v)
    {
        // Only process non-null scalars.
        if (is_array($v) or is_object($v) or $v === null)
        {
            continue;
        }

        if (!$this->checkFieldExists($table, $k))
        {
            continue;
        }

        if ($k[0] == '_')
        {
            // Internal field
            continue;
        }

        if ($k == $key && $key == 0)
        {
            continue;
        }

        $fields[] = $this->quoteName($k);
        $values[] = $this->Quote($v);
    }

    // Check null and not null values if have values
    if ($object instanceof JTable && $key !== null)
    {
        foreach ($object->getFields() AS $key_field => $value_field)
        {
            // if is not primary key set defaul value if not exist this value
            // for evade error "Cannot insert the value NULL into column 'XXX', 
            // table 'XXX'; column does not allow nulls.
            if (!in_array($this->quoteName($key_field), $fields) && $value_field->Null == "NO" && ((is_array($key) && !in_array($key_field, $key)) || (!is_array($key) && $key_field != $key)))
            {
                $fixed = null;
                if (gettype($value_field->Default) !== null)
                {
                    $fixed = preg_replace( "/(\A[\(][\'])|(\A[\(][\(])|([\)][\)]$)|([\'][\)]$)/i", "", $value_field->Default );
                }
                else
                {
                    switch ($value_field->Type)
                    {
                        case "char":  case "varchar":  case "text":
                        case "nchar": case "nvarchar": case "ntext":
                            $fixed = '';
                            break;

                        case "bigint":   case "numeric": case "bit":
                        case "smallint": case "decimal": case "smallmoney":
                        case "int":      case "tinyint": case "money":
                        case "int":      case "float":   case "real":
                            $fixed = 0;
                            break;  

                        default:
                            $fixed = '';
                            break;
                    }
                }

                if ($fixed !== null)
                {
                    $fields[] = $this->quoteName($key_field);
                    $values[] = $this->Quote($value_field);
                }
            }
        }
    }
    // die("");


    // Set the query and execute the insert.
    $this->setQuery(sprintf($statement, implode(',', $fields), implode(',', $values)));

    if (!$this->execute())
    {
        return false;
    }

    $id = $this->insertid();

    if ($key && $id)
    {
        $object->$key = $id;
    }

    return true;
}
avatar vzenix vzenix - open - 21 Jan 2015
avatar vzenix
vzenix - comment - 21 Jan 2015

Change line

$values[] = $this->Quote($value_field);
for
$values[] = $this->Quote($fixed);

My Fault

avatar brianteeman
brianteeman - comment - 21 Jan 2015

Please can you retest against the current staging release that you can download here http://developer.joomla.org/cms-packages/

If you still have the error please can you submit a PR with your fix https://docs.joomla.org/Filing_bugs_and_issues#Issue_a_pull_request_directly_on_Joomla.21.27s_GitHub_repository


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5850.

avatar brianteeman brianteeman - change - 21 Jan 2015
Status New Information Required
avatar brianteeman brianteeman - change - 23 Jan 2015
Labels Added: ?
avatar brianteeman brianteeman - change - 23 Jan 2015
Labels Added: ?
avatar JeremyLC
JeremyLC - comment - 26 Jan 2015

I'm not sure how this is supposed to have been fixed in 3.4. A cursory glance at the affected files doesn't show any (relevant) changes.

avatar brianteeman
brianteeman - comment - 26 Jan 2015

No one said it had been. There have been changes obviously throughout 3.4 so it is important to confirm that an issue found in 3.3.6 can be repeated in 3.4 before spending any time on it.

If you still have the error please can you submit a PR with your fix https://docs.joomla.org/Filing_bugs_and_issues#Issue_a_pull_request_directly_on_Joomla.21.27s_GitHub_repository

avatar vzenix
vzenix - comment - 27 Jan 2015

Version 3.4 has a bug in IIS and MSSQL, this close the sessiĆ³n when you try to install components and can't check this.

I need free time for check this first. I'll check this when i have time at work.

avatar JeremyLC
JeremyLC - comment - 27 Jan 2015

Probably bug 5890 #5890

This is exposed by the extension installer because it ignores which dbms an extension is designed for (extensions are required to have this in their configuration file) and just passes whatever SQL it finds in to whatever dbms you're using with any kind of checking. (detailed here: http://forum.joomla.org/viewtopic.php?f=728&t=871724 ) I spent quite awhile trying to sort out why I couldn't get that particular extension to install. I'd be glad to file a bug for that, too, but I'm not quite sure how it should be filed. It's almost a feature request, but it seems like a feature that should've already been implemented. Moreover, it seems like support for non-MySQL systems is really poor overall, as there seem to be places in the code and documentation where it is just assumed you're using MySQL.

avatar Ayniac
Ayniac - comment - 23 May 2015

@vzenix
Same problem, solution found :

edit php.ini
increase upload_max_filesize and post_max_size from 2M to 10M or more
iisreset

Now you could install packages but still have the NULL or NOT NULL issue described by Alikon in bug #4207.

avatar alikon alikon - reference | 7ab00f8 - 9 Jun 15
avatar alikon
alikon - comment - 9 Jun 2015

@vzenix tested "your code" successfully
so I took the liberty to #7145

jmssql administration system information

  • able to install a module
  • solve #4207 able to save a menu item
avatar brianteeman brianteeman - change - 29 Jul 2015
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2015-07-29 08:06:56
Closed_By brianteeman
avatar brianteeman brianteeman - close - 29 Jul 2015

Add a Comment

Login with GitHub to post a comment