Hi,

I'm looking for some PHP programmers to assist with extending the database abstraction layer for Oracle support. I'm bringing the Oracle background to the table and can submit a new Oracle database build script that provides proper table structure, indexes, procedures, etc. But I have zero PHP experience, and am looking for someone to help make that portion happen. Here are the major tasks that need attention:

1) Develop Oracle database build script - I'll handle this
2) Develop Oracle database abstraction layer - unassigned
3) Document Installation procedure for use of Oracle database:
- install document will require update to reflect requirement of installing Oracle Database module and recompile of PHP, plus Drupal specific configuration steps. - unassigned.
4) Testing - Verify that Drupal handles Oracle's CLOB accessor methods properly and properly invokes database procedures. Solution should be tested with the Forum Module, Tracker Module and any module that uses the CLOB data type (which will be any module that uses a Text data type in MySQL). - unassigned.

Please reply if you're interested in contributing to this effort. :-)

Thanks,

Mac

Comments

rinehart’s picture

For all who are interested: while CLOB is the Oracle equivalent of Text, there are substantial differences. If you're interested in ensuring your pet module works with Oracle and you are not familiar with CLOBs, please read this document.

1) Text contains up to 65535 bytes. CLOBs hold up to 4 GB. I don't know about Text storage but CLOBs are stored out of line from the database table. CLOBs are variable length. Each CLOB field, once initialized, contains a pointer to a separate memory area in the Oracle database.

2) CLOBs require initialization before use with the function EMPTY_CLOB(). Initialization can be made implicit by using the 'default EMPTY_CLOB()' phrase as part of the column definition in the CREATE TABLE statement. In the new schema all Text fields with "NOT NULL" qualifiers in DDL are implicitly initialized in the DDL. Any Text field with the NULL qualifier or no qualifier will require initialization when a new row is inserted. :shocked: If you believe that 'NULL' Text fields need to be implicitly initialized please say something. Note that implicit initialization will consume memory with every insert - if a Text field is often left null after a row is inserted then don't ask for the field to be initialized implicitly. :smile:

3) CLOBs are implicitly initialized if a text string is assigned to the field by an SQL Insert statement. If no string is assigned in the insert statement, the field CANNOT be updated without first initializing the field explicitly using the EMPTY_CLOB() function. :evil: This is important. If the new row is not implicitly initialized (via an insert or DDL default statement), subsequent attempts to update the field with a text string will fail unless the field is initialized first. It's may be possible to handle initialization using an column update Trigger that implicitly initializes a CLOB field, but that will cause DML performance to suffer. If possible, column update triggers are a better choice than implicit initialization for those tables where CLOB fields are rarely updated, and may often be null when the row is created. Please advise if you believe a trigger is required. :smile:

4) When updating a CLOB with straight SQL, the CLOB content is replaced. SQL select statements can retrieve the entire content of a CLOB field. Oracle provides a built-in package of "Mutator" and "Observer" functions for enhanced access. Mutators can modify CLOBs (APPEND, COPY, ERASE, TRIM, WRITE) and Observers can read CLOBs (COMPARE, INSTR, GETLENGTH, READ, SUBSTR). Implementation of mutator and observer functions will require careful consideration in the database abstraction layer. If you require these services of the database please advise.

5) Thoughts regarding Caching and CLOBs are welcome. I presume if users endeavor to completely fill a few 4 GB CLOBs and then Drupal attempts to cache those fields, the consequences might not be pretty. I'm not sure how Drupal handles caching but this is something to think about.

6) CLOB alternatives: VARCHAR2 is a variable length text field. Length can be up to 4000 Bytes, and must be specified in DDL. The content is stored inline with the table row. If you want to support multi-byte characters, then assume that the length is 2-bytes per character when assigning length. My review of the DDL shows heavy use of Text fields. Are they all required? If some of these fields can be redefined to VARCHAR2 fields, Oracle DBAs everywhere will sleep better.

:puzzled: A lot to think about here. I welcome all feedback, and I'm not idiot proff ;)(I'm human and make mistakes so if you see something that doesn't look right please speak up).

Cheers,

Mac

Steven’s picture

I can't help you with oracle, but I'd like to point out that as of recently, all text fields in Drupal now support at least 2GB of data (some database platforms offer even more).

rinehart’s picture

Thanks, my info was based on an apparently out of date document from the web. Here are data type conversions I made from The MSSQL schema to Oracle. Note that where precision or scale are specified I left them the same, just substituting the data type name if required. Translations were made based on a conversion posting in the Expert Exchange forum.

1. SMALLINT --> NUMBER(38)
2. TINYINT --> NUMBER(38) -- EWAG
3. INT --> NUMBER(38)
4. FLOAT --> NUMBER -- unconstrained
5. NUMERIC(x) --> NUMBER(x)
6. NUMERIC( x, y) --> NUMBER( x, y)
7. VARCHAR(x) --> VARCHAR2(x) -- max len is 4000 in Oracle, which is shorter than 8000 limit used in some Drupal Columns. :evil:
8. NVARCHAR(x) --> NVARCHAR2(x)
9. TEXT NOT NULL --> CLOB default EMPTY_CLOB() -- initialized
10. TEXT [NULL] --> CLOB -- not initialized

