public MetaType(IDictionary <object, string> values, IType baseType) { _baseType = baseType ?? throw new ArgumentNullException(nameof(baseType)); _baseLiteralType = baseType as ILiteralType; _values = values; if (_values == null) { if (baseType.ReturnedClass != typeof(string)) { throw new ArgumentException( $"Meta type base type {baseType} does not yield string but {baseType.ReturnedClass}, while no " + "meta-value mapping has been provided", nameof(baseType)); } if (_baseLiteralType == null) { _baseLiteralType = NHibernateUtil.String; } } else { _keys = new Dictionary <string, object>(); foreach (var me in values) { _keys[me.Value] = me.Key; } } }
private string ResolveToLiteralString(IType type) { try { ILiteralType literalType = (ILiteralType)type; Dialect.Dialect dialect = _factory.Dialect; return(literalType.ObjectToSQLString(_constantValue, dialect)); } catch (Exception t) { throw new QueryException(LiteralProcessor.ErrorCannotFormatLiteral + Text, t); } }
/// <summary> /// Add a column with a specific value to the INSERT sql /// </summary> /// <param name="columnName">The name of the Column to add.</param> /// <param name="val">The value to set for the column.</param> /// <param name="literalType">The NHibernateType to use to convert the value to a sql string.</param> /// <returns>The SqlInsertBuilder.</returns> public SqlInsertBuilder AddColumn(string columnName, object val, ILiteralType literalType) { return(AddColumn(columnName, literalType.ObjectToSQLString(val, Dialect))); }
private void SetConstantValue(DotNode node, string text, object value) { if (log.IsDebugEnabled()) { log.Debug("setConstantValue() {0} -> {1} {2}", text, value, value.GetType().Name); } node.ClearChildren(); // Chop off the rest of the tree. if (value is string) { node.Type = HqlSqlWalker.QUOTED_String; } else if (value is char) { node.Type = HqlSqlWalker.QUOTED_String; } else if (value is byte) { node.Type = HqlSqlWalker.NUM_INT; } else if (value is short) { node.Type = HqlSqlWalker.NUM_INT; } else if (value is int) { node.Type = HqlSqlWalker.NUM_INT; } else if (value is long) { node.Type = HqlSqlWalker.NUM_LONG; } else if (value is double) { node.Type = HqlSqlWalker.NUM_DOUBLE; } else if (value is decimal) { node.Type = HqlSqlWalker.NUM_DECIMAL; } else if (value is float) { node.Type = HqlSqlWalker.NUM_FLOAT; } else { node.Type = HqlSqlWalker.CONSTANT; } IType type; try { type = TypeFactory.HeuristicType(value.GetType().Name); } catch (MappingException me) { throw new QueryException(me); } if (type == null) { throw new QueryException(LiteralProcessor.ErrorCannotDetermineType + node.Text); } try { ILiteralType literalType = (ILiteralType)type; NHibernate.Dialect.Dialect dialect = _walker.SessionFactoryHelper.Factory.Dialect; node.Text = literalType.ObjectToSQLString(value, dialect); } catch (Exception e) { throw new QueryException(LiteralProcessor.ErrorCannotFormatLiteral + node.Text, e); } node.DataType = type; node.SetResolvedConstant(text); }
/// <summary> /// Add a column with a specific value to the INSERT sql /// </summary> /// <param name="columnName">The name of the Column to add.</param> /// <param name="val">The value to set for the column.</param> /// <param name="literalType">The NHibernateType to use to convert the value to a sql string.</param> /// <returns>The SqlInsertBuilder.</returns> public SqlInsertBuilder AddColumn(string columnName, object val, ILiteralType literalType) { return AddColumn(columnName, literalType.ObjectToSQLString(val, Dialect)); }
/// <summary> /// Add a column with a specific value to the INSERT sql /// </summary> /// <param name="columnName">The name of the Column to add.</param> /// <param name="val">The value to set for the column.</param> /// <param name="literalType">The NHibernateType to use to convert the value to a sql string.</param> /// <returns>The SqlUpdateBuilder.</returns> public SqlUpdateBuilder AddColumn(string columnName, object val, ILiteralType literalType) { return AddColumn(columnName, literalType.ObjectToSQLString(val)); }
/// <summary> /// Add a column with a specific value to the INSERT sql /// </summary> /// <param name="columnName">The name of the Column to add.</param> /// <param name="val">The value to set for the column.</param> /// <param name="literalType">The NHibernateType to use to convert the value to a sql string.</param> /// <returns>The SqlUpdateBuilder.</returns> public SqlUpdateBuilder AddColumn(string columnName, object val, ILiteralType literalType) { return(AddColumn(columnName, literalType.ObjectToSQLString(val))); }