0
if ($insert_ver) {
   $sth = $dbh->prepare(qq|
      insert into db_change (database_version,
       script_name, run_date) values (?,?,?) |);
   $sth->execute("$SQLFILES{$serverType[$serverIndex]}{DBVERSION}[$fileIndex]",
                 "$SQLFILES{$serverType[$serverIndex]}{FILENAME}[$fileIndex]",
                 "$currentDate");
 }

I am getting the error shown below when I ran alter_db.pl which is the script that updates the Informix database:

Can't call method "execute" on an undefined value at D:\ImageMark\opt\siips\classa\patches\alter_db.pl line 421.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • $dbh = databaseConnect("$dbName", $autoCommit, $debug); – user3291891 Jun 30 '20 at 14:01
  • Create the connection with attribute `{ RaiseError => 1 }` or `{ PrintError => 1 }` or both (`{ RaiseError => 1, PrintError => 1 }`). At least you'll know when things are going wrong. If you won't use either, the onus is on you to check that methods work correctly — producing defined handles, etc. – Jonathan Leffler Jun 30 '20 at 18:34

1 Answers1

3

You should change your code to:

$sth = $dbh->prepare(qq|
     insert into db_change (database_version,
         script_name, run_date) values (?,?,?)
     |) || die "Can't prepare statement: $DBI::errstr";

Then you would get the appropriate error.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Georg Mavridis
  • 2,312
  • 1
  • 15
  • 23
  • The above error is thrown only when table has some data in the database. If table doesn't have nay data then It works fine. This is leading to the confusion, why the Alter commands are not working when data is present in tables. – user3291891 Jun 30 '20 at 14:43
  • 2
    $sth is undefined. That means the "prepare-statement" failed. The reason is in $DBI::errstr – Georg Mavridis Jun 30 '20 at 14:56
  • Can we alter informix table when it has data in it? – user3291891 Jul 01 '20 at 02:39
  • The above error is thrown only when table has some data in the database. I truncated all the tables which has data then script executed successfully. Why alter table commands failing when data is present in the table. – user3291891 Jul 01 '20 at 02:51
  • Change the one statement as told, rerun the script and show the error. Someone might be able to help than. – Georg Mavridis Jul 01 '20 at 07:14