Re: Passing unicode strings to prepare method and other unicode questions

Tim Bunce <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.sybase.devel
Message-ID <[email protected]>
On Mon, Sep 01, 2008 at 01:48:25PM +0100, Martin Evans wrote:
>
> Ok, as you say the change is trivial for a unicode username and password:
>
> #ifdef dbd_db_login6_sv
>     ST(0) = dbd_db_login6(dbh, imp_dbh, dbname, username, password, 
> attribs) ? &sv_yes : &sv_no;
> #elif defined(dbd_db_login6)
>     ST(0) = dbd_db_login6(dbh, imp_dbh, dbname, u, p, attribs) ? &sv_yes : 
> &sv_no;
> #else
>     ST(0) = dbd_db_login( dbh, imp_dbh, dbname, u, p) ? &sv_yes : &sv_no;
> #endif
>
> and an additional line in dbd_xsh.h I presume but not "dbname" which is the 
> one I'd really like as it is currently char *. How do I get dbname to be an 
> SV - as you may have guessed by now I'm not an XS expert. Is it just a case 
> of changing my DBD::ODBC::db::_login to say it is an SV*?

Something like the appended change should do it (untested).

Tim.

===================================================================
--- Driver.xst  (revision 11611)
+++ Driver.xst  (working copy)
@@ -84,7 +84,7 @@
 void
 _login(dbh, dbname, username, password, attribs=Nullsv)
     SV *        dbh
-    char *      dbname
+    SV *        dbname
     SV *        username
     SV *        password
     SV *        attribs
@@ -95,9 +95,9 @@
     char *u = (SvOK(username)) ? SvPV(username,lna) : "";
     char *p = (SvOK(password)) ? SvPV(password,lna) : "";
 #ifdef dbd_db_login6
-    ST(0) = dbd_db_login6(dbh, imp_dbh, dbname, u, p, attribs) ?  &sv_yes : &sv_no;
+    ST(0) = dbd_db_login6(dbh, imp_dbh, SvPV_nolen(dbname), u, p, attribs) ? &sv_yes : &sv_no;
 #else
-    ST(0) = dbd_db_login( dbh, imp_dbh, dbname, u, p) ? &sv_yes : &sv_no;
+    ST(0) = dbd_db_login( dbh, imp_dbh, SvPV_nolen(dbname), u, p) ?  &sv_yes : &sv_no;
 #endif
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.