Re: Proposing an API for the extension for simplifying database connections

2005-01-13 Thread Tim Bunce
Feel free to create a DBD::DBH or somesuch.

Tim.

p.s. Best not to cross-post dbi-users and dbi-dev. This sort of 'requirements 
spec'
discussion is best on dbi-users as they would be your customers.

On Thu, Jan 13, 2005 at 12:40:49AM -0600, David Nicol wrote:
   That's what DBI wrappers do, and I have one of those too.  But my DBI
   wrapper reads its connection information for each logical data source 
   from
   a hash.  Then there's a build_dsn() method that assembles the pieces
   according to the name of the driver.
  
   If each DBD did that for me, I could just pass a reference to my 
   connection
   info hash directly to DBI-connect() and then remove the build_dsn() code
   from my wrapper.
  
  Assuming that each DBD used the same names for elements with the same 
  meaning
  (database vs dbname vs db vs sid etc etc).
  
  Tim.
 
 mandating a new method for all compliand DBDs is, as ever, outrageeous.
 
 Here's a proposed compromise:  A new DBD that takes the elements of
 the attributes hash, and at connect time this DBD will build the DSN (or
 croak and complain explicitly about what is missing in a well defined way)
 and return a real $dbh resulting from calling DBI-connect with the build DSN.
 
 DBI doc tells us:
$dbh = DBI-connect($dsn, $user, $password,
   { RaiseError = 1, AutoCommit = 0 });
 
 
 DBD::dsn (DBD::any?  DBD::DBH?) would work like this:
$dbh = DBI-connect('DBI:DBH', $user, $password,
   { RaiseError = 1, AutoCommit = 0,
  host = $dbhost, dbd = 'pg', port = $dbport });
 
 That way, DBI-connect doesn't need to be rewritten to allow a hash -- it
 already allows the %attr hash -- and the intermediate DSN created by
 the build_dsn method is hidden away in the inner workings.
 
 Am I missing something?


Proposing an API for the extension for simplifying database connections

2005-01-13 Thread David Nicol
  That's what DBI wrappers do, and I have one of those too.  But my DBI
  wrapper reads its connection information for each logical data source from
  a hash.  Then there's a build_dsn() method that assembles the pieces
  according to the name of the driver.
 
  If each DBD did that for me, I could just pass a reference to my connection
  info hash directly to DBI-connect() and then remove the build_dsn() code
  from my wrapper.
 
 Assuming that each DBD used the same names for elements with the same meaning
 (database vs dbname vs db vs sid etc etc).
 
 Tim.

mandating a new method for all compliand DBDs is, as ever, outrageeous.

Here's a proposed compromise:  A new DBD that takes the elements of
the attributes hash, and at connect time this DBD will build the DSN (or
croak and complain explicitly about what is missing in a well defined way)
and return a real $dbh resulting from calling DBI-connect with the build DSN.

DBI doc tells us:
   $dbh = DBI-connect($dsn, $user, $password,
  { RaiseError = 1, AutoCommit = 0 });


DBD::dsn (DBD::any?  DBD::DBH?) would work like this:
   $dbh = DBI-connect('DBI:DBH', $user, $password,
  { RaiseError = 1, AutoCommit = 0,
 host = $dbhost, dbd = 'pg', port = $dbport });

That way, DBI-connect doesn't need to be rewritten to allow a hash -- it
already allows the %attr hash -- and the intermediate DSN created by
the build_dsn method is hidden away in the inner workings.

Am I missing something?


Re: Proposing an API for the extension for simplifying database connections

2005-01-13 Thread Jochen Wiedmann
On Thu, 13 Jan 2005 00:40:49 -0600, David Nicol [EMAIL PROTECTED] wrote:

 Am I missing something?

Yes, to convince, at least me. I still don't understand, what this
should be good for. If it is fine for you, with a limited number of
drivers supported, then you may very well use it. You may as well
write a DBIx extension or do whatever you want. For example, this
could easily be implemented as a DBI subclass with a slightly
different connect method.

However, in general, the DBI is based on the DSN as a string with
almost no syntactical rules. Drivers have used this liberty, with good
reasons. Why leave this at all?


Jochen

-- 
Sum. Cogitone?


joins and the DBD::CSV module

