Based on my limited knowledge of the $db_prefix parameter in the settings file, this is a prefix to the table's name ("access" => "dp6_access"). However the code seems to be treating it like the oracle schema name by adding a dot (".") between the prefix and table name. I was able to fix this in the code by removing the dots from oracle_prefix_tables().
Also $db_prefix doesn't play well with looking up sequence names either (Oracle Package identifier.sequence_for_table). The actual sequence name is dp6_seq_access_aid, the function produces "seq_dp6_access_aid". You could use the following SQL statement to get the sequence for the table (could be refined some to factor in some more checking if more than one row is returned).
select referenced_owner, referenced_name
into v_schema, v_sequence_oname
from all_dependencies
where (name, type) in (
select name, type
from all_dependencies
where referenced_owner = v_schema
and referenced_name = v_table_oname
and referenced_type = 'TABLE'
)
and referenced_type = 'SEQUENCE';I also had to change the oracle_get_table_info() function as well to run the table name through oracle_prefix_tables()...
function oracle_get_table_info($table)
{
global $tableInformation;
$table = oracle_prefix_tables('{' . strtoupper($table) . '}');
$schema= oracle_get_table_schema($table);
[...]Thanks for writing this driver, you have no idea how great it is to upgrade from Drupal 4.7. I'll test it out some more over the next few days and report any more errors I find...
Comments
Comment #1
aaaristo commentedHi siromega,
you are right i translate the $db_prefix as an oracle schema. This choice is due to the fact that a lot of drupal objects exceed the maximum oracle allowed length for identifiers (30 characters) .. So treating the prefix as a schema we have 30 characters more to play with. It is also a logically consistent choice because db_prefix is mostly used for multisite, so having site specific objects into a site specific schema is a good thing... If you remove the schema part the long_identifiers handling code came to make thing works... But it'll be slooower... So, i would prefer to let the db_prefix in the schema domain...
Why would you prefer not to use schemas?
Andrea
Comment #2
aaaristo commentedyour code is buggy:
function oracle_get_table_info($table)
{
global $tableInformation;
$table = oracle_prefix_tables('{' . strtoupper($table) . '}');
$schema= oracle_get_table_schema($table);
[...]
is already fixed in the downloadable version i think:
global $tableInformation;
$schema= oracle_get_table_schema(oracle_prefix_tables('{' . strtoupper($table) . '}'));
if (!isset($tableInformation[$schema."|".$table]))
This is the reason why you get: "seq_dp6_access_aid" intead of "dp6.seq_access_aid":
$table = oracle_prefix_tables('{' . strtoupper($table) . '}');
...here the table becomes dp6_access..
the PL/SQL function sequence_for_table wants the primitive table name as table parameter (access) and the db_prefix as schema parameter...
Andrea
Comment #3
aaaristo commentedComment #4
siromega commentedI was using $db_prefix as a table name prefix because in my organization, we have a bunch of applications in one schema, where all objects are prefixed with something to make them unique. It may not be the best practice (I'm sure its not), but it beats asking the DBAs for a new schema. The way my objects look is...
myschema.dp6_access
myschema.dp6_nodes
etc...
I understand using it $db_prefix for a schema, it makes complete sense. If I had a choice I'd implement it that way as well...
Otherwise, I've been using it for a few days with my minor mods and its been working fine. I'm still trying to port my 4.7 data over (its mostly a pain because all the CLOBs reside within the tables themselves rather than a pointer with a separate table).
I'm sure its ancient knowledge as to why clobs are separated, but can I ask why?
Thanks again for the oracle driver!
Comment #5
aaaristo commentedMay be you can ask your DBA either:
1. To give the drupal user the grants needed to create other users and to manage their objects (not necessarly the DBA ROLE)...
2. To precreate the db_prefix's users and to give the drupal user the ability to manage their objects
About CLOBs:
The reason why CLOBs (they really are BLOBs because PDO_OCI does not support CLOBs actually, and we have to use PDO_OCI instead of oci8 for future release compatibility 7.x driver have to be on PDO_OCI) are separated is that there are statements that does things like:
select distinct field1, field2, blobfield3 from tablex
or
select field1, field2, blobfield3, count(*) from tablex group by field1, field2, blobfield3
or
i'am pretty sure there was i binding problem too, but actually i cannot remember the case...
So we need to have blobs like "simple-type" columns or translating those kind of statements is a nightmare...
Actually BLOB columns are varchar2(4000), once 4000 is exceed the value is translated in B^#and the
real value is inserted into the BLOBS table with an md5 hash to eventually reuse it....
To migrate from the 4.3 data i suggest you to write a pl/sql procedure... You can check the migration.sql that you can find
into the oracle-6***tar.gz root. It is not supposed to be used for the 4.3, but you can find usefull ideas i think...
May be you would like to contribute that procedure to this project once you wrote it! ;)
Comment #6
siromega commentedGetting the DBAs to grant those privs will not likely happen. I'm just constrained to work within the space I've been given. I've got it working and I'm happy.
The blob solution makes sense. I can remember trying to write an Oracle driver for D4.7 many years ago (see http://drupal.org/node/39260#comment-359135) and the LOB issue was a huge pain. We had taken to pulling apart and rebuilding every SQL query through _db_query. It didn't work too well.
And yes, once I get the procedure done I'll publish it. The difficulty is both upgrading the existing tables as well as separating out the clobs and reforming the tables. Based on that migration script you provided, it doesn't appear that column order matters - I can add a varchar2(4000) column at the end of the table and remove the clob column and everything will still work (I'll assume there are no inserts without specifying column order anywhere in the drupal source...).
Comment #7
aaaristo commentedThis DB Prefix thing is interesting... I was discussing with Crell the last week and he said:
"universal availability is a key goal for Drupal" (http://www.garfieldtech.com/blog/orm-vs-query-builders)
...where "universal availability" means also (i think) that you do not have to fight your DBA.. so may be we can:
1. add a parameter in the settings.php to make $db_prefix work in your deployment profile:
i am a bit scared about adding complexity to the driver... it is quite complex right now..
and there are a lot of "dependencies" in the way it works to keep in mind, so i see this
choice risky to support in the long run.
2. Define a better schema granting mechanism, to make a DBA happy. Actually i simply have had no time
to do it. I think there are good tools in oracle to achieve this thing. Remember also that creating schemas in
Oracle does not mean wasting space... (So the space he gave you does not change, eg. use the same DRUPAL
tablespace/s for all the drupal schemas...).
Yes, i think you can ignore the column order..
Comment #8
siromega commentedThe way my DBA prefers it would be that I would be given one schema for my workgroup, and in that schema would contain various tables for all of our work processes (with a few strictly controlled exceptions - usually purchased apps that require their own schema). I don't know if this is the norm in the Oracle community (it could very well not be, in which case I'm the odd man out and will just work around it).
I think for most DBAs, removing any grant privs that include DBA or "{action} ANY {object}" would suffice - considering that it might not be the DBA running install routines. The idea is that you would get a new schema (or use an existing one) and go from there and conduct all operations (db creation, all edits, etc) from that schema.
I'm still working on the OraDrup 4.7.x -> Oracle D6.x upgrade script - it involves manually upgrading the core tables from 4.x to 5.x to 6.x then factoring out clobs. Once I get that far I'll do a diff on the same tables a fresh D6 install and see if there is anything I missed...