Date: Tuesday, January 24, 2006 @ 12:23:10
  Author: csaba
    Path: /cvsroot/carob/libmysequoia/src

Modified: MySQLAPI.cpp (1.30 -> 1.31)

Implemented mysql_real_escape_string() and mysql_escape_string()  (not using 
the charset information)


--------------+
 MySQLAPI.cpp |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 54 insertions(+), 7 deletions(-)


Index: libmysequoia/src/MySQLAPI.cpp
diff -u libmysequoia/src/MySQLAPI.cpp:1.30 libmysequoia/src/MySQLAPI.cpp:1.31
--- libmysequoia/src/MySQLAPI.cpp:1.30  Mon Jan 23 12:28:41 2006
+++ libmysequoia/src/MySQLAPI.cpp       Tue Jan 24 12:23:10 2006
@@ -701,25 +701,72 @@
 /* Misc functions */
 
 unsigned long STDCALL
-mysql_escape_string (char *to, const char *from, unsigned long from_length)
+mysql_escape_string (char *to, const char *from, unsigned long length)
 {
-  LOG4CXX_DEBUG(logger, "Entering mysql_escape_string: to=" << to << " from=" 
<< from << "from_length=" << from_length);
+  LOG4CXX_DEBUG(logger, "Entering mysql_escape_string: to=" << to << " from=" 
<< from << "length=" << length);
 
-  // TODO implementation
-  unsigned long result = 0;
+  unsigned long result = mysql_real_escape_string(0, to, from, length);
   
   LOG4CXX_DEBUG(logger, "Leaving mysql_escape_string: result=" << result);
   return result;
 }
 
 unsigned long STDCALL
-mysql_real_escape_string (MYSQL * mysql, char *to, const char *from,
-        unsigned long length)
+mysql_real_escape_string (MYSQL * mysql, char *to, const char *from, unsigned 
long length)
 {
   LOG4CXX_DEBUG(logger, "Entering mysql_real_escape_string: mysql=" << mysql 
<< " to=" << to << " from=" << from << "length=" << length);
 
-  // TODO implementation
+  // TODO use the encoding found in the mysql parameter
+  
   unsigned long result = 0;
+  char *start = to;
+  char *end = to + 2*length;
+  char esc;
+    
+  while (length-- > 0)
+  {
+    esc = 0;
+    
+    switch (*from)
+    {
+      case '\0': esc = '0'; break;
+      case '\n': esc = 'n'; break;
+      case '\r': esc = 'r'; break;
+      case '\\': esc = '\\'; break;
+      case '\'': esc = '\''; break;
+      case '"':  esc = '"'; break;
+      case '\032': esc = 'Z'; break;
+    }
+    if (esc)
+    {
+      if (to + 2 < end)
+      {
+        *to++= '\\';
+        *to++= esc;
+      }
+      else
+      {
+        result = 1;
+        break;
+      }
+    }
+    else
+    {
+      if (to + 1 < end)
+      {
+        *to++= *from;
+      }
+      else
+      {
+        result = 1;
+        break;
+      }
+    }
+  from++;
+  }
+
+  *to = 0;
+  result = (result == 0) ? (unsigned long) (to - start) : (unsigned long) ~0;
 
   LOG4CXX_DEBUG(logger, "Leaving mysql_real_escape_string: result=" << result);
   return result;

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to