Py Test Holder

  import pyodbc
import pyodbc as po
 
cnxn_str = (
        r'DRIVER=ODBC Driver 17 for SQL Server;'
        r'SERVER=(LocalDB)\MSSQLLocalDB;'
        r'Trusted_Connection=yes;'
        r'AttachDbFileName=D:\StockProject\tickertestdb.mdf;'
    )
 
try:
    # Connection string
    cnxn = po.connect(cnxn_str)
    cursor = cnxn.cursor()
    cursor2 = cnxn.cursor()
    
    stp = "Exec GetTickers"
    cursor.execute( stp )
    row = cursor.fetchone()
    while row:
        # Print the row
        print(row[0])
        
        cursor = cnxn.cursor()
        storedProc2 = "Exec WUP_FindCrosses @ScriptId = ?"
        params = (row[0])
        cursor2.execute( storedProc2, params )

        print("Fetch Success")
        row2 = cursor2.fetchone()
        try:
            while row2:
                # Print the row
                print(str(row2[0]) + " : " + str(row2[1] or '') )
                row2 = cursor2.fetchone()

            row = cursor.fetchone()
        except Exception as t:
            print("Error: %s" % t)            
    # Prepare the stored procedure execution script and parameter values
    # storedProc = "Exec WUP_FindCrosses @ScriptId = ?"
    # params = (1)
 
    # Execute Stored Procedure With Parameters
    # cursor.execute( storedProc, params )
 
    # Iterate the cursor
    # row = cursor.fetchone()
    # while row:
    #     # Print the row
    #     print(str(row[0]) + " : " + str(row[1] or '') )
    #     row = cursor.fetchone()
 
    # Close the cursor and delete it
    cursor.close()
    del cursor
 
    # Close the database connection
    cnxn.close()
 
except Exception as e:
    print("Error: %s" % e)

import pyodbc import pyodbc as po cnxn_str = ( r'DRIVER=ODBC Driver 17 for SQL Server;' r'SERVER=(LocalDB)\MSSQLLocalDB;' r'Trusted_Connection=yes;' r'AttachDbFileName=D:\StockProject\tickertestdb.mdf;' ) try: # Connection string cnxn = po.connect(cnxn_str) cursor = cnxn.cursor() cursor2 = cnxn.cursor() stp = "Exec GetTickers" cursor.execute( stp ) row = cursor.fetchone() while row: # Print the row print(row[0]) cursor = cnxn.cursor() storedProc2 = "Exec WUP_FindCrosses @ScriptId = ?" params = (row[0]) cursor2.execute( storedProc2, params ) print("Fetch Success") row2 = cursor2.fetchone() try: while row2: # Print the row print(str(row2[0]) + " : " + str(row2[1] or '') ) row2 = cursor2.fetchone() row = cursor.fetchone() except Exception as t: print("Error: %s" % t) # Prepare the stored procedure execution script and parameter values # storedProc = "Exec WUP_FindCrosses @ScriptId = ?" # params = (1) # Execute Stored Procedure With Parameters # cursor.execute( storedProc, params ) # Iterate the cursor # row = cursor.fetchone() # while row: # # Print the row # print(str(row[0]) + " : " + str(row[1] or '') ) # row = cursor.fetchone() # Close the cursor and delete it cursor.close() del cursor # Close the database connection cnxn.close() except Exception as e: print("Error: %s" % e)

Search This Blog

Link Within Related Posts Plugin for WordPress, Blogger...