Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15138/NHibernate/Dialect Modified Files: Dialect.cs FirebirdDialect.cs GenericDialect.cs MsSql2000Dialect.cs MySQLDialect.cs Oracle9Dialect.cs Added Files: TypeNames.cs Log Message: Readded typeNames to get schema-export working like hibernate. Index: Dialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/Dialect.cs,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** Dialect.cs 11 Jul 2004 21:04:13 -0000 1.33 --- Dialect.cs 19 Jul 2004 03:24:02 -0000 1.34 *************** *** 26,29 **** --- 26,32 ---- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Dialect)); + private TypeNames typeNames = new TypeNames("$1"); + private IDictionary properties = new Hashtable(); + private static readonly IDictionary aggregateFunctions = new Hashtable(); *************** *** 41,44 **** --- 44,60 ---- } + /// <summary> + /// The base constructor for Dialect. + /// </summary> + /// <remarks> + /// Every subclass should override this and call Register() with every <see cref="DbType"/> except + /// <see cref="DbType.Object"/>, <see cref="DbType.SByte"/>, <see cref="DbType.UInt16"/>, <see cref="DbType.UInt32"/>, + /// <see cref="DbType.UInt64"/>, <see cref="DbType.VarNumeric"/>. + /// + /// <para> + /// The Default properties for this Dialect should also be set - such as whether or not to use outer-joins + /// and what the batch size should be. + /// </para> + /// </remarks> protected Dialect() { *************** *** 46,50 **** } - private IDictionary properties = new Hashtable(); /// <summary> --- 62,65 ---- *************** *** 55,58 **** --- 70,133 ---- /// <summary> + /// Get the name of the database type associated with the given + /// <see cref="NHibernate.SqlTypes.SqlType"/>, + /// </summary> + /// <param name="code">The SqlType</param> + /// <returns>The database type name used by ddl.</returns> + public virtual string GetTypeName(SqlType sqlType) + { + string result = typeNames.Get(sqlType.DbType); + if(result==null) + { + throw new HibernateException( "No default type mapping for SqlType " + sqlType.ToString() ); + } + + return result; + } + + /// <summary> + /// Get the name of the database type associated with the given + /// <see cref="SqlType"/>. + /// </summary> + /// <param name="sqlType">The SqlType </param> + /// <param name="length">The length of the SqlType</param> + /// <returns>The database type name used by ddl.</returns> + public virtual string GetTypeName(SqlType sqlType, int length) + { + string result = typeNames.Get(sqlType.DbType, length); + if(result==null) + { + throw new HibernateException( "No type mapping for SqlType " + sqlType.ToString() + " of length " + length ); + } + return result; + } + + /// <summary> + /// Subclasses register a typename for the given type code and maximum + /// column length. <c>$1</c> in the type name will be replaced by the column + /// length (if appropriate) + /// </summary> + /// <param name="code">The typecode</param> + /// <param name="capacity">Maximum length of database type</param> + /// <param name="name">The database type name</param> + protected void Register(DbType code, int capacity, string name) + { + typeNames.Put(code, capacity, name); + } + + /// <summary> + /// Suclasses register a typename for the given type code. <c>$1</c> in the + /// typename will be replaced by the column length (if appropriate). + /// </summary> + /// <param name="code">The typecode</param> + /// <param name="name">The database type name</param> + protected void Register(DbType code, string name) + { + typeNames.Put(code, name); + } + + + + /// <summary> /// Does this dialect support the <c>ALTER TABLE</c> syntax? /// </summary> *************** *** 260,264 **** { string dialectName = Cfg.Environment.Properties[Cfg.Environment.Dialect] as string; ! if (dialectName==null) throw new HibernateException("The dialect was not set. Set the property hibernate.dialect."); try { --- 335,339 ---- { string dialectName = Cfg.Environment.Properties[Cfg.Environment.Dialect] as string; ! if (dialectName==null) throw new HibernateException("The dialect was not set. Set the property hibernate.dialect."); try { *************** *** 458,702 **** - /// <summary> ! /// Converts the SqlType to the Dialect specific column type string used when ! /// <c>CREATE</c>ing the table. /// </summary> - /// <param name="sqlType">The SqlType to convert to a string</param> - /// <returns>A string that can be used in the table CREATE statement.</returns> /// <remarks> /// <para> ! /// This method uses SqlType.DbType to call the appropriate protected method of SqlTypeToString(). ! /// All Dialects should override the SqlTypeToString methods because that is where the underlying ! /// SqlType is converted to a string. /// </para> /// </remarks> ! public string SqlTypeToString(SqlType sqlType) ! { ! switch(sqlType.DbType) ! { ! case DbType.AnsiString: ! return SqlTypeToString((AnsiStringSqlType)sqlType); ! case DbType.AnsiStringFixedLength: ! return SqlTypeToString((AnsiStringFixedLengthSqlType)sqlType); ! case DbType.Binary : ! return SqlTypeToString((BinarySqlType)sqlType); ! case DbType.Boolean : ! return SqlTypeToString((BooleanSqlType)sqlType); ! case DbType.Byte: ! return SqlTypeToString((ByteSqlType)sqlType); ! case DbType.Currency: ! return SqlTypeToString((CurrencySqlType)sqlType); ! case DbType.Date: ! return SqlTypeToString((DateSqlType)sqlType); ! case DbType.DateTime: ! return SqlTypeToString((DateTimeSqlType)sqlType); ! case DbType.Decimal: ! return SqlTypeToString((DecimalSqlType)sqlType); ! case DbType.Double: ! return SqlTypeToString((DoubleSqlType)sqlType); ! case DbType.Guid: ! return SqlTypeToString((GuidSqlType)sqlType); ! case DbType.Int16: ! return SqlTypeToString((Int16SqlType)sqlType); ! case DbType.Int32: ! return SqlTypeToString((Int32SqlType)sqlType); ! case DbType.Int64: ! return SqlTypeToString((Int64SqlType)sqlType); ! case DbType.Single: ! return SqlTypeToString((SingleSqlType)sqlType); ! case DbType.StringFixedLength: ! return SqlTypeToString((StringFixedLengthSqlType)sqlType); ! case DbType.String: ! return SqlTypeToString((StringSqlType)sqlType); ! case DbType.Time: ! return SqlTypeToString((TimeSqlType)sqlType); ! default: ! throw new ApplicationException("Unmapped DBType"); ! //break; ! } ! ! } ! ! /// <summary> ! /// Converts an AnsiStringSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(AnsiStringSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an AnsiStringFixedLengthSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(AnsiStringFixedLengthSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an BinarySqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(BinarySqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an BooleanSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(BooleanSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an ByteSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(ByteSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an CurrencySqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(CurrencySqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an DateSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(DateSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an DateTimeSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(DateTimeSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an DecimalSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(DecimalSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an DoubleSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(DoubleSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an GuidSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(GuidSqlType sqlType) { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); } /// <summary> ! /// Converts an Int16SqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(Int16SqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an Int32SqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(Int32SqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an Int64SqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(Int64SqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an SingleSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(SingleSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an StringFixedLengthSqlType to the Database specific column type. ! /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(StringFixedLengthSqlType sqlType) ! { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); ! } ! ! /// <summary> ! /// Converts an StringSqlType to the Database specific column type. /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(StringSqlType sqlType) { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); } /// <summary> ! /// Converts an TimeSqlType to the Database specific column type. /// </summary> ! /// <param name="sqlType">The SqlType to convert to a string.</param> ! /// <returns>A string that can be used for the column type when creating the table.</returns> ! protected virtual string SqlTypeToString(TimeSqlType sqlType) { ! throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); } - /// <summary> --- 533,592 ---- /// <summary> ! /// The largest value that can be set in IDbDataParameter.Size for a parameter ! /// that contains an AnsiString. /// </summary> /// <remarks> /// <para> ! /// Setting the value to 0 indicates that there is no Maximum Size or that it ! /// does not need to be set to Prepare the IDbCommand. ! /// </para> ! /// <para> ! /// Currently the only Driver that needs to worry about setting the Param size ! /// is MsSql /// </para> /// </remarks> ! public virtual int MaxAnsiStringSize { ! get { throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); } } /// <summary> ! /// The largest value that can be set in IDbDataParameter.Size for a parameter ! /// that contains a Binary. /// </summary> ! /// <remarks> ! /// <para> ! /// Setting the value to 0 indicates that there is no Maximum Size or that it ! /// does not need to be set to Prepare the IDbCommand. ! /// </para> ! /// <para> ! /// Currently the only Driver that needs to worry about setting the Param size ! /// is MsSql ! /// </para> ! /// </remarks> ! public virtual int MaxBinarySize { ! get { throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); } } /// <summary> ! /// The largest value that can be set in IDbDataParameter.Size for a parameter ! /// that contains an Unicode String. /// </summary> ! /// <remarks> ! /// <para> ! /// Setting the value to 0 indicates that there is no Maximum Size or that it ! /// does not need to be set to Prepare the IDbCommand. ! /// </para> ! /// <para> ! /// Currently the only Driver that needs to worry about setting the Param size ! /// is MsSql ! /// </para> ! /// </remarks> ! public virtual int MaxStringSize { ! get { throw new NotImplementedException("should be implemented by subclass - this will be converted to abstract"); } } /// <summary> Index: FirebirdDialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FirebirdDialect.cs 20 Mar 2004 03:37:59 -0000 1.5 --- FirebirdDialect.cs 19 Jul 2004 03:24:02 -0000 1.6 *************** *** 12,15 **** --- 12,41 ---- public FirebirdDialect() : base() { + Register( DbType.AnsiStringFixedLength, "CHAR(255)"); + Register( DbType.AnsiStringFixedLength, 8000, "CHAR($1)" ); + Register( DbType.AnsiString, "VARCHAR(255)" ); + Register( DbType.AnsiString, 8000, "VARCHAR($1)" ); + Register( DbType.AnsiString, 2147483647, "BLOB"); // should use the IType.ClobType + Register( DbType.Binary, "BLOB(8000) SUB_TYPE 0"); + Register( DbType.Binary, 8000, "BLOB($1) SUB_TYPE 0"); + Register( DbType.Binary, 2147483647, "BLOB SUB_TYPE 0" );// should use the IType.BlobType + Register( DbType.Boolean, "SMALLINT" ); + Register( DbType.Byte, "SMALLINT" ); + Register( DbType.Currency, "DECIMAL(16,4)"); + Register( DbType.Date, "DATE"); + Register( DbType.DateTime, "TIMESTAMP" ); + Register( DbType.Decimal, "DECIMAL(19,0)" ); // NUMERIC(19,0) is equivalent to DECIMAL(19,0) + Register( DbType.Decimal, 19, "DECIMAL(19, $1)"); + Register( DbType.Double, "DOUBLE PRECISION" ); + Register( DbType.Int16, "SMALLINT" ); + Register( DbType.Int32, "INTEGER" ); + Register( DbType.Int64, "BIGINT" ); + Register( DbType.Single, "FLOAT" ); + Register( DbType.StringFixedLength, "CHAR(255)"); + Register( DbType.StringFixedLength, 4000, "CHAR($1)"); + Register( DbType.String, "VARCHAR(255)" ); + Register( DbType.String, 4000, "VARCHAR($1)" ); + Register( DbType.String, 1073741823, "BLOB SUB_TYPE 1" );// should use the IType.ClobType + Register( DbType.Time, "TIME" ); } *************** *** 41,171 **** get { return true; } } - - - private string SqlTypeToString(string name, int length) - { - return name + "(" + length + ")"; - } - - private string SqlTypeToString(string name, int precision, int scale) - { - if (precision > 18) precision = 18; - return name + "(" + precision + ", " + scale + ")"; - } - - protected override string SqlTypeToString(AnsiStringFixedLengthSqlType sqlType) - { - - if(sqlType.Length <= 8000) - { - return SqlTypeToString("CHAR", sqlType.Length); - } - else - { - return "BLOB SUB_TYPE 1"; // should use the IType.ClobType - } - - } - - protected override string SqlTypeToString(BinarySqlType sqlType) - { - return "BLOB SUB_TYPE 0"; // should use the IType.BlobType - } - - protected override string SqlTypeToString(BooleanSqlType sqlType) - { - return "SMALLINT"; - } - - protected override string SqlTypeToString(ByteSqlType sqlType) - { - return "SMALLINT"; - } - - protected override string SqlTypeToString(CurrencySqlType sqlType) - { - return "DECIMAL(16,4)"; - } - - protected override string SqlTypeToString(DateSqlType sqlType) - { - return "DATE"; - } - - protected override string SqlTypeToString(DateTimeSqlType sqlType) - { - return "TIMESTAMP"; - } - - protected override string SqlTypeToString(DecimalSqlType sqlType) - { - return SqlTypeToString("DECIMAL", sqlType.Precision, sqlType.Scale); - } - - protected override string SqlTypeToString(DoubleSqlType sqlType) - { - return "DOUBLE PRECISION"; - } - - protected override string SqlTypeToString(Int16SqlType sqlType) - { - return "SMALLINT"; - } - - protected override string SqlTypeToString(Int32SqlType sqlType) - { - return "INTEGER"; - } - - protected override string SqlTypeToString(Int64SqlType sqlType) - { - return "BIGINT"; - } - - protected override string SqlTypeToString(SingleSqlType sqlType) - { - return "FLOAT"; - } - - protected override string SqlTypeToString(StringFixedLengthSqlType sqlType) - { - if(sqlType.Length <= 4000) - { - return SqlTypeToString("CHAR", sqlType.Length); - } - else - { - return "BLOB SUB_TYPE 1"; // should use the IType.ClobType - } - } - - protected override string SqlTypeToString(StringSqlType sqlType) - { - if(sqlType.Length <= 4000) - { - return SqlTypeToString("VARCHAR", sqlType.Length); - } - else - { - return "BLOB SUB_TYPE 1"; - } - } - - protected override string SqlTypeToString(TimeSqlType sqlType) - { - return "TIME"; - } - - protected override string SqlTypeToString(AnsiStringSqlType sqlType) - { - if(sqlType.Length <= 4000) - { - return SqlTypeToString("CHAR", sqlType.Length); - } - else - { - return "BLOB SUB_TYPE 1"; // should use the IType.ClobType - } - } } } --- 67,70 ---- Index: MsSql2000Dialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MsSql2000Dialect.cs 11 Jul 2004 21:04:13 -0000 1.13 --- MsSql2000Dialect.cs 19 Jul 2004 03:24:02 -0000 1.14 *************** *** 15,18 **** --- 15,58 ---- public MsSql2000Dialect() : base() { + Register( DbType.AnsiStringFixedLength, "CHAR(255)"); + Register( DbType.AnsiStringFixedLength, 8000, "CHAR($1)" ); + Register( DbType.AnsiString, "VARCHAR(255)" ); + Register( DbType.AnsiString, 8000, "VARCHAR($1)" ); + Register( DbType.AnsiString, 2147483647, "TEXT"); // should use the IType.ClobType + // TODO: figure out how to support this - VARCHAR > 8000 since + // there is no DbType.CLOB - might just make it a mapping + // requirement that they specify a sql-type or make NHibernate's + // own DbType enum or use SqlType as the key for Register + //Register( DbType.AnsiString, "TEXT" ); + Register( DbType.Binary, "VARBINARY(8000)"); + Register( DbType.Binary, 8000, "VARBINARY($1)"); + Register( DbType.Binary, 2147483647, "IMAGE" );// should use the IType.BlobType + Register( DbType.Boolean, "BIT" ); //Sybase BIT type does not support null values + Register( DbType.Byte, "TINYINT" ); + Register( DbType.Currency, "MONEY"); + Register( DbType.Date, "DATETIME"); + Register( DbType.DateTime, "DATETIME" ); + // TODO: figure out if this is the good way to fix the problem + // with exporting a DECIMAL column + // NUMERIC(precision, scale) has a hardcoded precision of 19, even though it can range from 1 to 38 + // and the scale has to be 0 <= scale <= precision. + // I think how I might handle it is keep the type="Decimal(29,5)" and make them specify a + // sql-type="decimal(20,5)" if they need to do that. The Decimal parameter and ddl will get generated + // correctly with minimal work. + Register( DbType.Decimal, "DECIMAL(19,5)" ); + Register( DbType.Decimal, 19, "DECIMAL(19, $1)"); + Register( DbType.Double, "DOUBLE PRECISION" ); //synonym for FLOAT(53) + Register( DbType.Guid, "UNIQUEIDENTIFIER" ); + Register( DbType.Int16, "SMALLINT" ); + Register( DbType.Int32, "INT" ); + Register( DbType.Int64, "BIGINT" ); + Register( DbType.Single, "REAL" ); //synonym for FLOAT(24) + Register( DbType.StringFixedLength, "NCHAR(255)"); + Register( DbType.StringFixedLength, 4000, "NCHAR($1)"); + Register( DbType.String, "NVARCHAR(255)" ); + Register( DbType.String, 4000, "NVARCHAR($1)" ); + Register( DbType.String, 1073741823, "NTEXT" );// should use the IType.ClobType + Register( DbType.Time, "DATETIME" ); + DefaultProperties[Cfg.Environment.OuterJoin] = "true"; DefaultProperties[Cfg.Environment.StatementBatchSize] = NoBatch; *************** *** 87,90 **** --- 127,146 ---- } + public override int MaxAnsiStringSize + { + get { return 8000; } + } + + public override int MaxBinarySize + { + get { return 8000; } + } + + public override int MaxStringSize + { + get { return 4000; } + } + + protected override char CloseQuote { *************** *** 118,265 **** return quoted.Replace( new string(CloseQuote, 2), CloseQuote.ToString() ); } - - private string SqlTypeToString(string name, int length) - { - return name + "(" + length + ")"; - } - - private string SqlTypeToString(string name, int precision, int scale) - { - return name + "(" + precision + ", " + scale + ")"; - } - - protected override string SqlTypeToString(AnsiStringSqlType sqlType) - { - if(sqlType.Length <= 8000) - { - return SqlTypeToString("VARCHAR", sqlType.Length); - } - else - { - return "TEXT"; // should use the IType.ClobType - } - } - - protected override string SqlTypeToString(AnsiStringFixedLengthSqlType sqlType) - { - - if(sqlType.Length <= 8000) - { - return SqlTypeToString("CHAR", sqlType.Length); - } - else - { - return "TEXT"; // should use the IType.ClobType - } - - } - - protected override string SqlTypeToString(BinarySqlType sqlType) - { - - if(sqlType.Length <= 8000) - { - return SqlTypeToString("VARBINARY", sqlType.Length); - } - else - { - return "IMAGE"; // should use the IType.BlobType - } - - } - - protected override string SqlTypeToString(BooleanSqlType sqlType) - { - return "BIT"; - } - - - protected override string SqlTypeToString(ByteSqlType sqlType) - { - return "TINYINT"; - } - - protected override string SqlTypeToString(CurrencySqlType sqlType) - { - return "MONEY"; - } - - protected override string SqlTypeToString(DateSqlType sqlType) - { - return "DATETIME"; - } - - protected override string SqlTypeToString(DateTimeSqlType sqlType) - { - return "DATETIME"; - } - - protected override string SqlTypeToString(TimeSqlType sqlType) - { - return "DATETIME"; - } - - protected override string SqlTypeToString(DecimalSqlType sqlType) - { - return SqlTypeToString("DECIMAL", sqlType.Precision, sqlType.Scale); - } - - protected override string SqlTypeToString(DoubleSqlType sqlType) - { - return SqlTypeToString("FLOAT", sqlType.Length); - } - - protected override string SqlTypeToString(GuidSqlType sqlType) - { - return "UNIQUEIDENTIFIER"; - } - - protected override string SqlTypeToString(Int16SqlType sqlType) - { - return "SMALLINT"; - } - - protected override string SqlTypeToString(Int32SqlType sqlType) - { - return "INT"; - } - - protected override string SqlTypeToString(Int64SqlType sqlType) - { - return "BIGINT"; - } - - protected override string SqlTypeToString(SingleSqlType sqlType) - { - return SqlTypeToString("FLOAT", sqlType.Length); - } - - protected override string SqlTypeToString(StringFixedLengthSqlType sqlType) - { - - if(sqlType.Length <= 4000) - { - return SqlTypeToString("NCHAR", sqlType.Length); - } - else - { - return "NTEXT"; // should use the IType.ClobType - } - - } - - protected override string SqlTypeToString(StringSqlType sqlType) { - - if(sqlType.Length <= 4000) - { - return SqlTypeToString("NVARCHAR", sqlType.Length); - } - else - { - return "NTEXT"; - } - - } - } } --- 174,177 ---- Index: Oracle9Dialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/Oracle9Dialect.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Oracle9Dialect.cs 11 Jul 2004 21:04:13 -0000 1.9 --- Oracle9Dialect.cs 19 Jul 2004 03:24:02 -0000 1.10 *************** *** 28,31 **** --- 28,60 ---- DefaultProperties[Cfg.Environment.OuterJoin] = "true"; + Register( DbType.AnsiStringFixedLength, "CHAR(255)"); + Register( DbType.AnsiStringFixedLength, 2000, "CHAR($1)" ); + Register( DbType.AnsiString, "VARCHAR2(255)" ); + Register( DbType.AnsiString, 2000, "VARCHAR2($1)" ); + Register( DbType.AnsiString, 2147483647, "CLOB"); // should use the IType.ClobType + Register( DbType.Binary, "RAW(2000)"); + Register( DbType.Binary, 2000, "VARBINARY($1)"); + Register( DbType.Binary, 2147483647, "BLOB" ); + Register( DbType.Boolean, "NUMBER(1,0)" ); + Register( DbType.Byte, "NUMBER(3,0)" ); + Register( DbType.Currency, "NUMBER(19,1)"); + Register( DbType.Date, "DATE"); + Register( DbType.DateTime, "DATE" ); + Register( DbType.Decimal, "NUMBER(19,5)" ); + Register( DbType.Decimal, 19, "NUMBER(19, $1)"); + Register( DbType.Double, "DOUBLE PRECISION" ); + //Oracle does not have a guid datatype + //Register( DbType.Guid, "UNIQUEIDENTIFIER" ); + Register( DbType.Int16, "NUMBER(5,0)" ); + Register( DbType.Int32, "NUMBER(10,0)" ); + Register( DbType.Int64, "NUMBER(20,0)" ); + Register( DbType.Single, "FLOAT" ); + Register( DbType.StringFixedLength, "NCHAR(255)"); + Register( DbType.StringFixedLength, 2000, "NCHAR($1)"); + Register( DbType.String, "NVARCHAR2(255)" ); + Register( DbType.String, 2000, "NVARCHAR2($1)" ); + Register( DbType.String, 1073741823, "NCLOB" ); + Register( DbType.Time, "DATE" ); + // add all the functions from the base into this instance foreach(DictionaryEntry de in base.AggregateFunctions) *************** *** 109,116 **** p1.Name = "p1"; ! p1.DbType = DbType.Int16; p2.Name = "p2"; ! p2.DbType = DbType.Int16; /* --- 138,145 ---- p1.Name = "p1"; ! p1.SqlType = new Int16SqlType(); p2.Name = "p2"; ! p2.SqlType = new Int16SqlType(); /* *************** *** 163,275 **** - - private string SqlTypeToString(string name, int length) - { - return name + "(" + length + ")"; - } - - private string SqlTypeToString(string name, int precision, int scale) - { - if (precision > 19) precision = 19; - return name + "(" + precision + ", " + scale + ")"; - } - - protected override string SqlTypeToString(AnsiStringFixedLengthSqlType sqlType) - { - return SqlTypeToString("NVARCHAR2", 1000); - } - - protected override string SqlTypeToString(BinarySqlType sqlType) - { - if(sqlType.Length <= 8000) - { - return SqlTypeToString("RAW", sqlType.Length); - } - else - { - return "BLOB"; // should use the IType.BlobType - } - } - - protected override string SqlTypeToString(BooleanSqlType sqlType) - { - return "NUMBER(1,0)"; - } - - - protected override string SqlTypeToString(ByteSqlType sqlType) - { - return "NUMBER(3,0)"; - } - - protected override string SqlTypeToString(CurrencySqlType sqlType) - { - return "NUMBER(19, 1)"; - } - - protected override string SqlTypeToString(DateSqlType sqlType) - { - return "DATE"; - } - - protected override string SqlTypeToString(DateTimeSqlType sqlType) - { - return "DATE"; - } - - protected override string SqlTypeToString(DecimalSqlType sqlType) - { - return SqlTypeToString("NUMBER", sqlType.Precision, sqlType.Scale); - } - - protected override string SqlTypeToString(DoubleSqlType sqlType) - { - return "DOUBLE PRECISION"; - } - - protected override string SqlTypeToString(Int16SqlType sqlType) - { - return "NUMBER(5,0)"; - } - - protected override string SqlTypeToString(Int32SqlType sqlType) - { - return "NUMBER(10,0)"; - } - - protected override string SqlTypeToString(Int64SqlType sqlType) - { - return "NUMBER(20,0)"; - } - - protected override string SqlTypeToString(SingleSqlType sqlType) - { - return "FLOAT"; - } - - protected override string SqlTypeToString(StringFixedLengthSqlType sqlType) - { - if(sqlType.Length <= 2000) - { - return SqlTypeToString("NVARCHAR2", sqlType.Length); - } - else - { - return string.Empty; // should use the IType.ClobType - } - } - - protected override string SqlTypeToString(StringSqlType sqlType) - { - if(sqlType.Length <= 2000) - { - return SqlTypeToString("NVARCHAR2", sqlType.Length); - } - else - { - return string.Empty; // should use the IType.ClobType - } - } - public class SysdateQueryFunctionInfo : IQueryFunctionInfo { --- 192,195 ---- --- NEW FILE: TypeNames.cs --- using System; using System.Collections; using System.Data; using NHibernate.Util; namespace NHibernate.Dialect { /// <summary> /// This class maps a DbType to names. /// </summary> /// <remarks> /// Associations may be marked with a capacity. Calling the <c>Get()</c> /// method with a type and actual size n will return the associated /// name with smallest capacity >= n, if available and an unmarked /// default type otherwise. /// Eg, setting /// <code> /// Names.Put(DbType, "TEXT" ); /// Names.Put(DbType, 255, "VARCHAR($1)" ); /// Names.Put(DbType, 65534, "LONGVARCHAR($1)" ); /// </code> /// will give you back the following: /// <code> /// Names.Get(DbType) // --> "TEXT" (default) /// Names.Get(DbType,100) // --> "VARCHAR(100)" (100 is in [0:255]) /// Names.Get(DbType,1000) // --> "LONGVARCHAR(1000)" (100 is in [256:65534]) /// Names.Get(DbType,100000) // --> "TEXT" (default) /// </code> /// On the other hand, simply putting /// <code> /// Names.Put(DbType, "VARCHAR($1)" ); /// </code> /// would result in /// <code> /// Names.Get(DbType) // --> "VARCHAR($1)" (will cause trouble) /// Names.Get(DbType,100) // --> "VARCHAR(100)" /// Names.Get(DbType,1000) // --> "VARCHAR(1000)" /// Names.Get(DbType,10000) // --> "VARCHAR(10000)" /// </code> /// </remarks> public class TypeNames { private string placeholder; private Hashtable weighted = new Hashtable(); private Hashtable defaults = new Hashtable(); /// <summary> /// Constructor. /// </summary> /// <param name="placeholder">String to be replaced by actual size/length in type names</param> public TypeNames(string placeholder) { this.placeholder = placeholder; } /// <summary> /// Get default type name for specified type /// </summary> /// <param name="typecode">the type key</param> /// <returns>the default type name associated with the specified key</returns> public string Get(DbType typecode) { return (string) defaults[typecode]; } /// <summary> /// Get the type name specified type and size /// </summary> /// <param name="typecode">the type key</param> /// <param name="size">the (maximum) type size/length</param> /// <returns> /// The associated name with smallest capacity >= size if available and the /// default type name otherwise /// </returns> public string Get(DbType typecode, int size) { IDictionary map = weighted[typecode] as IDictionary; if (map != null && map.Count > 0) { foreach(int entrySize in map.Keys) { if (size <= entrySize) { return StringHelper.ReplaceOnce( (string) map[entrySize], placeholder, size.ToString() ); } } } return StringHelper.ReplaceOnce(Get(typecode), placeholder, size.ToString()); } /// <summary> /// Set a type name for specified type key and capacity /// </summary> /// <param name="typecode">the type key</param> /// <param name="size">the (maximum) type size/length</param> /// <param name="value">The associated name</param> public void Put(DbType typecode, int capacity, string value) { SequencedHashMap map = weighted[ typecode ] as SequencedHashMap; if (map==null) { weighted[typecode] = map = new SequencedHashMap(); } map[capacity] = value; } public void Put(DbType typecode, string value) { defaults[typecode] = value; } } } Index: GenericDialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/GenericDialect.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GenericDialect.cs 19 May 2004 04:14:18 -0000 1.8 --- GenericDialect.cs 19 Jul 2004 03:24:02 -0000 1.9 *************** *** 4,121 **** using NHibernate.SqlTypes; ! namespace NHibernate.Dialect { ! /// <summary> /// A generic SQL dialect which may or may not work on any actual databases /// </summary> ! public class GenericDialect : Dialect { ! ! public GenericDialect() : base() { ! } ! ! public override string AddColumnString { ! get { return "add column"; } ! } ! ! private string SqlTypeToString(string name, int length) ! { ! return name + "(" + length + ")"; ! } ! ! private string SqlTypeToString(string name, int precision, int scale) ! { ! return name + "(" + precision + ", " + scale + ")"; ! } ! ! protected override string SqlTypeToString(AnsiStringSqlType sqlType) ! { ! return SqlTypeToString("VARCHAR", sqlType.Length); ! } ! ! protected override string SqlTypeToString(AnsiStringFixedLengthSqlType sqlType) ! { ! return SqlTypeToString("CHAR", sqlType.Length); ! } ! ! protected override string SqlTypeToString(BinarySqlType sqlType) ! { ! return SqlTypeToString("VARBINARY", sqlType.Length); ! } ! ! protected override string SqlTypeToString(BooleanSqlType sqlType) ! { ! return "BIT"; ! } ! ! ! protected override string SqlTypeToString(ByteSqlType sqlType) ! { ! return "TINYINT"; ! } ! ! protected override string SqlTypeToString(CurrencySqlType sqlType) ! { ! return "MONEY"; ! } ! ! protected override string SqlTypeToString(DateSqlType sqlType) ! { ! return "DATETIME"; ! } ! ! protected override string SqlTypeToString(DateTimeSqlType sqlType) ! { ! return "DATETIME"; ! } ! ! protected override string SqlTypeToString(TimeSqlType sqlType) ! { ! return "DATETIME"; ! } ! ! protected override string SqlTypeToString(DecimalSqlType sqlType) ! { ! return SqlTypeToString("DECIMAL", sqlType.Precision, sqlType.Scale); ! } ! ! protected override string SqlTypeToString(DoubleSqlType sqlType) ! { ! return SqlTypeToString("FLOAT", sqlType.Length); ! } ! ! protected override string SqlTypeToString(GuidSqlType sqlType) ! { ! return "UNIQUEIDENTIFIER"; ! } ! ! protected override string SqlTypeToString(Int16SqlType sqlType) ! { ! return "SMALLINT"; ! } ! ! protected override string SqlTypeToString(Int32SqlType sqlType) ! { ! return "INTEGER"; ! } ! ! protected override string SqlTypeToString(Int64SqlType sqlType) ! { ! return "BIGINT"; ! } ! ! protected override string SqlTypeToString(SingleSqlType sqlType) { ! return SqlTypeToString("FLOAT", sqlType.Length); } ! protected override string SqlTypeToString(StringFixedLengthSqlType sqlType) { ! return SqlTypeToString("NCHAR", sqlType.Length); } - protected override string SqlTypeToString(StringSqlType sqlType) - { - return SqlTypeToString("NVARCHAR", sqlType.Length); - } } } --- 4,42 ---- using NHibernate.SqlTypes; ! namespace NHibernate.Dialect ! { /// <summary> /// A generic SQL dialect which may or may not work on any actual databases /// </summary> ! public class GenericDialect : Dialect ! { ! public GenericDialect() : base() { ! Register( DbType.AnsiStringFixedLength, "CHAR($1)"); ! Register( DbType.AnsiString, "VARCHAR($1)" ); ! Register( DbType.Binary, "VARBINARY($1)"); ! Register( DbType.Boolean, "BIT" ); ! Register( DbType.Byte, "TINYINT" ); ! Register( DbType.Currency, "MONEY"); ! Register( DbType.Date, "DATE"); ! Register( DbType.DateTime, "DATETIME" ); ! Register( DbType.Decimal, "DECIMAL(19, $1)"); ! Register( DbType.Double, "DOUBLE PRECISION" ); ! Register( DbType.Guid, "UNIQUEIDENTIFIER" ); ! Register( DbType.Int16, "SMALLINT" ); ! Register( DbType.Int32, "INT" ); ! Register( DbType.Int64, "BIGINT" ); ! Register( DbType.Single, "REAL" ); ! Register( DbType.StringFixedLength, "NCHAR($1)"); ! Register( DbType.String, "NVARCHAR($1)" ); ! Register( DbType.Time, "TIME" ); ! } ! public override string AddColumnString { ! get { return "add column"; } } } } Index: MySQLDialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/MySQLDialect.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** MySQLDialect.cs 11 Jul 2004 21:04:13 -0000 1.16 --- MySQLDialect.cs 19 Jul 2004 03:24:02 -0000 1.17 *************** *** 9,13 **** { /// <summary> ! /// An SQL dialect for MySQL /// </summary> public class MySQLDialect : Dialect --- 9,13 ---- { /// <summary> ! /// A SQL dialect for MySQL /// </summary> public class MySQLDialect : Dialect *************** *** 15,18 **** --- 15,51 ---- public MySQLDialect() : base() { + Register( DbType.AnsiStringFixedLength, "CHAR(255)"); + Register( DbType.AnsiStringFixedLength, 16777215, "MEDIUMTEXT" ); + Register( DbType.AnsiStringFixedLength, 65535, "TEXT" ); + Register( DbType.AnsiStringFixedLength, 255, "CHAR($1)" ); + Register( DbType.AnsiString, "VARCHAR(255)" ); + Register( DbType.AnsiString, 16777215, "MEDIUMTEXT" ); + Register( DbType.AnsiString, 65535, "TEXT" ); + Register( DbType.AnsiString, 255, "VARCHAR($1)" ); + Register( DbType.Binary, "LONGBLOB"); + Register( DbType.Binary, 16777215, "MEDIUMBLOB"); + Register( DbType.Binary, 65535, "BLOB"); + Register( DbType.Binary, 255, "VARCHAR($1) BINARY"); + Register( DbType.Boolean, "TINYTINT(1)" ); + Register( DbType.Byte, "TINYINT UNSIGNED" ); + Register( DbType.Currency, "MONEY"); + Register( DbType.Date, "DATE"); + Register( DbType.DateTime, "DATETIME" ); + Register( DbType.Decimal, "NUMERIC(19, $1)"); + Register( DbType.Double, "FLOAT" ); + Register( DbType.Int16, "SMALLINT" ); + Register( DbType.Int32, "INTEGER" ); + Register( DbType.Int64, "BIGINT" ); + Register( DbType.Single, "FLOAT" ); + Register( DbType.StringFixedLength, "CHAR(255)"); + Register( DbType.StringFixedLength, 16777215, "MEDIUMTEXT" ); + Register( DbType.StringFixedLength, 65535, "TEXT" ); + Register( DbType.StringFixedLength, 255, "CHAR($1)" ); + Register( DbType.String, "VARCHAR(255)" ); + Register( DbType.String, 16777215, "MEDIUMTEXT" ); + Register( DbType.String, 65535, "TEXT" ); + Register( DbType.String, 255, "VARCHAR($1)" ); + Register( DbType.Time, "TIME" ); + DefaultProperties[Cfg.Environment.OuterJoin] = "true"; DefaultProperties[Cfg.Environment.StatementBatchSize] = DefaultBatchSize; *************** *** 75,238 **** .ToString(); } - - private string SqlTypeToString(string name, int length) - { - return name + "(" + length + ")"; - } - - private string SqlTypeToString(string name, int precision, int scale) - { - return name + "(" + precision + ", " + scale + ")"; - } - - protected override string SqlTypeToString(AnsiStringFixedLengthSqlType sqlType) - { - - if(sqlType.Length <= 255) - { - return SqlTypeToString("CHAR", sqlType.Length); - } - else if(sqlType.Length <= 65535) - { - return "TEXT"; - } - else if(sqlType.Length <= 16777215) - { - return "MEDIUMTEXT"; - } - else - { - return "LONGTEXT"; - } - - } - - protected override string SqlTypeToString(BinarySqlType sqlType) - { - - if(sqlType.Length <= 255) - { - //return SqlTypeToString("VARBINARY", sqlType.Length); - return "TINYBLOB"; - } - else if (sqlType.Length <= 65535) - { - return "BLOB"; - } - else if (sqlType.Length <= 16777215) - { - return "MEDIUMBLOB"; - } - else { - return "LONGBLOB"; - } - - } - - protected override string SqlTypeToString(BooleanSqlType sqlType) - { - return "TINYINT(1)"; - } - - - protected override string SqlTypeToString(ByteSqlType sqlType) - { - return "TINYINT UNSIGNED"; - } - - protected override string SqlTypeToString(CurrencySqlType sqlType) - { - return "MONEY"; - } - - protected override string SqlTypeToString(DateSqlType sqlType) - { - return "DATE"; - } - - protected override string SqlTypeToString(DateTimeSqlType sqlType) - { - return "DATETIME"; - } - - protected override string SqlTypeToString(DecimalSqlType sqlType) - { - return SqlTypeToString("NUMERIC", sqlType.Precision, sqlType.Scale); - } - - protected override string SqlTypeToString(DoubleSqlType sqlType) - { - return SqlTypeToString("FLOAT", sqlType.Length); - } - - protected override string SqlTypeToString(Int16SqlType sqlType) - { - return "SMALLINT"; - } - - protected override string SqlTypeToString(Int32SqlType sqlType) - { - return "INTEGER"; - } - - protected override string SqlTypeToString(Int64SqlType sqlType) - { - return "BIGINT"; - } - - protected override string SqlTypeToString(SingleSqlType sqlType) - { - return SqlTypeToString("FLOAT", sqlType.Length); - } - - protected override string SqlTypeToString(StringFixedLengthSqlType sqlType) - { - - if(sqlType.Length <= 255) - { - return SqlTypeToString("CHAR", sqlType.Length); - } - else if(sqlType.Length <= 65535) - { - return "TEXT"; - } - else if(sqlType.Length <= 16777215) - { - return "MEDIUMTEXT"; - } - else - { - return "LONGTEXT"; - } - - } - - protected override string SqlTypeToString(StringSqlType sqlType) - { - - if(sqlType.Length <= 255) - { - return SqlTypeToString("VARCHAR", sqlType.Length); - } - else if(sqlType.Length <= 65535) - { - return "TEXT"; - } - else if(sqlType.Length <= 16777215) - { - return "MEDIUMTEXT"; - } - else - { - return "LONGTEXT"; - } - - } - - protected override string SqlTypeToString(TimeSqlType sqlType) - { - return "TIME"; - } - } } --- 108,111 ---- |