[Tritonn-commit 144] [svn] [158] upgraded ha_tritonn::write_row

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 6月 25日 (水) 17:04:58 JST


Revision: 158
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=tritonn&view=rev&rev=158
Author:   mir
Date:     2008-06-25 17:04:57 +0900 (Wed, 25 Jun 2008)

Log Message:
-----------
upgraded ha_tritonn::write_row

Modified Paths:
--------------
    trunk/src/ha_tritonn.cc


-------------- next part --------------
Modified: trunk/src/ha_tritonn.cc
===================================================================
--- trunk/src/ha_tritonn.cc	2008-06-25 06:30:37 UTC (rev 157)
+++ trunk/src/ha_tritonn.cc	2008-06-25 08:04:57 UTC (rev 158)
@@ -559,28 +559,53 @@
   }
 }
 
+const char* tritonn_escape_string(const char* str){
+  int i,len,cnt,offset;
+  for (i=0,len=strlen(str),cnt=0; i<len; i++) {
+    if (*(str+i) == '\\' || *(str+i) == '"') cnt++;
+  }
+  if (cnt == 0) return str;
+  char *res = (char*) sql_alloc(len+cnt);
+  for (i=0,offset=0; i<len; i++) {
+    if (*(str+i) == '\\') {
+      *(res+i+offset) = '\\';
+      offset++;
+      *(res+i+offset) = '\\';
+    } else if (*(str+i) == '"') {
+      *(res+i+offset) = '\\';
+      offset++;
+      *(res+i+offset) = '"';
+    } else {
+      *(res+i+offset) = *(str+i);
+    }
+  }
+  return res;
+}
+
 int ha_tritonn::write_row(uchar* buf)
 {
   DBTN;
   int i=0;
   char ql[1024];
-  char *pkey_str;
+  char* pkey;
   for (Field **field=table->field; *field; field++) {
     String str;
     (*field)->val_str(&str);
     str.chop();
     if (i==0) {
-      pkey_str = (char*) sql_alloc(str.length()+1);
-      strncpy(pkey_str,str.ptr(),str.length()+1);
-      my_snprintf(ql,1024,"(<%s> ::new \"%s\")",share->short_name,pkey_str);
+      pkey = (char*) sql_alloc(strlen(str.ptr()));
+      strcpy(pkey,str.ptr());
+      my_snprintf(ql,1024,"(<%s> ::new \"%s\")",share->short_name,
+		  tritonn_escape_string(str.ptr()));
     } else {
       my_snprintf(ql,1024,"((<%s> : \"%s\") :%s \"%s\")",
-		  share->short_name,pkey_str, (*field)->field_name,str.ptr());
+		  share->short_name,
+		  tritonn_escape_string(pkey), (*field)->field_name,
+		  tritonn_escape_string(str.ptr()));
     }
     call_senna_ql(ctx,ql);
     i++;
   }
-
   return 0;
 }
 


Tritonn-commit メーリングリストの案内
Back to archive index