/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct SOdbcQuery = [ SQLIQ_sName : S, SQLIQ_sQuery : S, SQLIQ_sOutput : S ] mkSOdbcQuery;; fun saveList(l)= let sizelist l -> size in let nil -> ndata in let 0 -> i in ( while i < size do ( let nth_list l i -> [name qstr] in set ndata = [(strcat "queryName" (itoa i)) name]:: [(strcat "querySql" (itoa i)) qstr.SQLIQ_sQuery]:: [(strcat "queryOut" (itoa i)) qstr.SQLIQ_sOutput]:: ["ACTION" (strcat "Exec " name)]:: ["EVENT" (strcat "Result " name)]::ndata; set i = i + 1; ); ndata; );; fun cbCloseEdit(p)= let p -> [ctrldbname ctrldblogin ctrldbpass ctrldbutf8 dlqstr] in let dlqstr -> [lqstr] in let getEdCtrlTextLineValue ctrldbname -> dbname in let getEdCtrlTextLineValue ctrldblogin -> dblogin in let getEdCtrlTextLineValue ctrldbpass -> dbpass in let getEdCtrlCheckState ctrldbutf8 -> dbutf8 in ["dbname" dbname]:: ["dblogin" dblogin]:: ["dbpass" dbpass]:: ["dbutf8" itoa dbutf8]:: (saveList lqstr);; fun loadQueries(inst)= let nil -> l in let nil -> query in let 0 -> i in ( while ((set query = getPluginInstanceParam inst (strcat "queryName" (itoa i))) != nil) do ( let getPluginInstanceParam inst (strcat "querySql" (itoa i)) -> sql in let getPluginInstanceParam inst (strcat "queryOut" (itoa i)) -> out in let mkSOdbcQuery[query sql out] -> qstr in set l = [query qstr]::l; set i = i + 1; ); revertlist l; );; fun addQuery(l, name, sql, out)= let switchstr l name -> qstr in if (qstr != nil) then l else let mkSOdbcQuery[name sql out] -> qstr in set l = lcat l [name qstr]::nil;; fun removeQuery(l, name)= set l = remove_sid_from_list l name;; fun getQueryByName(l, name)= switchstr l name;; fun updateQuery(qstr, sql, out)= set qstr.SQLIQ_sQuery = sql; set qstr.SQLIQ_sOutput = out; 0;; fun cbRefreshBtn(pickbtn, p)= let p -> [ctrlobjname] in setEdCtrlTextLineValue ctrlobjname ""; 0;; fun fillQueriesList(ctrllist, lqstr)= while (lqstr != nil) do ( let hd lqstr -> [name qstr] in addEdCtrlList ctrllist name nil nil; set lqstr = tl lqstr; ); 0;; fun cbSelectList(ctrlstr, pos, elem, lval, type, p)= let p -> [ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout [lqstr]] in let getQueryByName lqstr elem -> qstr in if (qstr != nil) then ( setEdCtrlEditTextEnable ctrlquerysql 1; setEdCtrlEditTextEnable ctrlqueryout 1; setEdCtrlEditTextValue ctrlquerysql qstr.SQLIQ_sQuery; setEdCtrlEditTextValue ctrlqueryout qstr.SQLIQ_sOutput; setEdCtrlButtonEnable ctrlbtndel 1; setEdCtrlButtonEnable ctrlbtnren 1; ) else ( setEdCtrlEditTextEnable ctrlquerysql 0; setEdCtrlEditTextEnable ctrlqueryout 0; setEdCtrlEditTextValue ctrlquerysql ""; setEdCtrlEditTextValue ctrlqueryout ""; setEdCtrlButtonEnable ctrlbtndel 0; setEdCtrlButtonEnable ctrlbtnren 0; ); 0;; fun cbBtnNewQuery(ctrlstr, text, p)= let p -> [[ewinstr ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr] winstr ctrltext] in let dlqstr -> [lqstr] in let getEdCtrlTextLineValue ctrltext -> name in let getQueryByName lqstr name -> qstr in if (qstr != nil) then nil else ( mutate dlqstr <- [addQuery lqstr name "" ""]; addEdCtrlList ctrllist name nil nil; selectEdCtrlList ctrllist name; cbSelectList ctrllist 0 name nil nil [ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; dsEdWindow winstr; ); 0;; fun cbBtnCancelQuery(ctrlbtn, winstr)= dsEdWindow winstr; 0;; fun cbBtnNew(ctrlstr, p)= let p -> [ewinstr ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr] in let [330 90] -> [iw ih] in let getEdWindowScreenPos ewinstr -> [px py] in let getEdWindowSize ewinstr -> [pw ph] in let [(px + ((pw / 2) - (iw / 2))) (py + ((ph / 2) - (ih / 2)))] -> [x y] in let setEdWindowIcon (crEdModalDialogWindow _channel ewinstr x y iw ih WN_NOSCOL|WN_MENU|WN_DIALOG nil (loc "OS3DODBC_0007")) sWinDlgIcon -> winstr in let crEdCtrlLabel winstr 10 12 120 20 (loc "OS3DODBC_0007") nil -> label in let crEdCtrlTextLine winstr 140 10 (iw - 150) 20 "" nil EDWIN_RESIZE_MW -> ctrltext in ( setEdctrlTextLineFocus ctrltext; setEdCtrlTextLineCbValidate ctrltext mkfun3 @cbBtnNewQuery [p winstr ctrltext]; setEdCtrlButtonCb (crEdCtrlButton winstr 10 (ih - 30) 90 20 (loc "OS3D_0282") EDWIN_RESIZE_MW) mkfun2 mkfun3 @cbBtnNewQuery [p winstr ctrltext] nil; setEdCtrlButtonCb (crEdCtrlButton winstr (iw - 100) (ih - 30) 90 20 (loc "OS3D_0084") EDWIN_RESIZE_MW) mkfun2 @cbBtnCancelQuery winstr; ); 0;; fun cbBtnRenameQuery(ctrlstr, text, p)= let p -> [[ewinstr ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr] qstr winstr ctrltext] in let dlqstr -> [lqstr] in let getEdCtrlTextLineValue ctrltext -> name in let getQueryByName lqstr name -> oqstr in if (!strcmp name qstr.SQLIQ_sName) then ( dsEdWindow winstr; ) else if (oqstr != nil) then nil else ( renameEdCtrlListElement ctrllist qstr.SQLIQ_sName name; mutate dlqstr <- [rename_sid_from_list lqstr qstr.SQLIQ_sName name]; set qstr.SQLIQ_sName = name; selectEdCtrlList ctrllist name; cbSelectList ctrllist 0 name nil nil [ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; dsEdWindow winstr; ); 0;; fun cbBtnRename(ctrlstr, p)= let p -> [ewinstr ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr] in let dlqstr -> [lqstr] in let getSelectedEdCtrlList2 ctrllist -> [pos name _ _] in let getQueryByName lqstr name -> qstr in if (qstr == nil) then nil else ( let [330 90] -> [iw ih] in let getEdWindowScreenPos ewinstr -> [px py] in let getEdWindowSize ewinstr -> [pw ph] in let [(px + ((pw / 2) - (iw / 2))) (py + ((ph / 2) - (ih / 2)))] -> [x y] in let setEdWindowIcon (crEdModalDialogWindow _channel ewinstr x y iw ih WN_NOSCOL|WN_MENU|WN_DIALOG nil (loc "OS3DODBC_0007")) sWinDlgIcon -> winstr in let crEdCtrlLabel winstr 10 12 120 20 (loc "OS3DODBC_0007") nil -> label in let crEdCtrlTextLine winstr 140 10 (iw - 150) 20 name nil EDWIN_RESIZE_MW -> ctrltext in ( setEdctrlTextLineFocus ctrltext; setEdCtrlTextLineCbValidate ctrltext mkfun3 @cbBtnRenameQuery [p qstr winstr ctrltext]; setEdCtrlButtonCb (crEdCtrlButton winstr 10 (ih - 30) 90 20 (loc "OS3D_0282") EDWIN_RESIZE_MW) mkfun2 mkfun3 @cbBtnRenameQuery [p qstr winstr ctrltext] nil; setEdCtrlButtonCb (crEdCtrlButton winstr (iw - 100) (ih - 30) 90 20 (loc "OS3D_0084") EDWIN_RESIZE_MW) mkfun2 @cbBtnCancelQuery winstr; ); ); 0;; fun cbSelectListDbClick(ctrlstr, pos, elem, lval, type, p)= cbBtnRename nil p; 0;; fun cbBtnDel(ctrlstr, p)= let p -> [ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr] in let getSelectedEdCtrlList2 ctrllist -> [pos name _ _] in if (name == nil) then nil else let dlqstr -> [lqstr] in ( delEdCtrlList ctrllist name; mutate dlqstr <- [removeQuery lqstr name]; selectEdCtrlListByPos ctrllist pos; let getSelectedEdCtrlList ctrllist -> [name _ _] in cbSelectList ctrllist 0 name nil nil [ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; ); 0;; fun cbQuerySqlChange(ctlstr, text, p)= let p -> [ctrllist ctrlquerysql ctrlqueryout dlqstr] in let getSelectedEdCtrlList ctrllist -> [name _ _] in let dlqstr -> [lqstr] in let getQueryByName lqstr name -> qstr in if (qstr == nil) then nil else set qstr.SQLIQ_sQuery = text; 0;; fun cbQueryOutChange(ctlstr, text, p)= let p -> [ctrllist ctrlquerysql ctrlqueryout dlqstr] in let getSelectedEdCtrlList ctrllist -> [name _ _] in let dlqstr -> [lqstr] in let getQueryByName lqstr name -> qstr in if (qstr == nil) then nil else set qstr.SQLIQ_sOutput = text; 0;; fun dynamicedit(ewinstr, inst, viewstr, applybtn)= let [455 515] -> [iw ih] in let 10 -> ypos in ( setEdWindowSize ewinstr iw ih; let getPluginInstanceParam inst "dbname" -> dbname in let getCurrentDateTime 0 -> [day month year hours minutes seconds] in let if (dbname == nil) then "" else dbname -> dbname in let getPluginInstanceParam inst "dblogin" -> dblogin in let getPluginInstanceParam inst "dbpass" -> dbpass in let atoi getPluginInstanceParam inst "dbutf8" -> dbutf8 in let if (dbutf8 == nil) then 0 else dbutf8 -> dbutf8 in let loadQueries inst -> lqstr in let crEdFrameWindow _channel ewinstr 0 0 iw 130 EDWIN_RESIZE_MW nil (loc "OS3DODBC_0001") (loc "OS3DODBC_0002") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 110 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlLabel winstr 10 (ypos + 2) 120 20 (loc "OS3DODBC_0003") nil -> labeldbfile in let crEdCtrlTextLine winstr 140 ypos (iw - 300) 20 dbname nil EDWIN_RESIZE_MW -> ctrldbname in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 120 20 (loc "OS3DODBC_0004") nil -> labeldblogin in let crEdCtrlTextLine winstr 140 ypos (iw - 300) 20 dblogin nil EDWIN_RESIZE_MW -> ctrldblogin in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 120 20 (loc "OS3DODBC_0005") nil -> labeldbpass in let crEdCtrlTextLine winstr 140 ypos (iw - 300) 20 dbpass ET_BORDER|ET_AHSCROLL|ET_TABFOCUS|ET_PASSWORD EDWIN_RESIZE_MW -> ctrldbpass in let crEdCtrlCheck winstr 10 (set ypos = ypos + 25) 280 20 (loc "OS3DODBC_0015") EDWIN_RESIZE_MW -> ctrldbutf8 in let crEdFrameWindow _channel ewinstr 0 0 iw 385 EDWIN_RESIZE_MW nil (loc "OS3DODBC_0006") (loc "OS3DODBC_0002") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 365 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlList winstr 10 (set ypos = 10) (iw - 20) 90 LB_BORDER|LB_VSCROLL|ET_TABFOCUS EDWIN_RESIZE_MW|EDWIN_RESIZE_MH -> ctrllist in let crEdCtrlLabel winstr 10 (set ypos = ypos + 95) + 2 (iw - 20) 20 (loc "OS3DODBC_0008") nil -> labelquerysql in let crEdCtrlEditText winstr 10 (set ypos = ypos + 25) (iw - 20) 100 "" ET_AVSCROLL|ET_VSCROLL|ET_ALIGN_LEFT|ET_BORDER nil -> ctrlquerysql in let crEdCtrlLabel winstr 10 (set ypos = ypos + 110) + 2 (iw - 20) 20 (loc "OS3DODBC_0009") nil -> labelqueryout in let crEdCtrlEditText winstr 10 (set ypos = ypos + 25) (iw - 20) 60 "" ET_AVSCROLL|ET_VSCROLL|ET_ALIGN_LEFT|ET_BORDER nil -> ctrlqueryout in let crEdCtrlButton winstr (iw - 225) (set ypos = ypos + 75) 70 20 (loc "OS3DODBC_0010") EDWIN_RESIZE_MW -> ctrlbtnadd in let crEdCtrlButton winstr (iw - 150) ypos 70 20 (loc "OS3DODBC_0011") EDWIN_RESIZE_MW -> ctrlbtnren in let crEdCtrlButton winstr (iw - 75) ypos 70 20 (loc "OS3DODBC_0012") EDWIN_RESIZE_MW -> ctrlbtndel in // keep the list in tuple so we can change it staticaly in other functions let [lqstr] -> dlqstr in ( setEdCtrlCheckState ctrldbutf8 dbutf8; fillQueriesList ctrllist lqstr; setEdCtrlEditTextEnable ctrlquerysql 0; setEdCtrlEditTextEnable ctrlqueryout 0; setEdCtrlListCbClick ctrllist mkfun6 @cbSelectList [ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; setEdCtrlListCbDbClick ctrllist mkfun6 @cbSelectListDbClick [ewinstr ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; selectEdCtrlListByPos ctrllist 0; let getSelectedEdCtrlList ctrllist -> [name _ _] in cbSelectList ctrllist 0 name nil nil [ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; setEdCtrlEditTextCbChange ctrlquerysql mkfun3 @cbQuerySqlChange [ctrllist ctrlquerysql ctrlqueryout dlqstr]; setEdCtrlEditTextCbChange ctrlqueryout mkfun3 @cbQueryOutChange [ctrllist ctrlquerysql ctrlqueryout dlqstr]; setEdCtrlButtonCb ctrlbtnadd mkfun2 @cbBtnNew [ewinstr ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; setEdCtrlButtonCb ctrlbtnren mkfun2 @cbBtnRename [ewinstr ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; setEdCtrlButtonCb ctrlbtndel mkfun2 @cbBtnDel [ctrllist ctrlbtndel ctrlbtnren ctrlquerysql ctrlqueryout dlqstr]; [mkfun1 @cbCloseEdit [ctrldbname ctrldblogin ctrldbpass ctrldbutf8 dlqstr] nil]; ); );;