DELETE from table with database name prefix in Editor PHP

DELETE from table with database name prefix in Editor PHP

boni.mboni.m Posts: 3Questions: 2Answers: 0

Hello, I think there is a little inconsistency using database name prefix in Editor (1.6.3)
Suppose I have something like
$editor = Editor::inst( $db, 'db.table' )
and all fields referencing db.table.field
Then I'm not able to delete records from this table.
In Editor.php file there is a _remove_table function with condition:
$this->_part( $field->dbField(), 'table' ) === $table && ...
The table on the left side doesn't have a prefix while on the right side there is a db.table variable.
I think that's why the DELETE query is never generated.
There should be probably something like:
$this->_part( $field->dbField(), 'db' ).'.'.$this->_part( $field->dbField(), 'table' ) === $table && ... instead.

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited July 2017
    $editor = Editor::inst( $db, 'db.table' )
    

    Why do you think you need "db.table"? The database name is already in the $db object.

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Thanks for flagging this up. I haven't tried to replicate it here yet, but I agree that very much does sound like a bug.

    If you are able to, then @tangerine's suggestion of dropping the db prefix would be a way to workaround this. Although if you are using it as an intradatabase connection, that wouldn't work.

    Allan

  • boni.mboni.m Posts: 3Questions: 2Answers: 0

    Thanks for your answers.
    I need to join tables from different databases, so I assume that using db prefix is the only way to do it...

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    I need to join tables from different databases,

    Ah, ok. I didn't think of that as I've never needed to do it myself.

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Yes - the db prefix is the way to do it. If it worked... I'll post back here once I've dug into it and applied a fix.

    Thanks,
    Allan

  • milan.kratochvilmilan.kratochvil Posts: 5Questions: 3Answers: 0

    Hello allan,

    just a reminder:
    The bug in Editor.php (v 1.8.1) _remove_table function, row 1933 still persists.

    Any chance for fix? :-)

    Thanks, MK

This discussion has been closed.