fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
578 stars 146 forks source link

Oracle provider does not work correctly when quoted identifiers are used #778

Open keimpema opened 1 year ago

keimpema commented 1 year ago

Describe the bug Like Firebug (#431) Oracle also has a problem with quoted table names. Actually the same goes for schema names and column names as well. (ref). When a table is created with quoted identifiers:

CREATE TABLE "SchemaName"."table_name" 
   (    "timestamp" TIMESTAMP (6) NOT NULL ENABLE, 
    "text" NVARCHAR2(50) NOT NULL ENABLE  )

Identifiers with quotes are case sensitive. Identifiers without quotes are treated as uppercase. To maintain the casing of the identifier names, they should be referenced everywhere with quotes:

SELECT t."timestamp", t."text" FROM "SchemaName"."table_name" t

To Reproduce Steps to reproduce the behavior:

  1. create a table like mentioned above
  2. create a query to retrieve records from that table
    let records = 
    query {
        for t in context.SchemName.TableName do
        select ( t.Timestamp, t.Text )
    }

    It wil fail with Oracle.ManagedDataAccess.Client.OracleException: 'ORA-00942: table or view does not exist' because it creates the query:

    SELECT table_name.timestamp as "timestamp", table_name.text as "text" FROM SchemaName.table_name table_name

    Which is interpreted by Oracle as something that cannot be found:

    SELECT table_name.TIMESTAMP as "timestamp", table_name.TEXT as "text" FROM SCHEMANAME.TABLE_NAME table_name

    Expected behavior The schema object identifiers schema name, table name and column name should be quoted in statements when they were created as quoted identifiers. Preferably automatically otherwise with a flag like the one used in the Firebird solution (#431). The resulting query in this case should look like:

    SELECT table_name."timestamp" as "timestamp", table_name."text" as "text" FROM "SchemaName"."table_name" table_name

    Desktop (please complete the following information):

    • OS: windows 11
    • Oracle 12
    • SqlProvider 1.3.5

Libraries used for resolution