From: Michael D. <mik...@us...> - 2004-06-25 20:38:54
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Id In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22086/NHibernate/Id Modified Files: TableGenerator.cs Log Message: TableGenerator now works with Drivers that don't support "?" as the parameter. It uses a SqlString instead of string holding sql. Index: TableGenerator.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Id/TableGenerator.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TableGenerator.cs 10 Apr 2004 05:34:15 -0000 1.7 --- TableGenerator.cs 25 Jun 2004 20:38:46 -0000 1.8 *************** *** 6,9 **** --- 6,10 ---- using NHibernate.Dialect; using NHibernate.Engine; + using NHibernate.SqlCommand; using NHibernate.SqlTypes; using NHibernate.Type; *************** *** 11,15 **** ! namespace NHibernate.Id { /// <summary> /// An <c>IIdentifierGenerator</c> that uses a database table to store the last --- 12,17 ---- ! namespace NHibernate.Id ! { /// <summary> /// An <c>IIdentifierGenerator</c> that uses a database table to store the last *************** *** 42,46 **** private string columnName; private string query; ! private string update; public virtual void Configure(IType type, IDictionary parms, Dialect.Dialect dialect) --- 44,49 ---- private string columnName; private string query; ! ! private SqlString updateSql; public virtual void Configure(IType type, IDictionary parms, Dialect.Dialect dialect) *************** *** 54,58 **** query = "select " + columnName + " from " + tableName; if ( dialect.SupportsForUpdate ) query += " for update"; ! update = "update " + tableName + " set " + columnName + " = " + StringHelper.SqlParameter + " where " + columnName + " = " + StringHelper.SqlParameter; } --- 57,82 ---- query = "select " + columnName + " from " + tableName; if ( dialect.SupportsForUpdate ) query += " for update"; ! ! // build the sql string for the Update since it uses parameters ! Parameter setParam = new Parameter(); ! setParam.Name = columnName; ! setParam.DbType = DbType.Int32; ! ! Parameter whereParam = new Parameter(); ! whereParam.Name = columnName; ! whereParam.DbType = DbType.Int32; ! ! SqlStringBuilder builder = new SqlStringBuilder(); ! builder.Add("update " + tableName + " set ") ! .Add(columnName) ! .Add(" = ") ! .Add(setParam) ! .Add(" where ") ! .Add(columnName) ! .Add(" = ") ! .Add(whereParam); ! ! updateSql = builder.ToSqlString(); ! } *************** *** 100,118 **** } ! IDbCommand ups = conn.CreateCommand(); ! ups.CommandText = update; ! ups.CommandType = CommandType.Text; ups.Transaction = trans; try { ! IDbDataParameter parm1 = ups.CreateParameter(); ! parm1.DbType = DbType.Int32; ! parm1.Value = result + 1; ! ups.Parameters.Add(parm1); ! IDbDataParameter parm2 = ups.CreateParameter(); ! parm2.DbType = DbType.Int32; ! parm2.Value = result; ! ups.Parameters.Add(parm2); rows = ups.ExecuteNonQuery(); } --- 124,137 ---- } ! ! IDbCommand ups = updateSql.BuildCommand(session.Factory.ConnectionProvider.Driver); ! ups.Connection = conn; ups.Transaction = trans; try { ! ((IDbDataParameter)ups.Parameters[0]).Value = result + 1; ! ((IDbDataParameter)ups.Parameters[1]).Value = result; ! rows = ups.ExecuteNonQuery(); } |