Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Can I access pre-existing SQL databases with this module? If not, what's a good third-party module for this kind of thing?
I just need to be able to pick up 2 columns from a table that is updated every day.
Please let me know if there's anything I should clarify. Thanks!
EDIT: I noticed that I wasn't asking about the right thing... I'm very unfamiliar with SQL and the one I use is connected to a server that needs login info and a host... can someone remove this question?
This is what the first parameter of the connect function is for:
import sqlite3
db = sqlite3.connect("C:/temp/MyLittleDatabase")
db.execute("CREATE TABLE IF NOT EXISTS T(x)")
db.execute("INSERT INTO T VALUES (42)")
cursor = db.execute("SELECT x FROM T")
for row in cursor:
print row[0]
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
I'm making a code in python with flask that deals with registering products, and I'm using buttons that allow me to edit and delete the product, I can't get it to edit the product every time I try, it doesn't give me an error but it doesn't get edited, I do not know how to fix it
I checked the query to mysql but it's not that, and I've been checking for a long time and I don't know what it is
I am using html, python, js
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
I have a large SQL script which is too large to run from SQL Server Management Studio.
Is there a way to run such a script using Python?
SQLite3 doesn't seem to work. I keep getting syntax errors but the query is standard SQL.
Is there an MSSQL equivalent library in Python?
Use cursor from a pyodbc connection.
cursor.execute(<sql code as string>)
cursor.commit()
If you use sqlalchemy, you can get the cursor from engine as follows:
engine.raw_connection().cursor()
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I've been trying to create a program that registers and logs in a user, the register part should store the details into a database but I've experienced a bit of trouble with taking input from the QT text box and inserting it into my database. It doesn't take any input from the text box, so I've tried to use qtsql to help me input data, but I can't manage to get it working.
#Register
def InsertData(self):
db=QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("/home/user/test.db")
if db.open():
query=QSqlQuery
query.exec_("INSERT INTO users(email_address,password) VALUES(?,?)",self.password.text,self.email.text)
db.commit()
db.close()
You can‘t get the value in your SQL statement, because you are not calling the object for password and email
Try:
val_password = self.password.text()
val_email = self.email.text()
query.exec_("INSERT INTO users(email_address,password) VALUES(?,?)",val_password, val_email)
I‘m not used to qtsql, but in sqlite you also have to assign a cursor to your sql connection, you might also want to check that.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am using the mysql.connector python library to connect to mysql. I need to display a table present in my database in a python program using the pyqt5 GUI framework.
This is me trying to print out the number of rows in my tables but even though i have 3 rows its showing up 0.
cursor=mydb.cursor()
command = "select * from MENU"
result = cursor.execute(command)
self.tableWidget.setRowCount(cursor.rowcount)
print(cursor.rowcount)
That is because you haven't fetched anything from the cursor yet.
As the docs say:
For nonbuffered cursors, the row count cannot be known before the rows have been fetched. In this case, the number of rows is -1 immediately after query execution and is incremented as rows are fetched.
So to fix you can get the cursor like this: cursor=mydb.cursor(buffered=True) or you can fetch all the results with something like results = cursor.fetchall().
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
What sql query can be used to search for a variable in a table, with the aim that the variable isn't there. How do I know if a value is in my table? Because I haven't found a search query yet.
I tried making the sql query a varible and setting it to true/false but that didn't work.
I created the table in sqlite it has the following fields ('CustomerID', 'UserName', 'FirstName', 'Password', 'Email') . I'm doing validation and I want to check if a username has already been used.
You could use a SQL check something like...
SELECT 1 AS userExists
FROM yourTable
WHERE userName = 'JoeBloggs'
LIMIT 1
(Return the value 1 for each row where the username is JoeBloggs, but limit the results to just one row.)
Then, in the python, check how many rows it returns. 0 rows = it doesn't exist, 1 row = it exists at least once.