mò &U²Ic@s‚dZdkZdkZdkZdkZdkZdklZlZdk Z y dk TWne j odk TnXdefd„ƒYZdefd„ƒYZdfd „ƒYZd efd „ƒYZd efd „ƒYZdefd„ƒYZdefd„ƒYZdZdZd„ZdZdZdZd„Zd„Zd„Zd„Zd„Z d„Z!dfd„ƒYZ"dS( s5$Id: dbtables.py 36901 2004-08-08 00:54:21Z tim_one $N(sListTypes StringType(t*t TableDBErrorcBstZRS(N(t__name__t __module__(((t+/data/zmath/lib/python2.4/bsddb/dbtables.pyR$stTableAlreadyExistscBstZRS(N(RR(((RR&stCondcBstZdZd„ZRS(s!This condition matches everythingcCsdS(Ni((tselfts((Rt__call__,s(RRt__doc__R (((RR*s t ExactCondcBs tZdZd„Zd„ZRS(s)Acts as an exact match condition functioncCs ||_dS(N(t strtomatchR(RR ((Rt__init__1scCs ||ijS(N(RRR (RR((RR 3s(RRR R R (((RR /s  t PrefixCondcBs tZdZd„Zd„ZRS(s9Acts as a condition function for matching a string prefixcCs ||_dS(N(tprefixR(RR((RR 8scCs|t|iƒ |ijS(N(RtlenRR(RR((RR :s(RRR R R (((RR6s  t PostfixCondcBs tZdZd„Zd„ZRS(s:Acts as a condition function for matching a string postfixcCs ||_dS(N(tpostfixR(RR((RR ?scCs|t|iƒ |ijS(N(RRRR(RR((RR As(RRR R R (((RR=s  tLikeCondcBs&tZdZeid„Zd„ZRS(sÇ Acts as a function that will match using an SQL 'LIKE' style string. Case insensitive and % signs are wild cards. This isn't perfect but it should work for the simple common cases. cCsfd}x$|D]}|i|d|ƒ}q W|iddƒ|_tid|id|ƒ|_dS(Ns.*+()[]?s\t%s.*t^t$(tchars_to_escapetchartlikestrtreplaceRtretcompiletre_flags(RRRRR((RR Js cCs|ii|ƒS(N(RRtmatchR(RR((RR Rs(RRR Rt IGNORECASER R (((RRDs t__TABLE_NAMES__s ._COLUMNS__cCs|tS(N(ttablet_columns(R!((Rt _columns_key[ss._DATA_.s ._ROWID_.icCs|t|t|S(N(R!t_datatcoltrowid(R!R%R&((Rt _data_keyfscCs|t|tS(N(R!R$R%(R!R%((Rt_search_col_data_keyiscCs|tS(N(R!R$(R!((Rt_search_all_data_keylscCs|t|tS(N(R!t_rowidR&(R!R&((Rt _rowid_keyoscCs|tS(N(R!R*(R!((Rt_search_rowid_keyrscCsh|itƒdjpB|itƒdjp,|itƒdjp|itƒdjodSndSdS(s‚Verify that the given string does not contain any metadata strings that might interfere with dbtables database operation. iiN(Rtfindt_table_names_keyR"R$R*(R((Rtcontains_metastringsusXt bsdTableDBcBsÈtZdddddd„Zd„Zd„Zdd„Zd„Zd„Zd „Zd „Z d „Z d „Z d „Z d„Z d„Zhhd„Zhd„Zhd„Zd„Zd„ZRS(Nii€c Cs“d|_t}|o|tO}nttBt Bt B|B} y|t O}Wntj onX|o| tB} ntƒ|_|iitƒ|ii||| Bƒ|o|tO}nt|iƒ|_|iidƒ|iitƒ|ii|t||B|ƒ||_ |ii!ƒ} yC|ii#t$| ƒp)|ii%t$t&i'gdƒd| ƒnWn| i(ƒ‚n X| i)ƒh|_*dS(sÇbsdTableDB.open(filename, dbhome, create=0, truncate=0, mode=0600) Open database name in the dbhome BerkeleyDB directory. Use keyword arguments when calling this constructor. ittxnN(+tNoneRtdbt DB_THREADtmyflagstcreatet DB_CREATEt DB_INIT_MPOOLt DB_INIT_LOCKt DB_INIT_LOGt DB_INIT_TXNtdbflagst flagsforenvtDB_AUTO_COMMITtAttributeErrortrecovert DB_RECOVERtDBEnvtenvt set_lk_detecttDB_LOCK_DEFAULTtopentdbhomettruncatet DB_TRUNCATEtDBtset_get_returns_nonet set_flagstDB_DUPtfilenametDB_BTREEtmodet dbfilenamet txn_beginR1thas_keyR.tputtpickletdumpstaborttcommitt_bsdTableDB__tablecolumns( RRNRGR6RHRPR@R<R5R1R=((RR „s>   -  cCs|iƒdS(N(Rtclose(R((Rt__del__³scCsX|idj o|iiƒd|_n|idj o|iiƒd|_ndS(N(RR3R2RZRC(R((RRZ¶s    cCs.y|ii|ƒWntj onXdS(N(RRCttxn_checkpointtminstDBIncompleteError(RR]((Rt checkpoint¾scCs+y|iiƒWntj onXdS(N(RR3tsyncR^(R((RR`ÄscCs›dGH|iiƒ}yc|iƒ\}}xJth||<ƒGH|iƒ}|o|\}}q,|i ƒdSq,WWnt j o|i ƒnXdS(s*Print the database to stdout for debuggings5******** Printing raw database for debugging ********iN( RR3tcursortcurtfirsttkeytdatatreprtnextRZtDBNotFoundError(RRbRgRdRe((Rt _db_printÊs   cCsod}y+t|ƒotdƒ‚nx+|D]#}t|ƒotdƒ‚q-q-Wt|ƒ}|i i |ƒo t d‚n|i iƒ}|i i|ti|dƒd|ƒti|i itd|dtƒƒ}|i|ƒ|i it|ƒ|i itti|dƒd|ƒ|iƒd}Wn7tj o+}|o|iƒnt|d‚nXdS(s’CreateTable(table, columns) - Create a new table in the database raises TableDBError if it already exists or for other DB errors. s-bad table name: contains reserved metastringss.bad column name: contains reserved metastringsstable already existsiR1tflagsN(R2R1R/R!t ValueErrortcolumnstcolumnR#tcolumnlist_keyRR3RSRRCRRRTRURVtloadstgetR.tDB_RMWt tablelisttappendtdeleteRXtDBErrortdberrorRWR(RR!RlR1RvRmRnRr((Rt CreateTableÜs4    % %  cCsst|ƒo td‚nt|ƒ}|ii|ƒpgSn|ii|ƒ}|ot i |ƒSngSdS(s\Return a list of columns in the given table. [] if the table doesn't exist. s-bad table name: contains reserved metastringsN( R/R!RkR#RnRR3RSRptpickledcolumnlistRURo(RR!RnRx((RtListTableColumnss   cCs2|iitƒ}|oti|ƒSngSdS(s)Return a list of tables in this database.N(RR3RpR.tpickledtablelistRURo(RRz((Rt ListTabless c Cs|y|i||ƒWnatj oUd}yt|ƒ}|i i ƒ}t i |i i|d|dtƒƒ}h}x|D]}||| '   cCswy|iit|ƒƒ}Wn#tj otd|f‚nX|ptd|f‚nti |ƒ|i |value mapping dictionaries. * columns is a list of which column data to return. If columns is None, all columns will be returned. * conditions is a dictionary keyed on column names containing callable conditions expecting the data string as an argument and returning a boolean. iN(RRYRSR!RRlR2R›RœRRuRvRtvalues(RR!RlRœRRv((RtSelectõs cCsö|ii|ƒp|i|ƒn|djo|i|}nxC||i ƒD]1}|i|i |ƒpt d|f‚qSqSWh}h} d„} |iƒ} | i| ƒ|iiƒ}d}x[| D]S\}}|d}t||ƒ}||jo d}nd}yÞ|i|ƒ\}} xÂ|t|ƒ |joª|t }| i|ƒpy| p || ƒo;|i|ƒph||