Re: MySql driver code

Franck Routier <[email protected]> Fri, 11 Jun 2010 09:59:39 +0200
Newsgroups gmane.comp.java.orm.simpleorm
Organization Axège sarl
Message-ID <1276243179.3797.21.camel@franck-laptop>
Hi,

thanks for this. I had a look on the other drivers that implement this,
and they return 0 on null result.

Is this something we would want to do for MySql ?

Franck


Le vendredi 11 juin 2010 à 07:17 +0000, hkara1 a écrit :
>   
> 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/