Hello,
I’m using Perl script where executing SQL query which connecting to SQL loader to insert my data into table. When the script runs the success status returns, but the loader doesn’t load anything to DB, I want to get the Perl return value to compare it.
Here is the example:

my $sql_command = here executing the load process

After this how can I get the $sql_command return value?

Thanks in advance.
Regards

I don't know about SQL loader but have you tried the usual way of assigning the result of Perl commands? For example if I wanted to show the result of executing the print command I would do this:

my $result = print "hello world\n";
print $result;

which shows that the print command returns a value of 1 when it prints successfully.

As I say, I don't have MySQL or SQL loader installed yet so I may be misunderstanding your question.

I don't know about SQL loader but have you tried the usual way of assigning the result of Perl commands?
For example if I wanted to show the result of executing the print command I would do this:

my $result = print "hello world\n";
            print $result;

which shows that the print command returns a value of 1 when it prints successfully.

As I say, I don't have MySQL or SQL loader installed yet so I may be misunderstanding your question.

Hello, thanks for your answer, but I don’t want to get the result, I need to get the return value. For example, when you executing some function, it should be return some value of that execution, the return value must be 0 or -1 etc…
regards

This depends on how you implement the DBI connection (assuming you're using DBI to access the database). The function that you call must return the appropriate value or return an object reference from which you can get the value. When I wish to have the results, I usually return an ARRAY of HASH references with the rows:

my $f=&function("sql");
for (@$f){
   print "$_->{column}\n";
}

However, if you wish to return the status code, you can do that as well. Where is the code that implements the loader and what does it return? If it returns a handle to an object, you can use that handle to run a function that returns the status code.

I would need more information about the function before I could tell you for sure.


Look at the DBI interface to see what the options are as far as status codes and errors:
http://search.cpan.org/~timb/DBI/DBI.pm

Hello, thanks for your answer, but I don’t want to get the result, I need to get the return value. For example, when you executing some function, it should be return some value of that execution, the return value must be 0 or -1 etc…
regards

I usually return a hash, and the values that I wanted from my SQL command are some sort of table...based off of my perl book, this is the best solution I have for all my SQL queries:

# Query the user's data
  $sqlcmd  = ....insert your command here.....
  eval {
    $sth = $dbh->prepare($sqlcmd);
    $nr  = $sth->execute();
  };
  if ($@) {
    $error  = 1;
    $errmsg = "SQL command failed: $sqlcmd";
    return;
  }

  # Grab the returned data
  my $ref = $sth->fetchrow_hashref();

  # Walk down the data struct, and add in the data
  foreach my $href (@table) {
    $href->{val} = $ref->{$href->{member}};
  }

  $sth->finish();

The last walk-down will associate values to elements and populate an array (@table) with the values from the database. When trying to view your @table data, you can simply:

foreach $member (@table){
   $mname = $member->{"member"}; 
   $mytype = $member->{"type"};
   $val = $member->{"value"};


....
}

You can then put in logic in this foreach using your queried data.

Hello,
I’m using Perl script where executing SQL query which connecting to SQL loader to insert my data into table. When the script runs the success status returns, but the loader doesn’t load anything to DB, I want to get the Perl return value to compare it.
Here is the example:

my $sql_command = here executing the load process

After this how can I get the $sql_command return value?

Thanks in advance.
Regards

I know what you want but without providing the implementation of "here executing load process" there's no way to give it to you. If you post that code it will be simple to see where it is occurring, yet you want a balck box to provide you with something it is not providing. Until you open the black box - the function - it will never give you what you wish. It is completely possible to get what you want, but only if you delve into the called function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.