src/cats/postgresql.c
static char *pgsql_copy_escape(char *dest, char *src, size_t len) 
{ 
    /* we have to escape \t, \n, \r, \ */
    char c = '\0' ;
 
    while (len > 0 && *src) {
       switch (*src) {
       case '\n':
          c = 'n';
          break;
       case '\\':
          c = '\\';
          break;
       case '\t':
          c = 't';
          break;
       case '\r':
          c = 'r';
          break;
       default:
          c = '\0' ;
       }

       if (c) {
          *dest = '\\';
          dest++;
          *dest = c;
       } else {
          *dest = *src;
       }

       len--;
       src++;
       dest++;
    }

    *dest = '\0';
    return dest;
}
/* 
 * Escape strings so PostgreSQL is happy on COPY
 * 
 * len is the length of the old string. Your new
 *   string must be long enough (max 2*old+1) to hold
 *   the escaped output.
 */
Escape strings so PostgreSQL is happy on COPY

len is the length of the old string. Your new
string must be long enough (max 2*old+1) to hold
the escaped output.
Escape strings so PostgreSQL is happy on COPY len is the length of the old string . Your new string must be long enough ( max 2 * old + 1 ) to hold the escaped output .
static char *pgsql_copy_escape(char *dest, char *src, size_t len) 
{ 
    char c = '\0' ;
    while (len > 0 && *src) {
       switch (*src) {
       case '\n':
          c = 'n';
          break;
       case '\\':
          c = '\\';
          break;
       case '\t':
          c = 't';
          break;
       case '\r':
          c = 'r';
          break;
       default:
          c = '\0' ;
       }
       if (c) {
          *dest = '\\';
          dest++;
          *dest = c;
       } else {
          *dest = *src;
       }
       len--;
       src++;
       dest++;
    }
    *dest = '\0';
    return dest;
}
static char * pgsql_copy_escape ( char * dest , char * src , size_t len ) { char c = ' \0 ' ; while ( len > 0 && * src ) { switch ( * src ) { case ' \n ' : c = ' ' ; break ; case ' \\ ' : c = ' \\ ' ; break ; case ' \t ' : c = ' ' ; break ; case ' \r ' : c = ' ' ; break ; default : c = ' \0 ' ; } if ( c ) { * dest = ' \\ ' ; dest ++ ; * dest = c ; } else { * dest = * src ; } len -- ; src ++ ; dest ++ ; } * dest = ' \0 ' ; return dest ; }
Escape strings so PostgreSQL is happy on COPY
Escape strings so PostgreSQL is happy on COPY
/* we have to escape \t, \n, \r, \ */