def get_volume(dsn, year): conn=ODBC.connect(dsn=dsn, user="", password="") cursor=conn.cursor() query='select kind, V1 as mol1, V2 as mol2, Vsr as srd, Vpr as prs, VIspper as spl_per, Vper as per from "S%s$"' % year #print query cursor.execute(query) #print cursor.description #print cursor.fetchall() rc=ModelParameter() data=cursor.fetchone() s=0 while data: (kind, mol1, mol2, srd, prs, spl_per, per)=data spl=spl_per - per kind=int(kind) setattr(rc, "mol1_%i" % kind, mol1) setattr(rc, "mol2_%i" % kind, mol2) setattr(rc, "srd_%i" % kind, srd) setattr(rc, "prs_%i" % kind, prs) setattr(rc, "spl_%i" % kind, spl) setattr(rc, "per_%i" % kind, per) s+=mol1+ mol2+ srd+ prs+ spl_per data=cursor.fetchone() print "Summ vol:", s return ModelParameter({"V":rc})
def __init__(self, dsn, regions, last_year=2050, tree_names=[], **keyargs): global ForestKind self.dsn=dsn self.last_year=last_year tree_names=FOREST_KIND self.regions=regions self.conn=ODBC.connect(dsn=dsn, user="", password="") ForestModel.__init__(self, tree_names, **keyargs) self.options["culture_kind"]=101 # i.e. Sosna
def connect(self): """ Установить связь с БД. """ self.disconnect() connection_string = self.getConnectionString() try: self.connection = mx_odbc.DriverConnect(connection_string) except: io_prnt.outErr( u'ODBC: Ошибка установления связи с БД. ConnectionString: <%s>' % connection_string) return self.connection
def __init__(self, dsn, **keyargs): conn=ODBC.connect(dsn=dsn, user="", password="") c=conn.cursor() c.execute("select P34, LESX from bd_les_o") all=c.fetchall() n=[] for (year, name) in all: try: if int(year)>0: n.append(int(name)) except ValueError: pass #print n #n=[11252218,11252207] #n=[11252218] GISForestModel.__init__(self, dsn, n, **keyargs)
def __init__(self, dsn, year=1973, tree_names=[], **keyargs): global ForestKind self.dsn=dsn self.year=year if DEBUG<10: self.conn=ODBC.connect(dsn, user="", password="", clear_auto_commit=0) cursor=self.conn.cursor() cursor.execute('select Kind from "S%s$"' % year) fks=cursor.fetchall() if fks is None: raise ValueError, "wrong year is given (returned empty set)" tree_names=map(lambda (x,): int(x), fks) else: tree_names=[101,102,103,104,105,124,125] #tree_names=[101] if DEBUG: print "tree_names:", tree_names #raw_input("Connect debugger") ForestModel.__init__(self, tree_names, **keyargs) self.options["culture_kind"]=101 # i.e. Sosna
import mx.ODBC.Windows as odbc import dbcp # contains pp function conn = odbc.connect("MyDSN") curs = conn.cursor() curs.execute("""SELECT Name, LinkText, Pageset FROM StdPage ORDER BY PageSet, Name""") rows = curs.fetchall() print "\n\nWithout rowlens:" print dbcp.pp(curs, rows) print "\n\nWith rowlens:" print dbcp.pp(curs, rows, rowlens=1) conn.close()
import mx.ODBC.Windows as odbc #To find out what you can use to access the database, run this command #datasource = odbc.DataSources() #2 possible ways to hit an access file driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:/tmp/a.mdb' #driv2='FILEDSN=c:/tmp/a.mdb' conn = odbc.DriverConnect(driv) c = conn.cursor() c.execute ("select * from the_table_name where columna = 'fred'") #get column names cols= [ i[0] for i in c.description ] print('\n\ncols=',cols) ##print '\n\n',c.fetchone() rows = c.fetchall() print('\n\n','length of rows: ',len(rows)) print('\n\n') cnt = 0 for r in rows: cnt += 1 print(cnt,' ',r) if cnt > 10: break
import dtuple import mx.ODBC.Windows as odbc flist = ["Name", "Num", "LinkText"] descr = dtuple.TupleDescriptor([[n] for n in flist]) conn = odbc.connect("HoldenWebSQL") # Connect to a database curs = conn.cursor() # Create a cursor sql = """SELECT %s FROM StdPage WHERE PageSet='Std' AND Num<25 ORDER BY PageSet, Num""" % ", ".join(flist) print sql curs.execute(sql) rows = curs.fetchall() for row in rows: row = dtuple.DatabaseTuple(descr, row) print "Attribute: Name: %s Number: %d" % (row.Name, row.Num or 0) print "Subscript: Name: %s Number: %d" % (row[0], row[1] or 0) print "Mapping: Name: %s Number: %d" % (row["Name"], row["Num"] or 0) conn.close()
def __init__(self,dsn,isTemporary=False): #self.dbapi = sqlite self._dbconn = odbc.connect(dsn) self._isTemporary = isTemporary self._dsn = dsn
def __init__(self, dsn, isTemporary=False): #self.dbapi = sqlite self._dbconn = odbc.connect(dsn) self._isTemporary = isTemporary self._dsn = dsn