cmeeren / Facil

Facil generates F# data access source code from SQL queries and stored procedures. Optimized for developer happiness.
MIT License
140 stars 7 forks source link

InsertBatch temp table case insensitive column names cases #57

Closed rchybicki closed 10 months ago

rchybicki commented 10 months ago

Hello,

The insertBatch script generated for this table:

CREATE TABLE [dbo].[zzz](
    [PRCo] [tinyint] NOT NULL,
    [Employee] [int] NOT NULL,
    [Document] [varchar](255) NOT NULL,
    ....
) ON [PRIMARY]
GO

looks like this:

    let configureCmd sqlParams (cmd: SqlCommand) =
      cmd.CommandText <- """-- zzz
INSERT INTO [dbo].[zzz]
(
  [PRCo],
  [Employee],
  [Document],
....
)
SELECT
  [pRCo],
  [employee],
  [document],
...
FROM #args"""

While the CreateTempTable code is:

    [<EditorBrowsable(EditorBrowsableState.Never)>]
    member this.CreateTempTableData
      (
        ``args``: seq<``zzz``.``args``>
      ) =
      [
        TempTableData
          (
            "#args",
            """
            CREATE TABLE #args (
              [PRCo] TINYINT NOT NULL,
              [Employee] INT NOT NULL,
              [Document] VARCHAR(255) COLLATE Latin1_General_BIN NOT NULL,
              ...
            )
            """,
            (``args`` |> Seq.map (fun x -> x.Fields)),
            12,
            Action<_> this.userConfigureBulkCopy
          )
      ]

When this is executed on a case sensitive sql server, it doesn't work. The case of the column names should be preserved I believe, or am I doing something wrong? The collation of the DB that Facil is generating from is case sensitive, though the SQL Server's collation of that DB's server is not.

cmeeren commented 10 months ago

I believe you're right. I'll investigate.

cmeeren commented 10 months ago

Good catch! Should be fixed in 2.7.3 which is in the pipeline now.

rchybicki commented 10 months ago

Nice! I appreciate the super-fast reaction.