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

Support for SYSDATE in oracle Date column #4452

Closed
rjmohammad opened this issue Jul 17, 2019 · 0 comments · Fixed by #5305
Closed

Support for SYSDATE in oracle Date column #4452

rjmohammad opened this issue Jul 17, 2019 · 0 comments · Fixed by #5305

Comments

@rjmohammad
Copy link
Contributor

Issue type:

[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ x] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x ] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Can't use SYSDATE in date column fields for Oracle because of this line
https://github.com/typeorm/typeorm/blob/master/src/driver/oracle/OracleDriver.ts#L364
the logic tries to parse the string or function being passed down.

Sample Oracle Query

INSERT INTO SOME_TABLE (Last_Upd_By, Last_Upd_Date)

VALUES ( P_Last_Upd_By, SYSDATE);

Sample Code:
Entity:

@Column('date', {
    nullable: true,
    name: 'CANCEL_REQ_DATE'
  })
  CANCEL_REQ_DATE: Date | null;

  @Column('date', {
    nullable: true,
    name: 'PLAN_END_DATE'
  })
  PLAN_END_DATE: Date | null;

@Column('varchar2', {
    nullable: true,
    length: 20,
    name: 'LAST_UPD_BY'
  })
  LAST_UPD_BY: string | null;

insertion:

    LAST_UPD_BY: lastUpdatedBy,
    CANCEL_REQ_DATE: 'SYSDATE', // for issue sample
    LAST_UPD_DATE: () => 'SYSDATE', // for issue sample
  });

Both SYSDATE format gives error.

Possible solutions may include adding a conditional on line #360

if (typeof value === 'function') {
  return value
}

Above proposed solution will give alot of flexibility to the users to run their desired queries/SQL functions if they don't want the default behavior.

The current workaround on my end includes creating a patch file that patches that piece of code at the time of my docker container creation.

I can make a PR if we are fine with my proposed solution.

Thanks!
RJ

pleerock pushed a commit that referenced this issue Jan 22, 2020
* fix: resolves oracle sql expression bug for date columns

Closes: #4452

* fix: resolves sql expression bug in insert query builder

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

Successfully merging a pull request may close this issue.

2 participants