/usr/share/perl5/UR/DataSource/Oracle.pm is in libur-perl 0.430-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | package UR::DataSource::Oracle;
use strict;
use warnings;
require UR;
our $VERSION = "0.43"; # UR $VERSION;
UR::Object::Type->define(
class_name => 'UR::DataSource::Oracle',
is => ['UR::DataSource::RDBMS'],
is_abstract => 1,
);
sub driver { "Oracle" }
sub owner { shift->_singleton_object->login }
sub can_savepoint { 1 } # Oracle supports savepoints inside transactions
sub does_support_recursive_queries { 'connect by' };
sub set_savepoint {
my($self,$sp_name) = @_;
my $dbh = $self->get_default_handle;
my $sp = $dbh->quote($sp_name);
$dbh->do("savepoint $sp_name");
}
sub rollback_to_savepoint {
my($self,$sp_name) = @_;
my $dbh = $self->get_default_handle;
my $sp = $dbh->quote($sp_name);
$dbh->do("rollback to $sp_name");
}
my $DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
my $TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SSXFF';
sub _set_date_format {
my $self = shift;
foreach my $sql ("alter session set NLS_DATE_FORMAT = '$DATE_FORMAT'",
"alter session set NLS_TIMESTAMP_FORMAT = '$TIMESTAMP_FORMAT'"
) {
$self->do_sql($sql);
}
}
*_init_created_dbh = \&init_created_handle;
sub init_created_handle {
my ($self, $dbh) = @_;
return unless defined $dbh;
$dbh->{LongTruncOk} = 0;
$self->_set_date_format();
return $dbh;
}
sub _dbi_connect_args {
my @args = shift->SUPER::_dbi_connect_args(@_);
$args[3]{ora_module_name} = (UR::Context::Process->get_current->prog_name || $0);
return @args;
}
sub _prepare_for_lob {
{ ora_auto_lob => 0 }
}
sub _post_process_lob_values {
my ($self, $dbh, $lob_id_arrayref) = @_;
return
map {
if (defined($_)) {
my $length = $dbh->ora_lob_length($_);
my $data = $dbh->ora_lob_read($_, 1, $length);
# TODO: bind to a file for items of a certain size to save RAM.
# Special work with tying a scalar to the file?
$data;
}
else {
undef;
}
} @$lob_id_arrayref;
}
sub _ignore_table {
my $self = shift;
my $table_name = shift;
return 1 if $table_name =~ /\$/;
}
sub get_table_last_ddl_times_by_table_name {
my $self = shift;
my $sql = qq|
select object_name table_name, last_ddl_time
from all_objects o
where o.owner = ?
and (o.object_type = 'TABLE' or o.object_type = 'VIEW')
|;
my $data = $self->get_default_handle->selectall_arrayref(
$sql,
undef,
$self->owner
);
return { map { @$_ } @$data };
};
sub _get_next_value_from_sequence {
my($self,$sequence_name) = @_;
# we may need to change how this db handle is gotten
my $dbh = $self->get_default_handle;
my $new_id = $dbh->selectrow_array("SELECT " . $sequence_name . ".nextval from DUAL");
if ($dbh->err) {
die "Failed to prepare SQL to generate a column id from sequence: $sequence_name.\n" . $dbh->errstr . "\n";
return;
}
return $new_id;
}
sub get_bitmap_index_details_from_data_dictionary {
my($self, $table_name) = @_;
my $sql = qq(
select c.table_name,c.column_name,c.index_name
from all_indexes i join all_ind_columns c on i.index_name = c.index_name
where i.index_type = 'BITMAP'
);
my @select_params;
if ($table_name) {
@select_params = $self->_resolve_owner_and_table_from_table_name($table_name);
$sql .= " and i.table_owner = ? and i.table_name = ?";
}
my $dbh = $self->get_default_handle;
my $rows = $dbh->selectall_arrayref($sql, undef, @select_params);
return undef unless $rows;
my @ret = map { { table_name => $_->[0], column_name => $_->[1], index_name => $_->[2] } } @$rows;
return \@ret;
}
sub get_unique_index_details_from_data_dictionary {
my ($self, $owner_name, $table_name) = @_;
my $sql = qq(
select cc.constraint_name, cc.column_name
from all_cons_columns cc
join all_constraints c
on c.constraint_name = cc.constraint_name
and c.owner = cc.owner
and c.constraint_type = 'U'
where cc.table_name = ?
and cc.owner = ?
union
select ai.index_name, aic.column_name
from all_indexes ai
join all_ind_columns aic
on aic.index_name = ai.index_name
and aic.index_owner = ai.owner
where ai.uniqueness = 'UNIQUE'
and aic.table_name = ?
and aic.index_owner = ?
);
my $dbh = $self->get_default_handle();
return undef unless $dbh;
my $sth = $dbh->prepare($sql);
return undef unless $sth;
$sth->execute($table_name, $owner_name, $table_name, $owner_name);
my $ret;
while (my $data = $sth->fetchrow_hashref()) {
$ret->{$data->{'CONSTRAINT_NAME'}} ||= [];
push @{ $ret->{ $data->{CONSTRAINT_NAME} } }, $data->{COLUMN_NAME};
}
return $ret;
}
sub set_userenv {
# there are two places to set these oracle variables-
# 1. this method in UR::DataSource::Oracle is a class method
# that can be called to change the values later
# 2. the method in YourSubclass::DataSource::Oracle is called in
# init_created_handle which is called while the datasource
# is still being set up- it operates directly on the db handle
my ($self, %p) = @_;
my $dbh = $p{'dbh'} || $self->get_default_handle();
# module is application name
my $module = $p{'module'} || $0;
# storing username in 'action' oracle variable
my $action = $p{'action'};
if (! defined($action)) {
$action = getpwuid($>); # real UID
}
my $sql = q{BEGIN dbms_application_info.set_module(?, ?); END;};
my $sth = $dbh->prepare($sql);
if (!$sth) {
warn "Couldnt prepare query to set module/action in Oracle";
return undef;
}
$sth->execute($module, $action) || warn "Couldnt set module/action in Oracle";
}
sub get_userenv {
# there are two ways to set these values but this is
# the only way to retrieve the values after they are set
my ($self, $dbh) = @_;
if (!$dbh) {
$dbh = $self->get_default_handle();
}
if (!$dbh) {
warn "No dbh";
return undef;
}
my $sql = q{
SELECT sys_context('USERENV','MODULE') as module,
sys_context('USERENV','ACTION') as action
FROM dual
};
my $sth = $dbh->prepare($sql);
return undef unless $sth;
$sth->execute() || die "execute failed: $!";
my $r = $sth->fetchrow_hashref();
return $r;
}
my %ur_data_type_for_vendor_data_type = (
'VARCHAR2' => ['Text', undef],
'BLOB' => ['XmlBlob', undef],
);
sub ur_data_type_for_data_source_data_type {
my($class,$type) = @_;
$type = $class->normalize_vendor_type($type);
my $urtype = $ur_data_type_for_vendor_data_type{$type};
unless (defined $urtype) {
$urtype = $class->SUPER::ur_data_type_for_data_source_data_type($type);
}
return $urtype;
}
sub _alter_sth_for_selecting_blob_columns {
my($self, $sth, $column_objects) = @_;
for (my $n = 0; $n < @$column_objects; $n++) {
next unless defined ($column_objects->[$n]); # No metaDB info for this one
if ($column_objects->[$n]->data_type eq 'BLOB') {
$sth->bind_param($n+1, undef, { ora_type => 23 });
}
}
}
sub get_connection_debug_info {
my $self = shift;
my @debug_info = $self->SUPER::get_connection_debug_info(@_);
push @debug_info, (
"DBD::Oracle Version: ", $DBD::Oracle::VERSION, "\n",
"TNS_ADMIN: ", $ENV{TNS_ADMIN}, "\n",
"ORACLE_HOME: ", $ENV{ORACLE_HOME}, "\n",
);
return @debug_info;
}
# This is a near cut-and-paste from DBD::Oracle, with the exception that
# the query hint is removed, since it performs poorly on Oracle 11
sub get_table_details_from_data_dictionary {
my $self = shift;
my $version = $self->_get_oracle_major_server_version();
if ($version < '11') {
return $self->SUPER::get_table_details_from_data_dictionary(@_);
}
my($CatVal, $SchVal, $TblVal, $TypVal) = @_;
my $dbh = $self->get_default_handle();
# XXX add knowledge of temp tables, etc
# SQL/CLI (ISO/IEC JTC 1/SC 32 N 0595), 6.63 Tables
if (ref $CatVal eq 'HASH') {
($CatVal, $SchVal, $TblVal, $TypVal) =
@$CatVal{'TABLE_CAT','TABLE_SCHEM','TABLE_NAME','TABLE_TYPE'};
}
my @Where = ();
my $SQL;
if ( defined $CatVal && $CatVal eq '%' && (!defined $SchVal || $SchVal eq '') && (!defined $TblVal || $TblVal eq '')) { # Rule 19a
$SQL = <<'SQL';
SELECT NULL TABLE_CAT
, NULL TABLE_SCHEM
, NULL TABLE_NAME
, NULL TABLE_TYPE
, NULL REMARKS
FROM DUAL
SQL
}
elsif ( defined $SchVal && $SchVal eq '%' && (!defined $CatVal || $CatVal eq '') && (!defined $TblVal || $TblVal eq '')) { # Rule 19b
$SQL = <<'SQL';
SELECT NULL TABLE_CAT
, s TABLE_SCHEM
, NULL TABLE_NAME
, NULL TABLE_TYPE
, NULL REMARKS
FROM
(
SELECT USERNAME s FROM ALL_USERS
UNION
SELECT 'PUBLIC' s FROM DUAL
)
ORDER BY TABLE_SCHEM
SQL
}
elsif ( defined $TypVal && $TypVal eq '%' && (!defined $CatVal || $CatVal eq '') && (!defined $SchVal || $SchVal eq '') && (!defined $TblVal || $TblVal eq '')) { # Rule 19c
$SQL = <<'SQL';
SELECT NULL TABLE_CAT
, NULL TABLE_SCHEM
, NULL TABLE_NAME
, t.tt TABLE_TYPE
, NULL REMARKS
FROM
(
SELECT 'TABLE' tt FROM DUAL
UNION
SELECT 'VIEW' tt FROM DUAL
UNION
SELECT 'SYNONYM' tt FROM DUAL
UNION
SELECT 'SEQUENCE' tt FROM DUAL
) t
ORDER BY TABLE_TYPE
SQL
}
else {
$SQL = <<'SQL';
SELECT *
FROM
(
SELECT
NULL TABLE_CAT
, t.OWNER TABLE_SCHEM
, t.TABLE_NAME TABLE_NAME
, decode(t.OWNER
, 'SYS' , 'SYSTEM '
, 'SYSTEM' , 'SYSTEM '
, '' ) || t.TABLE_TYPE TABLE_TYPE
, c.COMMENTS REMARKS
FROM ALL_TAB_COMMENTS c
, ALL_CATALOG t
WHERE c.OWNER (+) = t.OWNER
AND c.TABLE_NAME (+) = t.TABLE_NAME
AND c.TABLE_TYPE (+) = t.TABLE_TYPE
)
SQL
if ( defined $SchVal ) {
push @Where, "TABLE_SCHEM LIKE '$SchVal' ESCAPE '\\'";
}
if ( defined $TblVal ) {
push @Where, "TABLE_NAME LIKE '$TblVal' ESCAPE '\\'";
}
if ( defined $TypVal ) {
my $table_type_list;
$TypVal =~ s/^\s+//;
$TypVal =~ s/\s+$//;
my @ttype_list = split (/\s*,\s*/, $TypVal);
foreach my $table_type (@ttype_list) {
if ($table_type !~ /^'.*'$/) {
$table_type = "'" . $table_type . "'";
}
$table_type_list = join(", ", @ttype_list);
}
push @Where, "TABLE_TYPE IN ($table_type_list)";
}
$SQL .= ' WHERE ' . join("\n AND ", @Where ) . "\n" if @Where;
$SQL .= " ORDER BY TABLE_TYPE, TABLE_SCHEM, TABLE_NAME\n";
}
my $sth = $dbh->prepare($SQL) or return undef;
$sth->execute or return undef;
$sth;
}
sub get_column_details_from_data_dictionary {
my $self = shift;
my $version = $self->_get_oracle_major_server_version();
if ($version < '11') {
return $self->SUPER::get_column_details_from_data_dictionary(@_);
}
my $dbh = $self->get_default_handle();
my $attr = ( ref $_[0] eq 'HASH') ? $_[0] : {
'TABLE_SCHEM' => $_[1],'TABLE_NAME' => $_[2],'COLUMN_NAME' => $_[3] };
my($typecase,$typecaseend) = ('','');
my $v = DBD::Oracle::db::ora_server_version($dbh);
if (!defined($v) or $v->[0] >= 8) {
$typecase = <<'SQL';
CASE WHEN tc.DATA_TYPE LIKE 'TIMESTAMP% WITH% TIME ZONE' THEN 95
WHEN tc.DATA_TYPE LIKE 'TIMESTAMP%' THEN 93
WHEN tc.DATA_TYPE LIKE 'INTERVAL DAY% TO SECOND%' THEN 110
WHEN tc.DATA_TYPE LIKE 'INTERVAL YEAR% TO MONTH' THEN 107
ELSE
SQL
$typecaseend = 'END';
}
my $SQL = <<"SQL";
SELECT *
FROM
(
SELECT
to_char( NULL ) TABLE_CAT
, tc.OWNER TABLE_SCHEM
, tc.TABLE_NAME TABLE_NAME
, tc.COLUMN_NAME COLUMN_NAME
, $typecase decode( tc.DATA_TYPE
, 'MLSLABEL' , -9106
, 'ROWID' , -9104
, 'UROWID' , -9104
, 'BFILE' , -4 -- 31?
, 'LONG RAW' , -4
, 'RAW' , -3
, 'LONG' , -1
, 'UNDEFINED', 0
, 'CHAR' , 1
, 'NCHAR' , 1
, 'NUMBER' , decode( tc.DATA_SCALE, NULL, 8, 3 )
, 'FLOAT' , 8
, 'VARCHAR2' , 12
, 'NVARCHAR2', 12
, 'BLOB' , 30
, 'CLOB' , 40
, 'NCLOB' , 40
, 'DATE' , 93
, NULL
) $typecaseend DATA_TYPE -- ...
, tc.DATA_TYPE TYPE_NAME -- std.?
, decode( tc.DATA_TYPE
, 'LONG RAW' , 2147483647
, 'LONG' , 2147483647
, 'CLOB' , 2147483647
, 'NCLOB' , 2147483647
, 'BLOB' , 2147483647
, 'BFILE' , 2147483647
, 'NUMBER' , decode( tc.DATA_SCALE
, NULL, 126
, nvl( tc.DATA_PRECISION, 38 )
)
, 'FLOAT' , tc.DATA_PRECISION
, 'DATE' , 19
, tc.DATA_LENGTH
) COLUMN_SIZE
, decode( tc.DATA_TYPE
, 'LONG RAW' , 2147483647
, 'LONG' , 2147483647
, 'CLOB' , 2147483647
, 'NCLOB' , 2147483647
, 'BLOB' , 2147483647
, 'BFILE' , 2147483647
, 'NUMBER' , nvl( tc.DATA_PRECISION, 38 ) + 2
, 'FLOAT' , 8 -- ?
, 'DATE' , 16
, tc.DATA_LENGTH
) BUFFER_LENGTH
, decode( tc.DATA_TYPE
, 'DATE' , 0
, tc.DATA_SCALE
) DECIMAL_DIGITS -- ...
, decode( tc.DATA_TYPE
, 'FLOAT' , 2
, 'NUMBER' , decode( tc.DATA_SCALE, NULL, 2, 10 )
, NULL
) NUM_PREC_RADIX
, decode( tc.NULLABLE
, 'Y' , 1
, 'N' , 0
, NULL
) NULLABLE
, cc.COMMENTS REMARKS
, tc.DATA_DEFAULT COLUMN_DEF -- Column is LONG!
, decode( tc.DATA_TYPE
, 'MLSLABEL' , -9106
, 'ROWID' , -9104
, 'UROWID' , -9104
, 'BFILE' , -4 -- 31?
, 'LONG RAW' , -4
, 'RAW' , -3
, 'LONG' , -1
, 'UNDEFINED', 0
, 'CHAR' , 1
, 'NCHAR' , 1
, 'NUMBER' , decode( tc.DATA_SCALE, NULL, 8, 3 )
, 'FLOAT' , 8
, 'VARCHAR2' , 12
, 'NVARCHAR2', 12
, 'BLOB' , 30
, 'CLOB' , 40
, 'NCLOB' , 40
, 'DATE' , 9 -- not 93!
, NULL
) SQL_DATA_TYPE -- ...
, decode( tc.DATA_TYPE
, 'DATE' , 3
, NULL
) SQL_DATETIME_SUB -- ...
, to_number( NULL ) CHAR_OCTET_LENGTH -- TODO
, tc.COLUMN_ID ORDINAL_POSITION
, decode( tc.NULLABLE
, 'Y' , 'YES'
, 'N' , 'NO'
, NULL
) IS_NULLABLE
FROM ALL_TAB_COLUMNS tc
, ALL_COL_COMMENTS cc
WHERE tc.OWNER = cc.OWNER
AND tc.TABLE_NAME = cc.TABLE_NAME
AND tc.COLUMN_NAME = cc.COLUMN_NAME
)
WHERE 1 = 1
SQL
my @BindVals = ();
while ( my ( $k, $v ) = each %$attr ) {
if ( $v ) {
$SQL .= " AND $k LIKE ? ESCAPE '\\'\n";
push @BindVals, $v;
}
}
$SQL .= " ORDER BY TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION\n";
my $sth = $dbh->prepare( $SQL ) or return undef;
$sth->execute( @BindVals ) or return undef;
$sth;
}
sub get_primary_key_details_from_data_dictionary {
my $self = shift;
my $version = $self->_get_oracle_major_server_version();
if ($version < '11') {
return $self->SUPER::get_primary_key_details_from_data_dictionary(@_);
}
my $dbh = $self->get_default_handle();
my($catalog, $schema, $table) = @_;
if (ref $catalog eq 'HASH') {
($schema, $table) = @$catalog{'TABLE_SCHEM','TABLE_NAME'};
$catalog = undef;
}
my $SQL = <<'SQL';
SELECT *
FROM
(
SELECT
NULL TABLE_CAT
, c.OWNER TABLE_SCHEM
, c.TABLE_NAME TABLE_NAME
, c.COLUMN_NAME COLUMN_NAME
, c.POSITION KEY_SEQ
, c.CONSTRAINT_NAME PK_NAME
FROM ALL_CONSTRAINTS p
, ALL_CONS_COLUMNS c
WHERE p.OWNER = c.OWNER
AND p.TABLE_NAME = c.TABLE_NAME
AND p.CONSTRAINT_NAME = c.CONSTRAINT_NAME
AND p.CONSTRAINT_TYPE = 'P'
)
WHERE TABLE_SCHEM = ?
AND TABLE_NAME = ?
ORDER BY TABLE_SCHEM, TABLE_NAME, KEY_SEQ
SQL
#warn "@_\n$Sql ($schema, $table)";
my $sth = $dbh->prepare($SQL) or return undef;
$sth->execute($schema, $table) or return undef;
$sth;
}
sub get_foreign_key_details_from_data_dictionary {
my $self = shift;
my $version = $self->_get_oracle_major_server_version();
if ($version < '11') {
return $self->SUPER::get_foreign_key_details_from_data_dictionary(@_);
}
my $dbh = $self->get_default_handle();
my $attr = ( ref $_[0] eq 'HASH') ? $_[0] : {
'UK_TABLE_SCHEM' => $_[1],'UK_TABLE_NAME ' => $_[2]
,'FK_TABLE_SCHEM' => $_[4],'FK_TABLE_NAME ' => $_[5] };
my $SQL = <<'SQL'; # XXX: DEFERABILITY
SELECT *
FROM
(
SELECT
to_char( NULL ) UK_TABLE_CAT
, uk.OWNER UK_TABLE_SCHEM
, uk.TABLE_NAME UK_TABLE_NAME
, uc.COLUMN_NAME UK_COLUMN_NAME
, to_char( NULL ) FK_TABLE_CAT
, fk.OWNER FK_TABLE_SCHEM
, fk.TABLE_NAME FK_TABLE_NAME
, fc.COLUMN_NAME FK_COLUMN_NAME
, uc.POSITION ORDINAL_POSITION
, 3 UPDATE_RULE
, decode( fk.DELETE_RULE, 'CASCADE', 0, 'RESTRICT', 1, 'SET NULL', 2, 'NO ACTION', 3, 'SET DEFAULT', 4 )
DELETE_RULE
, fk.CONSTRAINT_NAME FK_NAME
, uk.CONSTRAINT_NAME UK_NAME
, to_char( NULL ) DEFERABILITY
, decode( uk.CONSTRAINT_TYPE, 'P', 'PRIMARY', 'U', 'UNIQUE')
UNIQUE_OR_PRIMARY
FROM ALL_CONSTRAINTS uk
, ALL_CONS_COLUMNS uc
, ALL_CONSTRAINTS fk
, ALL_CONS_COLUMNS fc
WHERE uk.OWNER = uc.OWNER
AND uk.CONSTRAINT_NAME = uc.CONSTRAINT_NAME
AND fk.OWNER = fc.OWNER
AND fk.CONSTRAINT_NAME = fc.CONSTRAINT_NAME
AND uk.CONSTRAINT_TYPE IN ('P','U')
AND fk.CONSTRAINT_TYPE = 'R'
AND uk.CONSTRAINT_NAME = fk.R_CONSTRAINT_NAME
AND uk.OWNER = fk.R_OWNER
AND uc.POSITION = fc.POSITION
)
WHERE 1 = 1
SQL
my @BindVals = ();
while ( my ( $k, $v ) = each %$attr ) {
if ( $v ) {
$SQL .= " AND $k = ?\n";
push @BindVals, $v;
}
}
$SQL .= " ORDER BY UK_TABLE_SCHEM, UK_TABLE_NAME, FK_TABLE_SCHEM, FK_TABLE_NAME, ORDINAL_POSITION\n";
my $sth = $dbh->prepare( $SQL ) or return undef;
$sth->execute( @BindVals ) or return undef;
$sth;
}
sub _get_oracle_major_server_version {
my $self = shift;
unless (exists $self->{'__ora_major_server_version'}) {
my $dbh = $self->get_default_handle();
my @data = $dbh->selectrow_arrayref('select version from v$instance');
$self->{'__ora_major_server_version'} = (split(/\./, $data[0]->[0]))[0];
}
return $self->{'__ora_major_server_version'};
}
sub cast_for_data_conversion {
my($class, $left_type, $right_type, $operator, $sql_clause) = @_;
my @retval = ('%s','%s');
# compatible types
if ($left_type->isa($right_type)
or
$right_type->isa($left_type)
) {
return @retval;
}
if (! $left_type->isa('UR::Value::Text')
and
! $right_type->isa('UR::Value::Text')
) {
# We only support cases where one is a string, for now
# hopefully the DB can sort it out
return @retval;
}
# Oracle can auto-convert strings into numbers and dates in the 'where'
# clause, but has issues in joins
if ($sql_clause eq 'where') {
return @retval;
}
# Figure out which one is the non-string
my($data_type, $i) = $left_type->isa('UR::Value::Text')
? ( $right_type, 1)
: ( $left_type, 0);
if ($data_type->isa('UR::Value::Number')) {
$retval[$i] = q{to_char(%s)};
} elsif ($data_type->isa('UR::Value::Timestamp')) {
# These time formats shoule match what's given in init_created_handle
$retval[$i] = qq{to_char(%s, '$TIMESTAMP_FORMAT')};
} elsif ($data_type->isa('UR::Value::DateTime')) {
$retval[$i] = qq{to_char(%s, '$DATE_FORMAT')};
} else {
@retval = $class->SUPER::cast_for_data_conversion($left_type, $right_type);
}
return @retval;
}
sub _vendor_data_type_for_ur_data_type {
return ( TEXT => 'VARCHAR2',
STRING => 'VARCHAR2',
BOOLEAN => 'INTEGER',
__default__ => 'VARCHAR2',
shift->SUPER::_vendor_data_type_for_ur_data_type(),
);
};
1;
=pod
=head1 NAME
UR::DataSource::Oracle - Oracle specific subclass of UR::DataSource::RDBMS
=head1 DESCRIPTION
This module provides the Oracle-specific methods necessary for interacting with
Oracle databases
=head1 SEE ALSO
L<UR::DataSource>, L<UR::DataSource::RDBMS>
=cut
|