Skip to content

ObjectToSQLString implementations are problematic #3516

Open
@gliljas

Description

@gliljas

While working with DateOnly and TimeOnly support I realized that the ObjectToSQLString method of ILiteralType is quite problematic.

AbstractStringType:
"'" + (string)value + "'"

  • SQL injection
  • No N-prefix for unicode (required in SQL server when the string is outside ANSI)

AbstractCharType:
'\'' + value.ToString() + '\''

  • SQL injection
  • No N-prefix for unicode (required in SQL server when the string is outside ANSI)

AbstractDateTimeType:
"'" + (DateTime) value + "'"

  • No guarantee that the stringified DateTime will be a supported datetime syntax

DateTimeOffsetType:
"'" + ((DateTimeOffset) value) + "'"

  • No guarantee that the stringified DateTimeOffset will be a supported datetimeoffset syntax

DateType:
"\'" + ((DateTime)value).ToShortDateString() + "\'"

  • No guarantee that the stringified DateTime will be a supported datetime syntax

DecimalType:
value.ToString()

  • Could very well be a decimal with the wrong kind of decimal separator

And there are more.

Since the method has access to the dialect, maybe more formatting should be moved there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions