8000 Fix transform escape rules for SQL escape syntax, again. by dimitri · Pull Request #349 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix transform escape rules for SQL escape syntax, again. #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/bin/pgcopydb/ld_transform.c
8000
Original file line number Diff line number Diff line change
Expand Up @@ -2106,12 +2106,37 @@ stream_write_sql_escape_string_constant(FILE *out, const char *str)
{
switch (str[i])
{
case '\'':
case '\b':
{
fformat(out, "\\b");
break;
}

case '\f':
{
fformat(out, "\\f");
break;
}

case '\n':
{
fformat(out, "\\n");
break;
}

case '\r':
{
fformat(out, "\\r");
break;
}

case '\t':
{
fformat(out, "\\t");
break;
}

case '\'':
case '\\':
{
fformat(out, "\\%c", str[i]);
Expand Down
10 changes: 8 additions & 2 deletions tests/follow-data-only/copydb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pgcopydb copy table-data
psql -v a=11 -v b=20 -d ${PGCOPYDB_SOURCE_PGURI} -f /usr/src/pgcopydb/dml.sql

# start following and applying changes from source to target
pgcopydb follow --notice
pgcopydb follow --verbose

# the follow command ends when reaching endpos, set in inject.sh
pgcopydb stream cleanup
Expand All @@ -59,7 +59,13 @@ kill -TERM ${COPROC_PID}
wait ${COPROC_PID}

# check how many rows we have on source and target
sql="select count(*), sum(some_field) from table_a"
sql="select count(*), sum(f1) from table_a"
psql -d ${PGCOPYDB_SOURCE_PGURI} -c "${sql}" > /tmp/s.out
psql -d ${PGCOPYDB_TARGET_PGURI} -c "${sql}" > /tmp/t.out

diff /tmp/s.out /tmp/t.out

sql="select f1, f2 from table_a where f2 is not null order by f1"
psql -d ${PGCOPYDB_SOURCE_PGURI} -c "${sql}" > /tmp/s.out
psql -d ${PGCOPYDB_TARGET_PGURI} -c "${sql}" > /tmp/t.out

Expand Down
2 changes: 1 addition & 1 deletion tests/follow-data-only/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
--- This file implements DDL changes in the pagila database.

begin;
CREATE TABLE table_a ( id serial PRIMARY KEY, some_field int4 );
CREATE TABLE table_a (id serial PRIMARY KEY, f1 int4, f2 text);
commit;
8 changes: 7 additions & 1 deletion tests/follow-data-only/dml.sql
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
INSERT INTO table_a ( some_field ) SELECT generate_series(:a,:b);
INSERT INTO table_a (f1, f2)
SELECT x,
(array[E'test new\nline',
E'\\\\Client\\S$\\2023\\Dir1\\Test_Doc №2',
E'test \rreturn',
E'test ''single'' quote'])[(x - 1) % 4 + 1]
FROM generate_series(:a,:b) as t(x);
7 changes: 3 additions & 4 deletions tests/follow-data-only/multi-wal-txn.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

BEGIN;

INSERT INTO table_a(some_field) VALUES ((random() * 100 + 1)::int);
INSERT INTO table_a(f1) VALUES ((random() * 100 + 1)::int);

SELECT
pg_switch_wal();

INSERT INTO table_a(some_field) VALUES ((random() * 100 + 1)::int);
INSERT INTO table_a(f1) VALUES ((random() * 100 + 1)::int);

SELECT
pg_switch_wal();

INSERT INTO table_a(some_field) VALUES ((random() * 100 + 1)::int);
INSERT INTO table_a(f1) VALUES ((random() * 100 + 1)::int);

SELECT
pg_switch_wal();

COMMIT;

5 changes: 3 additions & 2 deletions tests/follow-data-only/run-background-traffic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ set -e
# Run transactions that insert a variable number of rows at a time. The number
# of rows inserted varies between 1 and 100. Each insert will occur in the
# background and finish quickly which avoids excessive connections.
sql="INSERT INTO table_a(f1) SELECT generate_series(1,(random() * 100 + 1)::int);"

while true; do
psql -d ${PGCOPYDB_SOURCE_PGURI} \
-c "INSERT INTO table_a(some_field) SELECT generate_series(1,(random() * 100 + 1)::int);" &
psql -d ${PGCOPYDB_SOURCE_PGURI} -c "${sql}" &
# To control the rate, we include a sleep of 0.1 seconds between each insert
# operation.
sleep 0.1
Expand Down
0