From: Michael D. <mik...@us...> - 2004-11-01 16:26:14
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Id In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24416/NHibernate/Id Modified Files: IdentifierGeneratorFactory.cs Log Message: removed mssql specific use of GetDecimal. MySql has a slightly different return type. Index: IdentifierGeneratorFactory.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Id/IdentifierGeneratorFactory.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** IdentifierGeneratorFactory.cs 11 Oct 2004 23:57:54 -0000 1.11 --- IdentifierGeneratorFactory.cs 1 Nov 2004 16:26:04 -0000 1.12 *************** *** 5,9 **** using NHibernate.Type; - namespace NHibernate.Id { --- 5,8 ---- *************** *** 11,41 **** /// Factory methods for <c>IdentifierGenerator</c> framework. /// </summary> ! public sealed class IdentifierGeneratorFactory { ! public static object Get(IDataReader rs, System.Type clazz) { ! ! // here is an interesting one - MsSql's @@identity returns a ! // numeric - which translates to a C# decimal type. I don't know ! // if this is specific to the SqlServer provider or other providers ! ! decimal identityValue = rs.GetDecimal(0); ! ! if (clazz==typeof(long)) ! { ! return (long)identityValue; ! //return (long)rs[0]; ! } ! else if (clazz==typeof(int)) ! { ! return (int)identityValue; ! //return (int)rs.[0]; ! } ! else if (clazz==typeof(short)) { ! return (short)identityValue; ! //return (short)rs[0]; ! } ! else { ! throw new IdentifierGenerationException("this id generator generates Int64, Int32, Int16"); } } --- 10,28 ---- /// Factory methods for <c>IdentifierGenerator</c> framework. /// </summary> ! public sealed class IdentifierGeneratorFactory ! { ! public static object Get(IDataReader rs, System.Type clazz) ! { ! // here is an interesting one: ! // - MsSql's @@identity returns a numeric - which translates to a C# decimal type. ! // - MySql LAST_IDENITY() returns an Int64 ! try { ! object identityValue = rs[0]; ! return Convert.ChangeType( identityValue, clazz ); ! } ! catch( Exception e ) { ! throw new IdentifierGenerationException("this id generator generates Int64, Int32, Int16", e); } } |