dbi

copying a very large table from one DB2 to another, using perl and DBI

大兔子大兔子 提交于 2019-12-10 20:36:04
问题 I need to copy, on a daily basis, a very large (millions of rows) table from one DB2 DB to another, and I need to use perl and DBI. Is there a faster way to do this than to simply fetchrow_array each row from the first DB and insert them one-by-one into the second DB? Here's what I got: $sth1 = $udb1 -> prepare($read_query); $sth1 -> execute(); $sth1 -> bind_columns(\(@row{@{$sth1 -> {NAME_1c}}})); $sth2 = $udb2 -> prepare($write_query); while ($sth1 -> fetchrow_arrayref) { $sth2 -> execute(

Find foreign key information using Perl/DBI/MySQL/InnoDB

早过忘川 提交于 2019-12-10 18:24:37
问题 I want to programmatically find the the foreign keys on a particular InnoDB table in my MySQL database. I'm using Perl, and I stumbled across $dbh->foreign_key_info . I've just tried using it but it seems a bit faulty. It doesn't return the ON DELETE, and ON UPDATE information, even though it implies it can. And it's also returning regular indexes. Thanks for any help. use strict; use warnings; use DBI; use Data::Dumper; my $dbh = DBI->connect("DBI:mysql:database=db;host=localhost", "user",

disk I/O error with SQLite

十年热恋 提交于 2019-12-10 17:23:39
问题 I have a (tiny) dynamic website that is (roughly) a Perl CGI script using a SQLite database. Package DBI is the abstraction layer used in Perl. About one week ago, I started to see this error message: disk I/O error(10) at dbdimp.c line 271 Since this is a hosted site running Apache, I cannot see if the hard disk is (nearly) full. Access to command "df" is disabled.... but I used the (UNIX) shell command "yes > blah" to test the disk can still create new files. My database is very tiny --

Does SELECT DISTINCT work with Perl's DBD::CSV?

爱⌒轻易说出口 提交于 2019-12-10 15:19:10
问题 I found a SELECT-example on the web. When I try it in my script I get this error-message: Specifying DISTINCT when using aggregate functions isn't reasonable - ignored. at /usr/lib/perl5/site_perl/5.10.0/SQL/Parser.pm line 496. #!/usr/bin/perl use warnings; use strict; use DBI; my $dbh = DBI->connect( "DBI:CSV:", undef, undef, { RaiseError => 1, AutoCommit => 1 } ); my $table = 'artikel'; my $array_ref = [ [ 'a_nr', 'a_name', 'a_preis' ], [ 12, 'Oberhemd', 39.80, ], [ 22, 'Mantel', 360.00, ],

How can I check if a database query will return results?

六眼飞鱼酱① 提交于 2019-12-10 14:15:26
问题 Our website uses Perl to provide a simple mechanism for our HR people to post vacancies to our website. It was developed by a third party, but they have been long since kicked into touch, and sadly we do not have any Perl skills in-house. This is what happens when Marketing people circumvent their in-house IT team! I need to make a simple change to this application. Currently, the vacancies page says 'We currently have the following vacancies:', regardless of whether there are any vacancies!

Perl Parallel::ForkManager with DBI database handlers

久未见 提交于 2019-12-10 13:27:03
问题 im interested in performing multiple database actions in parallel. I have played with Perl Parallel::ForkManager but not used it with any databases yet. I have read that database connectivity is not supported very well with this. Does anyone have experience with this? As an example i would probably be spawning a system call(which does the DBI work) NOT raw code, i.e. #!/opt/local/bin/perl -w use strict; use Parallel::ForkManager; $| = 1; my $max_procs = 10; my $pm = new Parallel::ForkManager(

Which one represents null? undef or empty string

☆樱花仙子☆ 提交于 2019-12-10 12:57:51
问题 I want to insert null in a column in a table. Which one represents null? undef or empty string '' . Which one should be used and Why? I know about defined and that I can check it. But I am looking more from perspective of database. Which one represents null more properly? Update: I am using DBI module. 回答1: DBI uses undef to represent a SQL NULL . The empty string represents an empty string. However, some databases don't make a distinction between NULL and the empty string. Oracle is a

How do I tell DBD::mysql where mysql.sock is?

被刻印的时光 ゝ 提交于 2019-12-10 03:11:17
问题 Using DBD::mysql with DBI, I am getting the following error when attempting to connect to the database. DBI connect('database=mydb:host=localhost','someuser',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at ./myscript.pl line 97 Yes MySQL is up and running. The problem is that mysql.sock is not in /tmp. I know the location of mysql.sock and I currently have it hacked so that it works, I created a soft link to the current location of the mysql.sock file.

How can I fetch a single count value from a database with DBI?

假如想象 提交于 2019-12-09 05:09:16
问题 The following code seems to be just too much, for getting a single count value. Is there a better, recommended way to fetch a single COUNT value using plain DBI? sub get_count { my $sth = $dbh->prepare("SELECT COUNT(*) FROM table WHERE..."); $sth->execute( @params ); my $($count) = $sth->fetchrow_array; $sth->finish; return $count; } This is shorter, but I still have two statements. sub get_count_2 { my $ar = $dbh->selectall_arrayref("SELECT ...", undef, @params) return $ar->[0][0]; } 回答1:

Perl warning: Use of uninitialized value in join or string

萝らか妹 提交于 2019-12-08 19:46:30
问题 I'm getting: "Use of uninitialized value in join or string at ./test_script.pl line 69, <fh> line 91." The code creating this warning is here: # Write results of SQL execution to output file if ($@) { print "\n DB Error : ", $@; exit; } open(FH, ">$output_file") or die "\n cannot write to the file $output_file. Check the file permissions"; while(my @row= $sth->fetchrow_array) { print FH join($delimiter, @row). "\n"; } It is coming from the "print ... join ...." line in the "while" block, but