allrite’s picture

Also note that the Oracle default date format (dd-MON-YY) differs from the MySQL yyyy-mm-dd format (I'm basing this on Oracle 7 and 8 - there are conversion functions, I think).

rinehart’s picture

Happy New Year!

I'll doublecheck but I didn't see any dates on the schema. There are timestamp fields that were stored as Floats. I translated that to unconstraned Number in Oracle.

- Mac

allrite’s picture

I'm possibly interested in such a project, though it would be dependant on my job situation and whether my employer decides to continue using Oracle (our old server is very flaky).

Cheers,

allrite

rinehart’s picture

Great. I don't think there is much coding here, just two files:

1) database.oracle.inc needs to be created. database.mysql.inc can be used as a prototype.
2) database.inc needs another condition that imports the database.oracle.inc file if the database is oracle.

I'd suggest keeping it simple first, assume that all Clobs are initialized on insert and no special Clob accessors are required. We can enhance later if it's necessary.

rinehart’s picture

Encountered the following serious problems with the Drupal schema in Oracle:

1) Table name 'access' is not allowed
2) Column name 'uid' is not allowed (Tables: accesslog, authmap, comments, history, node, sessions, users, watchdog)
3) Column name 'size' is not allowed (Site table)

:sad:

bertboerland’s picture

now someone form the core team has to decide
* go one (oracle wont be an option)
* change names toward less generic names that are clear in *any database

--
groets

bertb

--
groets
bert boerland

dries’s picture

I don't know Oracle but AFAIK are these table and column names not ANSI SQL reserved keywords. Can't Oracle be configured to adhere to any of the ANSI SQL standards? Stupid question I guess but I want to make sure as having to rename uid is a daunting task.

rinehart’s picture

As far as Oracle's words are concerned, they do adhere to the ANSI standards, but have additional words that are reserved beyond those standards. Here's a reference to all of the reserved words for Oracle.

I noticed that "size" is also an ANSI reserved word, according to Oracle's documentation. I suppose that give the need to change that column more weight.

acro’s picture

These reserved words are not a problem you just need to double quote them.

This works fine:

SQL> create table drupal ("uid" number, "access" number, "size" number);

Table created.

SQL>

You also need to tweak _db_query to quote Oracle reserved column named in queries too.

bruno’s picture

Drupal provides support for other databases than MySQL thru database.pear.inc, which is a (kind of) wrapper to PEAR DB.

Have anyone had a look at using PEAR MDB instead? PEAR MDB supports Oracle and its API looks very close to PEAR DB's one.

moshe weitzman’s picture

i have an mdb prototype in my andbox. see contrib/sandbox/moshe

also, pear can connect to any ODBC database. is that not sufficient for oracle?

rinehart’s picture

I thought I read elsewhere that Oracle's CLOBs where a problem with PEAR, but after reviewing I think I missunderstood that post. PEAR could work, but that still leaves the table and column naming issues.

- Mac

allrite’s picture

MDB supports Oracle CLOBs - I use it myself at work. It's PEAR's DB abstraction layer that doesn't support Oracle CLOBs. Note that MDB2 is in the works (I haven't looked at this).

I have no idea if ODBC is good enough, but I suspect that it's not desirable.

rinehart’s picture

Hi all,

In MySQL and MsSQL it appears that you can insert and empty string '' into a NOT NULL field without trouble. I assume this is the case because it's done in the build scripts.

Oracle treats an empty string as a Null, and will not allow it to be interested into a NOT NULL field. Further it is not possible to have a NOT NULL column with a DEFAULT '' clause. To address this issue I'm loosing the constraints on fields that contain a DEFAULT '' clause to allow nulls. I'll also allow nulls on all fields that have empty strings inserted into them in the database build script. This only applies to the Oracle build script I'm creating.

In a column definition DEFAULT '' and NULL are redundant in Oracle - I will drop default expressions but make the NULL statement explicit.

- Mac

allrite’s picture

Hi again!

I just recalled another gotcha I have had with porting database applications to Oracle. When returning results as associative arrays, Oracle uses all-caps for the field names - unlike MySQL.

Cheers,

Andrew

mandric’s picture

hello, just thought i'd chime in ... haven't looked around that much
but is there an official project for this port?

Cainan’s picture

I now also find myself in a desperate need to have Drupal on Oracle. I have much resources coding time-wise, but will confess i am NOT a Oracle DBA. (though i plan to fix that and SOON)

I can however volunteer many man hours of programming time to help make a port/mod for running Oracle DB under Drupal, if someone were to lead such a project