Created
February 7, 2021 20:33
-
-
Save HectorTorres/516e0b9e62bdc676fe7a8d2fba6715f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyodbc | |
import time | |
import sys | |
import os | |
from datetime import datetime | |
from configparser import ConfigParser | |
dummyVar = 1 | |
va = 12 | |
vc = "Texto" | |
vd = "125.5" | |
ve = 35 | |
config = ConfigParser() | |
def getInfo(val,configuration): | |
config.read('C:/Users/HECTOR/Desktop/PythonTutorial/info.ini') | |
return config.get(configuration,val) | |
def insert(): | |
global dummyVar | |
stringConn = ('Driver={};\ | |
SERVER={};\ | |
DATABASE={};\ | |
UID={};\ | |
PWD={};\ | |
Trusted_Connection=no')\ | |
.format(getInfo('Driver','DataBase'), | |
getInfo('Server','DataBase'), | |
getInfo('Database','DataBase'), | |
getInfo('UID','DataBase'), | |
getInfo('PWD','DataBase'),) | |
vb = datetime.now() | |
print(stringConn) | |
conn = pyodbc.connect(stringConn) | |
conn.autocommit = True | |
cursor = conn.cursor() | |
dummyVar = dummyVar +1 | |
queryWrite = ("INSERT INTO dbo.testT3 (a,b,c,d,e) VALUES ('{}','{}','{}','{}','{}')".format(va,vb,vc,vd, ve)) | |
print(queryWrite) | |
cursor.execute(queryWrite) | |
queryRead = ('SELECT * FROM dbo.testT3') | |
cursor.execute(queryRead) | |
for row in cursor: | |
print(row) | |
if __name__ == '__main__': | |
print("Database test...") | |
while True: | |
try: | |
insert() | |
except OSError as e: | |
print("OSError {0}".format(e)) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment