13
votes
Accepted
Python class to manage a table in SQLite
I exposed the database connection and database cur as instance variables. Is that a good practice?
Having a cursor defined as an instance variable is a common practice. The problem though here is that ...
10
votes
Accepted
Searching for a word in a list of tuple extracted from a db via SQL
You could try doing the filtering at the database level. Something like:
...
10
votes
Accepted
Repository with SQLite in Python
We're using black, isort, ruff, and type checkers -- terrific!
Lots of best practices in ...
8
votes
Flagging employees whose spending is close to the budgeted amount
There's two ways you can go about this. Stick with your current way, or use SQL more.
Current way
I'd change your for loop to assign to one value.
I'd make a function that tells you if the values ...
8
votes
Accepted
Python update SQLite DB Values
SQL (and thus SQLite) support a variety of operators suitable (amongst others) in UPDATE statements.
This means that you can simplify your whole loop into a single statement:
...
8
votes
School House Points (Python + SQLite)
DRY
This repetitive code is an anti-pattern:
blueTotal = 0
greenTotal = 0
redTotal = 0
yellowTotal = 0
Please define
...
7
votes
Accepted
Python simple Class with sqlite and unit testing
This is an interesting question. Thanks for posting it!
IMO, you don't actually have a User class here. A User would be a system ...
7
votes
Accepted
Optimizing the insertion of 400 000 records in sqlite
Other than @PavloSlavynskyy's correct recommendation to add indices:
Whereas autocommit is off by default for the Python library, I doubt your code is doing what you think it's doing because as soon ...
7
votes
Accepted
Database schema for an upcoming comment hosting system
deps, topo sort order
The FK
DAG
induces a
topological order
across various DB objects, such as tables.
Consider writing these in a different order:
...
7
votes
Repository with SQLite in Python
Your code can benefit from a TypedDict or two.
Consider this assignment:
...
6
votes
Accepted
Flagging employees whose spending is close to the budgeted amount
I would say being a small code, you can change a couple things to make it a bit more readable
Specially the part with the conditionals, is a bit hard to follow
...
6
votes
Searching for a word in a list of tuple extracted from a db via SQL
You should remove the re.compile from the second for loop, this will save some time. You only have to compile once per word in ...
6
votes
School House Points (Python + SQLite)
Here are some hints on how to decrease the size of your code and make it more Pythonic.
Stack Ifs
Anytime you see stacked ifs, that are all basically the same, you should consider using a ...
6
votes
Accepted
Mapping named parameters to indices for PreparedStatement
Name of the class doesn't indicate its purpose.
The class is called "ParameterMap" but its use-case (filling in values in a query) doesn't need to know about it having a map somewhere inside ...
6
votes
Repository with SQLite in Python
Since I use SqlAlchemy with SQLite, here is my personal fix using SqlAlchemy events, basically these are hooks.
My models.py looks like this:
...
5
votes
Python update SQLite DB Values
Mathias’ answer is the correct way of solving your problem but since this is a code review site, let’s look at the rest of your code.
First off, your code style is fundamentally tidy and clear, so ...
5
votes
Optimizing the insertion of 400 000 records in sqlite
Indexes!
Tables basically has array-like access: to find something, an engine should check all the values in a table. If you have a big table, this can be slow. But there's a solution: indexes. ...
5
votes
Accepted
Searchable database with Java and SQL
Block form over statement form
if (!dBfile.exists())
createNewTable();
This is a risky pattern. Say you (or someone else, perhaps a Python ...
4
votes
Python class to manage a table in SQLite
To allow for more flexibility, I would give the user the ability to set the database location:
...
4
votes
Unwinding shortened URLs with Python, SQLite, and multithreading
__
There is liitle need for the __. A single _ should suffice to make people clear it's a ...
4
votes
Accepted
Simple one time pad cipher
The hard problems for one-time pads are
randomly generating the pad, and
securely sharing the pad between the participants (and nobody else).
The first problem is not solved, because the ...
4
votes
Accepted
Uploading songs from website to database and then to Spotify
Some simple suggestions after a first look at scraper.py:
class Song defines a method called ...
4
votes
Accepted
OOP bank account program in Python 3
Some suggestions:
Running this code through a linter such as flake8 will give you some hints towards producing more idiomatic code. You can also use Black to automatically format your code to be more ...
4
votes
RAII wrapper for SQLite transactions
There's not a lot of code here to be reviewed, but I'll have a go.
A small efficiency gain is possible, by moving the db_ argument in the initializer list, rather ...
4
votes
Accepted
Add as newest ID to SQLite Database
Really you don't need DR to be stored as it's a user convenience. That is you can add DR when extracting the value. You also don't need to check calculate the next number as SQlite can do this on your ...
4
votes
Gold Price Tracker Web Scraper using Python
General
There are so, so many examples of people scraping stock tracker sites. For beginners it's an understandable urge: you can see the data on the web, and you want to be able to translate those ...
4
votes
Accepted
decorator to execute sqlite statement
It's cool that you are experimenting, but from my point of view this is just trying to be fancy for no good reason.
How is this better than just executing the code safely at end of your ...
4
votes
Mapping named parameters to indices for PreparedStatement
commenting
var index = 1 // <-- JDBC starts counting with 1
Thank you for the
one-origin
reminder, that's a helpful comment.
...
4
votes
Database schema for an upcoming comment hosting system
In table users, there is a role field which I suspect may not really be used at present. But it could make sense to add one more ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sqlite × 227python × 87
java × 47
sql × 37
android × 37
c# × 30
python-3.x × 27
performance × 26
database × 26
object-oriented × 14
beginner × 13
php × 9
javascript × 8
python-2.x × 7
csv × 7
tkinter × 7
c++ × 6
design-patterns × 6
swift × 5
mvvm × 5
flask × 5
multithreading × 4
unit-testing × 4
bash × 4
xml × 4