2005-01-13 Thread Jeff Benton

 I am trying to do a join across to csv files but have been unsuccessful
 up to this point.
 
 I have two tables:
 tab1.csv
 TAB_ONE_ID,NAME,TAB_TWO_ID
 1,row1,100
 2,row2,200
 
 tab2.csv
 TAB_TWO_ID,CATEGORY
 100,cat1
 200,cat2
 
 I am running the following query:
 select TAB_ONE.NAME,TAB_TWO.CATEGORY 
 from TAB_ONE, TAB_TWO 
 where TAB_ONE.TAB_TWO_ID = TAB_TWO.TAB_TWO_ID
 
 I expect the following:
 row1, cat1
 row2, cat2
 
 I get the following:
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 553, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 553, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 553, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 554, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 554, GEN1 line 1.
 Use of uninitialized value in string eq at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 556, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 560, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 560, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 560, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 562, GEN1 line 1.
 Use of uninitialized value in concatenation (.) or string at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 562, GEN1 line 1.
 Use of uninitialized value in array element at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 891, GEN0 line 3.
 Use of uninitialized value in array element at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 891, GEN0 line 3.
 Use of uninitialized value in array slice at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
 Use of uninitialized value in array slice at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
 Use of uninitialized value in array slice at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
 Use of uninitialized value in array slice at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
 Use of uninitialized value in array slice at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
 Use of uninitialized value in array slice at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
 Use of uninitialized value in array slice at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
 Use of uninitialized value in array slice at
 /usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
 1, 1
 1, 1
 2, 2
 2, 2
 
 platform:
 OS: Linux 2.6.8-1-686 #1 Thu Nov 25 04:34:30 UTC 2004 GNU/Linux
 Perl: This is perl, v5.8.4 built for i386-linux-thread-mult
 DBD::CSV: 0.21
 SQL::Statement: 1.09
 
 here is the script
 --- snip ---
 #! /usr/bin/perl -w
 
 use DBI;
 
 $dbh = DBI-connect(DBI:CSV:f_dir='.',
{'select' = {'join' = 1}})
 or die Cannot connect:  . $DBI::errstr;
 
 $dbh-{'csv_tables'}-{'TAB_ONE'} = { 'file' = 'tab1.csv'};
 $dbh-{'csv_tables'}-{'TAB_TWO'} = { 'file' = 'tab2.csv'};
 $dbh-{'csv_eol'} = \n;
 
 my $sth = $dbh-prepare(select TAB_ONE.NAME,TAB_TWO.CATEGORY
 from TAB_ONE, TAB_TWO
 where TAB_ONE.TAB_TWO_ID =
 TAB_TWO.TAB_TWO_ID);
 $sth-execute();
 while ( @row = $sth-fetchrow_array ) {
 $row[length @row] = '' if(! defined $row[length @row]);
 print join(', ', @row), \n;
 }
 $sth-finish();
 $dbh-disconnect();
 
 --- snip ---
 
 Can anyone help me.




New in DBI

2005-01-13 Thread Hernan Arredondo
Hi all, I'm new in DBI and I'm really stuck, some can explain me this code:

use DBI;

my $dbh = DBI-connect( 'dbi:Oracle:db',
   '$username',
   '$passwd',
 ) or die $DBI::errstr;
EOF

its supposed I get a connection with that ?

'dbi:Oracle:db' - this is the driver and the database associated,
where I can config the host where the Oracle DB resides ?

Please excuse if my question is stupid but I search in the docs and
nothing about this is explained

Hernan Dario A.

-- 
No matter how fast processors get,
software consistently finds new ways to eat up the extra speed


RE: New in DBI

2005-01-13 Thread Reidy, Ron
Please read the DBD::Oracle docs 
http://search.cpan.org/~timb/DBD-Oracle-1.16/Oracle.pm

-
Ron Reidy
Lead DBA
Array BioPharma, Inc.


