* Check whether a command is one of those for which we should NOT start * a new transaction block (ie, send a preceding BEGIN). * * These include the transaction control statements themselves, plus * certain statements that the backend disallows inside transaction blocks. */
| 1904 | * certain statements that the backend disallows inside transaction blocks. |
| 1905 | */ |
| 1906 | static bool |
| 1907 | command_no_begin(const char *query) |
| 1908 | { |
| 1909 | int wordlen; |
| 1910 | |
| 1911 | /* |
| 1912 | * First we must advance over any whitespace and comments. |
| 1913 | */ |
| 1914 | query = skip_white_space(query); |
| 1915 | |
| 1916 | /* |
| 1917 | * Check word length (since "beginx" is not "begin"). |
| 1918 | */ |
| 1919 | wordlen = 0; |
| 1920 | while (isalpha((unsigned char) query[wordlen])) |
| 1921 | wordlen += PQmblenBounded(&query[wordlen], pset.encoding); |
| 1922 | |
| 1923 | /* |
| 1924 | * Transaction control commands. These should include every keyword that |
| 1925 | * gives rise to a TransactionStmt in the backend grammar, except for the |
| 1926 | * savepoint-related commands. |
| 1927 | * |
| 1928 | * (We assume that START must be START TRANSACTION, since there is |
| 1929 | * presently no other "START foo" command.) |
| 1930 | */ |
| 1931 | if (wordlen == 5 && pg_strncasecmp(query, "abort", 5) == 0) |
| 1932 | return true; |
| 1933 | if (wordlen == 5 && pg_strncasecmp(query, "begin", 5) == 0) |
| 1934 | return true; |
| 1935 | if (wordlen == 5 && pg_strncasecmp(query, "start", 5) == 0) |
| 1936 | return true; |
| 1937 | if (wordlen == 6 && pg_strncasecmp(query, "commit", 6) == 0) |
| 1938 | return true; |
| 1939 | if (wordlen == 3 && pg_strncasecmp(query, "end", 3) == 0) |
| 1940 | return true; |
| 1941 | if (wordlen == 8 && pg_strncasecmp(query, "rollback", 8) == 0) |
| 1942 | return true; |
| 1943 | if (wordlen == 7 && pg_strncasecmp(query, "prepare", 7) == 0) |
| 1944 | { |
| 1945 | /* PREPARE TRANSACTION is a TC command, PREPARE foo is not */ |
| 1946 | query += wordlen; |
| 1947 | |
| 1948 | query = skip_white_space(query); |
| 1949 | |
| 1950 | wordlen = 0; |
| 1951 | while (isalpha((unsigned char) query[wordlen])) |
| 1952 | wordlen += PQmblenBounded(&query[wordlen], pset.encoding); |
| 1953 | |
| 1954 | if (wordlen == 11 && pg_strncasecmp(query, "transaction", 11) == 0) |
| 1955 | return true; |
| 1956 | return false; |
| 1957 | } |
| 1958 | |
| 1959 | /* |
| 1960 | * Commands not allowed within transactions. The statements checked for |
| 1961 | * here should be exactly those that call PreventInTransactionBlock() in |
| 1962 | * the backend. |
| 1963 | */ |
no test coverage detected