1

I want to access my database by using python script .

I can able to access all table by using

SELECT * FROM poorvika1.payment;

But i want to access the query by using VIEW Statement

SELECT * FROM poorvika1.pymentview;

This is my python script

import pyodbc

for py in pyodbc.drivers():
    print(py)
    
    
connection =pyodbc.connect(driver='SQL Server',server='localhost',database='test',uid='test',password='root')


cursor = connection.cursor()

for row in cursor.tables():
    print(row.table_name)

This Query is not working

cursor.execute('SELECT * FROM poorvika1.pymentview')

enter image description here

I want to access view query in pyodbc package

TallTed
  • 9,069
  • 2
  • 22
  • 37
Boxer Robert
  • 1,169
  • 2
  • 8
  • 14
  • Please [edit] your question to properly explain what you mean by "not working". Do you get an error? If so, what does it say? – Gord Thompson Oct 10 '20 at 12:28
  • @GordThompson https://i.stack.imgur.com/tbNGT.png please check this images link – Boxer Robert Oct 10 '20 at 12:50
  • The screenshot suggests that you are working with a MySQL_8 server, yet your connection string specifies `driver='SQL Server'` which is the driver for *Microsoft* SQL Server, so that will never work. If you really are hitting a MySQL database, consider using [mysqlclient](https://pypi.org/project/mysqlclient/) or [PyMySQL](https://pypi.org/project/pymysql/) instead of pyodbc. – Gord Thompson Oct 10 '20 at 13:45
  • For your understanding i created with mysql. But original one sql only. I connected sql several successfully. After connecting i can able to access store procedure and table also.but i want access views query – Boxer Robert Oct 10 '20 at 21:19
  • Okay, so you need to show what happens when you try running a SELECT against a SQL Server view via pyodbc. If you get an error then [edit] your question to include the complete stack trace. – Gord Thompson Oct 10 '20 at 22:27

1 Answers1

0

did you tried

cursor.execute('SELECT * FROM poorvika1..pymentview')

for row in cursor:
    print(row)
Manish Chaudhary
  • 498
  • 6
  • 14