Hi all,

I have a script that writes a single record to a single row on a GLOBALSettings 
table. I have a web page that does that and it does so successfully. I go into 
the database with SQL Server Enterprise Manager and see the value on the table. 
Then I use another page that takes advantage of that value, it selects with no 
criteria the needed field and the value gets wiped out from the DB and of 
course the app bombs. I tried using a dbh->commit at the end of the update 
script but that didn't work either. Does anyone know what is wrong? Sample code 
below:

#### INSERT SCRIPT

# Insert into DB
my($sql) = "UPDATE GLOBALSettings SET Lang = '$::lang_code'";
my($criteria_var) = "";
my($criteria) = "";
my($reference) = &SQL_Update($sql, $criteria_var, $criteria);

# Disconnect from database
$::rc = $::dbh->disconnect or
        &Error("Unable to disconnect from database.");

sub SQL_Update {

        my ($sql, $criteria_field, $criteria) = @_;

        # Append criteria if present
        if ($criteria_field && $criteria) {
                $sql.= " WHERE $criteria_field = ?";
        }

        # Debug the SQL statement (uncomment for testing)
        &Debug("$sql");

        # Prepare a SQL statement
        my $sth = $::dbh->prepare( $sql ) or
                &Error("Unable to prepare statement.");

        # Execute the SQL statement prepared above, use with or without 
criteria depending on if it is present
        # or not
        if ($criteria) {
                my $rc = $sth->execute ( $criteria ) or
                        &Error("Unable to execute statement", "$sql with 
criteria $criteria");
        } else {
                my $rc = $sth->execute or
                        &Error("Unable to execute statement", $sql);
        }

        # Return a TRUE value just so that the variable which gets assigned to 
the query execution on the caller
        # program does not report an empty value. If we got this far then all 
went OK
        1;
}
# SELECT SCRIPT

# Select current language
my ($sql)= "SELECT Lang FROM GLOBALSettings";
my ($reference) = &SQL_Select($sql);
my ($lang) = @[EMAIL PROTECTED];

sub SQL_Select {

        my ($sql, $criteria_field, $criteria, $add_criteria) = @_;

        # Debug the SQL statement (uncomment for testing)
        &Debug("$sql");
        
        # Append criteria if present
        if ($criteria_field && $criteria) {
                $sql.= " WHERE $criteria_field = ?";
        }

        # Any AND, OR or additional clauses
        if ($add_criteria) {
                $sql.= " $add_criteria";
        }

        # Prepare a SQL statement
        my $sth = $::dbh->prepare( $sql ) or
                &Error("Unable to prepare statement.");

        # Execute the SQL statement prepared above, use with or without 
criteria depending on if it is present
        # or not
        if ($criteria) {
                my $rc = $sth->execute ( $criteria ) or
                        &Error("Unable to execute statement", "$sql with 
criteria $criteria");
        } else {
                my $rc = $sth->execute or
                        &Error("Unable to execute statement", $sql);
        }

        # Return an array reference pointing to the results
        return my $result = $sth->fetchall_arrayref;
}

Regards,

Javier Moreno

Reply via email to