dbi

How can I select multiple rows using parameters from an array in Perl's DBI module?

安稳与你 提交于 2019-12-14 03:21:58
问题 I am required to pull out rows corresponding to column name . The rows being pulled out correspond to address in array @values . Following is my code: use strict; use DBI; open (FH, "/user/address") or die $!; my@values=<FH>; close(FH); my @names; my $query = "Select name from table where address = ?"; my $sth = $dbh->prepare( $query ) or die "could not prepare statement\n", $dbh->errstr; foreach my $value(@values){ #@values contain list of address $sth->execute($value) or die "could not

Can't locate object method via package subclassing DBI

这一生的挚爱 提交于 2019-12-13 14:56:23
问题 this is my first foray into subclassing with perl and I am wondering why I am getting this simple error... "Can't locate object method "prepare" via package "WebDB::st" at /home/dblibs/WebDB.pm line 19.". It seems to find the module WebDB ok, but not the prepare subroutine in ::st First here's my package (both packages are in one file, WebDB.pm) package WebDB; use strict; use DBI; sub connect { my $dbh = (DBI->connect ("DBI:mysql:test:127.0.0.1", "root","", { PrintError => 1, RaiseError => 0

How can I get a row count in DBI without running two separate calls to process?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 12:54:50
问题 I'm running DBI in Perl and can't figure out how, when I run a prepared statement, I can figure out if the returned row count is 0. I realize I can set a counter inside my while loop where I fetch my rows, but I was hoping there was a less ugly way to do it. 回答1: In order to find out how many rows are in a result set you have exactly two options: select count(*) Iterate over the result set and count the rows. You can introduce some magic via a stored procedure that returns an array or

Perl module, inhereting from DBI , “Can't call method 'prepare'” error [duplicate]

主宰稳场 提交于 2019-12-13 09:33:38
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Perl + POO and “Can't call method ”prepare" I learned poo and i got to play with perl, create this module but when I call the segudno method I skip the following error 'Use of uninitialized value $database in concatenation ( .) ... ' Followed by 'Can't call method 'prepare' mm i don't really understand, any suggestions? #!/usr/bin/perl use warnings; use strict; use DBI; use DBD::mysql; package MysqlTest; sub

Update in Perl DBI not working, why? (full source posting, including DDL to create database in MySQL)

你。 提交于 2019-12-13 03:53:45
问题 Why is the UPDATE in "Example 2" not working? # MySQL DDL to create database used by code # # CREATE DATABASE sampledb; # # USE sampledb; # # CREATE TABLE `dbtable` ( # `id` int(11) NOT NULL AUTO_INCREMENT, # `demo` longtext, # PRIMARY KEY (`id`) # ) ENGINE=InnoDB DEFAULT CHARSET=utf8; # PERL MODULES WE WILL BE USING use strict; use warnings; use DBI; # CONFIG VARIABLES my $platform = "mysql"; my $database = "sampledb"; my $host = "localhost"; my $port = "3306"; my $username = "root"; my

How to get SQL database connection compatible with DBI::dbGetQuery function when converting between R script and databricks R notebook?

爷,独闯天下 提交于 2019-12-13 03:48:38
问题 I have an R script that uses odbc::dbConnect to connect to an SQL database (some databases are Azure, some are on-premise but connected to the Azure VPNs via the company's network, though I don't have any understanding of the network infrastructure itself) and then uses DBI::dbGetQuery to run a series of fairly complicated SQL queries and store the results as R dataframes which can be manipulated and fed into my models. Because of insufficient memory on my local PC to run the script, I am

Is it possible to execute multiple statements in a single query using DBD::Oracle?

不打扰是莪最后的温柔 提交于 2019-12-12 20:23:10
问题 I'd like to know if it's possible to execute more than one SQL statement within a single execute() or do() call using DBD::Oracle via Perl DBI. Example: # Multiple SQL statements in a single query, separated by a ";" $sql = 'UPDATE foo SET bar = 123; DELETE FROM foo WHERE baz = 456'; $sth = $dbh->prepare($sql); $sth->execute; # ...or... $dbh->do($sql); I ask this not because I want to actually do such a thing, but rather because I want to gauge the damage possible through a successful SQL

Why doesn't joining multiple MySQL queries with semicolons work with Perl DBI?

♀尐吖头ヾ 提交于 2019-12-12 16:00:11
问题 I would like to insert values into two separate MySQL tables using DBI. I tried to combine two working INSERT queries into one by inserting a ; between them: $dbh->do(q{ INSERT INTO `testA`(test) values('testvalue111'); INSERT INTO `testB`(test) values('testvalue222'); }); But I always get an error: Syntactic error in "INSERT INTO `testB`(test) values('testvalue222 ..." If I separate the queries into two separate do calls, it works. But the combined query works fine in phpMyAdmin. Why does it

perl, dbi with sql statement with a like condition

梦想的初衷 提交于 2019-12-12 13:15:27
问题 in my code i must do a simple sql query with a like condition. i've do in this way my $out = "/Users/zero/out.log"; my $filename = "/Users/zero/data.txt"; my $dbh = DBI->connect("DBI:Oracle:sid=$sid;host=$host;port=$port", $user, $pwd) or die "Couldn't connect to database: " . DBI->errstr; my $query = "select SOMETHING from SOMETHING_1 where SOMETHING like ?||'%' "; my $sth = $dbh->prepare($query) or die "Connection Error: " . $dbh->errstr; open (IN,"< $filename") or die("Unable to open

How do I insert null fields with Perl's DBD::Pg?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 10:48:46
问题 I have a Perl script inserting data into Postgres according to a pipe delimited text file. Sometimes, a field is null (as expected). However, Perl makes this field into an empty string and the Postgres insert statement fails. Here's a snippet of code: use DBI; #Connect to the database. $dbh=DBI->connect('dbi:Pg:dbname=mydb','mydb','mydb',{AutoCommit=>1,RaiseError=>1,PrintError=>1}); #Prepare an insert. $sth=$dbh->prepare("INSERT INTO mytable (field0,field1) SELECT ?,?"); while (<>){ #Remove