Bug 224 - ODBC plugin calls MS SQL with LIMIT
Summary: ODBC plugin calls MS SQL with LIMIT
Status: CONFIRMED
Alias: None
Product: Orthanc
Classification: Unclassified
Component: Plugin - Other (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- major
Assignee: Alain Mazy
URL:
Depends on:
Blocks:
 
Reported: 2024-03-05 06:52 CET by sprog
Modified: 2024-03-08 11:06 CET (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sprog 2024-03-05 06:52:13 CET
Any lookup by Orthanc Explorer or Orthanc Explorer 2 fails with error.

E0305 08:27:05.266052           HTTP-0 PluginsManager.cpp:153] Error with the database engine: Cannot execute ODBC statement:
42000 : 1/102 [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'.
42000 : 2/8180 [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared.

Configuration file:

    "Odbc" : {
        "EnableIndex" : true,
        "EnableStorage" : false,
        "IndexConnectionString" : "Driver={ODBC Driver 17 for SQL Server};Server=tcp:localhost,1433;Database=Orthanc;Uid=...;Pwd=...",
        "StorageConnectionString" : "DSN=storage",
	"IndexConnectionsCount" : 1
    }

All studies lists as expected. Error flow up only when query contain count limitation.
Comment 1 sprog 2024-03-05 10:06:33 CET
workaround is set the LimitFindResults to 0 in orthanc.json
Comment 2 sprog 2024-03-05 13:59:53 CET
I think, it becouse orthanc-databases\Resources\Orthanc\Databases\ISqlLookupFormatter.cpp
contain
    if (limit != 0)
    {
      sql += " LIMIT " + boost::lexical_cast<std::string>(limit);
    }
in Apply and ApplySingleLevel
Comment 3 Alain Mazy 2024-03-08 11:06:06 CET
Hi,

I confirm I can reproduce it with the below setup based on https://github.com/orthanc-server/orthanc-setup-samples/tree/master/docker/mssql.

Note however that ODBC is usually considered quite a low priority for us.  You may get in touch with https://orthanc.team/ if you need this fixed with higher priority.

Alain.


Note for myself: we should add an integration tests with an explicit Limit argument in the tools/find.



version: "2"
services:
  orthanc-new-mssql:
    image: orthancteam/orthanc:24.3.3-full
    depends_on:
      db: 
        condition: service_healthy
    ports: ["8042:8042"]
    volumes: ["storage:/var/lib/orthanc/db"]
    environment:
      ORTHANC__ODBC__INDEX_CONNECTION_STRING: "Driver={ODBC Driver 18 for SQL Server};Server=tcp:db,1433;Database=orthanctest;Uid=sa;Pwd=MyStrOngPa55word!;Encrypt=yes;TrustServerCertificate=yes;Connection Timeout=30;"
      ORTHANC__ODBC__ENABLE_INDEX: "true"
      ORTHANC__ODBC__ENABLE_STORAGE: "false"
      ORTHANC__AUTHENTICATION_ENABLED: "false"
      VERBOSE_STARTUP: "true"
      VERBOSE_ENABLED: "true"
      ORTHANC__SAVE_JOBS: "false"
      ORTHANC__HTTP_THREADS_COUNT: "5"
      ORTHANC__ORTHANC_EXPLORER_2__UI_OPTIONS__STUDY_LIST_CONTENT_IF_NO_SEARCH: "empty"
      ORTHANC__ORTHANC_EXPLORER_2__UI_OPTIONS__STUDY_LIST_SEARCH_MODE: "search-button"
      ORTHANC__LIMIT_FIND_RESULTS: "100"

    restart: unless-stopped

  db:
    build: index
    ports: ["1434:1433"]
    volumes: ["index:/var/opt/mssql"]
    healthcheck:
      test: /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$$SA_PASSWORD" -Q "SELECT 1" || exit 1
      interval: 10s
      timeout: 3s
      retries: 10
      start_period: 10s
    environment:
      ACCEPT_EULA: "Y"
      SA_PASSWORD: "MyStrOngPa55word!"
    restart: unless-stopped


volumes:
  storage:
  index: