forked from apecloud/myduckserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: COPY FROM DATABASE (apecloud#173)
- Loading branch information
Showing
7 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
rm -f mysql.db mysql.db.wal mysql.bin .replica/* | ||
rm -f *.db *.db.wal *.bin .replica/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package pgserver | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestGuessStatementTag(t *testing.T) { | ||
tests := []struct { | ||
query string | ||
want string | ||
}{ | ||
{"SELECT * FROM table;", "SELECT"}, | ||
{"insert into table values (1);", "INSERT"}, | ||
{" UPDATE table SET col = 1;", "UPDATE"}, | ||
{"DELETE FROM table;", "DELETE"}, | ||
{"-- comment\nSELECT * FROM table;", "SELECT"}, | ||
{"/* block comment */ INSERT INTO table VALUES (1);", "INSERT"}, | ||
{"\n\n", ""}, | ||
{"INVALID QUERY", "INVALID"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
got := GuessStatementTag(tt.query) | ||
if got != tt.want { | ||
t.Errorf("GuessStatementTag(%q) = %q; want %q", tt.query, got, tt.want) | ||
} | ||
} | ||
} | ||
|
||
func TestRemoveLeadingComments(t *testing.T) { | ||
tests := []struct { | ||
query string | ||
want string | ||
}{ | ||
{"-- comment\nSELECT * FROM table;", "SELECT * FROM table;"}, | ||
{"/* block comment */ SELECT * FROM table;", "SELECT * FROM table;"}, | ||
{" \t\nSELECT * FROM table;", "SELECT * FROM table;"}, | ||
{"/* comment */ -- another comment\nSELECT * FROM table;", "SELECT * FROM table;"}, | ||
{"SELECT * FROM table;", "SELECT * FROM table;"}, | ||
{"", ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
got := RemoveLeadingComments(tt.query) | ||
if got != tt.want { | ||
t.Errorf("RemoveLeadingComments(%q) = %q; want %q", tt.query, got, tt.want) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE SCHEMA IF NOT EXISTS test_copy_db; | ||
|
||
USE test_copy_db; | ||
|
||
CREATE TABLE t (a int, b text); | ||
|
||
INSERT INTO t VALUES (1, 'a'), (2, 'b'), (3, 'c'); | ||
|
||
ATTACH 'test_copy_db.db' AS tmp; | ||
|
||
COPY FROM DATABASE mysql TO tmp; | ||
|
||
DETACH tmp; |