-Original Message-
From: Hernan Arredondo [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 13, 2005 12:11 PM
To: dbi-users@perl.org
Subject: New in DBI


Hi all, I'm new in DBI and I'm really stuck, some can explain me this code:

use DBI;

my $dbh = DBI-connect( 'dbi:Oracle:db',
   '$username',
   '$passwd',
 ) or die $DBI::errstr;
EOF

its supposed I get a connection with that ?

'dbi:Oracle:db' - this is the driver and the database associated,
where I can config the host where the Oracle DB resides ?

Please excuse if my question is stupid but I search in the docs and
nothing about this is explained

Hernan Dario A.

-- 
No matter how fast processors get,
software consistently finds new ways to eat up the extra speed

This electronic message transmission is a PRIVATE communication which contains
information which may be confidential or privileged. The information is 
intended 
to be for the use of the individual or entity named above. If you are not the 
intended recipient, please be aware that any disclosure, copying, distribution 
or use of the contents of this information is prohibited. Please notify the
sender  of the delivery error by replying to this message, or notify us by
telephone (877-633-2436, ext. 0), and then delete it from your system.



RE: New in DBI

2005-01-13 Thread Vergara, Michael \(TEM\)
Hernan:

In your string 'dbi:Oracle:db', the characters 'db' need
to be replaced with your Oracle SID.  For example, if
your database's SID is 'TEST' (e.g.: you connect to the
database with sqlplus system/[EMAIL PROTECTED]), then
your code should read 'dbi:Oracle:TEST'.

HTH,
Mike


