World Cup Database - CodeRoad refuses to recognize my worldcup db when I change insert_data.sh file

Tell us what’s happening:
I already finished my WC database project, but I can’t proceed to submit it. Since the beginning I noticed whenever I edit my insert_file.sh file, the CodeRoad stops recognizing every completed step, even the most basic one ( You should create a database named worldcup).

I thought about just downloading the files and submitting them, but I can’t either.

I tried to upload screenshots but I apparently can’t since I’m a new user.

Edit: Tried resetting CodeRoad, for a second it seemed like it worked except I still had to give .sh files executable permissions, and when I did, again coderoad tells me that I still have to create the worldcup database.

Your code so far
insert_info.sh:

#! /bin/bash

if [[ $1 == "test" ]]
then
  PSQL="psql --username=postgres --dbname=worldcuptest -t --no-align -c"
else
  PSQL="psql --username=freecodecamp --dbname=worldcup -t --no-align -c"
fi

# Do not change code above this line. Use the PSQL variable above to query your database.

cat games.csv | while IFS="," read year round winner opponent winner_goals opponent_goals
do
  if [[ $year != "year" ]]
  then
    # ADD TO TEAMS
    $($PSQL"INSERT INTO teams(name) VALUES('$winner')")
    $($PSQL"INSERT INTO teams(name) VALUES('$opponent')")

    # ADD TO GAMES
    # find teams IDs
    WINNER_ID=$($PSQL "SELECT team_id FROM teams WHERE name='$winner'")
    OPPONENT_ID=$($PSQL "SELECT team_id FROM teams WHERE name='$opponent'")

    # insert into table games
    $($PSQL"INSERT INTO games(year, round, winner_id, opponent_id, winner_goals, opponent_goals) VALUES($year, '$round', $WINNER_ID, $OPPONENT_ID, $winner_goals, $opponent_goals)")
  fi
  # if not, add it
done 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

Challenge: World Cup Database - Build a World Cup Database

Link to the challenge:

Hey sth similar happenned to me that every time I made some progress and left I had to redo it all over again. This worked for me:

PS: Make sure to have all your progress saved locally before doing it.

You can check it here Running the Relational Database Curriculum in your Browser

FIXED! It was apparently because the insert into commands were throwing errors to the terminal, that made CodeRoad say “nope this is wrong”.
Just an echo before the psql command and it goes smoothly.

1 Like

Hi, can you type more specific how to solve this problem - where do you put echo?

Right before PSQL queries. I finally ended up doing it more like FCC teaches to: Assign the querie to a RESULT variable.

ie:

Thanks, I tried adding echo before # ADD TO TEAMS queries like

echo $($PSQL "INSERT INTO teams(name) VALUES('$WINNER')")
echo $($PSQL "INSERT INTO teams(name) VALUES('$OPPONENT')")

or

INSERT_RESULT= $($PSQL"INSERT INTO teams(name) VALUES('$WINNER')")
INSERT_RESULT=$($PSQL "INSERT INTO teams(name) VALUES('$OPPONENT')")

but still CodeRoad is not progressing and tells me that I have to create worldcup database, despite the fact that the data gets inserted correctly into tables.

Isn’t the terminal showing any error message at all? Because I think that’s what messes up with CodeRoad.

SOLVED - I forgot to put echo in front of the last query, my bad:) Now CodeRoad approves

cat games.csv | while IFS="," read YEAR ROUND WINNER OPPONENT WINNER_GOALS OPPONENT_GOALS 
do
  if [[ $YEAR != "year" ]]
  then
    # ADD TO TEAMS
    echo $($PSQL "INSERT INTO teams(name) VALUES('$WINNER')")
    echo $($PSQL "INSERT INTO teams(name) VALUES('$OPPONENT')")

    # ADD TO GAMES
    # find teams IDs
    WINNER_ID=$($PSQL "SELECT team_id FROM teams WHERE name='$WINNER'")
    OPPONENT_ID=$($PSQL "SELECT team_id FROM teams WHERE name='$OPPONENT'")
 
    # insert into table games
    echo $($PSQL"INSERT INTO games(year, round, winner_id, opponent_id, winner_goals, opponent_goals) VALUES($YEAR, '$ROUND', $WINNER_ID, $OPPONENT_ID, $WINNER_GOALS, $OPPONENT_GOALS)")
  fi
  # if not, add it
done 
1 Like