Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Handling error when having a "Unique" key index

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 271 Views
  • Zyzzza
    Avatar
    Community Member
    25 Posts

    Handling error when having a "Unique" key index Link to this post

    Hi All,

    Anyone could advise - I've got a Unique index on Dataobject like

    static $indexes = array(
    "UniqName" => array(
    "type" => "unique",
    "value" => "`URL`"
    )
    );

    When i try writing a Dataobject with $item->write() it would give me a n error "[User Error] Couldn't run query: UPDATE... " ... Duplicate entry 'http://google.com' for key 2.

    I was pinpointed by UncleCheese over the IRC that error handling is :

       public function databaseError($msg, $errorLevel = E_USER_ERROR) {
    user_error($msg, $errorLevel);
    }

    So probably there wont be easy solution like try...catch or smth.

    But if you have found a solution for this - please post it here .

    PS - I cannot check for duplicates on each write, as there's over 100K records, and doing so would just kill the script .

    271 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.