Tuesday, November 18, 2008

UTF-8 Solution

  1. #!/usr/local/git/bin/perl
  2. # Test Char Set Issue
  3. # Tested By : Sivasakthi.kumar
  4. # IM : Sivasakthikumar@gmail.com

  5. use DBI;
  6. use DBD::Oracle qw(:ora_types);
  7. use utf8;
  8. use Encode;

  9. $string = "FuÔbalÀl";

  10. $ENV{NLS_LANG} = ".UTF8";
  11. $ENV{NLS_NCHAR} = "AL32UTF8";

  12. print "Before Insert DataBase :";
  13. print "$string";

  14. my $dbh;

  15. $dbh = DBI->connect("DBI:Oracle:SID=tosipo;HOST="localhost";PORT=1521",
  16. teststage,
  17. SSaih,
  18. {RaiseError => 1,
  19. PrintError => 0,
  20. AutoCommit => 0 }) or die $DBI::errstr;

  21. $sqlquery = "update TEST_ASSESSMENT set RESPONSE = \'$string\' where doc_id = 34 and version_id = \'1.0.0\'";
  22. print "\nSqlQuery : $sqlquery";
  23. $dbh->do("$sqlquery") or die $dbh->errstr;


  24. $sth = $dbh->prepare( "select response from TEST_ASSESSMENT where doc_id = 34 and version_id = '1.0.0'" ) or die $dbh->errstr;
  25. $sth->execute();

  26. while ( my($res) = $sth->fetchrow_array )
  27. {
  28. # $res = decode("ISO-8859-1", $res);
  29. #$res = encode("utf8", $res);
  30. print "\n$res";
  31. }

  32. $dbh->commit();
  33. $dbh->disconnect();