vipinh has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to pass a hash, to a stored procedure in SQL server. How do i do that ? and should i use Win32::ODBC or something else. i tried using Win32::ODBC, but i cant even pass a scalar value to the stored proc without getting an error message saying : "Can't call method "Execute" on an undefined value" .Could someone tell me what this means ?
Thanks,
Vipin

Replies are listed 'Best First'.
Re: Sending a hash to a stored proc
by Anonymous Monk on Sep 25, 2000 at 21:15 UTC
    It's very unclear what your trying to do. Are you trying to pass the hash keys and/or values as arguments to a stored procedure?
    Maybe you want something like:
    $sqlstmt = 'EXECUTE TestProcedure ('.join(",", values %hash).')'; Or to quote the values: $sqlstmt = 'EXECUTE TestProcedure ('.join(",", map {"'".$_."'"} values + %hash).')';
    That will give you an unordered list of the hash's values, which is unlikely to be what you want. If you need more help, you'll have to be more explicit about what you're trying to do.
Re: Sending a hash to a stored proc
by JanneVee (Friar) on Sep 24, 2000 at 20:39 UTC
    The question is quite unprecise... How do you try to pass the hash to the exec call?

    /JanneVee

      Hi, I use the Win32::ODBC , and use the SQL function like this
      $sqlstatement = "EXECUTE TestProcedure " . hash-name
      $db->Sql($sqlstatement);

      i also tried using the Run function instead of the Sql function, but no difference What am i doing wrong ? Does Perl not supprt connecting to Microsoft SQL Server 7 ?
Re: Sending a hash to a stored proc
by Fastolfe (Vicar) on Sep 26, 2000 at 20:20 UTC
    The error is consistent with an undefined object reference:
    $object->method(@arguments);
    If $object is undefined (if this were a database handle, I'd check to be sure the connection succeeded), you will receive an error message saying "Can't call method 'method' on an undefined value..."

    Since we're almost certainly talking about a database handle, I would examine your code around the area in question (or where that code is being called in your own code) and be certain that the object you're passing is defined.