[Dbix-class] last insert ID from MSSQL?

Matt S Trout dbix-class at trout.me.uk
Wed Oct 17 20:15:00 GMT 2007


On Tue, Oct 16, 2007 at 04:48:49PM -0700, Michael Higgins wrote:
> Folks --
> 
> Something changed to break the lousy hack I had to get this before...
> can't figure it out from the related code and changes. Was doing a
> "single" result on the auto_increment key, \"order by \"invoice #\"
> desc" knd of thing. And it broke after an update of perl modules.
> 
> Anyway, being unable to find out what broke it, I found a way to do it
> more directly... sort of. 
> 
> In the interest of posting some working code, this is what I have come
> up with:
> 
> The IDEA: "SELECT IDENT_CURRENT('tablename')"
> 
> The CODE:
> 
> our $last_bol = [$trex_schema->storage->dbh->selectall_arrayref("SELECT
> IDENT_CURRENT('data')")]->[0]->[0]->[0];
> 
> ... which actually works(!). At least, so it appears.
> 
> But, it seems like I should be able to do a ->last_insert_id or at
> least come up with some something less... nested..??
> 
> Is it because I'm using freeTDS? IOW, is there some way to get MSSQL
> quirks handled transparently with, like a
> 'schema->storage('::DBI::ODBC::MSSQL') type of call?

Yeah, storage objects are expected to provide a last_insert_id method which
DBIC then calls. Have a poke around at the existing implementations, the
ODBC storage already reblesses based on the db type so if you can find the
right name to create your class as it should all Just Work.

I'd be delighted to get you a commit bit so we can maintain this in mainline
DBIC if you're willing?

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list