Sponsored Content
Top Forums Shell Programming and Scripting perl DBI: populate a scalar from a select statement Post 302372305 by SFNYC on Tuesday 17th of November 2009 03:28:40 PM
Old 11-17-2009
Try this:
Code:
my $force;

my $dbh = DBI->connect("DBI:mysql:myDB","username","password",) or die $DBI::errstr;

my $sth = $dbh->prepare("SELECT forcewrite FROM table WHERE primac = '$primac") || die "Error parsing SQL: $DBI::errstr\n";

$sth->execute() || die "Error executing SQL: $DBI::errstr\n";

$sth->bind_col(1, \$force  ) || die "Error binding variable: $DBI::errstr\n";

while ( $sth->fetch ) {
    print "force = $force\n";
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PERL DBI module install

We ran into an issue trying to install DBI and DB2 modules for perl for AIX from the link http://www-306.ibm.com/software/data/db2/perl/ We tried to install the DBI module using bash# perl -MCPAN -e 'install DBI' command. However we ended up with the following error. Stop. ... (3 Replies)
Discussion started by: jerardfjay
3 Replies

2. Shell Programming and Scripting

perl scalar variable in backquoted string

hi I've been searching all over the internet to simply do the following: $tempfile = "/usr/school/tempfile.dat"; $myvar = param('add'); ###add is the variable assigned to a popup menu `ls -l $myvar * >> $tempfile` ###I also tried `ls -l ${myvar}* >>$tempfile` open(ADDLIST,... (6 Replies)
Discussion started by: mehdi9
6 Replies

3. Shell Programming and Scripting

scalar variable assignment in perl + { operator

When reading over some perl code in a software document, I came across an assignment statement like this $PATH = ${PROJECT}/......./.... In this particular form of scalar variable assignment, what does the curly braces operators do ? Also, what is the benefit in doing scalar assignment this... (3 Replies)
Discussion started by: JamesGoh
3 Replies

4. Programming

perl dbi to oracle getting disconnect_all for oracle dbi help

hi i am trying to connect to an oracle database using dbi and i get this :: Driver has not implemented the disconnect_all method. at /opt/perl/lib/site_perl/5.8.0/sun4-solaris/DBI.pm line 575 END failed--call queue aborted. for all i know, the script was working earlier, but has... (1 Reply)
Discussion started by: poggendroff
1 Replies

5. Shell Programming and Scripting

Installing Perl DBI and DBD

Hi, i have some queries on installing the Perl DBI and the DBD Oracle. I know that i have to install the DBI first. I have the source files in a folder in my home directory.The commands to install arecd /home/DBI Perl Makefile.PL make make installI would like to know, after executing these... (4 Replies)
Discussion started by: new2ss
4 Replies

6. Shell Programming and Scripting

populate PERL Hash

Hello I am new to perl and learning ...can you please explain why am i getting this error...as myHash is defined right above the code and I think it should be avilable in the sub function. Here is my code: <code> #!/usr/bin/perl use warnings; use strict; %myHash=(); sub... (2 Replies)
Discussion started by: uandme2k2
2 Replies

7. Shell Programming and Scripting

connect to MySQL from Perl using DBI

Hi, I want to connect perl with the mysql to select and so on but the connection don't work code #!/usr/bin/perl BEGIN { # PERL MODULES WE WILL BE USING use DBI; $dbh = DBI->connect('DBI:mysql:C:\Program Files\MySQL\MySQL Server 5.0\data\db1','','pass') or die $DBI::errstr;} #... (1 Reply)
Discussion started by: eng_shimaa
1 Replies

8. Shell Programming and Scripting

perl: help with DBI

Hi there, I have a bit of code similar to below (which ive actually got from perldoc, but mine is similar enough) $sth = $dbh->prepare(q{ SELECT region, sales FROM sales_by_region }); $sth->execute; my ($region, $sales); # Bind Perl variables to columns: $rv =... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

9. Shell Programming and Scripting

Perl DBI error

Hi All, I installed DBI module in a non INC location and using it in my script via "use lib". But it throw the below error at the "use DBI" step. Please help Usage: DBI::_install_method(dbi_class, meth_name, file, attribs=Nullsv) at /xx/xxx/xxxxx/xxxxx/oracle/lib/DBI.pm/oracle/lib/DBI.pm line... (2 Replies)
Discussion started by: prasperl
2 Replies

10. Shell Programming and Scripting

Perl : converting file to different scalar elements

I have a text file containing 2 exec statements as below and trying to store the below 2 execs into 2 different scalar variables in perl. /* ICD Dist, Total */ /* need to export to Excel, sheet=ICD_Dist__Total */ exec( 'select sum(count(*)) cast(count(*)*100.0/sum(count(*)) over() as... (7 Replies)
Discussion started by: scriptscript
7 Replies
DBD::File(3)						User Contributed Perl Documentation					      DBD::File(3)

NAME
DBD::File - Base class for writing DBI drivers SYNOPSIS
This module is a base class for writing other DBDs. It is not intended to function as a DBD itself. If you want to access flatfiles, use DBD::AnyData, or DBD::CSV, (both of which are subclasses of DBD::File). DESCRIPTION
The DBD::File module is not a true DBI driver, but an abstract base class for deriving concrete DBI drivers from it. The implication is, that these drivers work with plain files, for example CSV files or INI files. The module is based on the SQL::Statement module, a simple SQL engine. See DBI for details on DBI, SQL::Statement for details on SQL::Statement and DBD::CSV or DBD::IniFile for example drivers. Metadata The following attributes are handled by DBI itself and not by DBD::File, thus they all work like expected: Active ActiveKids CachedKids CompatMode (Not used) InactiveDestroy Kids PrintError RaiseError Warn (Not used) The following DBI attributes are handled by DBD::File: AutoCommit Always on ChopBlanks Works NUM_OF_FIELDS Valid after "$sth-"execute> NUM_OF_PARAMS Valid after "$sth-"prepare> NAME Valid after "$sth-"execute>; undef for Non-Select statements. NULLABLE Not really working, always returns an array ref of one's, as DBD::CSV doesn't verify input data. Valid after "$sth-"execute>; undef for Non-Select statements. These attributes and methods are not supported: bind_param_inout CursorName LongReadLen LongTruncOk Additional to the DBI attributes, you can use the following dbh attribute: f_dir This attribute is used for setting the directory where CSV files are opened. Usually you set it in the dbh, it defaults to the current directory ("."). However, it is overwritable in the statement handles. f_ext This attribute is used for setting the file extension where (CSV) files are opened. There are several possibilities. DBI:CSV:f_dir=data;f_ext=.csv In this case, DBD::File will open only "table.csv" if both "table.csv" and "table" exist in the datadir. The table will still be named "table". If your datadir has files with extensions, and you do not pass this attribute, your table is named "table.csv", which is probably not what you wanted. The extension is always case-insensitive. The table names are not. DBI:CSV:f_dir=data;f_ext=.csv/r In this case the extension is required, and all filenames that do not match are ignored. f_schema This will set the schema name. Default is the owner of the folder in which the table file resides. "undef" is allowed. my $dbh = DBI->connect ("dbi:CSV:", "", "", { f_schema => undef, f_dir => "data", f_ext => ".csv/r", }) or die $DBI::errstr; The effect is that when you get table names from DBI, you can force all tables into the same (or no) schema: my @tables $dbh->tables (); # no f_schema "merijn".foo "merijn".bar # f_schema => "dbi" "dbi".foo "dbi".bar # f_schema => undef foo bar Driver private methods data_sources The "data_sources" method returns a list of subdirectories of the current directory in the form "DBI:CSV:f_dir=$dirname". If you want to read the subdirectories of another directory, use my ($drh) = DBI->install_driver ("CSV"); my (@list) = $drh->data_sources (f_dir => "/usr/local/csv_data" ); list_tables This method returns a list of file names inside $dbh->{f_dir}. Example: my ($dbh) = DBI->connect ("DBI:CSV:f_dir=/usr/local/csv_data"); my (@list) = $dbh->func ("list_tables"); Note that the list includes all files contained in the directory, even those that have non-valid table names, from the view of SQL. KNOWN BUGS
o The module is using flock () internally. However, this function is not available on all platforms. Using flock () is disabled on MacOS and Windows 95: There's no locking at all (perhaps not so important on MacOS and Windows 95, as there's a single user anyways). AUTHOR
This module is currently maintained by H.Merijn Brand < h.m.brand at xs4all.nl > and Jens Rehsack < rehsack at googlemail.com > The original author is Jochen Wiedmann. COPYRIGHT AND LICENSE
Copyright (C) 2009 by H.Merijn Brand & Jens Rehsack Copyright (C) 2004 by Jeff Zucker Copyright (C) 1998 by Jochen Wiedmann All rights reserved. You may freely distribute and/or modify this module under the terms of either the GNU General Public License (GPL) or the Artistic License, as specified in the Perl README file. SEE ALSO
DBI, Text::CSV, Text::CSV_XS, SQL::Statement perl v5.12.1 2009-06-05 DBD::File(3)
All times are GMT -4. The time now is 05:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy