<commit_before># Test the lxd sql command.
test_sql() {
  # Invalid arguments
  ! lxd sql
  ! lxd sql foo "SELECT * FROM CONFIG"
  ! lxd sql global ""

  # Local database query
  lxd sql local "SELECT * FROM config" | grep -q "core.https_address"

  # Global database query
  lxd sql global "SELECT * FROM config" | grep -q "core.trust_password"

  # Global database insert
  lxd sql global "INSERT INTO config(key,value) VALUES('core.https_allowed_credentials','true')" | grep -q "Rows affected: 1"
  lxd sql global "DELETE FROM config WHERE key='core.https_allowed_credentials'" | grep -q "Rows affected: 1"

  # Standard input
  echo "SELECT * FROM config" | lxd sql global - | grep -q "core.trust_password"

  # Multiple queries
  lxd sql global "SELECT * FROM config; SELECT * FROM containers" | grep -q "=> Query 0"

  # Local database dump
  SQLITE_DUMP="${TEST_DIR}/dump.db"
  lxd sql local .dump | sqlite3 "${SQLITE_DUMP}"
  sqlite3 "${SQLITE_DUMP}" "SELECT * FROM patches" | grep -q invalid_profile_names
  rm -f "${SQLITE_DUMP}"

  # Local database schema dump
  SQLITE_DUMP="${TEST_DIR}/dump.db"
  lxd sql local .schema | sqlite3 "${SQLITE_DUMP}"
  sqlite3 "${SQLITE_DUMP}" "SELECT * FROM schema" | grep -q 1<commit_msg>tests: Fix negative tests in sql.sh<commit_after># Test the lxd sql command.
test_sql() {
  # Invalid arguments
  ! lxd sql || false
  ! lxd sql foo "SELECT * FROM CONFIG" || false
  ! lxd sql global "" || false

  # Local database query
  lxd sql local "SELECT * FROM config" | grep -q "core.https_address"

  # Global database query
  lxd sql global "SELECT * FROM config" | grep -q "core.trust_password"

  # Global database insert
  lxd sql global "INSERT INTO config(key,value) VALUES('core.https_allowed_credentials','true')" | grep -q "Rows affected: 1"
  lxd sql global "DELETE FROM config WHERE key='core.https_allowed_credentials'" | grep -q "Rows affected: 1"

  # Standard input
  echo "SELECT * FROM config" | lxd sql global - | grep -q "core.trust_password"

  # Multiple queries
  lxd sql global "SELECT * FROM config; SELECT * FROM containers" | grep -q "=> Query 0"

  # Local database dump
  SQLITE_DUMP="${TEST_DIR}/dump.db"
  lxd sql local .dump | sqlite3 "${SQLITE_DUMP}"
  sqlite3 "${SQLITE_DUMP}" "SELECT * FROM patches" | grep -q invalid_profile_names
  rm -f "${SQLITE_DUMP}"

  # Local database schema dump
  SQLITE_DUMP="${TEST_DIR}/dump.db"
  lxd sql local .schema | sqlite3 "${SQLITE_DUMP}"
  sqlite3 "${SQLITE_DUMP}" "SELECT * FROM schema" | grep -q 1
{'fraction_non_alphanumeric': 0.1193792280143255, 'fraction_numerical': 0.006366892160764027, 'mean_word_length': 3.919765166340509, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7417620', 'n_tokens_mistral': 857, 'n_tokens_neox': 802, 'n_words': 285}