Executing MSSQL File from Python 3.9 [closed] - python

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()

Related

Can i run a docker container from google sheet? [closed]

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 1 year ago.
Improve this question
I have, python code with i want to execute from google sheet.Maybe it is possible to do it with containers or it is not possible ?
It's possible using formulas.
Search: https://www.google.com/search?q=can+you+run+code+on+google+sheets
A tutorial:
https://towardsdatascience.com/using-r-and-python-in-google-sheets-formulas-b397b302098?gi=1610c314ad3e
With a bit of setup, you can create spreadsheet formulas for others to use that execute R, Python, or practically any programming language code!
^ excerpt from the tutorial
You could also try seeing if this topic helps: Trigger python code from Google spreadsheets?

get vaLues of MYSQL tables using mysql.connector module [closed]

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().

FileNotFoundError in SQL Server Python ML Services [closed]

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 use sql server ML(Python) and I have this problem when I use the [Pandas] library to read the file FileNotFoundError occurs
The Part Of Code:
df=pd.read_csv("C:\User\ussser\desktop\File.csv")
Error Picture :
To solve this problem, grant
ALL APPLICATION PACKAGES access to the Your directory.

driver to connect to mysql with python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i am trying to connect to a database and insert data with python.I found too many connector drivers like : mysql-connector,pymysql, MySQLdb. I want to know which way is better to communicate with database in python3.4 .
In our project we have remote machine with MySQL default client, we create SSH object of it and run sql query using traditional client. It's the most safe way and supports mostly everything with best optimized support.
However, if you want to prepare sql handle in python I will suggest go for pymysql, as pymysql is updated regularly & its very much stable & easy to use compared to others.
I would check out sqlalchemy http://www.sqlalchemy.org/. Or if you want more of an object-relational-manager then set up a small Django project https://www.djangoproject.com/.

Python: sqlite3 [closed]

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]

Categories