sql_checker.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. sql_checker_tests = [
  2. ("drop table person;", True),
  3. ("create table person(name string, age int, classId int);", True),
  4. ("select age from person;", True),
  5. ("select * from person;", True),
  6. ("select gender from person;", "column `gender` not exists in `person`"),
  7. ("select 123 from person;", True),
  8. ("drop table class;", True),
  9. ("create table class (id int, grade int, faculty string);", True),
  10. ("select * from class where grade = 2 and faculty = 'Computer Science';", True),
  11. (
  12. "select * from class where grade = 2 and count=33;",
  13. "column `count` not exists in `class`",
  14. ),
  15. ("select age, class.grade from class, person;", True),
  16. (
  17. "select age, person.grade from class, person;",
  18. "column `person.grade` not exists in `class, person`",
  19. ),
  20. (
  21. """SELECT person.name, grade, faculty
  22. FROM person
  23. WHERE name = '张三' and classId IN (
  24. SELECT *
  25. FROM class
  26. WHERE class.id = classId
  27. );
  28. """,
  29. "column `grade` not exists in `person`",
  30. ),
  31. (
  32. """select person.name
  33. from person join class
  34. on class.id=person.classId and person.grade=2
  35. where age=22;
  36. """,
  37. "column `person.grade` not exists in `person, class`",
  38. ),
  39. (
  40. """select person.name
  41. from person join class
  42. on class.id=person.classId and class.grade=2
  43. where age=22;
  44. """,
  45. True,
  46. ),
  47. (
  48. """select person.name
  49. from person join class
  50. on class.id=person.classId and class.grade = 'zxc'
  51. where age=22;
  52. """,
  53. "column `class.grade` type is `int`, but `string:'zxc'` type is `string`, cannot `相等`",
  54. ),
  55. (
  56. """select person.name
  57. from person where age>name;
  58. """,
  59. "column `age` type is `int`, but `name` type is `string`, cannot `大于`",
  60. ),
  61. (
  62. """select person.name
  63. from person join class
  64. on age=22 and class.id=person.classId ;
  65. """,
  66. True
  67. )
  68. ]