Permalink
Browse files

This commit was manufactured by cvs2svn to create tag 'REL_1_2_0_PRE1'.

  • Loading branch information...
1 parent b4b15f8 commit 280d34958d6fc2ff63d73386a0e8dfc1b6ee3613 cvs2svn committed Jun 2, 2006
@@ -1,31 +0,0 @@
-slony_subdir = src/parsestatements
-slony_top_builddir = ../..
-include $(slony_top_builddir)/Makefile.global
-
-PROG=test-scanner
-FLEX=flex
-
-ifeq ($(PORTNAME), win32)
-SUFFIX=.win32
-endif
-
-all: $(PROG) test
-
-scanner.o: scanner.c scanner.h
-
-$(PROG): $(PROG).o scanner.o
- $(CC) $(CFLAGS) -o $(PROG) test-scanner.c scanner.o
-
-test-scanner.o: test-scanner.c
-
-test: test-scanner
- ./test-scanner < /dev/null > emptytestresult.log
- cmp ./emptytestresult.log emptytestresult.expected$(SUFFIX)
- ./test-scanner < ./test_sql.sql > test_sql.log
- cmp ./test_sql.log ./test_sql.expected$(SUFFIX)
-
-install:
-
-clean:
- rm -f scanner.o test-scanner test-scanner.o
- rm -f *.log
@@ -1,10 +0,0 @@
-scanner.c is a scanner which uses a state machine to walk through a
-set of SQL statements and identify where the ends of statements are
-(e.g. - relevant ";"'s).
-
-It needs to handle various forms of quoting, notably with "double
-quotes", 'single quotes', and $dol$dollar quoting$dol$.
-
-This will need to get integrated into both slon and slonik in order
-to split DDL requests being submitted via EXECUTE SCRIPT into
-individual statements.
@@ -1 +0,0 @@
-Input:
@@ -1 +0,0 @@
-Input:
@@ -1,164 +0,0 @@
-/* $Id: scanner.c,v 1.1 2006-02-24 18:33:02 cbbrowne Exp $ */
-#include <stdio.h>
-#include "scanner.h"
-
-int STMTS[MAXSTATEMENTS];
-int scan_for_statements (const char *extended_statement) {
- int cpos;
- int bquote;
- int bpos;
- enum quote_states state;
- char cchar;
- int d1start, d1end, d2start, d2end, d1stemp, j;
- int statements;
-
- /* Initialize */
- cpos = 0;
- statements = 0;
- bquote = 0;
- bpos = 0; /* Location of last backquote */
- state = Q_NORMAL_STATE;
-
- while (state != Q_DONE) {
- cchar = extended_statement[cpos];
- switch (cchar) {
- case '\0':
- state = Q_DONE;
- break;
- case '/':
- if (state == Q_NORMAL_STATE) {
- state = Q_HOPE_TO_CCOMMENT;
- break;
- }
- if (state == Q_HOPE_CEND) {
- state = Q_NORMAL_STATE;
- break;
- }
- break;
- case '*':
- if (state == Q_HOPE_TO_CCOMMENT) {
- state = Q_CCOMMENT;
- break;
- }
- break;
- case '\\':
- if ((state == Q_DOUBLE_QUOTING) || (state == Q_SINGLE_QUOTING)) {
- if (bquote == 0) {
- bquote = 1;
- bpos = cpos;
- break;
- }
- }
-
- break;
- case '$':
- if (state == Q_NORMAL_STATE) {
- d1start = cpos;
- state = Q_DOLLAR_BUILDING;
- break;
- }
- if (state == Q_DOLLAR_BUILDING) {
- d1end = cpos;
- state = Q_DOLLAR_QUOTING;
- break;
- }
- if (state == Q_DOLLAR_QUOTING) {
- d2start = cpos;
- state = Q_DOLLAR_UNBUILDING;
- break;
- }
- if (state == Q_DOLLAR_UNBUILDING) {
- d2end = cpos;
- /* Compare strings - is this the delimiter the imperials are looking for? */
- if ((d1end - d1start) != (d2end - d2start)) {
- /* Lengths don't even match - these aren't the droids we're looking for */
- state = Q_DOLLAR_QUOTING; /* Return to dollar quoting mode */
- break;
- }
- int d1stemp = d1start;
- while (d1stemp < d1end) {
- if (extended_statement[d1stemp] != extended_statement[d2start]) {
- /* mismatch - these aren't the droids... */
- state = Q_DOLLAR_QUOTING;
- break;
- }
- d1stemp++; /* Step forward to the next character */
- d2start++;
- }
- if ((d1stemp >= d1end) && (state == Q_DOLLAR_UNBUILDING)) { /* No mismatches */
- state = Q_NORMAL_STATE;
- break;
- }
- }
- break;
- case '"':
- if (state == Q_NORMAL_STATE) {
- state = Q_DOUBLE_QUOTING;
- break;
- }
- if (state == Q_DOUBLE_QUOTING) {
- /* But a backquote hides this! */
- if ((bquote == 1) && (bpos == cpos -1)) {
- break; /* Ignore the quote */
- }
- state = Q_NORMAL_STATE;
- break;
- }
- break;
- case '\'':
- if (state == Q_NORMAL_STATE) {
- state = Q_SINGLE_QUOTING;
- break;
- }
- if (state == Q_SINGLE_QUOTING) {
- /* But a backquote hides this! */
- if ((bquote == 1) && (bpos == cpos -1)) {
- break; /* Ignore the quote */
- }
- state = Q_NORMAL_STATE;
- break;
- }
- break;
- case '-':
- if (state == Q_NORMAL_STATE) {
- state = Q_HOPE_TO_DASH;
- break;
- }
- if (state == Q_HOPE_TO_DASH) {
- state = Q_DASHING_STATE;
- break;
- }
- break;
- case '\n':
- if (state == Q_DASHING_STATE) {
- state = Q_NORMAL_STATE;
- }
- if (state == Q_DOLLAR_BUILDING) state = Q_NORMAL_STATE;
- if (state == Q_DOLLAR_UNBUILDING) state = Q_DOLLAR_QUOTING;
- break;
- case '\r':
- if (state == Q_DASHING_STATE) {
- state = Q_NORMAL_STATE;
- }
- if (state == Q_DOLLAR_BUILDING) state = Q_NORMAL_STATE;
- if (state == Q_DOLLAR_UNBUILDING) state = Q_DOLLAR_QUOTING;
- break;
- case ' ':
- if (state == Q_DOLLAR_BUILDING) state = Q_NORMAL_STATE;
- if (state == Q_DOLLAR_UNBUILDING) state = Q_DOLLAR_QUOTING;
- break;
- case ';':
- if (state == Q_NORMAL_STATE) {
- STMTS[statements++] = ++cpos;
- if (statements >= MAXSTATEMENTS) {
- return statements;
- }
- }
- break;
- default:
- break;
- }
- cpos++;
- }
- return statements;
-}
@@ -1,17 +0,0 @@
-/* $Id: scanner.h,v 1.1 2006-02-24 18:33:02 cbbrowne Exp $ */
-#define MAXSTATEMENTS 1000
-enum quote_states {
- Q_NORMAL_STATE,
- Q_HOPE_TO_DASH, /* If next char is -, then start a -- comment 'til the end of the line */
- Q_DASHING_STATE, /* comment using -- to the end of the line */
- Q_HOPE_TO_CCOMMENT, /* If next char is *, then start a C-style comment */
- Q_CCOMMENT, /* Inside a C-style comment */
- Q_HOPE_CEND, /* expecting the end of a C-style comment */
- Q_DOUBLE_QUOTING, /* inside a "double-quoted" quoting */
- Q_SINGLE_QUOTING, /* inside a 'single-quoted' quoting */
- Q_DOLLAR_QUOTING, /* inside a $doll$ dollar quoted $doll$ section */
- Q_DOLLAR_BUILDING, /* inside the $doll$ of a dollar quoted section */
- Q_DOLLAR_UNBUILDING, /* inside a possible closing $doll$ of a dollar quoted section */
- Q_DONE /* NULL ends it all... */
-};
-
@@ -1,27 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "scanner.h"
-
-char foo[65536];
-extern int STMTS[1024];
-extern int statements;
-
-int main (int argc, char *const argv[]) {
- int nstatements = 0;
- fread(foo, sizeof(char), 65536, stdin);
- printf("Input: %s\n", foo);
-
- nstatements = scan_for_statements (foo);
-
- int i, j, START;
- START = 0;
- for (i = 0; i < nstatements; i++) {
- printf("\nstatement %d\n-------------------------------------------\n", i);
- for (j = START; j < STMTS[i]; j++) {
- printf("%c", foo[j]);
- }
- START = STMTS[i];
- }
-
- return 0;
-}
@@ -1,117 +0,0 @@
-Input: select * from foo; select * from bar; select * from frobozz;
-alter table foo add column c integer;
-alter table foo alter column c set not null;
-
--- Comment line that should hide a whole bunch of quoting... ;; $$
--- '"''"; "\"\"\"$$ ;"\"""
-
--- Here is an old-style pl/pgsql function using heavy quoting
-create function foo (text) returns integer as '
- declare
- rc record;
- begin
- select * into rc from foo where name = ''Some Favored name'';
- return NULL;
- end;' language plpgsql;
-
-select * from foo; select * from bar; select * from frobozz;
-
-create or replace function foo (text) returns integer as $$
- begin
- select * into rc from foo where name = 'Some Favored name';
- return NULL;
- end;
-$$ language plpgsql;
-
-select * from foo; select * from bar; select * from frobozz;
-
--- This isn't actually a particularly well-framed stored function
--- but it abuses $$dollar quoting$$ quite nicely...
-create or replace function foo (text) returns integer as $$
- begin
- select * into rc from foo where name = $23$Some Favored name$23$;
- -- Use a secondary bit of quoting to make sure that nesting works...
- select $24$ -- another " " thing ' ' \\\'\$ $24$;
- return NULL;
- end;
-$$ language plpgsql;
-
-
-statement 0
--------------------------------------------
-select * from foo;
-statement 1
--------------------------------------------
- select * from bar;
-statement 2
--------------------------------------------
- select * from frobozz;
-statement 3
--------------------------------------------
-
-alter table foo add column c integer;
-statement 4
--------------------------------------------
-
-alter table foo alter column c set not null;
-statement 5
--------------------------------------------
-
-
--- Comment line that should hide a whole bunch of quoting... ;; $$
--- '"''"; "\"\"\"$$ ;"\"""
-
--- Here is an old-style pl/pgsql function using heavy quoting
-create function foo (text) returns integer as '
- declare
- rc record;
- begin
- select * into rc from foo where name = ''Some Favored name'';
- return NULL;
- end;' language plpgsql;
-statement 6
--------------------------------------------
-
-
-select * from foo;
-statement 7
--------------------------------------------
- select * from bar;
-statement 8
--------------------------------------------
- select * from frobozz;
-statement 9
--------------------------------------------
-
-
-create or replace function foo (text) returns integer as $$
- begin
- select * into rc from foo where name = 'Some Favored name';
- return NULL;
- end;
-$$ language plpgsql;
-statement 10
--------------------------------------------
-
-
-select * from foo;
-statement 11
--------------------------------------------
- select * from bar;
-statement 12
--------------------------------------------
- select * from frobozz;
-statement 13
--------------------------------------------
-
-
--- This isn't actually a particularly well-framed stored function
--- but it abuses $$dollar quoting$$ quite nicely...
-create or replace function foo (text) returns integer as $$
- begin
- select * into rc from foo where name = $23$Some Favored name$23$;
- -- Use a secondary bit of quoting to make sure that nesting works...
- select $24$ -- another " " thing ' ' \\\'\$ $24$;
- return NULL;
- end;
-$$ language plpgsql;
Oops, something went wrong. Retry.

0 comments on commit 280d349

Please sign in to comment.