| 1801 | // |
| 1802 | |
| 1803 | static gpre_ctx* par_alias( gpre_req* request, const TEXT* alias) |
| 1804 | { |
| 1805 | SCHAR error_string[ERROR_LENGTH]; |
| 1806 | |
| 1807 | assert_IS_REQ(request); |
| 1808 | |
| 1809 | // look through all contexts at this scope level |
| 1810 | // to find one that has a relation name or alias |
| 1811 | // name which matches the identifier passed |
| 1812 | |
| 1813 | gpre_ctx* relation_context = NULL; |
| 1814 | for (gpre_ctx* context = request->req_contexts; context; context = context->ctx_next) |
| 1815 | { |
| 1816 | if (context->ctx_scope_level != request->req_scope_level) |
| 1817 | continue; |
| 1818 | |
| 1819 | // check for matching alias |
| 1820 | |
| 1821 | if (context->ctx_alias) |
| 1822 | { |
| 1823 | const TEXT* p = context->ctx_alias; |
| 1824 | const TEXT* q = alias; |
| 1825 | for (; *p && *q; p++, q++) |
| 1826 | { |
| 1827 | if (UPPER(*p) != UPPER(*q)) |
| 1828 | break; |
| 1829 | } |
| 1830 | if (!*p && !*q) |
| 1831 | return context; |
| 1832 | } |
| 1833 | |
| 1834 | // check for matching relation name; aliases take priority so |
| 1835 | // save the context in case there is an alias of the same name; |
| 1836 | // also to check that there is no self-join in the query |
| 1837 | |
| 1838 | if (context->ctx_relation && !strcmp(context->ctx_relation->rel_symbol->sym_string, alias)) |
| 1839 | { |
| 1840 | if (relation_context) |
| 1841 | { |
| 1842 | fb_utils::snprintf(error_string, sizeof(error_string), |
| 1843 | "the table %s is referenced twice; use aliases to differentiate", |
| 1844 | alias); |
| 1845 | PAR_error(error_string); |
| 1846 | } |
| 1847 | relation_context = context; |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | return relation_context; |
| 1852 | } |
| 1853 | |
| 1854 | |
| 1855 | //____________________________________________________________ |
no test coverage detected