Logo Search packages:      
Sourcecode: freetds version File versions

int tds_quote_id ( TDSSOCKET *  tds,
char *  buffer,
const char *  id 
)

Quote an id

Parameters:
buffer buffer to store quoted id. If NULL do not write anything (useful to compute quote length)
id id to quote
Returns:
written chars (not including needed terminator)

Definition at line 783 of file query.c.

References TDS_IS_MSSQL, and tds_quote_id().

Referenced by tds_connect(), and tds_quote_id().

{
      int need_quote, len, i;
      char quoting;
      const char *src;
      char *dst;

      len = strlen(id);

      /* need quote ?? */
      need_quote = (strcspn(id, "\"\' ()[]{}") != len);

      if (!need_quote) {
            if (buffer)
                  memcpy(buffer, id, len + 1);
            return len;
      }

      /* quote */
      quoting = '\"';
      if (TDS_IS_MSSQL(tds))
            quoting = ']';

      src = id;
      if (!buffer) {
            i = 2 + len;
            for (; *src; ++src)
                  if (*src == quoting)
                        ++i;
            return i;
      }

      dst = buffer;
      *dst++ = (quoting == ']') ? '[' : quoting;
      for (; *src; ++src) {
            if (*src == quoting)
                  *dst++ = quoting;
            *dst++ = *src;
      }
      *dst++ = quoting;
      *dst = 0;
      return dst - buffer;
}


Generated by  Doxygen 1.6.0   Back to index