sqlite

Correctly Using Qmark (or Named) Style for SQL Queries

Correctly Using Qmark (or Named) Style for SQL Queries Question: I’ve got a a database filled with lots of data. Let’s make it simple and say the schema looks like this: CREATE TABLE foo ( col1 CHAR(25) PRIMARY KEY, col2 CHAR(2) NOT NULL, col3 CHAR(1) NOT NULL CONSTRAINT c_col2 (col2 = ‘an’ OR col2 = …

Total answers: 1

How do I ensure any object I create is saved in my django project?

How do I ensure any object I create is saved in my django project? Question: I’m working on a simple chat app that creates rooms for users to join. You enter your room name and it checks if the room exists already. If it does, you’re redirected to the room. If not, it creates a …

Total answers: 2

Dynamic SQL queries with SQLite3

Dynamic SQL queries with SQLite3 Question: I would like to allow users to query a sql database. The database is here So the user will be able to enter the queries they want: csr_city= input("Enter a city >>").lower().strip().replace(‘ ‘,”) csr_type = input("Enter a type >>").lower().strip() and then the query will execute: cur = conn.cursor() cur.execute(‘SELECT …

Total answers: 1

Read lines from .txt file into sql query

Read lines from .txt file into sql query Question: I want to run a .txt file line for line through an SQL query. The .txt file consists of songtitles that may or may not exist in the database. If there is more than one option that fits the songtitle in the database a selection menu …

Total answers: 1

Copying a table from an in-memory database to a on-disk database in sqlite3

Copying a table from an in-memory database to a on-disk database in sqlite3 Question: I want to copy one specific table from an in-memory sqlite database, using Python (3.9). Looking in the documentation, I should be able to simply attach the in-memory database to the file database, however while attaching throws no error, when I …

Total answers: 1

Python Sqlite and Excel output with headers and Row ID

Python Sqlite and Excel output with headers and Row ID Question: Please help to find correct solution from "simple to customize in future" point of view. I have SQLite table and very big select. After this select I got 5 column and any rows. I want to export this data to Special Excel file and …

Total answers: 1

how to send parameters with f-Strings in a sqllite query python

how to send parameters with f-Strings in a sqllite query python Question: how can i send a parameter to a query this is my code import pandas as pd import sqlite3 def query_brand(filter): sql_query = pd.read_sql(f’SELECT * FROM ps_lss_brands WHERE label = {filter}’, self.conn_brand) df = pd.DataFrame(sql_query, columns = [‘id_brand’, ‘label’]) # print(df["id_brand"][0]) print(df) query_brand("ACURA") …

Total answers: 1

Create ranking within set of rows resulting from GROUP BY

Create ranking within set of rows resulting from GROUP BY Question: I have the following table CREATE TABLE "results" ( "player" INTEGER, "tournament" INTEGER, "year" INTEGER, "course" INTEGER, "round" INTEGER, "score" INTEGER, ); With the following data sample for a single tournament / year / round-combination. 1 33 2016 895 1 20 2 33 2016 …

Total answers: 1

Iterator should return strings, not bytes (the file should be opened in text mode)

Iterator should return strings, not bytes (the file should be opened in text mode) Question: List item this is my code.. def import_excel(request): if request.method == ‘POST’: person_resource = PersonResource() dataset = Dataset() new_person = request.FILES[‘myfile’] if not new_person.name.endswith(‘csv’): messages.info(request,’Wrong format’) return render(request,’upload.html’) imported_data = dataset.load(new_person.read(),format=’csv’) for data in imported_data: value = Person( data[0], data[1], …

Total answers: 1

how to update sqlite python table Based on match between another table

how to update sqlite python table Based on match between another table Question: I tried to use the following code but it is giving errors: import sqlite3 conn = sqlite3.connect(‘stock.db’) cursor = conn.cursor() conn.execute("UPDATE COMSEC_STOCK SET COMSEC_STOCK.quantity = COMSEC_STOCK.quantity -1 FROM COMSEC_STOCK, Comsec_Out_Temp WHERE COMSEC_STOCK.product_id = Comsec_Out_Temp.product_id") cursor.close() conn.commit() Asked By: user21030066 || Source Answers: …

Total answers: 1