-Original Message-
From: Hernan Arredondo [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 13, 2005 11:11 AM
To: dbi-users@perl.org
Subject: New in DBI


Hi all, I'm new in DBI and I'm really stuck, some can explain me this code:

use DBI;

my $dbh = DBI-connect( 'dbi:Oracle:db',
   '$username',
   '$passwd',
 ) or die $DBI::errstr;
EOF

its supposed I get a connection with that ?

'dbi:Oracle:db' - this is the driver and the database associated,
where I can config the host where the Oracle DB resides ?

Please excuse if my question is stupid but I search in the docs and
nothing about this is explained

Hernan Dario A.

-- 
No matter how fast processors get,
software consistently finds new ways to eat up the extra speed


Re: New in DBI

2005-01-13 Thread Hernan Arredondo
Great, was a stupid question thanks...


On Thu, 13 Jan 2005 11:20:04 -0800, Vergara, Michael (TEM)
[EMAIL PROTECTED] wrote:
 Hernan:
 
 In your string 'dbi:Oracle:db', the characters 'db' need
 to be replaced with your Oracle SID.  For example, if
 your database's SID is 'TEST' (e.g.: you connect to the
 database with sqlplus system/[EMAIL PROTECTED]), then
 your code should read 'dbi:Oracle:TEST'.
 
 HTH,
 Mike
 
 
 -Original Message-
 From: Hernan Arredondo [mailto:[EMAIL PROTECTED]
 Sent: Thursday, January 13, 2005 11:11 AM
 To: dbi-users@perl.org
 Subject: New in DBI
 
 Hi all, I'm new in DBI and I'm really stuck, some can explain me this code:
 
 use DBI;
 
 my $dbh = DBI-connect( 'dbi:Oracle:db',
   '$username',
   '$passwd',
 ) or die $DBI::errstr;
 EOF
 
 its supposed I get a connection with that ?
 
 'dbi:Oracle:db' - this is the driver and the database associated,
 where I can config the host where the Oracle DB resides ?
 
 Please excuse if my question is stupid but I search in the docs and
 nothing about this is explained
 
 Hernan Dario A.
 
 --
 No matter how fast processors get,
 software consistently finds new ways to eat up the extra speed
 


-- 
No matter how fast processors get,
software consistently finds new ways to eat up the extra speed


RE: New in DBI

2005-01-13 Thread Ronald J Kimball


Hernan Arredondo [mailto:[EMAIL PROTECTED] wrote:
 
 Hi all, I'm new in DBI and I'm really stuck, some can explain me this
 code:
 
 use DBI;
 
 my $dbh = DBI-connect( 'dbi:Oracle:db',
'$username',
'$passwd',
  ) or die $DBI::errstr;
 EOF
 

Aside from the SID issue, you have single quotes around $username and
$passwd, which means you are passing those literal strings as the username
and password, rather than the contents of the variables.  You don't need
quotes at all around individual variables:

my $dbh = DBI-connect( 'dbi:Oracle:db',
$username,
$passwd,
  ) or die $DBI::errstr;

(with the correct SID still needing to be inserted)


Ronald




DBD::CSV and joins

2005-01-13 Thread Jeff Benton
Sorry if I posted this twice - I did not see my first post go through.

I am trying to do a join across to csv files but have been unsuccessful
up to this point.

I have two tables:
tab1.csv
TAB_ONE_ID,NAME,TAB_TWO_ID
1,row1,100
2,row2,200

tab2.csv
TAB_TWO_ID,CATEGORY
100,cat1
200,cat2

I am running the following query:
select TAB_ONE.NAME,TAB_TWO.CATEGORY 
from TAB_ONE, TAB_TWO 
where TAB_ONE.TAB_TWO_ID = TAB_TWO.TAB_TWO_ID

I expect the following:
row1, cat1
row2, cat2

I get the following:
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 553, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 553, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 553, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 554, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 554, GEN1 line 1.
Use of uninitialized value in string eq at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 556, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 560, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 560, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 560, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 562, GEN1 line 1.
Use of uninitialized value in concatenation (.) or string at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 562, GEN1 line 1.
Use of uninitialized value in array element at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 891, GEN0 line 3.
Use of uninitialized value in array element at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 891, GEN0 line 3.
Use of uninitialized value in array slice at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
Use of uninitialized value in array slice at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
Use of uninitialized value in array slice at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
Use of uninitialized value in array slice at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
Use of uninitialized value in array slice at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
Use of uninitialized value in array slice at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
Use of uninitialized value in array slice at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
Use of uninitialized value in array slice at
/usr/local/share/perl/5.8.4/SQL/Statement.pm line 898, GEN0 line 3.
1, 1
1, 1
2, 2
2, 2

platform:
OS: Linux 2.6.8-1-686 #1 Thu Nov 25 04:34:30 UTC 2004 GNU/Linux
Perl: This is perl, v5.8.4 built for i386-linux-thread-mult
DBD::CSV: 0.21
SQL::Statement: 1.09

here is the script
--- snip ---
#! /usr/bin/perl -w

use DBI;

$dbh = DBI-connect(DBI:CSV:f_dir='.',
   {'select' = {'join' = 1}})
or die Cannot connect:  . $DBI::errstr;

$dbh-{'csv_tables'}-{'TAB_ONE'} = { 'file' = 'tab1.csv'};
$dbh-{'csv_tables'}-{'TAB_TWO'} = { 'file' = 'tab2.csv'};
$dbh-{'csv_eol'} = \n;

my $sth = $dbh-prepare(select TAB_ONE.NAME,TAB_TWO.CATEGORY
from TAB_ONE, TAB_TWO
where TAB_ONE.TAB_TWO_ID =
TAB_TWO.TAB_TWO_ID);
$sth-execute();
while ( @row = $sth-fetchrow_array ) {
$row[length @row] = '' if(! defined $row[length @row]);
print join(', ', @row), \n;
}
$sth-finish();
$dbh-disconnect();

--- snip ---

Can anyone help me.




RE: Which ORACLE_HOME was used to build DBD?

2005-01-13 Thread Andy Hassall
[EMAIL PROTECTED] Oracle]# pwd
/usr/lib/perl5/site_perl/5.8.6/i686-linux/auto/DBD/Oracle
[EMAIL PROTECTED] Oracle]# head mk.pm 
$dbd_oracle_mm_opts = {
'NAME' = 'DBD::Oracle',
'INC' = '-I/u01/app/oracle/10.1/rdbms/demo
-I/u01/app/oracle/10.1/rdbms/public -I/u01/app/oracle/10.1/plsql/public
-I/u01/app/oracle/10.1/network/public -I/u01/app/oracle/10.1/rdbms/demo
-I/u01/app/oracle/10.1/plsql/public -I/u01/app/oracle/10.1/rdbms/public
-I/usr/lib/perl5/site_perl/5.8.6/i686-linux/auto/DBI/',
'AUTHOR' = 'Tim Bunce (dbi-users@perl.org)',

-- 
Andy Hassall [EMAIL PROTECTED] / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space 

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
 Sent: 12 January 2005 11:39
 To: dbi-users@perl.org
 Subject: Which ORACLE_HOME was used to build DBD?
 
 Hi All,
 
 I have a Redhat box with 2 ORACLE_HOMEs.  DBI and DBD_Oracle 
 have both 
 been installed.
 
 How can I tell which ORACLE_HOME was used to build the DBD?
 
 Cheers
 Tony