def main(): global conn # Connect to a database # Set an optional parameter "use_std_interface" to "True" conn = python_ncbi_dbapi.connect('ftds', 'MSSQL', 'MS_DEV1', 'DBAPI_Sample', 'DBAPI_test', 'allowed', True) CreateSchema() CreateSaleStat() GetSaleStat()
def main(): global conn # Connect to a database # Set an optional parameter "use_std_interface" to "True" conn = python_ncbi_dbapi.connect('ftds', 'MSSQL', 'MSDEV1', 'DBAPI_Sample', 'DBAPI_test', 'allowed', True) CreateSchema() CreateSaleStat() GetSaleStat()
def main(): global conn # Connect to a database # Set an optional parameter "use_std_interface" to "True" conn = python_ncbi_dbapi.connect("ftds", "MSSQL", "MS_DEV1", "DBAPI_Sample", "DBAPI_test", "allowed", True) CreateSchema() CreateCustomers() GetCustomers() # Delete the customer, and all her orders. DeleteCustomers()
def main(): global conn # Connect to a database # Set an optional parameter "use_std_interface" to "True" conn = python_ncbi_dbapi.connect('ftds', 'MSSQL', 'MSDEV1', 'DBAPI_Sample', 'DBAPI_test', 'allowed', True) CreateSchema() CreateCustomers() GetCustomers() # Delete the customer, and all her orders. DeleteCustomers()
# # Author: Sergey Sikorskiy # # Description: a basic NCBI DBAPI Python extension module usage pattern # (import, connect, cursor, execute, fetchone) # # =========================================================================== # 1) Import NCBI DBAPI Python extension module import python_ncbi_dbapi # 2) Connect to a database # Parameters: connect(driver_name, db_type, server_name, db_name, user_name, user_pswd, use_std_interface) # driver_name: ctlib, dblib, ftds, odbc, mysql # db_type (case insensitive): SYBASE, MSSQL, MYSQL # server_name: database server name # db_name: default database name # use_std_interface: an optional parameter (default value is "False") conn = python_ncbi_dbapi.connect('ftds', 'MSSQL', 'MS_DEV1', 'DBAPI_Sample', 'anyone', 'allowed') # 3) Allocate a cursor cursor = conn.cursor() # 4) Execute a SQL statement cursor.execute('select qq = 57 + 33') # 5) Get a result result = cursor.fetchone() print result
# Author: Sergey Sikorskiy # # Description: a basic NCBI DBAPI Python extension module usage pattern # (import, connect, cursor, execute, fetchone) # # =========================================================================== # 1) Import NCBI DBAPI Python extension module import python_ncbi_dbapi # 2) Connect to a database # Parameters: connect(driver_name, db_type, server_name, db_name, user_name, user_pswd, use_std_interface) # driver_name: ctlib, ftds, odbc, mysql # db_type (case insensitive): SYBASE, MSSQL, MYSQL # server_name: database server name # db_name: default database name # use_std_interface: an optional parameter (default value is "False") conn = python_ncbi_dbapi.connect('ftds', 'MSSQL', 'MSDEV1', 'DBAPI_Sample', 'anyone', 'allowed') # 3) Allocate a cursor cursor = conn.cursor() # 4) Execute a SQL statement cursor.execute('select qq = 57 + 33') # 5) Get a result result = cursor.fetchone() print(result)
# # Author: Sergey Sikorskiy # # =========================================================================== import os, sys, python_ncbi_dbapi if os.environ['SYBASE'] == None : os.environ['SYBASE'] = "/netopt/Sybase/clients/current/" pswd_file = open( './.dblogin', 'r' ) db_params_line = pswd_file.readline().strip() db_params = db_params_line.split(':') db_name = db_params[0] conn = python_ncbi_dbapi.connect( 'ftds', 'MSSQL', db_name, db_params[1], db_params[2], db_params[3] ) cursor = conn.cursor() if len( sys.argv ) < 2 : print("Please, provide Taxid") sys.exit( 1 ) taxid = sys.argv[1] sql = "select * from Taxonomy where taxid = " + taxid cursor.execute( sql ) for record in cursor.fetchall() : print(record)
# Description: a NCBI DBAPI Python extension module usage example # (import, connect, cursor, execute, fetchone, fetchmany, fetchall) # # =========================================================================== # 1) Import NCBI DBAPI Python extension module import python_ncbi_dbapi # 2) Connect to a database # Parameters: connect(driver_name, db_type, server_name, db_name, user_name, user_pswd, use_std_interface) # driver_name: ctlib, dblib, ftds, odbc, mysql # db_type (case insensitive): SYBASE, MSSQL, MYSQL # server_name: database server name # db_name: default database name # use_std_interface: an optional parameter (default value is "False") conn = python_ncbi_dbapi.connect("ftds", "MSSQL", "MS_DEV1", "DBAPI_Sample", "anyone", "allowed") # 3) Allocate a cursor cursor = conn.cursor() # 4) Execute a SQL statement cursor.execute("select name, type from sysobjects") # 5) Fetch one records from a resultset using different functions # 5.1) Fetch one record using 'fetchone()' print "Fetch one record using 'fetchone()'" print cursor.fetchone() # 5.2) Fetch one record using 'fetchmany(1)' print "Fetch one record using 'fetchmany(1)'"