dbi

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

青春壹個敷衍的年華 提交于 2019-11-28 03:16:30
问题 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

Perl DBI - run SQL Script with multiple statements

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 02:23:04
I have a sql file test.sql used to run some SQL (create object / update / delete / insert) that can look like this CREATE TABLE test_dbi1 ( test_dbi_intr_no NUMBER(15) , test_dbi_name VARCHAR2(100); UPDATE mytable SET col1=1; CREATE TABLE test_dbi2 ( test_dbi_intr_no NUMBER(15) , test_dbi_name VARCHAR2(100); Usually, i would just use SQLPLUS (from within Perl) to execute this test.sql using this command : @test.sql Is there a way to do the same thing, using DBI in Perl ? So far, i found DBI can only execute one statement at a time, and without the ";" at the end. The database controls how many

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

孤者浪人 提交于 2019-11-28 01:08:16
问题 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

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

妖精的绣舞 提交于 2019-11-27 16:44:55
问题 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; #

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

天涯浪子 提交于 2019-11-27 15:48:02
问题 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

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

心已入冬 提交于 2019-11-27 07:43:43
问题 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? 回答1: You should use placeholders and bind values. 回答2: 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