datacamp / sqlwhat

https://sqlwhat.readthedocs.io
GNU Affero General Public License v3.0
3 stars 8 forks source link

Add a better example for INSERT INTO #134

Open richierocks opened 5 years ago

richierocks commented 5 years ago

The docs give this INSERT INTO example.

Solution

INSERT INTO company VALUES (2, 'filip', 28, 'sql-lane', 42)

SCT

Ex().check_query('SELECT COUNT(*) AS c FROM company').has_equal_value()

This is weak because it only check that a row was added, not the contents.

I suggest a better check to include in the documentation.

Ex().check_correct(
  check_query("SELECT COUNT(*) FROM company WHERE name = 'filip' AND age = 28 AND street = 'sql-lane' AND house_number = 42").has_equal_value(incorrect_msg = "Did you use `INSERT INTO` to insert a row into `company`?"),
  multi(
    check_query("SELECT COUNT(*) FROM company WHERE name = 'filip'").has_equal_value(incorrect_msg = "Did you insert a row into `company` with `name` equal to `'filip'`?"),
    check_query("SELECT COUNT(*) FROM company WHERE age = 28").has_equal_value(incorrect_msg = "Did you insert a row into `company` with `age` equal to `28`?"),
    check_query("SELECT COUNT(*) FROM company WHERE street = 'sql-lane'").has_equal_value(incorrect_msg = "Did you insert a row into `company` with `street` equal to `'sql-lane'`?"),
    check_query("SELECT COUNT(*) FROM company WHERE house_number = 42").has_equal_value(incorrect_msg = "Did you insert a row into `company` with `house_number` equal to `42`?")
  )
)