55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
import pyodbc
|
|
|
|
try:
|
|
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("select HOST_NAME() as host_name")
|
|
|
|
print("[system function 1 - host_name results...]")
|
|
while 1:
|
|
row = cursor.fetchone()
|
|
if not row:
|
|
break
|
|
print("host name:",row.host_name)
|
|
|
|
print()
|
|
|
|
cursor.execute("select DB_NAME() as current_db_name")
|
|
print("[system function 2 - current database results...]")
|
|
|
|
while 1:
|
|
row = cursor.fetchone()
|
|
if not row:
|
|
break
|
|
print("current database name:", row.current_db_name)
|
|
|
|
print()
|
|
|
|
# sys func 3
|
|
prm_is_numeric = "202424"
|
|
cursor.execute("select ISNUMERIC(?) as is_numeric_value", prm_is_numeric)
|
|
|
|
print("[System function 3 - is numeric...]")
|
|
while 1:
|
|
row = cursor.fetchone()
|
|
if not row:
|
|
break
|
|
print("checking to see if param", prm_is_numeric, "is numeric. check resutl (0 / false, 1 / true):", row.is_numeric_value)
|
|
|
|
print()
|
|
|
|
cursor.close()
|
|
connection.close()
|
|
|
|
except pyodbc.Error as ex:
|
|
print()
|
|
print("exception: ",ex)
|
|
cursor.close()
|
|
connection.close()
|
|
print()
|
|
exit()
|
|
|
|
print()
|