|
|
| version 1.9, 2008/07/03 07:17:25 | version 1.11, 2010/10/27 22:48:51 |
|---|---|
| Line 190 public: | Line 190 public: |
| return true; // not needed | return true; // not needed |
| } | } |
| const char* quote(void *aconnection, const char *from, unsigned int length){ | // charset here is services.request_charset(), not connection.client_charset |
| // thus we can't use the sql server quoting support | |
| const char* quote(void *aconnection, const char *str, unsigned int length) | |
| { | |
| const char* from; | |
| const char* from_end=str+length; | |
| size_t quoted=0; | |
| for(from=str; from<from_end; from++){ | |
| if(*from=='\'') | |
| quoted++; | |
| } | |
| if(!quoted) | |
| return str; | |
| Connection& connection=*static_cast<Connection*>(aconnection); | Connection& connection=*static_cast<Connection*>(aconnection); |
| /* | char *result=(char*)connection.services->malloc_atomic(length + quoted + 1); |
| You must allocate the to buffer to be at least length*2+1 bytes long. | char *to = result; |
| In the worse case, each character may need to be encoded as using two bytes, | |
| and you need room for the terminating null byte. | for(from=str; from<from_end; from++){ |
| */ | if(*from=='\'') |
| char *result=(char*)connection.services->malloc_atomic(length*2+1); | *to++= '\''; // ' -> '' |
| char *to=result; | *to++=*from; |
| while(length--) { | |
| if(*from=='\'') { // ' -> '' | |
| *to++='\''; | |
| } else if(*from=='\"') { // " -> "" | |
| *to++='\"'; | |
| } | |
| *to++=*from++; | |
| } | } |
| *to=0; | *to=0; |
| return result; | return result; |
| } | } |