I'm trying to code up a small script which migrates data from a sql server database to a postgresql database.
I used pyodbc to connect to the sql server and did some test queries so far so good. Now for better structure i have decided to create a class for every database type e.g. PGManger and MSSQLManager.
Calling the same query from it's respective class instead of executing it directly yields an extra row with the value "none" and i am unable to figure out where this is comming from.
Code for the class looks like so:
import pyodbc
class MSSQLManger:
def __init__(self, connString):
self.conn = pyodbc.connect(connString)
self.cursor = self.conn.cursor()
def getTableNames(self):
cursor = self.cursor.execute("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'a%'
AND TABLE_TYPE = 'BASE TABLE';")
rows = cursor.fetchall()
for row in rows:
print(row)
Code in the "main" script:
from mssql import MSSQLManger
msql = MSSQLManger(conn_string)
print(msql.getTableNames())
Result is :
('tab_name1', )
('tab_name2', )
...
('tab_nameX', )
None
Now if get rid of the whole class thing, the None is gone, the question ist, where does it come from to begin with?