move to folder in relation to like sections right
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
print()
|
||||
print("Successfully connected to SQL Server")
|
||||
print()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ", ex)
|
||||
print("closing program")
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,43 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
print("select before deleteing...")
|
||||
|
||||
cursor.execute("select * from tblCustomers")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
cursor.execute("delete from tblCustomers where id = 2")
|
||||
connection.commit()
|
||||
|
||||
print("select after deleting")
|
||||
cursor.execute("select * from tblCustomers")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,44 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
print("select before deleteing...")
|
||||
|
||||
cursor.execute("select * from tblCustomers")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
prm_code = "code6"
|
||||
cursor.execute("delete from tblCustomers where code = ?", prm_code)
|
||||
connection.commit()
|
||||
|
||||
print("select after deleting")
|
||||
cursor.execute("select * from tblCustomers")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,45 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
print("")
|
||||
print("select statement before insert")
|
||||
cursor.execute("select * from tblCustomers")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
print("inserting into tblCustomers...")
|
||||
cursor.execute("insert into tblCustomers values (6, 'code6', 'firstName6', 'lastName6')")
|
||||
connection.commit()
|
||||
|
||||
print("select statement after insert")
|
||||
cursor.execute("select * from tblCustomers")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
|
||||
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,46 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
print("")
|
||||
print("select statement before insert")
|
||||
cursor.execute("select * from tblCustomers")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
prm_id = 7
|
||||
prm_code = "code7"
|
||||
prm_first_name = "firstName7"
|
||||
prm_last_name = "lastName7"
|
||||
print("inserting into tblCustomers...")
|
||||
cursor.execute("insert into tblCustomers values (?, ?, ?, ?)", prm_id, prm_code, prm_first_name, prm_last_name)
|
||||
connection.commit()
|
||||
|
||||
print("select statement after insert")
|
||||
cursor.execute("select * from tblCustomers")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,58 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
|
||||
# wuery 1
|
||||
print("counting all records in table...")
|
||||
cursor.execute("select count(*) as total_records from tblCustomers")
|
||||
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.total_records)
|
||||
print("--- next query ----")
|
||||
|
||||
# query 2
|
||||
print("fetching server name...")
|
||||
cursor.execute("select @@SERVERNAME as server_name")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.server_name)
|
||||
print("--- next query ----")
|
||||
|
||||
# query 3
|
||||
print("some DMV stuff...")
|
||||
cursor.execute("select top 10 wait_type, wait_time_ms from sys.dm_os_wait_stats where wait_time_ms > 5 order by wait_time_ms desc")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.wait_type, row.wait_time_ms)
|
||||
|
||||
print("--- no more queries ... ----")
|
||||
|
||||
|
||||
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,29 @@
|
||||
import pyodbc
|
||||
|
||||
print()
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.execute("select @@version as version")
|
||||
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.version)
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
print("closing program")
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,28 @@
|
||||
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 * from tblCustomers")
|
||||
|
||||
print("[query results...]")
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,35 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
prmID = 5
|
||||
|
||||
cursor.execute("select * from tblCustomers where id = ?",prmID)
|
||||
|
||||
print("[Query results...]")
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ", ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
print("select table before updating")
|
||||
|
||||
cursor.execute("select * from tblCustomers")
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
cursor.execute("update tblCustomers set lastName = 'lastName New 5' where id = 5")
|
||||
connection.commit()
|
||||
|
||||
print("table after updating")
|
||||
cursor.execute("select * from tblCustomers")
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
@@ -0,0 +1,40 @@
|
||||
import pyodbc
|
||||
|
||||
try:
|
||||
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
print("select table before updating")
|
||||
|
||||
cursor.execute("select * from tblCustomers")
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
prm_id = 7
|
||||
cursor.execute("update tblCustomers set lastName = 'lastName New 7' where id = ?", prm_id)
|
||||
connection.commit()
|
||||
|
||||
print("table after updating")
|
||||
cursor.execute("select * from tblCustomers")
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(row.id, row.code, row.firstName, row.lastName)
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
except pyodbc.Error as ex:
|
||||
print()
|
||||
print("exception: ",ex)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
print()
|
||||
exit()
|
||||
|
||||
print()
|
||||
Reference in New Issue
Block a user