Skip to main content
The 2024 Developer Survey results are live! See the results
36 votes
Accepted

Inserting robot moves into an SQLite3 database

Just a philosophical answer here. I think you're asking the wrong question. You shouldn't ask yourself "is my SQL code safe or vulnerable?" This is too hard to answer in any individual case, and ...
machine yearning's user avatar
18 votes

Inserting robot moves into an SQLite3 database

Your code is vulnerable to SQL injection! Use something like this to prevent it: ...
Grajdeanu Alex's user avatar
13 votes

Inserting robot moves into an SQLite3 database

There's no way for us tell, from reading this fragment of code, whether there is a SQL injection problem. On the one hand, the query is constructed using string interpolation, which is risky, but the ...
Gareth Rees's user avatar
  • 49.6k
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 ...
alecxe's user avatar
  • 17.3k
11 votes

Fetch live data from SQLite

I'm surprised nobody mentioned the code being vulnerable to SQL injection attacks: (XKCD source) Using string formatting and string concatenation to construct SQL queries is, first of all, unsafe ...
alecxe's user avatar
  • 17.3k
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: ...
defy's user avatar
  • 306
8 votes
Accepted

Sqlite.swift -- Selecting all rows and returning them in an array of tuples

Don't use tuples like this. The purpose of tuples is to make simple, short lived collections of values. For a use case like this, it is preferable to use a struct ...
Alexander's user avatar
  • 494
8 votes
Accepted

Fetch live data from SQLite

When it comes to SQLite, I like to first wrap everything related to database into its own class: ...
Grajdeanu Alex's user avatar
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 ...
Peilonrayz's user avatar
  • 43.4k
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: ...
301_Moved_Permanently's user avatar
7 votes

Find my colleagues

In geoload.py use with..as to ensure it is closed, even if any code in-between raises an exception: ...
Graipher's user avatar
  • 41k
7 votes

Find my colleagues

You can simplify geoload by using the requests package. In fact it says this in the urllib documentation: See also: The Requests package is recommended for a ...
Peilonrayz's user avatar
  • 43.4k
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 ...
aghast's user avatar
  • 12.4k
7 votes

School House Points (Python + SQLite)

DRY This repetitive code is an anti-pattern: blueTotal = 0 greenTotal = 0 redTotal = 0 yellowTotal = 0 Please define ...
J_H's user avatar
  • 30.8k
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 ...
Reinderien's user avatar
  • 62.8k
6 votes
Accepted

Find my colleagues

One function per file? I know you can do better than that. Compare geoload.py with: ...
301_Moved_Permanently's user avatar
6 votes

Python class to manage a table in SQLite

Security There is a security problem in your approach because you expose the database location. The minimum thing you could do would be to set DB_LOCATION to ...
Billal Begueradj's user avatar
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 ...
A. Romeu's user avatar
  • 1,065
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 ...
Ludisposed's user avatar
  • 11.6k
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 ...
QuasiStellar's user avatar
  • 2,249
6 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: ...
J_H's user avatar
  • 30.8k
5 votes

Managing a SQLite Database Connection

You don't need to create the database file if it doesn't exist, the SQLite driver will take care of it; to ensure your table does not exist on creation, you can ...
Stefano d'Antonio's user avatar
5 votes

Using SQLite in WPF Project

Refactoring for Modularity The whole point of using classes is making your code more modular. The ViewModel doesn't care about the database type. It could be SQLite, but it could also be PostgreSQL, ...
Queder's user avatar
  • 255
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 ...
Konrad Rudolph's user avatar
5 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 ...
Stephen Rauch's user avatar
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. ...
Pavlo Slavynskyy's user avatar
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 ...
mdfst13's user avatar
  • 21.6k
4 votes
Accepted

A class to create and modify SQLite3 databases with a terminal

Overall this looks good. Documentation and comments look pretty good, and the code is fairly sensible. Some comments: Beware of mutable default arguments! In particular, ...
alexwlchan's user avatar
  • 8,565
4 votes
Accepted

Extracting a conversation from a Skype sqlite database

First off, you should be using argparse for any argument parsing more complicated than python script.py arg1. It has automatic ...
Graipher's user avatar
  • 41k
4 votes
Accepted

Retrieve a number in a webpage and store in a SQLite3 db

Code smells your code is vulnerable to SQL injection attacks because you are using string formatting to put query parameters into a query. You need to proper parameterize your query with the help of ...
alecxe's user avatar
  • 17.3k

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