You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
709 B

  1. package testfixtures
  2. import (
  3. "database/sql"
  4. "path/filepath"
  5. )
  6. // SQLite is the SQLite Helper for this package
  7. type SQLite struct {
  8. baseHelper
  9. }
  10. func (*SQLite) paramType() int {
  11. return paramTypeQuestion
  12. }
  13. func (*SQLite) databaseName(db *sql.DB) (dbName string) {
  14. var seq int
  15. var main string
  16. db.QueryRow("PRAGMA database_list").Scan(&seq, &main, &dbName)
  17. dbName = filepath.Base(dbName)
  18. return
  19. }
  20. func (*SQLite) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) error {
  21. tx, err := db.Begin()
  22. if err != nil {
  23. return err
  24. }
  25. if _, err = tx.Exec("PRAGMA defer_foreign_keys = ON"); err != nil {
  26. return err
  27. }
  28. if err = loadFn(tx); err != nil {
  29. return err
  30. }
  31. return tx.Commit()
  32. }