Results 1 to 2 of 2

Thread: To fetch the data from table after execution

  1. #1
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25

    To fetch the data from table after execution

    Hi all,

    I want to fetch the data existing table to be displayed in the web-page. I pass the parameter tablename to a function. I build the query and pass it to a function to execute. On execution, I want the resultset to be sent back to the invokation.

    How could I be able to achieve this objective?

    Thanks in advance.
    kkeyan

  2. #2
    Join Date
    Feb 2003
    Location
    Johannesburg, South Africa
    Posts
    145
    You want to do something like this:

    Code:
         1	#!/usr/bin/perl
         2	
         3	my $result = myfunct( "tablename" );
         4	
         5	print "result=$result\n";
         6	
         7	exit;
         8	
         9	sub myfunct {
        10	
        11		my $tablename;
        12		if ( $_[0] ) { 
        13		
        14			$tablename = $_[0];
        15			
        16		} else {
        17		
        18			return 0;
        19		
        20		}
        21		
        22		my $sql = "SELECT * FROM $tablename";
        23		
        24		if ( runscript( $sql ) ) {
        25		
        26			return 1;
        27		
        28		} else {
        29		
        30			return 0;
        31			
        32		}
        33	
        34	}
        35	
        36	sub runscript {
        37	
        38		# this is a dummy routine. Change the return value below by commenting
        39		# out the value you don't want:
        40		
        41		#return 1;
        42		return 0;
        43	
        44	}
    Initially we call the first function with just the table name ( line 3 ). In the first function, we create the SQL, and call the execution function ( lines 9 to 34 ). The SQL execution will ultimately return either a 1 or a 0 for success or failure ( there are various ways in which you can achieve this ). Based on this result, the result is first passed back to the original function that called the SQL script, which evaluates the return result. Finally, the first function returns again either a 1 for success, or a 0 for failure to the main program.

    You should be able to easily insert the SQL bits in this skeleton.

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •