php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11320 sybase_connect is not able to change charset
Submitted: 2001-06-06 16:07 UTC Modified: 2001-06-26 17:05 UTC
From: awe at email dot cz Assigned:
Status: Closed Package: Sybase-ct (ctlib) related
PHP Version: 4.0.5 OS: linux 2.4.4 and all others
Private report: No CVE-ID: None
 [2001-06-06 16:07 UTC] awe at email dot cz
function sybase_connect doesn't accept fourth parameter, charset. Following patch solves the problem.

Martin Nedbal

--- php-4.0.5/ext/sybase_ct/php_sybase_ct.c	Sun Mar 11 05:13:53 2001
+++ php-4.0.5_sybase_ct_charset_path/ext/sybase_ct/php_sybase_ct.c	Wed Jun  6 15:29:42 2001
@@ -375,6 +375,8 @@
 
 
-static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char *user, char *passwd)
+static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char *user, char *passwd, char *charset)
 {
+CS_LOCALE *tmp_locale;
+
 	SybCtLS_FETCH();
 
@@ -398,4 +400,26 @@
 		ct_con_props(sybase->connection, CS_SET, CS_PASSWORD, passwd, CS_NULLTERM, NULL);
 	}
+	if (charset) {
+	// charset
+		if (cs_loc_alloc(SybCtG(context), &tmp_locale)!=CS_SUCCEED) { 
+			php_error(E_WARNING,"Sybase: Unable to allocate locale information."); 
+		} 
+		else { 
+			if (cs_locale(SybCtG(context), CS_SET, tmp_locale, CS_LC_ALL, NULL, CS_NULLTERM, NULL)!=CS_SUCCEED) {
+				php_error(E_WARNING,"Sybase: Unable to load default locale data."); 
+			} else { 
+			if (cs_locale(SybCtG(context), CS_SET, tmp_locale, CS_SYB_CHARSET, charset, CS_NULLTERM, NULL)!=CS_SUCCEED) {
+				php_error(E_WARNING,"Sybase: Unable to update character set."); 
+			} else { 
+				if (ct_con_props(sybase->connection, CS_SET, CS_LOC_PROP, tmp_locale, CS_UNUSED, NULL)!=CS_SUCCEED) {
+				php_error(E_WARNING,"Sybase: Unable to update connection properties."); 
+			}
+		}
+		}	
+		}
+//		ct_con_props(sybase->connection, CS_SET, CS_CHARSETCNV, CS_TRUE, CS_NULLTERM, NULL);
+//		ct_con_props(sybase->connection, CS_SET, CS_CHARSETCNV, charset, CS_NULLTERM, NULL);
+	}
+
 	ct_con_props(sybase->connection, CS_SET, CS_APPNAME, SybCtG(appname), CS_NULLTERM, NULL);
 
@@ -427,5 +451,5 @@
 static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
 {
-	char *user,*passwd,*host;
+	char *user,*passwd,*host,*charset;
 	char *hashed_details;
 	int hashed_details_length;
@@ -435,5 +459,5 @@
 	switch(ZEND_NUM_ARGS()) {
 		case 0: /* defaults */
-			host=user=passwd=NULL;
+			host=user=passwd=charset=NULL;
 			hashed_details_length=6+3;
 			hashed_details = (char *) emalloc(hashed_details_length+1);
@@ -487,4 +511,25 @@
 			}
 			break;
+
+		case 4: {
+				pval *yyhost,*yyuser,*yypasswd,*yycharset;
+
+				if (getParameters(ht, 4, &yyhost, &yyuser, &yypasswd, &yycharset) == FAILURE) {
+					RETURN_FALSE;
+				}
+				convert_to_string(yyhost);
+				convert_to_string(yyuser);
+				convert_to_string(yypasswd);
+				convert_to_string(yycharset);
+				host = yyhost->value.str.val;
+				user = yyuser->value.str.val;
+				passwd = yypasswd->value.str.val;
+				charset = yycharset->value.str.val;
+				hashed_details_length = yyhost->value.str.len+yyuser->value.str.len+yypasswd->value.str.len+yycharset->value.str.len+6+3;
+				hashed_details = (char *) emalloc(hashed_details_length+1);
+				sprintf(hashed_details,"sybase_%s_%s_%s_%s",yyhost->value.str.val,yyuser->value.str.val,yypasswd->value.str.val,yycharset->value.str.val); /* SAFE */
+			}
+			break;
+			
 		default:
 			WRONG_PARAM_COUNT;
@@ -515,5 +560,5 @@
 
 			sybase_ptr = (sybase_link *) malloc(sizeof(sybase_link));
-			if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd)) {
+			if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset)) {
 				free(sybase_ptr);
 				efree(hashed_details);
@@ -569,5 +614,5 @@
 				 */
 				memcpy(&sybase, sybase_ptr, sizeof(sybase_link));
-				if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd)) {
+				if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset)) {
 					memcpy(sybase_ptr, &sybase, sizeof(sybase_link));
 					efree(hashed_details);
@@ -612,5 +657,5 @@
 
 		sybase_ptr = (sybase_link *) emalloc(sizeof(sybase_link));
-		if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd)) {
+		if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset)) {
 			efree(sybase_ptr);
 			efree(hashed_details);

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-06 22:30 UTC] awe at email dot cz
Hi, 
previous patch had small bug, a memory leak, this should be ok.

Martin.

-------------------------------------------
Martin Nedbal COOPERnet
mailto: nedbal@cooper.cz

--- php-4.0.5_official_release/ext/sybase_ct/php_sybase_ct.c      Sun Mar
11 05:13:53 2001
+++ php-4.0.5/ext/sybase_ct/php_sybase_ct.c   Wed Jun  6 20:27:07 2001
@@ -374,8 +374,10 @@
 }


-static int php_sybase_do_connect_internal(sybase_link *sybase, char *host,
char *user, char *passwd)
+static int php_sybase_do_connect_internal(sybase_link *sybase, char *host,
char *user, char *passwd, char *charset)
 {
+CS_LOCALE *tmp_locale;
+
     SybCtLS_FETCH();

     /* set a CS_CONNECTION record */
@@ -397,6 +399,26 @@
     if (passwd) {
          ct_con_props(sybase->connection, CS_SET, CS_PASSWORD, passwd,
CS_NULLTERM, NULL);
     }
+    if (charset) {
+         if (cs_loc_alloc(SybCtG(context), &tmp_locale)!=CS_SUCCEED) {
+              php_error(E_WARNING,"Sybase: Unable to allocate locale
information.");
+         }
+         else {
+              if (cs_locale(SybCtG(context), CS_SET, tmp_locale,
CS_LC_ALL, NULL, CS_NULLTERM, NULL)!=CS_SUCCEED) {
+                   php_error(E_WARNING,"Sybase: Unable to load default
locale data.");
+              } else {
+              if (cs_locale(SybCtG(context), CS_SET, tmp_locale,
CS_SYB_CHARSET, charset, CS_NULLTERM, NULL)!=CS_SUCCEED) {
+                   php_error(E_WARNING,"Sybase: Unable to update character
set.");
+              } else {
+                   if (ct_con_props(sybase->connection, CS_SET,
CS_LOC_PROP, tmp_locale, CS_UNUSED, NULL)!=CS_SUCCEED) {
+                   php_error(E_WARNING,"Sybase: Unable to update
connection properties.");
+              }
+              cs_loc_drop (SybCtG(context),tmp_locale);
+         }
+         }
+         }
+    }
+
     ct_con_props(sybase->connection, CS_SET, CS_APPNAME, SybCtG(appname),
CS_NULLTERM, NULL);

     if (SybCtG(hostname)) {
@@ -426,7 +448,7 @@

 static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int
persistent)
 {
-    char *user,*passwd,*host;
+    char *user,*passwd,*host,*charset;
     char *hashed_details;
     int hashed_details_length;
     sybase_link *sybase_ptr;
@@ -434,7 +456,7 @@

     switch(ZEND_NUM_ARGS()) {
          case 0: /* defaults */
-              host=user=passwd=NULL;
+              host=user=passwd=charset=NULL;
               hashed_details_length=6+3;
               hashed_details = (char *) emalloc(hashed_details_length+1);
               strcpy(hashed_details, "sybase___");
@@ -486,6 +508,27 @@
                    sprintf(hashed_details, "sybase_%s_%s_%s",
yyhost->value.str.val, yyuser->value.str.val, yypasswd->value.str.val); /*
SAFE */
               }
               break;
+
+         case 4: {
+                   pval *yyhost,*yyuser,*yypasswd,*yycharset;
+
+                   if (getParameters(ht, 4, &yyhost, &yyuser, &yypasswd,
&yycharset) == FAILURE) {
+                        RETURN_FALSE;
+                   }
+                   convert_to_string(yyhost);
+                   convert_to_string(yyuser);
+                   convert_to_string(yypasswd);
+                   convert_to_string(yycharset);
+                   host = yyhost->value.str.val;
+                   user = yyuser->value.str.val;
+                   passwd = yypasswd->value.str.val;
+                   charset = yycharset->value.str.val;
+                   hashed_details_length =
yyhost->value.str.len+yyuser->value.str.len+yypasswd->value.str.len+yycharset->value.str.len+6+3;
+                   hashed_details = (char *)
emalloc(hashed_details_length+1);
+
sprintf(hashed_details,"sybase_%s_%s_%s_%s",yyhost->value.str.val,yyuser->value.str.val,yypasswd->value.str.val,yycharset->value.str.val);

/* SAFE */
+              }
+              break;
+
          default:
               WRONG_PARAM_COUNT;
               break;
@@ -514,7 +557,7 @@
               }

               sybase_ptr = (sybase_link *) malloc(sizeof(sybase_link));
-              if (!php_sybase_do_connect_internal(sybase_ptr, host, user,
passwd)) {
+              if (!php_sybase_do_connect_internal(sybase_ptr, host, user,
passwd, charset)) {
                    free(sybase_ptr);
                    efree(hashed_details);
                    RETURN_FALSE;
@@ -568,7 +611,7 @@
                     * NULL before trying to use it elsewhere . . .)
                     */
                    memcpy(&sybase, sybase_ptr, sizeof(sybase_link));
-                   if (!php_sybase_do_connect_internal(sybase_ptr, host,
user, passwd)) {
+                   if (!php_sybase_do_connect_internal(sybase_ptr, host,
user, passwd, charset)) {
                         memcpy(sybase_ptr, &sybase, sizeof(sybase_link));
                         efree(hashed_details);
                         RETURN_FALSE;
@@ -611,7 +654,7 @@
          }

          sybase_ptr = (sybase_link *) emalloc(sizeof(sybase_link));
-         if (!php_sybase_do_connect_internal(sybase_ptr, host, user,
passwd)) {
+         if (!php_sybase_do_connect_internal(sybase_ptr, host, user,
passwd, charset)) {
               efree(sybase_ptr);
               efree(hashed_details);
               RETURN_FALSE;


 [2001-06-26 08:53 UTC] joey@php.net
You're still missing a few things, but thanks for the patch!
I have something that is ready, I just want to test it a bit more before applying it, but I think you can expect to see it by 4.0.7. 
 [2001-06-26 17:05 UTC] joey@php.net
Closed in CVS.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 08 07:01:23 2021 UTC