AnghelLeonard

AnghelLeonard

Chief Technology Strategist

Member Since 8 years ago

Romania

Experience Points
276
follower
Lessons Completed
0
follow
Lessons Completed
25
stars
Best Reply Awards
28
repos

1998 contributions in the last year

Pinned
⚡ Collection of best practices for Java persistence performance in Spring Boot applications
⚡ Java Coding Problems, published by Packt
⚡ Up and Running with jOOQ, published by Packt
⚡ The Complete Coding Interview Guide in Java, published by Packt
⚡ Data Stream Development with Apache Spark, Kafka and Spring Boot by Packt Publishing
Activity
Oct
14
1 week ago
Activity icon
issue

AnghelLeonard issue jOOQ/jOOQ

AnghelLeonard
AnghelLeonard

The RESULT type render REF CURSOR instead of Oracle's SYS_REFCURSOR

Expected behavior

To render SYS_REFCURSOR (generally speaking, to render the proper cursor depending on dialect)

Actual behavior

Render REF CURSOR

Steps to reproduce the problem

For Oracle dialect, the following code:

Parameter<Long> pid = in("pid", BIGINT);
Parameter<Result<Record>> cursorResult = out("cursor_result", RESULT);

ctx.createOrReplaceProcedure("get_product_jooq")
     .parameters(pid, cursorResult)
     ...
     .execute();

Render the following:

create or replace procedure "get_product_jooq"("pid" number, "cursor_result" out ref cursor) 
as begin 
   ...
end;

Versions

  • jOOQ: 3.15.2
  • Java: 14
  • Database (include vendor): Oracle 18c
  • OS: -
  • JDBC Driver (include name if inofficial driver): -
Aug
17
2 months ago
Activity icon
issue

AnghelLeonard issue jOOQ/jOOQ

AnghelLeonard
AnghelLeonard

In MySQL, createProcedure() leads to an error: " You have an error in your SQL syntax ..."

Expected behavior

No errors.

Actual behavior

In MySQL, createProcedure() may lead to an error: "You have an error in your SQL syntax...".

Steps to reproduce the problem

I tried this problem:

Parameter<String> in_office_code = in("in_office_code", VARCHAR);

ctx.dropProcedureIfExists("get_emps_in_office_jooq")
      .execute();

ctx.createProcedure("get_emps_in_office_jooq")
      .parameters(in_office_code)
      .as(begin(
              select(OFFICE.CITY, OFFICE.COUNTRY, OFFICE.INTERNAL_BUDGET)
                                .from(OFFICE)
                                .where(OFFICE.OFFICE_CODE.eq(in_office_code)),
              select(EMPLOYEE.EMPLOYEE_NUMBER, EMPLOYEE.FIRST_NAME, EMPLOYEE.LAST_NAME)
                                .from(EMPLOYEE)
                                .where(EMPLOYEE.OFFICE_CODE.eq(in_office_code))
     ))
    .execute();

The rendered SQL contains syntax errors:

create procedure `get_emps_in_office_jooq`(`in_office_code` varchar) 
begin select `classicmodels`.`office`.`city`, `classicmodels`.`office`.`country`, 
`classicmodels`.`office`.`internal_budget` from `classicmodels`.`office` 
where `classicmodels`.`office`.`office_code` = `in_office_code`; 
select `classicmodels`.`employee`.`employee_number`, `classicmodels`.`employee`.`first_name`, 
`classicmodels`.`employee`.`last_name` from `classicmodels`.`employee` 
where `classicmodels`.`employee`.`office_code` = `in_office_code`; 
end;

In order to work I done this:

**DELIMITER $$;**
create procedure `get_emps_in_office_jooq`(`in_office_code` **varchar(20)**) 
begin select `classicmodels`.`office`.`city`, `classicmodels`.`office`.`country`, 
`classicmodels`.`office`.`internal_budget` from `classicmodels`.`office` 
where `classicmodels`.`office`.`office_code` = `in_office_code`; 
select `classicmodels`.`employee`.`employee_number`, `classicmodels`.`employee`.`first_name`, 
`classicmodels`.`employee`.`last_name` from `classicmodels`.`employee` 
where `classicmodels`.`employee`.`office_code` = `in_office_code`; 
end**$$**
**DELIMITER ;**

About rendering VARCHAR(20) I tried this:

Parameter<String> in_office_code = in("in_office_code", VARCHAR(20));

But, it still renders only VARCHAR without length.

Versions

  • jOOQ:3.15.0
  • Java:14
  • Database (include vendor):MySQL
  • OS:
  • JDBC Driver (include name if inofficial driver):
Aug
11
2 months ago
Activity icon
issue

AnghelLeonard issue jOOQ/jOOQ

AnghelLeonard
AnghelLeonard

In MySQL, createOrReplaceFunction/Procedure() leads to an error: " You have an error in your SQL syntax ..."

Expected behavior

No errors.

Actual behavior

In MySQL, createOrReplaceFunction/Procedure() leads to an error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'create function foo() returns int deterministic begin return 0; end' at line 1".

Steps to reproduce the problem

I tried this code:

ctx.createOrReplaceFunction("foo") 
    .returns(INTEGER)
    .deterministic()
    .as(return_(0))
    .execute();

The rendered code that produces the error is:

drop function if exists `foo`; 
create function `foo`() returns int 
  deterministic 
begin 
  return 0; 
end;

The code that works uses a MySQL explicit delimiter as:

drop function if exists `foo`; 
DELIMITER $$
create function `foo`() returns int 
  deterministic 
begin 
  return 0; 
end$$
DELIMITER ;

I am not sure, but I think that the same issue may occur in other scenarios like here:

create.begin(call(name("foo"))).execute();

Note: If I replace createOrReplaceFunction/Procedure() with the combo dropFunctionProcedureIfExists() and createFunction/Procedure() then it work as expected.

Versions

  • jOOQ: 3.15.0
  • Java: 14
  • Database (include vendor): MySQL
  • OS: -
  • JDBC Driver (include name if inofficial driver): -
Activity icon
issue

AnghelLeonard issue jOOQ/jOOQ

AnghelLeonard
AnghelLeonard

OUT parameters rendered as INOUT for PostgreSQL functions

Expected behavior

OUT parameters to be rendered as expected

Actual behavior

OUT parameters are rendered as INOUT parameters

Steps to reproduce the problem

I tried this function:

Parameter<Integer> min_sal = out("min_sal", INTEGER);
Parameter<Integer> max_sal = out("max_sal", INTEGER);
Parameter<Integer> avg_sal = out("avg_sal", INTEGER);

ctx.createOrReplaceFunction("get_salary_stat_jooq")
     .parameters(min_sal, max_sal, avg_sal)
     .returns(RECORD)
     .as(begin(select(min(EMPLOYEE.SALARY), max(EMPLOYEE.SALARY),
                        avg(EMPLOYEE.SALARY)).into(min_sal, max_sal, avg_sal)
                        .from(EMPLOYEE)))
     .execute();

Since the rendered code has INOUT params instead of OUT, I cannot call it as:

var result = ctx.select(function(name("get_salary_stat_jooq"), RECORD))
                .fetchOne();

Only as:

var result = ctx.select(function(name("get_salary_stat_jooq"), RECORD, val(0), val(0), val(0)))
                .fetchOne();

Versions

  • jOOQ: 3.15.0
  • Java: 14
  • Database (include vendor): PostgreSQL
  • OS:-
  • JDBC Driver (include name if inofficial driver):-