in reply to Passing a file into DBD-Oracle

TJRandall:

Your file read loop is keeping only the last line of the file, is that what you want? You're trying to pass undef (the value of $record) to the prepare subroutine, which just won't work. If not, p Perhaps you'd do better with:

open (FILEDATA, "$sql"); my $record = join("",<FILEDATA>); close(FILEDATA); print $record;

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Update: Struck out the incorrect statement (nice catch, bart!) and added the bit between them.

Replies are listed 'Best First'.
Re^2: Passing a file into DBD-Oracle
by bart (Canon) on Feb 11, 2011 at 21:29 UTC
    You're kinda right when you say the loop will not keep the contents of the file, except it won't even contain the contents of the last line of the file, because $record will be undef after the entire file is read, and the loop is left.

    And the title of this question is misleading, he doesn't want Oracle to use the file name; instead he wants and needs to send the contents of the file.

    I'm not sure what happens if you ask Oracle to execute the contents of an entire file in one go. You'll like have to split into single statements, and it's not clear how you send the source code for a package or package body. The invocation command "/" which is put after the end of a package or package body actually means "repeat the last command". How do you do the same through DBI? I have no idea.

      Overall, what I'm trying to do is to automate Oracle code builds. I check out the files locally, and then I load up a hash of hashes to keep track of what I'm loading, the compiled state, etc. So one of the key:value pairs for a named piece of code is 'full_name':'c:\..\..\..'. The files that I am working on contain Oracle functions, procedures, packages, etc.

      I didn't mean to be mis-leading in the Subject line - I would either (1) pass the actual file into DBI (like SQL Plus) or (2) read in the file contents, and then prepare() that. I just can't seem to get either to work. I will work on the suggestion from roboticus (thank you very much!) It didn't work on the first pass, but I will focus on the  undef issue. Thank you!
        Overall, what I'm trying to do is to automate Oracle code builds.
        I think your best bet is to invoke Sql*Plus from within Perl.