Changeset 52582cf in tol
- Timestamp:
- Oct 26, 2008, 10:36:44 AM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 6f22f5e
- Parents:
- e7bf535
- Location:
- tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/dynhlm
- Files:
-
- 2 edited
-
_db_api.tol (modified) (2 diffs)
-
_db_api.tools.tol (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/dynhlm/_db_api.tol
re7bf535 r52582cf 20 20 //Enables or disables SQL tracing 21 21 Real doQueryTrace = False; 22 22 //Enables or disables automatic SQL cache 23 Real allowAutoCache = False; 24 25 Struct CachedTableReg 26 { 27 Text table_; 28 Text path_; 29 Real file_; 30 Real numReg_ 31 }; 32 33 Real _autoCache = False; 34 Text _cacheQueryRootPath = ""; 35 Set _cachedTables = Copy(Empty); 36 37 Real SqlExecScript.NotImplemented(Text filePath) 38 { 39 WriteLn("[SqlExecScript.NotImplemented] Sorry assign " 40 "BysMcmc::Bsr::DynHlm::DBApi::SqlExecScript or disable "+ 41 "BysMcmc::Bsr::DynHlm::DBApi::allowAutoCache","E"); 42 Real Stop 43 }; 44 45 Code SqlExecScript = SqlExecScript.NotImplemented; 46 23 47 //Set of TOL alias for database tables 24 48 Set _.tableName = … … 58 82 Code SqlTableTrace; 59 83 Code SqlExecTrace; 84 Code SqlCachedTableFile; 85 Code SqlCachedInsert; 86 Code SqlStartCachedInsert; 87 Code SqlStopCachedInsert; 60 88 Code SqlFormatReal; 61 89 Code SqlFormatDate; -
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/dynhlm/_db_api.tools.tol
re7bf535 r52582cf 5 5 ////////////////////////////////////////////////////////////////////////////// 6 6 7 7 8 ////////////////////////////////////////////////////////////////////////////// 8 9 //Set current data base engine to MySQL … … 12 13 Text _.engine := SqlEngine::GesMys; 13 14 0 15 }; 16 17 ////////////////////////////////////////////////////////////////////////////// 18 //Trace and execute a non SELECT query returning nothing but success or not 19 Real SqlExecTrace(Text query) 20 ////////////////////////////////////////////////////////////////////////////// 21 { 22 If(doQueryTrace, 23 WriteLn("[Bsr::DynHlm::DBApi::SqlExecTrace] "+ 24 If(_autoCache,"CACHED","")+" "+ 25 "Query=\n"+query)); 26 DBExecQuery(query) 14 27 }; 15 28 … … 27 40 28 41 ////////////////////////////////////////////////////////////////////////////// 29 //Trace and execute a non SELECT query returning nothing but success or not30 Real SqlExecTrace(Text query)31 //////////////////////////////////////////////////////////////////////////////32 {33 If(doQueryTrace,34 WriteLn("[Bsr::DynHlm::DBApi::SqlExecTrace] Query=\n"+query));35 Real DBExecQuery(query);36 137 };38 39 //////////////////////////////////////////////////////////////////////////////40 42 Text SqlFormatDate(Date dte) 41 43 ////////////////////////////////////////////////////////////////////////////// … … 52 54 }; 53 55 56 ////////////////////////////////////////////////////////////////////////////// 57 // 58 Set SqlCachedTableFile(Text table) 59 ////////////////////////////////////////////////////////////////////////////// 60 { 61 Text id_table = ToName(table); 62 Real idx = FindIndexByName(_cachedTables,id_table); 63 If(idx, _cachedTables[idx], 64 { 65 Text path = _cacheQueryRootPath+id_table+".sql"; 66 Real file = FOpen(path,"w"); 67 Real FPutText(file,"INSERT INTO "+table+" VALUES"); 68 Set aux = CachedTableReg(table,path,file,0); 69 Set entry = SetOfSet(Eval(id_table+"=aux")); 70 Set Append(_cachedTables, entry); 71 Real SetIndexByName(_cachedTables); 72 entry[1] 73 }) 74 }; 75 76 ////////////////////////////////////////////////////////////////////////////// 77 // 78 Real SqlCachedInsert(Text table, Text values) 79 ////////////////////////////////////////////////////////////////////////////// 80 { 81 If(!_autoCache, 82 { 83 SqlExecTrace( 84 "INSERT INTO "+table+"\n"+ 85 "VALUES("+values+")") 86 }, 87 { 88 Set tabReg = SqlCachedTableFile(table); 89 Real FPutText(tabReg->file_, If(tabReg->numReg_,",","")+"\n"+ 90 "("+values+")"); 91 Real tabReg->numReg_ := tabReg->numReg_+1; 92 1 93 }) 94 }; 95 96 ////////////////////////////////////////////////////////////////////////////// 97 //Enables automatic cached queries 98 Real SqlStartCachedInsert(Real unused) 99 ////////////////////////////////////////////////////////////////////////////// 100 { 101 If(!allowAutoCache,1, 102 { 103 Real _autoCache := True; 104 Set _cachedTables := Copy(Empty); 105 //WriteLn("TRACE [SqlStartCachedInsert] 1"); 106 Text _cacheQueryRootPath := 107 Replace(TolAppDataPath,"\\","/")+"SqlScript/"+ 108 "tmp."+IntText(Rand(1,999999999))+"/"; 109 //WriteLn("TRACE [SqlStartCachedInsert] 2"); 110 WriteLn("[SqlStartCachedInsert] Storing SQL cache into "+ 111 _cacheQueryRootPath); 112 Real OSDirMake(_cacheQueryRootPath); 113 //WriteLn("TRACE [SqlStartCachedInsert] 3"); 114 1 115 }) 116 }; 117 118 ////////////////////////////////////////////////////////////////////////////// 119 //Disables automatic cached queries 120 Real SqlStopCachedInsert(Real unused) 121 ////////////////////////////////////////////////////////////////////////////// 122 { 123 Real ok = If(!allowAutoCache,1, 124 { 125 Real _autoCache := False; 126 Real ok.1 = SetMin(EvalSet(_cachedTables, Real(CachedTableReg tabReg) 127 { 128 Real FClose(tabReg->file_); 129 Text query = ReadFile(tabReg->path_); 130 Real ok.1.1 = SqlExecTrace(query); 131 //Real ok.1 = SqlExecScript(ReplaceSlash(tabReg->path_)); 132 Real ok.1.2 = OSFilRemove(tabReg->path_); 133 And(ok.1.1,ok.1.2) 134 })); 135 Real ok.2 = OSDirRemove(_cacheQueryRootPath); 136 Text _cacheQueryRootPath := ""; 137 Set _cachedTables := Copy(Empty); 138 And(ok.1,ok.2) 139 }); 140 ok 141 }; 54 142 55 143 //////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.
