/* This source file is part of the SCS module "Sqlite3" For the latest info, see http://www.scolring.org Copyright (c) 2010 Stephane Bisaro, aka Iri 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 3 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 For others informations, please contact us from http://www.scolring.org/ or http://www.irizone.net/ */ typeof editWin = ObjWin;; typeof winFile = ObjWin;; typeof winMemory = ObjWin;; typeof winTemp = ObjWin;; typeof txt_db_file = ObjText;; typeof txt_db_status = ObjText;; typeof ch_db_memory = ObjCheck;; typeof sh_db_file = ObjCheck;; typeof sh_db_temp = ObjCheck;; typeof bt_browse = ObjButton;; typeof dbType = I;; // 0 : file, 1 : memory, 2 : temp file, 3 : unknown proto cbDBtest = fun [ObjButton I] I;; /* proto createTool_gui = fun [] I;; */ fun cbDBnewFile (obj, u, pfile)= if pfile == nil then nil else _SETtext txt_db_file _PtoScol pfile; 0;; fun cbDBbrowse (obj, u)= _DLGrflopen _DLGOpenFile _channel editWin nil nil "All\0*.*\0\0" @cbDBnewFile 0; 0;; fun enableObject (type, enable)= set dbType = type; _ENbutton bt_browse enable; _ENtext txt_db_file enable; 0;; fun cbCheck (obj, u, state)= _SETcheck ch_db_memory !state; _SETcheck sh_db_file !state; _SETcheck sh_db_temp !state; _SETcheck obj state; if obj == sh_db_file then enableObject 0 1 else if obj == ch_db_memory then enableObject 1 0 else if obj == sh_db_temp then enableObject 2 0 else enableObject 3 1; _SETtext txt_db_status _locEditor "no_status" nil; 0;; fun cbTool (obj, u)= if dbType == 0 then // createTool_gui 0 else ( _SETtext txt_db_status _locEditor "tool_creation_launch_error" nil; 0 );; fun cbExist (obj, u, response)= if response then _openbrowserhttp "http://www.scolring.org/" else nil; 0;; fun Exist ()= _DLGrflmessage _DLGMessageBox _channel editWin "..:: WARNING ! ::.." _locEditor "load_error_message" nil 2 @cbExist 0; 0;; fun getLastPosSlash(s)= if s == nil then nil else let strlen s -> n in let n-1 -> i in ( while (i >=0) && ((nth_char s i) != '/) do // ' set i = i-1; i );; fun getClasPath (ed)= let ed.EditorCore.EDICOclassFile -> s in let getLastPosSlash s -> position in substr s 0 position+1;; /* Editor functions */ fun load(l)= let getInfo l "db_file" -> d in let if (!strcmp d ":memory") then ( set dbType = 1; cbCheck ch_db_memory nil 1; "" ) else if (!strcmp d ":temp") then ( set dbType = 2; cbCheck sh_db_temp nil 1; "" ) else if (!strcmp d "") then ( set dbType = 3; "" ) else ( set dbType = 0; cbCheck sh_db_file nil 1; d ) -> dbfile in _SETtext txt_db_file dbfile; 0;; fun save (filename, n)= ("action" :: "run" :: nil) :: ("event" :: "return" :: nil) :: ("event" :: "returnEx" :: nil) :: ("action" :: "runEx" :: nil) :: ("event" :: "log" :: nil) :: ("event" :: "destroyed" :: nil) :: ("db_file" :: (if dbType == 0 then _GETtext txt_db_file else if dbType == 1 then ":memory" else if dbType == 2 then ":temp" else "") :: nil) :: nil;; fun IniEditor(s)= let if (_test_exist "_sqliteOpenFile") then 1 else 0 -> exist in let [440 255] -> [w h] in let startEditor _channel nil nil nil w h WN_MENU EDITOR_NORMAL s "dms/db/sqlite3/sqlite3.dmc" nil nil @load @save nil -> ed in ( set editWin = getEditWin ed; /* database in file */ set winFile = _CRwindow _channel editWin 5 5 w-10 80 WN_CHILDINSIDE ""; set sh_db_file = _CRcheck _channel winFile 5 5 w-20 20 CH_RADIO|CH_LEFT _locEditor "database_file" nil; _CBcheck sh_db_file @cbCheck 0; _CRtext _channel winFile 5 30 w-20 20 0 _locEditor "b_database_file" nil; set txt_db_file = _CReditLine _channel winFile 5 55 w-110 20 ET_DOWN|ET_AHSCROLL let _GETtext txt_db_file -> s in if s == nil then "" else s; set bt_browse = _CBbutton _CRbutton _channel winFile w-100 55 85 20 0 _locEditor "browse" nil @cbDBbrowse 0; /* database in memory */ set winMemory = _CRwindow _channel editWin 5 95 w-10 30 WN_CHILDINSIDE ""; set ch_db_memory = _CRcheck _channel winMemory 5 5 w-20 20 CH_RADIO|CH_LEFT _locEditor "database_memory" nil; _CBcheck ch_db_memory @cbCheck 0; /* database in temp file */ set winTemp = _CRwindow _channel editWin 5 135 w-10 30 WN_CHILDINSIDE ""; set sh_db_temp = _CRcheck _channel winTemp 5 5 w-20 20 CH_RADIO|CH_LEFT _locEditor "database_temp" nil; _CBcheck sh_db_temp @cbCheck 0; /* Test database connection * First : test if Sqlite3 support is present * Second : if yes, enable the connection test */ if exist then _load strcat getClasPath ed "edb.pkg" else Exist; _ENbutton _CBbutton _CRbutton _channel editWin 5 h-80 w-10 20 0 _locEditor "test_connection" nil @cbDBtest 0 exist; /* Status */ set txt_db_status = _CRtext _channel editWin 5 h-55 w-10 20 ET_DOWN|ET_ALIGN_CENTER _locEditor "no_status" nil; /* Creation tool */ _ENbutton _CBbutton _CRbutton _channel editWin 5 h-25 w-10 20 0 _locEditor "tool_creation" nil @cbTool 0 // exist; 0; /* editor */ if s == nil then nil else openDMI ed ); 0;;