* Parse a possible variable reference (:varname). * * "sql" points at a colon. If what follows it looks like a valid * variable name, return a malloc'd string containing the variable name, * and set *eaten to the number of characters consumed (including the colon). * Otherwise, return NULL. */
| 1707 | * Otherwise, return NULL. |
| 1708 | */ |
| 1709 | static char * |
| 1710 | parseVariable(const char *sql, int *eaten) |
| 1711 | { |
| 1712 | int i = 1; /* starting at 1 skips the colon */ |
| 1713 | char *name; |
| 1714 | |
| 1715 | /* keep this logic in sync with valid_variable_name() */ |
| 1716 | if (IS_HIGHBIT_SET(sql[i]) || |
| 1717 | strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" |
| 1718 | "_", sql[i]) != NULL) |
| 1719 | i++; |
| 1720 | else |
| 1721 | return NULL; |
| 1722 | |
| 1723 | while (IS_HIGHBIT_SET(sql[i]) || |
| 1724 | strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" |
| 1725 | "_0123456789", sql[i]) != NULL) |
| 1726 | i++; |
| 1727 | |
| 1728 | name = pg_malloc(i); |
| 1729 | memcpy(name, &sql[1], i - 1); |
| 1730 | name[i - 1] = '\0'; |
| 1731 | |
| 1732 | *eaten = i; |
| 1733 | return name; |
| 1734 | } |
| 1735 | |
| 1736 | static char * |
| 1737 | replaceVariable(char **sql, char *param, int len, char *value) |
no test coverage detected