--- PApp-SQL/SQL.xs 2002/06/26 03:26:39 1.13 +++ PApp-SQL/SQL.xs 2005/09/01 08:57:28 1.18 @@ -12,6 +12,8 @@ # define CAN_UTF8 1 #endif +#define MAX_CACHED_STATEMENT_SIZE 8192 + static SV * sql_upgrade_utf8 (SV *sv) { @@ -62,7 +64,7 @@ /* this is primitive, yet effective */ /* the returned value must never be zero (or bad things will happen) */ #define lru_hash do { \ - hash = (((U32)dbh)>>2); \ + hash = (((U32)(long)dbh)>>2); \ hash += *statement;\ hash += len; \ } while (0) @@ -292,7 +294,8 @@ sth = POPs; - lru_store (dbh, sql, sth); + if (SvLEN (sql) < MAX_CACHED_STATEMENT_SIZE) + lru_store (dbh, sql, sth); } PUSHMARK (SP); @@ -300,7 +303,11 @@ PUSHs (sth); while (items > arg) { - PUSHs (maybe_upgrade_utf8 (ix & 1, ST(arg))); + SV *sv = ST(arg); + /* we sv_mortalcopy magical values since DBI seems to have a memory + * leak when magical values are passed into execute(). + */ + PUSHs (maybe_upgrade_utf8 (ix & 1, SvMAGICAL(sv) ? sv_mortalcopy(sv) : sv)); arg++; } @@ -332,6 +339,10 @@ EXTEND (SP, bind_last - bind_first + 2); PUSHs (sth); do { +#if CAN_UTF8 + if (ix & 1) + SvUTF8_on (SvRV(ST(bind_first))); +#endif PUSHs (ST(bind_first)); bind_first++; } while (bind_first != bind_last);