Forum Discussion

piasek's avatar
New Contributor
7 years ago

MS SQL database querying. How?


I am new to TC and have serious problem with getting data from the database. We use SQL Server and develop our tests in Python, so I would be looking for a Python solution if possible. What I exactly need is simple getting simple select result like in: 

sqlQuery = "select * from company where name= '" + companyName + "'"

The goal i to create a simple data access class, that will have a few methods, that take such query as argument and return result (handling opening and closing the connection in the process)

So far I have come up with something like that, but this works only for select count(*) from... query:

class DbHelper:
  def __init__(self):
    self.serv = Project.Variables.dbServer 

  def selectCountResult(self, sqlQuery):
    query = ADO.CreateADOQuery()
    query.ConnectionString = "DRIVER={SQL SERVER};SERVER=%s;DATABASE=4TransMDF;" % (self.serv)
    query.SQL = sqlQuery
    result = query.RecordCount
    return result

#end class


No RepliesBe the first to reply