DBSchema/DBD/Sybase.pm

filter: Statementstmt 27.0% 13 / 48 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 30.0% 3 / 10 Podpod 100% 4 / 4 totaltotal 25.9% 20 / 77 SCAR 36.7
CC
8
Cov
21%
columns
20.0
_all_indices
12.0
_index_fields
12.0
CRAP 39.2
« DBSchema/Index.pm ↑ Summary DBSchema/DBD/Oracle.pm »
1 package DBIx::DBSchema::DBD::Sybase;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @ISA %typemap);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use DBIx::DBSchema::DBD;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 $VERSION = '0.03';
8 1 @ISA = qw(DBIx::DBSchema::DBD);
9  
10 1 %typemap = (
11 # 'empty' => 'empty'
12 );
13  
14 =head1 NAME
15  
16 DBIx::DBSchema::DBD::Sybase - Sybase database driver for DBIx::DBSchema
17  
18 =head1 SYNOPSIS
19  
20 use DBI;
21 use DBIx::DBSchema;
22  
23 $dbh = DBI->connect('dbi:Sybase:dbname=database', 'user', 'pass');
24 $schema = new_native DBIx::DBSchema $dbh;
25  
26 =head1 DESCRIPTION
27  
28 This module implements a Sybase driver for DBIx::DBSchema.
29  
30 =cut
31  
32 sub columns {
33 0 ▶ my($proto, $dbh, $table) = @_;
Subroutine columns: not called CC=4 SCAR=30.0
Pod documented
34  
35 0 ▶ my $sth = $dbh->prepare("sp_columns \@table_name=$table")
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare("sp_columns \@table_name=$table") or die $dbh->errstr 0 0 0
36 or die $dbh->errstr;
37  
38 0 ▶ $sth->execute or die $sth->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or die $sth->errstr 0 0 0
39 my @cols = map {
40 [
41 $_->{'column_name'},
42 $_->{'type_name'},
43 ($_->{'nullable'} ? 1 : ''),
44 0 ▶ $_->{'length'},
Branch: 1 branch
BranchTrueFalseTotal
$_->{'nullable'} ? : 0 0 0
45 '', #default
46 '' #local
47 ]
48 0 } @{ $sth->fetchall_arrayref({}) };
49 0 $sth->finish;
50  
51 0 @cols;
52 }
53  
54 sub primary_key {
55 0 ▶ return("StubbedPrimaryKey");
Subroutine primary_key: not called CC=1 SCAR=6.9
Pod documented
56 }
57  
58  
59 sub unique {
60 0 ▶ my($proto, $dbh, $table) = @_;
Subroutine unique: not called CC=1 SCAR=6.9
Pod documented
61 0 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $table, $_ ) ] }
62 0 grep { $proto->_is_unique($dbh, $_ ) }
63 $proto->_all_indices($dbh, $table)
64 };
65 }
66  
67 sub index {
68 0 ▶ my($proto, $dbh, $table) = @_;
Subroutine index: not called CC=1 SCAR=6.9
Pod documented
69 0 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $table, $_ ) ] }
70 0 grep { ! $proto->_is_unique($dbh, $_ ) }
71 $proto->_all_indices($dbh, $table)
72 };
73 }
74  
75 sub _all_indices {
76 0 ▶ my($proto, $dbh, $table) = @_;
Subroutine _all_indices: not called CC=3 SCAR=24.8
77  
78 0 ▶ my $sth = $dbh->prepare_cached(<<END) or die $dbh->errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare_cached(" SELECT name\n FROM sysindexes\n WHERE id = object_id('${table}') and indid between 1 and 254\n") or die $dbh->errstr 0 0 0
79 SELECT name
80 FROM sysindexes
81 WHERE id = object_id('$table') and indid between 1 and 254
82 END
83 0 ▶ $sth->execute or die $sth->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or die $sth->errstr 0 0 0
84 0 my @indices = map { $_->[0] } @{ $sth->fetchall_arrayref() };
85 0 $sth->finish;
86 0 $sth = undef;
87 0 @indices;
88 }
89  
90 sub _index_fields {
91 0 ▶ my($proto, $dbh, $table, $index) = @_;
Subroutine _index_fields: not called CC=3 SCAR=24.8
92  
93 0 my @keys;
94  
95 0 my ($indid) = $dbh->selectrow_array("select indid from sysindexes where id = object_id('$table') and name = '$index'");
96 0 for (1..30) {
97 0 ▶ push @keys, $dbh->selectrow_array("select index_col('$table', $indid, $_)") || ();
Condition0%0/3
$dbh->selectrow_array("select index_col('${table}', $indid, $_)") || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbh->selectrow_array("select index_col('${table}', $indid, $_)") || ()
$dbh->selectrow_array("select index_col('${table}', $indid, $_)") ()
Truth table0%0/3
A || B
A= $dbh->selectrow_array("select index_col('${table}', $indid, $_)")B= ()
ABresult
1X1
011
000
98 }
99  
100 0 return @keys;
101 }
102  
103 sub _is_unique {
104 0 ▶ my($proto, $dbh, $table, $index) = @_;
Subroutine _is_unique: not called CC=1 SCAR=6.9
105  
106 0 my ($isunique) = $dbh->selectrow_array("select status & 2 from sysindexes where id = object_id('$table') and name = '$index'");
107  
108 0 return $isunique;
109 }
110  
111 =head1 AUTHOR
112  
113 Charles Shapiro <charles.shapiro@numethods.com>
114 (courtesy of Ivan Kohler <ivan-dbix-dbschema@420.am>)
115  
116 Mitchell Friedman <mitchell.friedman@numethods.com>
117  
118 Bernd Dulfer <bernd@widd.de>
119  
120 =head1 COPYRIGHT
121  
122 Copyright (c) 2001 Charles Shapiro, Mitchell J. Friedman
123 Copyright (c) 2001 nuMethods LLC.
124 All rights reserved.
125 This program is free software; you can redistribute it and/or modify it under
126 the same terms as Perl itself.
127  
128 =head1 BUGS
129  
130 Yes.
131  
132 The B<primary_key> method does not yet work.
133  
134 =head1 SEE ALSO
135  
136 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>, L<DBI::DBD>
137  
138 =cut
139  
140 1 1;
141  
« DBSchema/Index.pm ↑ Summary DBSchema/DBD/Oracle.pm »