Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 2.x
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Didnt find anything in the docs on this. Is D2 capable of doing an UPSERT [1] in case I am trying to persist an object that may or may not have been saved previously. Different RDBMS support different syntax for this case. Like MySQL has INSERT .. ON DUPLICATE KEY UPDATE (or even INSERT IGNORE) while the SQL standard defines a MERGE syntax which seems to be gaining support. Of course you can always fallback to a SELECT FOR UPDATE (or if you want to be hacky an INSERT which catches duplicate key violations .. but probably not a good idea since many RDBMS rollback on a failure inside a transaction).

      [1] http://en.wikipedia.org/wiki/Upsert

      See also http://opensource.atlassian.com/projects/hibernate/browse/HHH-3011 asking for MERGE support

      Ideally there would be a way to define on a model or model instance level if merge logic should be applied.

        Activity

        Lukas Kahwe created issue -
        Hide
        Robert Burkhead added a comment -

        Doctrine_Record defines a replace() method.

        In the MySQL Doctrine implementation, however, it is not the same as INSERT .. ON DUPLICATE KEY UPDATE. The replace() method implemented in Doctrine_Connection_Mysql uses the REPLACE INTO syntax, which is a DELETE and then INSERT when the key exists. This is fine, except for tables that use auto-increment fields. The delete-then-insert operation yields a new auto-incremented value, whereas INSERT .. ON DUPLICTATE KEY UPDATE would not.

        Show
        Robert Burkhead added a comment - Doctrine_Record defines a replace() method. In the MySQL Doctrine implementation, however, it is not the same as INSERT .. ON DUPLICATE KEY UPDATE. The replace() method implemented in Doctrine_Connection_Mysql uses the REPLACE INTO syntax, which is a DELETE and then INSERT when the key exists. This is fine, except for tables that use auto-increment fields. The delete-then-insert operation yields a new auto-incremented value, whereas INSERT .. ON DUPLICTATE KEY UPDATE would not.
        Hide
        Lukas Kahwe added a comment -

        MySQL (and SQLite) REPLACE is a no go. It causes way too much disc I/O and worse yet totally screws up the on disk data structures because of the deleting.

        Show
        Lukas Kahwe added a comment - MySQL (and SQLite) REPLACE is a no go. It causes way too much disc I/O and worse yet totally screws up the on disk data structures because of the deleting.
        Hide
        Benjamin Eberlei added a comment -

        Scheduled for 2.2

        Show
        Benjamin Eberlei added a comment - Scheduled for 2.2
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
        Fix Version/s 2.2-DEV [ 10157 ]
        Hide
        Benjamin Eberlei added a comment -

        Evaluating this makes me sad, except MySQL support for this is rather non-existant, and the oracle merge is aiming at batch operations.

        Show
        Benjamin Eberlei added a comment - Evaluating this makes me sad, except MySQL support for this is rather non-existant, and the oracle merge is aiming at batch operations.
        Hide
        Benjamin Eberlei added a comment -

        Should this be done with

        1. Select first, then insert
        2. Catch and evaluate exception then update

        I am leaning towards 1.

        Show
        Benjamin Eberlei added a comment - Should this be done with 1. Select first, then insert 2. Catch and evaluate exception then update I am leaning towards 1.
        Hide
        Guilherme Blanco added a comment -

        Updating fix version

        Show
        Guilherme Blanco added a comment - Updating fix version
        Guilherme Blanco made changes -
        Fix Version/s 2.x [ 10090 ]
        Fix Version/s 2.2 [ 10157 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 11585 ] jira-feedback [ 13856 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 13856 ] jira-feedback2 [ 15720 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 15720 ] jira-feedback3 [ 17977 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-668, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Lukas Kahwe
          • Votes:
            4 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: