Remove doesn't work, when using an ALIAS for the primary table

Remove doesn't work, when using an ALIAS for the primary table

it64it64 Posts: 3Questions: 0Answers: 0

We decided to use multisite for some of our WordPress instances.

In the definition of the EDITOR i used an ALIAS for the primary table, so that i don't need to define the table-prefixes through PHP- in JS-code .

Editor::inst( $db, $table.' as conclusion',"conclusion_id" )
->fields(...

With editing those rows, everything works fine, but when deleting/removing that row, i get an error
(in my case) : DELETE FROM pc_29_dataprocessor_conclusion as conclusion
WHERE (conclusion.conclusion_id = 22 )

So i extended the _delete-function in Query.php (version 1.9.2.) as follows. I would apprreciate, if that extension or attempt of improvement would be pushed and the solultion will find a way in one of the next versions:

   protected function _delete()
   {
     $del_sql = 'DELETE FROM ';
         if(strpos($this->_build_table(),'as') === FALSE)
         {
             $del_sql .= ''.$this->_build_table();
         }
         else
         {
             $tbl_array = explode(' as ',$this->_build_table());
             $org_tbl    = $tbl_array[0];
             $alias_tbl  = $tbl_array[1];

             $del_sql .= ''.$alias_tbl;
             $del_sql .= ' USING '.$this->_build_table();
         }
         $del_sql .=  $this->_build_where();

      $this->_prepare( $del_sql );

     return $this->_exec();
    } 

Replies

  • allanallan Posts: 54,886Questions: 1Answers: 8,603 Site admin

    Thanks for this. What database type are you using please?

    I put a similar fix into our NodeJS libraries recently. I've created an internal bug to ensure this goes into the PHP libs as well.

    Allan

  • it64it64 Posts: 3Questions: 0Answers: 0

    MySQL ! But i think it's similar in Oracle, Postgres or DB2.

  • allanallan Posts: 54,886Questions: 1Answers: 8,603 Site admin

    Thanks - I'll post back when we've got it fixed. I've flagged it for the next release (which will be 1.9.3).

    Allan

Sign In or Register to comment.