예제 #1
0
 def ado_db_con(self, mode, host, db, user, password, proxy, proxy_port,
                sql, output_type):
     conn_parm = {
         'host': r"%s" % host,
         'database': db,
         'user': user,
         'password': password
     }
     conn_parm['connection_string'] = """Provider=SQLOLEDB.1;
     user ID=%(user)s; Password=%(password)s;
     Initial Catalog=%(database)s; Data Source= %(host)s"""
     if len(proxy) > 1:
         import adodbapi.remote as ado_lib
         conn_parm['proxy_host'] = proxy
         if len(proxy_port) > 1:
             conn_parm['proxy_port'] = proxy_port
         else:
             pass
     else:
         import adodbapi as ado_lib
     ado = ado_lib.connect(conn_parm)
     ado_cur = ado.cursor()
     if mode == 'w':
         try:
             ado_cur.execute(sql)
             ado.commit()
             ado.close()
             return True
         except Exception as err:
             print(err)
             return False
     else:
         if output_type == 'Dict':
             ado_cur.execute(sql)
             columns = [column[0] for column in ado_cur.description]
             raw_data = []
             for Row in ado_cur.fetchall():
                 raw_data.append(dict(zip(columns, Row)))
             ado.close()
             return raw_data
         else:
             ado_cur.execute(sql)
             raw_data = []
             for Row in ado_cur.fetchall():
                 for row_data in Row:
                     raw_data.append(row_data)
             ado.close()
             return raw_data
예제 #2
0
            kw_args[s[0]] = s[1]
            
kw_args.setdefault('filename', "test.mdb") # assumes server is running from examples folder
kw_args.setdefault('table_name', 'Products') # the name of the demo table

# the server needs to select the provider based on his Python installation
provider_switch = ['provider', 'Microsoft.ACE.OLEDB.12.0', "Microsoft.Jet.OLEDB.4.0"]

# ------------------------ START HERE -------------------------------------
#create the connection
constr = "Provider=%(provider)s;Data Source=%(filename)s"
if 'proxy_host' in kw_args:
    import adodbapi.remote as db
else:
    import adodbapi as db
con = db.connect(constr, kw_args, macro_is64bit=provider_switch)

if kw_args['table_name'] == '?':
    print('The tables in your database are:')
    for name in con.get_table_names():
        print(name)
else:
#make a cursor on the connection
    with con.cursor() as c:

        #run an SQL statement on the cursor
        sql = 'select * from %s' % kw_args['table_name']
        print(('performing query="%s"'  % sql))
        c.execute(sql)

        #check the results
예제 #3
0
            kw_args[s[0]] = s[1]
            
kw_args.setdefault('filename', "test.mdb") # assumes server is running from examples folder
kw_args.setdefault('table_name', 'Products') # the name of the demo table

# the server needs to select the provider based on his Python installation
provider_switch = ['provider', 'Microsoft.ACE.OLEDB.12.0', "Microsoft.Jet.OLEDB.4.0"]

# ------------------------ START HERE -------------------------------------
#create the connection
constr = "Provider=%(provider)s;Data Source=%(filename)s"
if 'proxy_host' in kw_args:
    import adodbapi.remote as db
else:
    import adodbapi as db
con = db.connect(constr, kw_args, macro_is64bit=provider_switch)

if kw_args['table_name'] == '?':
    print('The tables in your database are:')
    for name in con.get_table_names():
        print(name)
else:
#make a cursor on the connection
    with con.cursor() as c:

        #run an SQL statement on the cursor
        sql = 'select * from %s' % kw_args['table_name']
        print(('performing query="%s"'  % sql))
        c.execute(sql)

        #check the results