@@ -1054,22 +1054,36 @@ func TestLoadData(t *testing.T) {
10541054 dbt .Fatalf ("rows count mismatch. Got %d, want 4" , i )
10551055 }
10561056 }
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
10571062 file , err := ioutil .TempFile ("" , "gotest" )
10581063 defer os .Remove (file .Name ())
10591064 if err != nil {
10601065 dbt .Fatal (err )
10611066 }
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 ())
10641068
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+ }
10671079
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 ()
10701083 dbt .mustExec (fmt .Sprintf ("LOAD DATA LOCAL INFILE %q INTO TABLE test" , file .Name ()))
10711084 verifyLoadDataResult ()
1072- // negative test
1085+
1086+ // Try with non-existing file
10731087 _ , err = dbt .db .Exec ("LOAD DATA LOCAL INFILE 'doesnotexist' INTO TABLE test" )
10741088 if err == nil {
10751089 dbt .Fatal ("load non-existent file didn't fail" )
0 commit comments