Hot answers tagged

4

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 birth 1988 ~/pset7/movies/ $


2

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. It will return a lot of results. Now the more columns you search the more result you will get. 2: This question is linked to the first as in the more letters ...


2

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

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

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 the names of the databases that you have created. To connect or disconnect to a particular db: ATTACH DATABASE DETACH DATABASE I'll leave it to you to ...


1

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 (:username, :hash)", username, password) is closest to correct. But no cigar. The part that's missing is where you tell the sql what to "substitute" for the bound ...


1

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

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 in a database that lives in a directory other than ~/login? If so, cd to that directory to run the program -OR- use full path in the SQL instance create command (...


1

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 and return the warning: if not result: return apology("You have not......") for example in the case where apology.html exists.


1

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 specific element from the SELECT result, eg stocks[0]['SUM(shares)']


1

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="hidden" name="projectId" value="{{ project["ID"] }}"> and projectId = request.form.get("projectId") in the ...


1

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 datetime('now') in command-line sqlite3 or phpliteadmin to see the result (no FROM is required). The problem with the Debugging snippet is at the end 'sell', ...


1

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


1

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. For example, I use a table CREATE TABLE 'transactions' ( 'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'user_id' INTEGER NOT NULL, [...], ...


1

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 in (and you don't need to explicitly list it in your query).


1

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 compiled with foreign key constraints enabled, it must still be enabled by the application at runtime, using the PRAGMA foreign_keys command. For example: sqlite&...


1

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 from the temp table matching on postal_code. Another approach would be to use sql and the concatenation operator to simply update the column in sql. The ...


1

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 duplicates. For example if id is the primary key on histories, it will only allow one row per user id.


1

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, symbol, stock_price, no_of_shares, total_cost) VALUES (:user_id, :symbol, :stock_price, :no_of_shares, :total_cost), user_id=user_id, symbol=symbol, ...


1

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


1

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

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 injection. Review the last 30 seconds of the register walkthrough for sample syntax, or the login function in application.py.


1

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 server. With GET the data is appended to the URL (for example when you search 'cats' on Google, you can see 'cats' in the search results' URL). POST carries the ...


1

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 have to be very (very) forgiving because there is a lot of bad code out there. If you validate your code (type="text") with a code validator (for example Nu Html ...


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