Hot answers tagged

3 votes
Accepted

How to test pset7 queries in the terminal window?

Are you running that in the terminal? (ie, not inside sqlite3)? A common problem is trying to run it at the sqlite3 prompt. ~/pset7/movies/ $ cat 2.sql | sqlite3 movies.db ...
  • 18.4k
2 votes
Accepted

2017 pset8 mashup: Slow search - how to improve search performance?

1: The more columns you are searching the more results you return. For example as you start to type the word "Boston" the search query takes 'B' and looks for every word in the column with a 'B' in it....
  • 96
2 votes
Accepted

Pset7 buy - RuntimeError sqlite3.OperationalError near transaction

transaction is a sqlite reserved word. You'll need to escape the column name with quotes (eg 'transaction') or create the table again and rename the column.
2 votes
Accepted

How to use multiple "WHERE" while updating table in sqlite

You can use the AND logic keyword, as below: UPDATE table SET field1=value1 WHERE field2=value2 AND field3=value3 There is also an OR keyword.
2 votes
Accepted

Pset 7 - create table (with foreign key) from command-line

I'll wager that you haven't connected to the database before executing the create table commamds, but that's just a guess on my part. You may find some other commands useful: .database will list ...
  • 64.7k
1 vote
Accepted

pset7 finance insert new row

There is no ? in cs50x 2018 version of sql; ":bound :variables" are used to mitigate sql injection attacks. Of the three "options" this db.execute("INSERT INTO users (username, hash) VALUES (:...
1 vote
Accepted

CS50 Finance ValueError: FOREIGN KEY constraint failed

A foreign key constraint fail usually means that the code is trying to insert something into table b with data that requires a field that must already exist in table a. In this case, I'd say that ...
  • 64.7k
1 vote

CS50 PSET7 Movies "query did not return results" 12.sql

Consider the potential problems that might result from hardcoding an id and running the query on a different database. Hint: you know the name of the person to look for.
1 vote
Accepted

My code gives error RuntimeError: no such table: File_Name

This is a clear and unambiguous error message. The connected database ("File_Name" in ~/login directory) does not have a table named "File_Name". Did you perhaps create the table ...
1 vote
Accepted

Check if query returns empty value

db.execute always returns an array, you can always print to the console to see its content, if your intention is to debug. If what you want is to warn the user, simply check that result is not null ...
  • 5,181
1 vote
Accepted

Runtime Error Unsupported Value in pset9 Finance

From the doc for execute in CS50 Library for Python Returns for SELECT, a list of dict objects, each of which represents a row in the result set The argument to the INSERT query needs to be a ...
1 vote
Accepted

Final Project: Problem to UPDATE table (Flask and SQLite) - RuntimeError ("unsupported value: {}".format(value))

There are a lot of problems that are visible. Firstly, when update is clicked, the projectId is not returned. This can be solved simply be adding the following statement in the form <input type=&...
  • 992
1 vote
Accepted

Pset8 Finance problems with SQLite inserting into a table

This datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') is not valid sqlite syntax. You can simply use datetime('now'). It will return the current datetime in YYYY-MM-DD HH:MM:SS format. Try SELECT ...
1 vote
Accepted

Finance PSET8: Error: execute() takes 2 positional arguments but 3 were given

The VALUES and parameters are switched up. The VALUES clause should be VALUES (:username,:password) The parameters would be username = username, password = password.
1 vote

Pset 7 - create table (with foreign key) from command-line

You could .open finance.db, or start with sqlite3 finance.db to open that specific file. Without an open file, the tables created are all temporary. I am not sure you got the term "foreign key" right....
  • 20.7k
1 vote

How to represent current date and time of purchase in table

How about making your time column in your table have a default value of CURRENT_TIMESTAMP so it gets filled in automatically. That way, each time you insert into transactions, the value will be put ...
  • 18.4k
1 vote
Accepted

Set foreign key in phpLiteAdmin

If by this recommended syntax for adding a column using SQLite does not appear to work. you mean foreign key is not enforced, check out section 2 in SQLite doc, which says Assuming the library is ...
1 vote
Accepted

How to insert data from a txt file to specific SQLite table column

You could do something like: make the text file have 2 columns, postal_code and full_location. Then import that file into a temp table. Then write a sql to update the places table with full_location ...
1 vote

db.execute() executing only single time

There is nothing in the posted code that would prevent the db.execute from executing more than one time. One possible explanation is the primary key or a unique index on the tables is preventing ...
1 vote
Accepted

`RuntimeError: no such column: user_id` pset7 [buy]

I solved it using this link Challenge inserting into database from buy() as a resource. The problem was with the placement of my quotes I changed db.execute("INSERT INTO transactions (user_id, ...
  • 231
1 vote
Accepted

Challenge inserting into database from buy()

I vote sophisticated :) The problem is :transaction_date, or lack thereof.
1 vote

Problem set 7 insert statement fails - RuntimeError: 'str' object has no attribute 'key'

It's bad syntax. Review walkthrough 2 around 2:20 to see how to properly set the bind variable arguments. You can also review the select query in the login route.
1 vote
Accepted

Finance: Update SQL Data: db.execute

If you don't use bound variables with the CS50 sql module, sqlite will read num_sell as a column name, thus the "no such column" error. You need to use bound variables ostensibly to prevent sql ...
1 vote

CS50 Pset7: Final Questions before Wrap-Up

I'm no expert, but I thought I'd give it a try since I just finished the problem set myself: Your questions 1 and 2 are related. GET and POST are methods that determine how data is submitted to the ...
  • 13
1 vote
Accepted

CS50 Pset7: Final Questions before Wrap-Up

The button does the action defined in the action attribute of the <form> tag. text is not a valid type for a button (see MDN doc on button and form) but it doesn't fail because, well, browsers ...

Only top scored, non community-wiki answers of a minimum length are eligible