| 1 |
## Sql_Get.py
|
| 2 |
## This program will serve as a funtion that will allow me to get information from the mw repository.
|
| 3 |
## It shouldent be run as a program but instead be imported and run once when a program needs a new
|
| 4 |
## list of info. For example a firm dir program should only update a static list once a day and get
|
| 5 |
## its info from the list and not reconnect to the server everytime.
|
| 6 |
|
| 7 |
|
| 8 |
import dbi
|
| 9 |
import odbc
|
| 10 |
|
| 11 |
def Connect_to_db(CS_RetrieveList):
|
| 12 |
""" This program takes one argument and returns the huge list. The one argument, which is what you want
|
| 13 |
returned, should be seperated by a comma and a space. (case matters!)"""
|
| 14 |
myconn = odbc.odbc('MW_repository')
|
| 15 |
mycursor = myconn.cursor()
|
| 16 |
#mycursor.execute('SELECT NetLogin, NameFull FROM Employees')
|
| 17 |
mycursor.execute('SELECT %s FROM Employees'% CS_RetrieveList)
|
| 18 |
mydata = mycursor.fetchall()
|
| 19 |
mycursor.close()
|
| 20 |
myconn.close()
|
| 21 |
return mydata
|
| 22 |
|
| 23 |
if __name__ == '__main__':
|
| 24 |
#sql_data will give you a list of tuples that will need to be converted to a list of strings.
|
| 25 |
sql_data = Connect_to_db('NetLogin, NameFull')
|
| 26 |
w = open('u:\\sql.txt','w')
|
| 27 |
w.writelines(sql_data)
|
| 28 |
w.close() |