--On Donnerstag, Januar 18, 2007 14:33:36 -0500 Mark Stosberg
<[EMAIL PROTECTED]> wrote:
slonik_execute_script has a "-c" option to give a single command to run
on the command line, which is convenient.
I ran something like this:
slonik_execute_script -c 'ALTER TABLE a RENAME to b' set3 | slonik
This silently failed. Slonik accepted the command, but nothing happened.
Hmm, i see the following:
[bernd slony] (1) HEAD $ slonik_execute_script --config
~/pgsql-dev/configs/slony/slon_tools.conf -c 'ALTER TABLE tapes DROP COLUMN
idf2' set1 | slonik
DDL script consisting of 0 SQL statements
Submit DDL Event to subscribers...
So slonik tells you indeed that something went wrong...
The reason is there is no trailing semicolon, so slonik interpreted this
as "0 commands".
I addressed this in the script by adding a trailing semicolon if there
is not one given with the "-c" option.
I don't like this idea, because it mask's a fundamental problem in slonik,
i think. A better option
would be at least to check if the last command in the given SQL string is
terminated and if not, to error out. But as already said, i think this is
the wrong place...
However, I think "slonik" should also be updated to at least provide a
warning if it receives "0 commands" to process.
The problem is scan_for_statements() in src/parsestatements/scanner.c,
which scans for multiple query strings in a given command string. These
needs to be terminated by ';', otherwise the last query string doesn't get
counted and is going to be ignored.
What we can do here in slonik is to check wether we have any remaining
bytes left in the current query string and to issue them as the final
query. I propose the attached fix to scanner.c, but i admit that it needs
a deeper thinking maybe. Comments?
Bernd
--
Thanks
BerndIndex: src/parsestatements/scanner.c
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/parsestatements/scanner.c,v
retrieving revision 1.3
diff -r1.3 scanner.c
28a29,41
>
> /*
> * if the string has no ';' as its last literal, we need to
> * treat all remaining bytes as an query string, too. If the
> * last saved cpos of ';' is smaller than the current cpos - 1, save
> * the remaining bytes, too.
> */
> if (state == Q_NORMAL_STATE) {
> if ((statements >= 0) && (STMTS[statements] < cpos - 1)) {
> STMTS[statements++] = ++cpos;
> }
> }
>
_______________________________________________
Slony1-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/slony1-general