MCPcopy
hub / github.com/go-sql-driver/mysql / TestLoadData

Function TestLoadData

driver_test.go:1332–1431  ·  driver_test.go::TestLoadData
(t *testing.T)

Source from the content-addressed store, hash-verified

1330}
1331
1332func TestLoadData(t *testing.T) {
1333 runTests(t, dsn, func(dbt *DBTest) {
1334 verifyLoadDataResult := func() {
1335 rows, err := dbt.db.Query("SELECT * FROM test")
1336 if err != nil {
1337 dbt.Fatal(err.Error())
1338 }
1339
1340 i := 0
1341 values := [4]string{
1342 "a string",
1343 "a string containing a \t",
1344 "a string containing a \n",
1345 "a string containing both \t\n",
1346 }
1347
1348 var id int
1349 var value string
1350
1351 for rows.Next() {
1352 i++
1353 err = rows.Scan(&id, &value)
1354 if err != nil {
1355 dbt.Fatal(err.Error())
1356 }
1357 if i != id {
1358 dbt.Fatalf("%d != %d", i, id)
1359 }
1360 if values[i-1] != value {
1361 dbt.Fatalf("%q != %q", values[i-1], value)
1362 }
1363 }
1364 err = rows.Err()
1365 if err != nil {
1366 dbt.Fatal(err.Error())
1367 }
1368
1369 if i != 4 {
1370 dbt.Fatalf("rows count mismatch. Got %d, want 4", i)
1371 }
1372 }
1373
1374 dbt.db.Exec("DROP TABLE IF EXISTS test")
1375 dbt.mustExec("CREATE TABLE test (id INT NOT NULL PRIMARY KEY, value TEXT NOT NULL) CHARACTER SET utf8")
1376
1377 // Local File
1378 file, err := os.CreateTemp("", "gotest")
1379 defer os.Remove(file.Name())
1380 if err != nil {
1381 dbt.Fatal(err)
1382 }
1383 RegisterLocalFile(file.Name())
1384
1385 // Try first with empty file
1386 dbt.mustExec(fmt.Sprintf("LOAD DATA LOCAL INFILE %q INTO TABLE test", file.Name()))
1387 var count int
1388 err = dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&count)
1389 if err != nil {

Callers

nothing calls this directly

Calls 11

runTestsFunction · 0.85
RegisterLocalFileFunction · 0.85
RegisterReaderHandlerFunction · 0.85
ScanMethod · 0.80
mustExecMethod · 0.80
OpenMethod · 0.80
QueryMethod · 0.45
ErrorMethod · 0.45
NextMethod · 0.45
ExecMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected