™N έ/ŠEcs\dZkZdfd„ƒYZdfd„ƒYZdfd„ƒYZdfd„ƒYZd S( s! Members: class base indexable using a tuple of the DB-API v2.0 module and the single argument to be passed to the connect call the index call will return a class dbdict Example: dbwrap.base()[(pgdb, ":dbname")] clase dbdict(dbmod = None, dsn = None) can initalize w/o having to call the following two routines by hand setmod -> sets the DB-API v2.0 module to use setdsn -> sets the dsn string and connect to the db This is not normally called directly. Use the base class to get an instance. To use, index using the table name. It will return a tbdict instance. Example: dbdict['table'] class tbdict(db, cursor, table) db is the DB-API v2.0 module to use cursor is a cursor to use for all queries table is the name of the table we will work with append(dict) -> adds dict to table getfields() -> returns a list (that can change) containing all the columns of the table keys() -> returns a list of the data from the first column of the table (this may not be primary key of the table) values() -> returns a list of all rows has_key((column, value)) -> check to see if column has a row with value in it __getitem__(key) -> key can be a tuple, a dict, or an object representable as a string. If it is a tuple or a dict, it will return a rwdict using key. If it is a string, then we will return all values from the column that matches the string. __setitem__(key, value) -> calls rwdict's setdict w/ value. class rwdict(db, cursor, table, fields, key) All data is passed down through previous class. key can be a tuple (two or three elemnts) or a dict. If a tuple, it is (column, value [, ordered by]) If a dict: { 'field': column, 'key': value, ['orderby': orderedby,] } keys() -> returns a list of column minus the column the table is key'd on values() -> returns the first value that matches the passed in key getdict() -> returns a dict of the row getall() -> get all that match key srwdictcsSd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd „ZRS( Ncsχ||_||_||_||_d|_t|ƒtfƒjoB|d|_ |d|_t |ƒdjo|d|_nnEt|ƒthƒjo+|d|_ |d|_|d|_n|iod|i|_ n d|_ dS( Nsiiisfieldskeysorderbys order by %s( sdbsselfscurscursorstablesfieldssobdstypeskeyskeyfslensob(sselfsdbscurstablesfieldsskeys./jmpc/python/dbwrap.pys__init__Js"          csh|iidƒ oItd„|iƒ|_y|ii|iƒWntj onXn|iSdS(Nskeydictcs|dS(Ni(sx(sxs./jmpc/python/dbwrap.pys`s( sselfs__dict__shas_keysmapsfieldsskeydictsremoveskeyfs ValueError(sselfs./jmpc/python/dbwrap.pyskeys^s cs[|iidti|iƒdƒ|i|it|i ƒ|i ffƒ|ii ƒSdS(Ns!select %s from %s where %s = %s%ss,( sselfscursorsexecutesstringsjoinskeysstableskeyfsreprskeysobsfetchone(sselfs./jmpc/python/dbwrap.pysvalueshsJcsW|iƒ}|iƒ}h}x.tt|ƒƒdr}|||||ss,supdate %s set %s where %s = %ss'insert into %s (%s, %s) values (%s, %s)s'cs d|dS(Ns'(sx(sxs./jmpc/python/dbwrap.pyss(sstringsjoinsmapsvalueskeyssvaluessvlsselfscursorsexecutestableskeyfsreprskeysrowcountsdbscommit(sselfsvaluesstringsvls./jmpc/python/dbwrap.pyssetdict‹s -.g( s__init__skeyssvaluessgetdicts setfieldssgetalls __getitem__s __setitem__ssetdict(s./jmpc/python/dbwrap.pysrwdictIs     stbdictcsSd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd „ZRS( Ncs*|iid|ifƒ|iiƒSdS(Nsselect * from %s(sselfscursorsexecutestablesfetchall(sselfs./jmpc/python/dbwrap.pysgetall•scslk}k}|iid|i|i|iƒdƒ|it d„|i ƒƒdƒfƒ|i i ƒdS(Nsinsert into %s (%s) values (%s)s,cs t|ƒS(N(sreprsx(sxs./jmpc/python/dbwrap.pyss( sstringssyssselfscursorsexecutestablesjoinsvalueskeyssmapsvaluessdbscommit(sselfsvaluesstringssyss./jmpc/python/dbwrap.pysappend™sOcs@|iid|iƒ|ii|idt|iƒ+|iSdS(Nsselect * from %s limit 1i(sselfscursorsexecutestables descriptionsfieldsslen(sselfs./jmpc/python/dbwrap.pys getfields scsq|iid|idd|iƒg}x;|iiƒdr(}|i|idd|dfƒq=W|SdS(Nsselect %s from %%si( sselfscursorsexecutesfieldsstablesretsfetchallsisappend(sselfsretsis./jmpc/python/dbwrap.pyskeys¦s %&cs'|iid|iƒ|iiƒSdS(Nsselect * from %s(sselfscursorsexecutestablesfetchall(sselfs./jmpc/python/dbwrap.pysvalues―scs]|iid|idd|i|df|dƒ|iiƒ}ddg|tjSdS(Ns"select %s from %s where %s = '%%s'ii( sselfscursorsexecutesfieldsstableskeysfetchonestsNone(sselfskeysts./jmpc/python/dbwrap.pyshas_key³s6cs;||_||_||_g|_|iƒh|_dS(N(scursorsselfstablesdbsfieldss getfieldsskeydict(sselfsdbscursorstables./jmpc/python/dbwrap.pys__init__Έs      cs‘t|ƒtfƒjpt|ƒthƒjo,t|i|iiƒ|i|i|ƒSn3|iiƒ}|i d||ifƒ|i ƒSt d|‚dS(Nsselect %s from %ssinvalid key %s( stypeskeysrwdictsselfsdbscursorstablesfieldsscursexecutesfetchallsKeyError(sselfskeyscurs./jmpc/python/dbwrap.pys __getitem__Αs 2, csΊk}k}||i|ƒdSt|ƒt|iƒjo td‚n|i t d„|iƒdƒ}|i t d„|ƒdƒ}|i id|i|f|ƒ|iiƒdS(Ns num of data not equal to columnscs|dS(Ni(sx(sxs./jmpc/python/dbwrap.pysΦss,cs d|dS(Ns'(sx(sxs./jmpc/python/dbwrap.pysΧss insert into %s (%s) values (%%s)(stypessstringsselfskeyssetdictsvalueslensfieldss TypeErrorsjoinsmapssstscursorsexecutestablesdbscommit(sselfskeysvaluestypessstringsssts./jmpc/python/dbwrap.pys __setitem__Μs ! ( sgetallsappends getfieldsskeyssvaluesshas_keys__init__s __getitem__s __setitem__(s./jmpc/python/dbwrap.pystbdict”s      sdbdictcs,d„Zd„Zeed„Zd„ZRS(Ncs-|iidƒo td‚n||_dS(Nsdbmods Already set(sselfs__dict__shas_keysAttributeErrorsmodsdbmod(sselfsmods./jmpc/python/dbwrap.pyssetdbmodέs csE|iidƒo td‚n||_|ii|iƒ|_dS(Nsdsns Already set(sselfs__dict__shas_keysAttributeErrorsdsnsdbmodsconnectscon(sselfsdsns./jmpc/python/dbwrap.pyssetdsnγs  csGh|_| odSn|i|ƒ| odSn|i|ƒdS(N(sselfstablessdbmodssetdbmodsdsnssetdsn(sselfsdbmodsdsns./jmpc/python/dbwrap.pys__init__κs  csL|ii|ƒ o)t|i|iiƒ|ƒ|i|