Update of /cvsroot/mysql-cocoa/SMySQL
In directory usw-pr-cvs1:/tmp/cvs-serv5380
Modified Files:
SMySQLConnection.h SMySQLConnection.m
Log Message:
Added a prepareString method to SMySQLConnection.
Serge Cohen; MySQL Cocoa project, May 30th 2002.
Index: SMySQLConnection.h
===================================================================
RCS file: /cvsroot/mysql-cocoa/SMySQL/SMySQLConnection.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SMySQLConnection.h 15 May 2002 11:07:30 -0000 1.9
--- SMySQLConnection.h 30 May 2002 08:32:33 -0000 1.10
***************
*** 75,78 ****
--- 75,79 ----
- (NSString *) prepareBinaryData:(NSData *) theData;
+ - (NSString *) prepareString:(NSString *) theString;
- (SMySQLResult *) queryString:(NSString *) query;
Index: SMySQLConnection.m
===================================================================
RCS file: /cvsroot/mysql-cocoa/SMySQL/SMySQLConnection.m,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SMySQLConnection.m 15 May 2002 11:07:30 -0000 1.9
--- SMySQLConnection.m 30 May 2002 08:32:34 -0000 1.10
***************
*** 331,336 ****
{
const char *theCDataBuffer = [theData bytes];
! unsigned int theLength;
! char *theCEscBuffer = (char *)calloc(sizeof(char),((theLength = [theData length])*2) + 1);
NSString *theReturn;
--- 331,336 ----
{
const char *theCDataBuffer = [theData bytes];
! unsigned int theLength = [theData length];
! char *theCEscBuffer = (char *)calloc(sizeof(char),(theLength*2) + 1);
NSString *theReturn;
***************
*** 342,345 ****
--- 342,362 ----
+ - (NSString *) prepareString:(NSString *) theString
+ /*"
+ Takes a string and escape any special character (like single quote : ') so that the string can be used directly in a query.
+ "*/
+ {
+ const char *theCStringBuffer = [self cStringFromString:theString];
+ unsigned int theLength = strlen(theCStringBuffer);
+ char *theCEscBuffer = (char *)calloc(sizeof(char),(theLength * 2) + 1);
+ NSString *theReturn;
+
+ mysql_real_escape_string(mConnection, theCEscBuffer, theCStringBuffer, theLength);
+ theReturn = [self stringWithCString:theCEscBuffer];
+ free (theCEscBuffer);
+ return theReturn;
+ }
+
+
- (SMySQLResult *) queryString:(NSString *) query
/*"
***************
*** 358,362 ****
}
else {
! NSLog (@"Query worked but gives no output\n");
[theResult init];
}
--- 375,379 ----
}
else {
! // NSLog (@"Query worked but gives no output\n");
[theResult init];
}
|