Sponsored Content
Top Forums Shell Programming and Scripting Access to database/eval command Post 302202979 by chriss_58 on Friday 6th of June 2008 08:01:24 AM
Old 06-06-2008
Access to database/eval command

Hi

i have the following code:
if(($line!=1) and (@field[0]!='\$')){
print ( "\nTRY TO CONNECT TO DATABASE................\n");

my $dbh = DBI->connect($dsn, $user, $pass);
print ("CONNECTED TO DATABASE\n");

eval
{
print("PERFORM THE SELECT COMMAND\n");
#my $sql = qq{ SELECT * FROM cc_test_cases};
my $sql= qq{select test_case_id, test_case_category, service_desc from cc_test_cases where sncode=$sncode AND zncode=$zncode AND zpcode
=$zpcode};

my $sth = $dbh->prepare( $sql );
$sth->execute( );
};

if ($@) {
print "An error occurred ($@), continuing\n";
next;
}




while(@row = $sth->fetchrow_array()) {
print("MATCH FOUND!\n");
print "$row[0]: $row[1]: $row[2]\n";
push (@field, $row[0].$row[1]);
push (@field,$row[2].'$');
..................................
................................

My rpoblem is that when i am tryying to run this code i get the following error:

Can't call method "fetchrow_array" without a package or object reference at program line 186, <MYFILE> line 3


If i remove the eval command the program works fine.
Any idea why this happens??

Thank you.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Database access

Hi, I tried to run this code but it isnt giving me any output or errors. My aim is to retrieve the row based on the flag name(this is the primary key). flag_test is my table This is how i ran it: perl read_db.pl flag1 flag1 is the criteria in where clause -------- this is my... (2 Replies)
Discussion started by: mercuryshipzz
2 Replies

2. Shell Programming and Scripting

problem trying to access a database

hi guys, I am using the following code in order to access a database. #!/usr/bin/perl print "READ DATA FROM DATABASE\n"; use DBI; use strict; #use DBD::Oracle; my $user='reassure'; my $pass='R3Assur3'; #my $dsn="dbi:Oracle:orcl"; my $dsn='dbi:Oracle:cobscs.world'; my $dbh =... (1 Reply)
Discussion started by: chriss_58
1 Replies

3. Shell Programming and Scripting

Database access

Hell all, I have the following snippet of code: $sql=qq{select * from ( select to_char(t.start_time_timestamp,'yyyy/mm/dd hh24:mi:ss') start_time,t.s_p_number_address, null cos_icsa_code, null cos_icsa_subcode from cc_unrated_msc_flow t union select... (2 Replies)
Discussion started by: chriss_58
2 Replies

4. Shell Programming and Scripting

Eval command help

I have file called myfile which has the text "myserver" in it. I need to have a command to ping "myserver". How would I do that? I tried when I type at the terminal I get the output as . How do I do something like a ? thanks, Nick (5 Replies)
Discussion started by: nikhilfake
5 Replies

5. UNIX for Dummies Questions & Answers

Access to a database

Hello all, is it possible to write a script in order to connect to a database, load data in a specific domain and execute the corresponding command? (3 Replies)
Discussion started by: FelipeAd
3 Replies

6. Shell Programming and Scripting

Strange result of eval, how does eval really work with ssh?

Hi all, some small script with eval turned me to crazy. my OS is linux Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux below script works well #!/bin/bash eval ssh remotehost date eval ssh remotehost ls below... (1 Reply)
Discussion started by: summer_cherry
1 Replies

7. Shell Programming and Scripting

Help with perl eval command .....

Hi All, I read the above written code (perl code) in another perl script and evaluates this code for each line of text file,but using exit statement in code make this not to work and i could not get the desired results. However if i use return it works fine. I just need to know why it doesn't... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (1 Reply)
Discussion started by: vivek d r
1 Replies

9. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (13 Replies)
Discussion started by: vivek d r
13 Replies

10. Shell Programming and Scripting

Usage of '-' in eval command.

Hi, I am trying to use eval command to evaluate a variable(HAPROXY_LISTENER_rabbitmq_project-test-BRHM_PORT) which consists of '-' but unfortunately the eval command is unable to interpret the value of variable and trims the variable name after '-' and produces the string output rather than the... (10 Replies)
Discussion started by: Kuldip
10 Replies
DBD::Proxy(3)						User Contributed Perl Documentation					     DBD::Proxy(3)

NAME
DBD::Proxy - A proxy driver for the DBI SYNOPSIS
use DBI; $dbh = DBI->connect("dbi:Proxy:hostname=$host;port=$port;dsn=$db", $user, $passwd); # See the DBI module documentation for full details DESCRIPTION
DBD::Proxy is a Perl module for connecting to a database via a remote DBI driver. See DBD::Gofer for an alternative with different trade- offs. This is of course not needed for DBI drivers which already support connecting to a remote database, but there are engines which don't offer network connectivity. Another application is offering database access through a firewall, as the driver offers query based restrictions. For example you can restrict queries to exactly those that are used in a given CGI application. Speaking of CGI, another application is (or rather, will be) to reduce the database connect/disconnect overhead from CGI scripts by using proxying the connect_cached method. The proxy server will hold the database connections open in a cache. The CGI script then trades the database connect/disconnect overhead for the DBD::Proxy connect/disconnect overhead which is typically much less. Note that the connect_cached method is new and still experimental. CONNECTING TO THE DATABASE
Before connecting to a remote database, you must ensure, that a Proxy server is running on the remote machine. There's no default port, so you have to ask your system administrator for the port number. See DBI::ProxyServer for details. Say, your Proxy server is running on machine "alpha", port 3334, and you'd like to connect to an ODBC database called "mydb" as user "joe" with password "hello". When using DBD::ODBC directly, you'd do a $dbh = DBI->connect("DBI:ODBC:mydb", "joe", "hello"); With DBD::Proxy this becomes $dsn = "DBI:Proxy:hostname=alpha;port=3334;dsn=DBI:ODBC:mydb"; $dbh = DBI->connect($dsn, "joe", "hello"); You see, this is mainly the same. The DBD::Proxy module will create a connection to the Proxy server on "alpha" which in turn will connect to the ODBC database. Refer to the DBI documentation on the "connect" method for a way to automatically use DBD::Proxy without having to change your code. DBD::Proxy's DSN string has the format $dsn = "DBI:Proxy:key1=val1; ... ;keyN=valN;dsn=valDSN"; In other words, it is a collection of key/value pairs. The following keys are recognized: hostname port Hostname and port of the Proxy server; these keys must be present, no defaults. Example: hostname=alpha;port=3334 dsn The value of this attribute will be used as a dsn name by the Proxy server. Thus it must have the format "DBI:driver:...", in particular it will contain colons. The dsn value may contain semicolons, hence this key *must* be the last and it's value will be the complete remaining part of the dsn. Example: dsn=DBI:ODBC:mydb cipher key usercipher userkey By using these fields you can enable encryption. If you set, for example, cipher=$class;key=$key (note the semicolon) then DBD::Proxy will create a new cipher object by executing $cipherRef = $class->new(pack("H*", $key)); and pass this object to the RPC::PlClient module when creating a client. See RPC::PlClient. Example: cipher=IDEA;key=97cd2375efa329aceef2098babdc9721 The usercipher/userkey attributes allow you to use two phase encryption: The cipher/key encryption will be used in the login and authorisation phase. Once the client is authorised, he will change to usercipher/userkey encryption. Thus the cipher/key pair is a host based secret, typically less secure than the usercipher/userkey secret and readable by anyone. The usercipher/userkey secret is your private secret. Of course encryption requires an appropriately configured server. See <DBD::ProxyServer/CONFIGURATION FILE>. debug Turn on debugging mode stderr This attribute will set the corresponding attribute of the RPC::PlClient object, thus logging will not use syslog(), but redirected to stderr. This is the default under Windows. stderr=1 logfile Similar to the stderr attribute, but output will be redirected to the given file. logfile=/dev/null RowCacheSize The DBD::Proxy driver supports this attribute (which is DBI standard, as of DBI 1.02). It's used to reduce network round-trips by fetching multiple rows in one go. The current default value is 20, but this may change. proxy_no_finish This attribute can be used to reduce network traffic: If the application is calling $sth->finish() then the proxy tells the server to finish the remote statement handle. Of course this slows down things quite a lot, but is perfectly good for reducing memory usage with persistent connections. However, if you set the proxy_no_finish attribute to a TRUE value, either in the database handle or in the statement handle, then finish() calls will be suppressed. This is what you want, for example, in small and fast CGI applications. proxy_quote This attribute can be used to reduce network traffic: By default calls to $dbh->quote() are passed to the remote driver. Of course this slows down things quite a lot, but is the safest default behaviour. However, if you set the proxy_quote attribute to the value '"local"' either in the database handle or in the statement handle, and the call to quote has only one parameter, then the local default DBI quote method will be used (which will be faster but may be wrong). KNOWN ISSUES
Unproxied method calls If a method isn't being proxied, try declaring a stub sub in the appropriate package (DBD::Proxy::db for a dbh method, and DBD::Proxy::st for an sth method). For example: sub DBD::Proxy::db::selectall_arrayref; That will enable selectall_arrayref to be proxied. Currently many methods aren't explicitly proxied and so you get the DBI's default methods executed on the client. Some of those methods, like selectall_arrayref, may then call other methods that are proxied (selectall_arrayref calls fetchall_arrayref which calls fetch which is proxied). So things may appear to work but operate more slowly than the could. This may all change in a later version. Complex handle attributes Sometimes handles are having complex attributes like hash refs or array refs and not simple strings or integers. For example, with DBD::CSV, you would like to write something like $dbh->{"csv_tables"}->{"passwd"} = { "sep_char" => ":", "eol" => " "; The above example would advice the CSV driver to assume the file "passwd" to be in the format of the /etc/passwd file: Colons as separators and a line feed without carriage return as line terminator. Surprisingly this example doesn't work with the proxy driver. To understand the reasons, you should consider the following: The Perl compiler is executing the above example in two steps: 1. The first step is fetching the value of the key "csv_tables" in the handle $dbh. The value returned is complex, a hash ref. 2. The second step is storing some value (the right hand side of the assignment) as the key "passwd" in the hash ref from step 1. This becomes a little bit clearer, if we rewrite the above code: $tables = $dbh->{"csv_tables"}; $tables->{"passwd"} = { "sep_char" => ":", "eol" => " "; While the examples work fine without the proxy, the fail due to a subtle difference in step 1: By DBI magic, the hash ref $dbh->{'csv_tables'} is returned from the server to the client. The client creates a local copy. This local copy is the result of step 1. In other words, step 2 modifies a local copy of the hash ref, but not the server's hash ref. The workaround is storing the modified local copy back to the server: $tables = $dbh->{"csv_tables"}; $tables->{"passwd"} = { "sep_char" => ":", "eol" => " "; $dbh->{"csv_tables"} = $tables; AUTHOR AND COPYRIGHT
This module is Copyright (c) 1997, 1998 Jochen Wiedmann Am Eisteich 9 72555 Metzingen Germany Email: joe@ispsoft.de Phone: +49 7123 14887 The DBD::Proxy module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. In particular permission is granted to Tim Bunce for distributing this as a part of the DBI. SEE ALSO
DBI, RPC::PlClient, Storable perl v5.18.2 2013-06-24 DBD::Proxy(3)
All times are GMT -4. The time now is 04:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy