dbi

How to Install DBD::Oracle in Strawberry Perl

蓝咒 提交于 2019-11-29 17:50:36
问题 I am trying to install DBD::Oracle using the CPAN shell in Strawberry Perl. I initially experienced an error because the Makefile could not locate an OCI library, so I installed the instant client from Oracle. I thought this would fix the problem, but now I get a large mixture of errors and warnings from Oracle.h , dbdimp.h , Oracle.c , Oracle.xsi , and Oracle.xs . Any suggestions for how I should proceed? Is it possible that there is a problem with existing Oracle software on my computer? I

How can I use a query with placeholder inside quotes? (perl / postgresql)

大憨熊 提交于 2019-11-29 14:15:45
I'm trying to execute the following script: #!/usr/bin/perl -w use strict; use DBI; my $db = "Pg"; my $db_database = "whatever"; my $user = "whatever"; my $password = "whatever"; my $dbh = DBI->connect("dbi:$db:dbname=$db_database", $user, $password); my $query = $dbh->prepare (q{SELECT arrival_date - INTERVAL '? MINUTE' FROM emails LIMIT 1}) or die ("unable to prepare"); $query->execute(60) or die("unable to execute"); print $query->fetchrow_array, "\n"; (arrival_date has this format: timestamp with time zone NOT NULL default CURRENT_TIMESTAMP) The problem is that the question mark

How do I connect to an MS Access database using Perl?

走远了吗. 提交于 2019-11-29 11:27:36
I have a .accdb file on my local machine and I am trying to connect to it and read some data from 3 tables within the DB. How do I establish the connection using Perl? So far I have scraped together this much for MS Access, but I am getting errors saying that I am not using the correct driver. Any ideas? my $msaccess_dbh = DBI->connect( 'dbi:ODBC:driver=microsoft access driver (*.accdb);' . 'dbq=C:\path\to\database\databasefile.accdb' ); Thanks! EDIT: Just to clarify, I have no real requirements here. I just need to do 2 or 3 selections from this MS Access DB, and then I will be done with it.

Why can't DBD::SQLite insert into a database through my Perl CGI script?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 09:33:07
I am running a SQLite database within a Perl CGI script which is being accessed by DBD::SQLite . This is being run as a straight CGI on Apache. The DBI connection works fine and selects are able to be run. However, when I attempt to do an insert I get a die with the following error: DBD::SQLite::st execute failed: unable to open database file(1) at dbdimp.c line 402 at index.cgi line 66 I have tried changing the database file permission to 666 to try to fix this however I am still receiving the error. Any advice? It looks like the directory needs write permission, the reason is: SQLite needs

Why does SQLite give a “database is locked” for a second query in a transaction when using Perl's DBD::SQLite?

余生颓废 提交于 2019-11-29 07:23:06
Is there a known problem with SQLite giving a "database is locked" error for a second query in a single transaction when using Perl DBD::SQLite? Scenario: Linux, Perl DBI, AutoCommit => 0, a subroutine with two code blocks (using the blocks to localize variable names). In the first code block a query handle is created by prepare() on a select statement, it is executed() and the block closed. The second code block another query handle is created by prepare for an update statement, and frequently (30% of the time) SQLite/DBI gives a database locked error at this stage. I think the error happens

How can I fetch the last row I inserted using DBI?

若如初见. 提交于 2019-11-29 05:25:11
How can I fetch the last row that was inserted using DBI ( DBD::mysql )? Code sample: my $sth = $dbh->prepare('INSERT INTO a ( x, y, z ) VALUES ( ?, ?, ? )'); $sth->execute( $x, $y, $z ); How can I get access to the data that was inserted by the above prepare statement? I need to get the primary ID ( AUTOINCREMENT ) value. UPDATE: From DBD::mysql documentation: An alternative way for accessing this attribute is via $dbh->{'mysql_insertid'} . Thank you Manni and n0rd for your answers. :-) This is a property of the statement handle. You should be able to access the ID like that: $sth->{mysql

Perl Module Method Calls: Can't call method “X” on an undefined value at ${SOMEFILE} line ${SOMELINE}

心不动则不痛 提交于 2019-11-29 02:29:02
All over the place, especially in DBI, I see this message come up all the time. It's confusing, because the first thing that comes to mind is that the arguments I'm passing the function are set to undef (or something similar), but it's clearly not the case. Given a module and a corresponding script... Module: ./lib/My/Module.pm package My::Module; use strict; use warnings; sub trim { my $str = shift; $str =~ s{ \A \s+ }{}xms; # remove space from front of string $str =~ s{ \s+ \z }{}xms; # remove space from end of string return $str; } Script: ./test.pl #!/usr/bin/perl use strict; use warnings;

How do I know how many rows a Perl DBI query returns?

泄露秘密 提交于 2019-11-29 01:21:55
I'm trying to basically do a search through the database with Perl to tell if there is an item with a certain ID. This search can return no rows, but it can also return one. I have the following code: my $th = $dbh->prepare(qq{SELECT bi_exim_id FROM bounce_info WHERE bi_exim_id = '$exid'}); $th->execute(); if ($th->fetch()->[0] != $exid) { ... Basically, this tries to see if the ID was returned and if it's not, continue with the script. But it is throwing a Null array reference error on the $th->fetch()->[0] thing. How can i just simply check to see if it returned rows or now? Paul Tomblin my

Dump prepared sql query from DBI statement in PERL

只谈情不闲聊 提交于 2019-11-29 00:10:55
im using DBI in Perl to connect to my PostgreSQL Database. Everything is working fine but in my debugging (printing results etc.) iam not able to see if the query prepared by perls DBI module is really correct. I have something like this: $sth->prepare( qq{SELECT * FROM company WHERE companyname LIKE ? AND city = ?}); $sth->execute( $name.'%', $city); Iam not able to see how the sql query looks after calling execute, as execute is the latest step where parameters are binded to the query. I would like to have something like $sth->getLastExecutedQuery() or something to see how the query looked

Is there an equivalent of PHP's mysql_real_escape_string() for Perl's DBI?

偶尔善良 提交于 2019-11-28 13:31:48
Could some tell me if there is a function which works the same as PHP's mysql_real_escape_string() for Perl from the DBI module? You should use placeholders and bind values . Don't. Escape. SQL. Don't. Quote. SQL. Use SQL placeholders/parameters ( ? ). The structure of the SQL statement and the data values represented by the placeholders are sent to the database completely separately, so (barring a bug in the database engine or the DBD module) there is absolutely no way that the data values can be interpreted as SQL commands. my $name = "Robert'); DROP TABLE Students; --"; my $sth = $dbh-