@@ -1054,22 +1054,36 @@ func TestLoadData(t *testing.T) {
1054
1054
dbt .Fatalf ("rows count mismatch. Got %d, want 4" , i )
1055
1055
}
1056
1056
}
1057
+
1058
+ dbt .db .Exec ("DROP TABLE IF EXISTS test" )
1059
+ dbt .mustExec ("CREATE TABLE test (id INT NOT NULL PRIMARY KEY, value TEXT NOT NULL) CHARACTER SET utf8" )
1060
+
1061
+ // Local File
1057
1062
file , err := ioutil .TempFile ("" , "gotest" )
1058
1063
defer os .Remove (file .Name ())
1059
1064
if err != nil {
1060
1065
dbt .Fatal (err )
1061
1066
}
1062
- file .WriteString ("1\t a string\n 2\t a string containing a \\ t\n 3\t a string containing a \\ n\n 4\t a string containing both \\ t\\ n\n " )
1063
- file .Close ()
1067
+ RegisterLocalFile (file .Name ())
1064
1068
1065
- dbt .db .Exec ("DROP TABLE IF EXISTS test" )
1066
- dbt .mustExec ("CREATE TABLE test (id INT NOT NULL PRIMARY KEY, value TEXT NOT NULL) CHARACTER SET utf8" )
1069
+ // Try first with empty file
1070
+ dbt .mustExec (fmt .Sprintf ("LOAD DATA LOCAL INFILE %q INTO TABLE test" , file .Name ()))
1071
+ var count int
1072
+ err = dbt .db .QueryRow ("SELECT COUNT(*) FROM test" ).Scan (& count )
1073
+ if err != nil {
1074
+ dbt .Fatal (err .Error ())
1075
+ }
1076
+ if count != 0 {
1077
+ dbt .Fatalf ("unexpected row count: got %d, want 0" , count )
1078
+ }
1067
1079
1068
- // Local File
1069
- RegisterLocalFile (file .Name ())
1080
+ // Then fille File with data and try to load it
1081
+ file .WriteString ("1\t a string\n 2\t a string containing a \\ t\n 3\t a string containing a \\ n\n 4\t a string containing both \\ t\\ n\n " )
1082
+ file .Close ()
1070
1083
dbt .mustExec (fmt .Sprintf ("LOAD DATA LOCAL INFILE %q INTO TABLE test" , file .Name ()))
1071
1084
verifyLoadDataResult ()
1072
- // negative test
1085
+
1086
+ // Try with non-existing file
1073
1087
_ , err = dbt .db .Exec ("LOAD DATA LOCAL INFILE 'doesnotexist' INTO TABLE test" )
1074
1088
if err == nil {
1075
1089
dbt .Fatal ("load non-existent file didn't fail" )
0 commit comments