MySql driver code

"hkara1" <[email protected]> Fri, 11 Jun 2010 07:17:04 -0000
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hi,

I am using simpleorm with MySql for a project, and I was surprised
to see that the SDriverMySql does not handle "insert key generation"
though this is mentioned in the docs.

here is what I added to make it work :

  @Override
  public boolean supportsInsertKeyGeneration() { return true; }
  
  @Override
  protected long retrieveInsertedKey(SRecordMeta<?> rec, SFieldScalar keyFld) 
  {
    Object lastInsertIdObj = getSession().rawQuerySingle("SELECT LAST_INSERT_ID()", false);
    if (lastInsertIdObj instanceof Number) {
      Number lastInsertId = (Number) lastInsertIdObj;
      return lastInsertId.longValue();
    }
    else {
      throw new SException.Error("Not a number : " + lastInsertIdObj);
    }
  }

Hope it helps,

Harry Karadimas





------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/