--- PApp-SQL/SQL.xs 2001/12/31 03:05:03 1.9 +++ PApp-SQL/SQL.xs 2002/06/26 03:26:39 1.13 @@ -8,7 +8,7 @@ # define call_sv perl_call_sv #endif -#if (PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION <= 5)) +#if (PERL_VERSION > 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION >= 6)) # define CAN_UTF8 1 #endif @@ -23,17 +23,17 @@ } static SV * -sql_force_utf8 (SV *sv) +mortalcopy_and_maybe_force_utf8(int utf8, SV *sv) { + sv = sv_mortalcopy (sv); #if CAN_UTF8 - if (SvPOK (sv)) + if (utf8 && SvPOK (sv)) SvUTF8_on (sv); #endif return sv; } #define maybe_upgrade_utf8(utf8,sv) ((utf8) ? sql_upgrade_utf8 (sv) : (sv)) -#define maybe_force_utf8(utf8,sv) ((utf8) ? sql_force_utf8 (sv) : (sv)) #define is_dbh(sv) ((sv) && sv_isobject (sv) && sv_derived_from ((sv), "DBI::db")) @@ -235,13 +235,15 @@ /* first check wether we should use an explicit db handle */ if (!is_dbh (dbh)) { - dbh = get_sv ("DBH", FALSE); + /* the next line doesn't work - check why later maybe */ + /* dbh = get_sv ("DBH", FALSE); if (!is_dbh (dbh)) - { + {*/ dbh = GvSV(DBH); if (!is_dbh (dbh)) - croak ("sql_exec: no $DBH found in current package or in PApp::SQL::"); - } + croak ("sql_exec: no $DBH argument and no fallback in $PApp::SQL::DBH"); + /*croak ("sql_exec: no $DBH found in current package or in PApp::SQL::"); + }*/ } else arg++; /* we consumed one argument */ @@ -313,14 +315,14 @@ if (count != 1) croak ("sql_exec: execute() didn't return any value ('%s'): %s", SvPV (sql, dc), - SvPV (get_sv ("DBI::errstr", TRUE), dc)); + SvPV (get_sv ("DBI::errstr", TRUE), dd)); execute = POPs; if (!SvTRUE (execute)) croak ("sql_exec: unable to execute statement '%s' (%s)", SvPV (sql, dc), - SvPV (get_sv ("DBI::errstr", TRUE), dc)); + SvPV (get_sv ("DBI::errstr", TRUE), dd)); sv_setsv (GvSV(sql_exec), execute); @@ -341,12 +343,12 @@ if (count != 1) croak ("sql_exec: bind_columns() didn't return any value ('%s'): %s", SvPV (sql, dc), - SvPV (get_sv ("DBI::errstr", TRUE), dc)); + SvPV (get_sv ("DBI::errstr", TRUE), dd)); if (!SvOK (POPs)) croak ("sql_exec: bind_columns() didn't return a true ('%s'): %s", SvPV (sql, dc), - SvPV (get_sv ("DBI::errstr", TRUE), dc)); + SvPV (get_sv ("DBI::errstr", TRUE), dd)); } /* free our arguments from the stack */ @@ -378,14 +380,14 @@ break; case G_SCALAR: /* the first element */ - XPUSHs (maybe_force_utf8 (ix & 1, *av_fetch ((AV *)SvRV (row), 0, 1))); + XPUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, *av_fetch ((AV *)SvRV (row), 0, 1))); break; case G_ARRAY: av = (AV *)SvRV (row); count = AvFILL (av) + 1; EXTEND (SP, count); for (arg = 0; arg < count; arg++) - PUSHs (maybe_force_utf8 (ix & 1, AvARRAY (av)[arg])); + PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY (av)[arg])); break; default: @@ -420,10 +422,10 @@ EXTEND (SP, count); if (columns == 1) for (arg = 0; arg < count; arg++) - PUSHs (maybe_force_utf8 (ix & 1, AvARRAY ((AV *)SvRV (AvARRAY (av)[arg]))[0])); + PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY ((AV *)SvRV (AvARRAY (av)[arg]))[0])); else for (arg = 0; arg < count; arg++) - PUSHs (maybe_force_utf8 (ix & 1, AvARRAY (av)[arg])); + PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY (av)[arg])); } } }