From: <pa...@us...> - 2011-03-27 05:11:06
|
Revision: 5548 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5548&view=rev Author: patearl Date: 2011-03-27 05:10:59 +0000 (Sun, 27 Mar 2011) Log Message: ----------- SQLite: Support non-repeating identity sequences. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs trunk/nhibernate/src/NHibernate/Mapping/Table.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-27 02:18:06 UTC (rev 5547) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2011-03-27 05:10:59 UTC (rev 5548) @@ -1187,6 +1187,16 @@ { get { throw new MappingException("Dialect does not support identity key generation"); } } + + /// <summary> + /// Set this to false if no table-level primary key constraint should be generated when an identity column has been specified for the table. + /// This is used as a work-around for SQLite so it doesn't tell us we have "more than one primary key". + /// </summary> + public virtual bool GenerateTablePrimaryKeyConstraintForIdentityColumn + { + get { return true; } + } + #endregion #region SEQUENCE support Modified: trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2011-03-27 02:18:06 UTC (rev 5547) +++ trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2011-03-27 05:10:59 UTC (rev 5548) @@ -154,13 +154,20 @@ { get { - // identity columns in sqlite are marked as being integer primary key - // the primary key part will be put in at the end of the create table, - // so just the integer part is needed here - return "integer"; + // Adding the "autoincrement" keyword ensures that the same id will + // not be generated twice. When just utilizing "integer primary key", + // SQLite just takes the max value currently in the table and adds one. + // This causes problems with caches that use primary keys of deleted + // entities. + return "integer primary key autoincrement"; } } + public override bool GenerateTablePrimaryKeyConstraintForIdentityColumn + { + get { return false; } + } + public override string Qualify(string catalog, string schema, string table) { StringBuilder qualifiedName = new StringBuilder(); Modified: trunk/nhibernate/src/NHibernate/Mapping/Table.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Table.cs 2011-03-27 02:18:06 UTC (rev 5547) +++ trunk/nhibernate/src/NHibernate/Mapping/Table.cs 2011-03-27 05:10:59 UTC (rev 5548) @@ -409,7 +409,7 @@ buf.Append(dialect.GetColumnComment(col.Comment)); } } - if (HasPrimaryKey) + if (HasPrimaryKey && (dialect.GenerateTablePrimaryKeyConstraintForIdentityColumn || !identityColumn)) { buf.Append(StringHelper.CommaSpace).Append(PrimaryKey.SqlConstraintString(dialect, defaultSchema)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |