in reply to Re^4: update db problem
in thread update db problem

The following is scrubbed code I use to get a handle to an Oracle database.

#!/usr/bin/perl use strict; use warnings; use DBI; require DBD::Oracle; my $oracle = do{ my $db_name = 'dbname'; my $db_user = 'userid'; my $db_pass = 'password'; my @dbi_path = ("dbi:Oracle:$db_name",$db_user,$db_pass); DBI->connect( @dbi_path, { PrintError => 1, RaiseError => 1, AutoCommit => 0 } ) or die "Database connect to $db_name failed: $DBI::errstr"; };

The code in the do block is executed, keeping the connection parameters localized to the block and returning the last thing evaluated (ie the handle). Note you will have to modify those connection parameters to reflect your case, in particular all references to Oracle should be changed to reflect your chosen technology. What brand of database are you attempting to connect to? What are the diagnostics that tell you 'it doesn't work'? If you plan on doing much work in Perl, figuring out how to work with DBI is definitely time worth while.

On the question of the original approach, I suspect that you are not disconnecting from your database between update and select when you run the commands from the command line. If your database is set to automatically rollback changes (likely), this would cause issues just like yours to manifest. On the other hand, I believe MS SQL does not really support the rollback concept, which explains why changing technologies causes a change in behavior. What happens when you try the following in your original script:

$cmd = $connString."update [dbname].[record] set record = 7;commit\nGO\nquit\n";

Replies are listed 'Best First'.
Re^6: update db problem
by mybend (Initiate) on Jun 14, 2010 at 20:50 UTC

    Unfortunatelly, there is no way I can use DBI. Not my choice...

    The following didn't help either... :(

    $cmd = $connString."update [dbname].[record] set record = 7;commit\nGO +\nquit\n";

      Though I don't know exact why you can't use DBI, a read through Yes, even you can use CPAN might be useful for you.

      You say you can accomplish your goal on the command line, but not with Perl. Perl is literally passing the string you are storing in $cmd to the OS. It should not be possible for that same exact string to fail in the Perl context and succeed on the command line (assuming you are performing the actions with the same environmental variables). What is the result when you modify your code to literally print the content of $cmd to STDOUT and then type that same code yourself?