Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Oracle database support#11

Draft
butschster wants to merge 2 commits into
cycle:feature/oracle from
butschster:feature/oracle
Draft

Oracle database support #11
butschster wants to merge 2 commits into
cycle:feature/oracle from
butschster:feature/oracle

Conversation

@butschster

@butschster butschster commented Oct 12, 2021
edited by rustatian
Loading

Copy link
Copy Markdown
Contributor
  • Added oracle driver
  • Added tests for oracle driver
  • Added oracle-xe-11g-r2 docker container
  • Added docker container PHP with pdo_oci
  • Added bash script with pdo_oci installer

Oracle Features

Uppercase

Naming system tables and fields in uppercase (at least in version 11). In SQL queries, lowercase can be used, but the returned arrays will have uppercase.

Schemas

In Oracle, there's a concept called schema and by default, every user upon connection has access to a schema with the username. The work with schemas from the Postgres driver was used as a basis, as it is more similar to Oracle.

By default, after launching a Docker container, the user SYSTEM is available and it has a bunch of system tables. This feature can complicate testing the retrieval of the entire table list through getTableNames.

Auto increment

In Oracle DB, auto increment is implemented through Sequences. It's necessary to create a Sequence, name it, and when adding a new record to the DB, specify which field should use which Sequence. There's no direct link between the table field and the sequence, i.e., it's impossible to know which field corresponds to which sequence.

Creating a Sequence

CREATE SEQUENCE author_seq
 START WITH 1
 INCREMENT BY 1
 NOCACHE
 NOCYCLE

Inserting a row into the DB

create table author(
 id NUMBER(6) PRIMARY KEY,
 fname VARCHAR2(20) NOT NULL,
 lname VARCHAR2(20) NOT NULL,
 email VARCHAR2(50),
 phone_number VARCHAR2(20)
)
INSERT INTO author
VALUES
 (author_seq.nextval, 'Stephen', 'King', 'stephen@king.com', NULL)

Detailed example here

Column types

Oracle has its own typing for fields. You can view the list of types, for instance, here. Pay attention to this when mapping.

LIMIT OFFSET

In Oracle, working with LIMIT OFFSET is similar to the SqlServer driver.

Sample

SELECT
 product_name,
 quantity
FROM
 inventories
INNER JOIN products
 USING(product_id)
ORDER BY
 quantity DESC 
FETCH NEXT 5 ROWS ONLY;

Note the syntax as there are variations.

[ OFFSET offset ROWS]
 FETCH NEXT [ row_count | percent PERCENT ] ROWS [ ONLY | WITH TIES ] 

SELECT ... FOR UPDATE

The SELECT FOR UPDATE command allows you to lock the records in the resulting cursor set. The record lock is released when the following commit or rollback commands are executed.

CURSOR c1
IS
 SELECT course_number, instructor
 FROM courses_tbl
 FOR UPDATE OF instructor;

Foreign keys

As far as I understood, in version 11 of Oracle DB, there is no possibility to use ON UPDATE, instead triggers are suggested.

create table table1(
 column1 number primary key
);
create table table2(
 column2 number references table1(column1)
);
create or replace trigger cascade_update
after update of column1 on table1
for each row
begin
 update table2
 set column2 = :new.column1 
 where column2 = :old.column1;
end;

Drop constraint drop index

Dropping an index with constraint is allowable as follows

alter table foo drop constraint un_foo drop index

There might be other specific things, possibly from version 11 Oracle added a bunch of innovations and it's worth updating the Docker container to the latest version. The current version is 21c.

butschster reacted with heart emoji
- Added oracle driver
- Added tests for oracle driver
- Added oracle-xe-11g-r2 docker container
- Added docker container PHP with pdo_oci
- Added bash script with pdo_oci installer
FROM all_cons_columns a
JOIN all_constraints c ON a.owner = c.owner AND a.constraint_name = c.constraint_name
JOIN all_constraints c_pk ON c.r_owner = c_pk.owner AND c.r_constraint_name = c_pk.constraint_name
JOIN all_cons_columns a_pk ON a_pk.owner = c_pk.owner AND a_pk.constraint_name = c_pk.constraint_name

@butschster butschster Oct 12, 2021
edited by rustatian
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely, this line goes into recursion

butschster reacted with eyes emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@roxblnfk roxblnfk Awaiting requested review from roxblnfk

Labels

type: feature New feature.

Projects

Status: Backlog

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /