Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Oracle Stored Procedure #9199

Open
JakeR92 opened this issue Sep 9, 2024 · 4 comments
Open

[Bug]: Oracle Stored Procedure #9199

JakeR92 opened this issue Sep 9, 2024 · 4 comments
Labels

Comments

@JakeR92
Copy link

JakeR92 commented Sep 9, 2024

Module

Core

Testcontainers version

1.19.8

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version

Client: Docker Engine - Community
 Version:           27.2.0
 API version:       1.47
 Go version:        go1.21.13
 Git commit:        3ab4256
 Built:             Tue Aug 27 14:15:13 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.2.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.21.13
  Git commit:       3ab5c7d
  Built:            Tue Aug 27 14:15:13 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.21
  GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

The init script runner removes all ";" when splitting, however oracles stored procedure command requires the ";" at the end otherwise it gets a compile error. Can you change it not to remove the ";" from the split commands?

Relevant log output

No response

Additional Information

No response

@eddumelendez
Copy link
Member

Hi @JakeR92, can you please share a project that reproduce the issue?

/cc @inponomarev who has been contributing to this feature :)

@JakeR92
Copy link
Author

JakeR92 commented Sep 20, 2024

Hi,

I have the following stored procedure in an sql file that is passed into the test container to be run upon startup.
CREATE TABLE "Konnekt"."ProcedureVarChar"
(
"primaryKey" VARCHAR2(255 CHAR) NOT NULL,
"uniqueKey" VARCHAR2(255 CHAR) NOT NULL,
"mandatory" VARCHAR2(255 CHAR) NOT NULL,
"optional" VARCHAR2(255 CHAR),
"defaultValue" VARCHAR2(255 CHAR) DEFAULT 'default' NOT NULL,
PRIMARY KEY ("primaryKey"),
UNIQUE ("uniqueKey")
);

INSERT INTO "Konnekt"."ProcedureVarChar" ("primaryKey", "uniqueKey", "mandatory", "optional", "defaultValue")
VALUES ('pk1', 'uq1', 'man', 'opt', 'Hello World');
INSERT INTO "Konnekt"."ProcedureVarChar" ("primaryKey", "uniqueKey", "mandatory", "optional")
VALUES ('pk2', 'uq2', 'man', 'opt');
INSERT INTO "Konnekt"."ProcedureVarChar" ("primaryKey", "uniqueKey", "mandatory")
VALUES ('pk3', 'uq3', 'man');

CREATE TABLE "Konnekt"."ProcedureVarCharBK" AS
SELECT *
FROM "Konnekt"."ProcedureVarChar";

CREATE OR REPLACE PROCEDURE "Konnekt"."insert_varchar_data"(
p_primarykey VARCHAR2,
p_unique VARCHAR2,
p_mandatory VARCHAR2,
p_optional VARCHAR2 DEFAULT NULL,
p_default VARCHAR2 DEFAULT NULL
)
IS
BEGIN
IF p_default IS NULL THEN
INSERT INTO "Konnekt"."ProcedureVarChar" ("primaryKey", "uniqueKey", "mandatory", "optional")
VALUES (p_primarykey, p_unique, p_mandatory, p_optional);
ELSE
INSERT INTO "Konnekt"."ProcedureVarChar" ("primaryKey", "uniqueKey", "mandatory", "optional", "defaultValue")
VALUES (p_primarykey, p_unique, p_mandatory, p_optional, p_default);
END IF;
END;

Whenever I call the function it gets compile error. I debugged it and found that by the time the script runner runs the commands it is:

CREATE OR REPLACE PROCEDURE "Konnekt"."insert_varchar_data"(
p_primarykey VARCHAR2,
p_unique VARCHAR2,
p_mandatory VARCHAR2,
p_optional VARCHAR2 DEFAULT NULL,
p_default VARCHAR2 DEFAULT NULL
)
IS
BEGIN
IF p_default IS NULL THEN
INSERT INTO "Konnekt"."ProcedureVarChar" ("primaryKey", "uniqueKey", "mandatory", "optional")
VALUES (p_primarykey, p_unique, p_mandatory, p_optional);
ELSE
INSERT INTO "Konnekt"."ProcedureVarChar" ("primaryKey", "uniqueKey", "mandatory", "optional", "defaultValue")
VALUES (p_primarykey, p_unique, p_mandatory, p_optional, p_default);
END IF;
END

Without the final ";". Oracle requires this final ";" otherwise it will not compile properly.

@JakeR92
Copy link
Author

JakeR92 commented Oct 9, 2024

Any updates?

@tetv
Copy link

tetv commented Oct 10, 2024

If the statement ends with ;; can we split by the last ; and keep the first ; as part of the statement?

Example: init.oracle.sql:

CREATE OR REPLACE PROCEDURE "sp_get_all_my_table"(total_count OUT INTEGER) AS
BEGIN
    SELECT COUNT(*) INTO total_count FROM "MyTable";
END;;

Split by last ; and therefore, the statement will be:

CREATE OR REPLACE PROCEDURE "sp_get_all_my_table"(total_count OUT INTEGER) AS
BEGIN
    SELECT COUNT(*) INTO total_count FROM "MyTable";
END;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants