Luigi Posted March 5, 2011 Share Posted March 5, 2011 (edited) Part I (The beggining...)Greetings!I write this script to show information in real time from a SQLite database's.It's is usefull to show a little panel from a database in school, to students pratice a few commands about SQL DataBase, like to update.The script work, but I have a little problem, the datas showed in fields "Control x" is changing all the time with old datas typed.Exemple, when I start de script, it's show all the fields correctly, when I start a window's SQLite to type the commands update, field called "Control 1" show old data and the new data too... If I type more one data, all values is changing in the time in the current field.Someone can help-me to optimize this script to show only the last data type in SQLite's terminal?Best regards.===Part II (Edited).I write this code's variant, for me, is not perfect, but, is better from original code...When I change the values in the terminal's SQLITE3, the changing of datas in the panel is not smoth or your visiual is not "professional", it is "ugly".I am will seek the code, like something "professional".To work I put more auxiliary variables in the code.The master variable is $a, I need put the $ta ($temporarya or $ta), adding the new variable make a pause in the write on program [GUICtrlCreateLabel($a, 50, 25)], writing the new value with only a new value in the database. If don´t have diferences between mastar variable and slava variable, nothing is write in the box.I hate write master variabe or slave variable, that is not hard disk... I forgot how do write correctly, sorry.===expandcollapse popup#include <GUIConstantsEx.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Opt('MustDeclareVars', 1) Local $Database Local $filemenu, $fileitem Local $exititem, $okbutton, $cancelbutton, $gui Local $msg, $file Local $aRow, $sSQliteDll, $a, $b, $c, $d Local $ta, $tb, $tc, $td $sSQliteDll = _SQLite_Startup () IF not FileExists ("base.db") Then $Database = _SQLite_Open("base.db") _SQLite_Exec (-1, "CREATE TABLE access (control, value);") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('1','5');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('2','10');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('3','15');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('4','20');") EndIf If @error Then ConsoleWrite("SQLite Error: SQLite.dll Can't be Loaded!" & @CRLF) Exit - 1 EndIf _SQLite_Close() _SQLite_Shutdown () _Main() Func _Main() _SQLite_Startup () _SQLite_Open("base.db") $gui = GUICreate("DataBase READER", 230, 170) $filemenu = GUICtrlCreateMenu("File") $exititem = GUICtrlCreateMenuItem("E&xit", $filemenu) $cancelbutton = GUICtrlCreateButton("E&xit", 150, 125, 70, 20) GUICtrlCreateGroup("Control 1", 5, 5, 100, 50) GUICtrlCreateGroup("Ccontrol 3", 5, 60, 100, 50) GUICtrlCreateGroup("Control 2", 125, 5, 100, 50) GUICtrlCreateGroup("Control 4", 125, 60, 100, 50) GUISetState() While 1 $msg = GUIGetMsg() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '1' LIMIT 1;",$a) If $a[0] <> $ta then _FuncA() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '2' LIMIT 1;",$b) If $b[0] <> $tb then _FuncB() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '3' LIMIT 1;",$c) If $c[0] <> $tc then _FuncC() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '4' LIMIT 1;",$d) If $d[0] <> $td then _FuncD() ;GUICtrlCreateLabel($d[0], 170, 80) Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton _SQLite_Close() _SQLite_Shutdown() ExitLoop Case $msg = $exititem _SQLite_Close() _SQLite_Shutdown() ExitLoop EndSelect WEnd GUIDelete() Exit EndFunc Func _FuncA() $a = $a[0] GUICtrlCreateLabel($a, 50, 25) $ta = $a EndFunc Func _FuncB() $b = $b[0] GUICtrlCreateLabel($b, 170, 25) $tb = $b EndFunc Func _FuncC() $c = $c[0] GUICtrlCreateLabel($c, 50, 80) $tc = $c EndFunc Func _FuncD() $d = $d[0] GUICtrlCreateLabel($d, 170, 80) $td = $d EndFunc Edited March 6, 2011 by detefon Visit my repository Link to comment Share on other sites More sharing options...
martin Posted March 6, 2011 Share Posted March 6, 2011 (edited) Part I (The beggining...) Greetings! I write this script to show information in real time from a SQLite database's. It's is usefull to show a little panel from a database in school, to students pratice a few commands about SQL DataBase, like to update. The script work, but I have a little problem, the datas showed in fields "Control x" is changing all the time with old datas typed. Exemple, when I start de script, it's show all the fields correctly, when I start a window's SQLite to type the commands update, field called "Control 1" show old data and the new data too... If I type more one data, all values is changing in the time in the current field. Someone can help-me to optimize this script to show only the last data type in SQLite's terminal? Best regards. === Part II (Edited). I write this code's variant, for me, is not perfect, but, is better from original code... When I change the values in the terminal's SQLITE3, the changing of datas in the panel is not smoth or your visiual is not "professional", it is "ugly". I am will seek the code, like something "professional". To work I put more auxiliary variables in the code. The master variable is $a, I need put the $ta ($temporarya or $ta), adding the new variable make a pause in the write on program [GUICtrlCreateLabel($a, 50, 25)], writing the new value with only a new value in the database. If don´t have diferences between mastar variable and slava variable, nothing is write in the box. I hate write master variabe or slave variable, that is not hard disk... I forgot how do write correctly, sorry. === expandcollapse popup#include <GUIConstantsEx.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Opt('MustDeclareVars', 1) Local $Database Local $filemenu, $fileitem Local $exititem, $okbutton, $cancelbutton, $gui Local $msg, $file Local $aRow, $sSQliteDll, $a, $b, $c, $d Local $ta, $tb, $tc, $td $sSQliteDll = _SQLite_Startup () IF not FileExists ("base.db") Then $Database = _SQLite_Open("base.db") _SQLite_Exec (-1, "CREATE TABLE access (control, value);") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('1','5');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('2','10');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('3','15');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('4','20');") EndIf If @error Then ConsoleWrite("SQLite Error: SQLite.dll Can't be Loaded!" & @CRLF) Exit - 1 EndIf _SQLite_Close() _SQLite_Shutdown () _Main() Func _Main() _SQLite_Startup () _SQLite_Open("base.db") $gui = GUICreate("DataBase READER", 230, 170) $filemenu = GUICtrlCreateMenu("File") $exititem = GUICtrlCreateMenuItem("E&xit", $filemenu) $cancelbutton = GUICtrlCreateButton("E&xit", 150, 125, 70, 20) GUICtrlCreateGroup("Control 1", 5, 5, 100, 50) GUICtrlCreateGroup("Ccontrol 3", 5, 60, 100, 50) GUICtrlCreateGroup("Control 2", 125, 5, 100, 50) GUICtrlCreateGroup("Control 4", 125, 60, 100, 50) GUISetState() While 1 $msg = GUIGetMsg() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '1' LIMIT 1;",$a) If $a[0] <> $ta then _FuncA() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '2' LIMIT 1;",$b) If $b[0] <> $tb then _FuncB() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '3' LIMIT 1;",$c) If $c[0] <> $tc then _FuncC() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '4' LIMIT 1;",$d) If $d[0] <> $td then _FuncD() ;GUICtrlCreateLabel($d[0], 170, 80) Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton _SQLite_Close() _SQLite_Shutdown() ExitLoop Case $msg = $exititem _SQLite_Close() _SQLite_Shutdown() ExitLoop EndSelect WEnd GUIDelete() Exit EndFunc Func _FuncA() $a = $a[0] GUICtrlCreateLabel($a, 50, 25) $ta = $a EndFunc Func _FuncB() $b = $b[0] GUICtrlCreateLabel($b, 170, 25) $tb = $b EndFunc Func _FuncC() $c = $c[0] GUICtrlCreateLabel($c, 50, 80) $tc = $c EndFunc Func _FuncD() $d = $d[0] GUICtrlCreateLabel($d, 170, 80) $td = $d EndFunc I know almost nothing about SQLite, but maybe your problem is not to do with that. When you want to change the text in a label you should only do that. Don't create a new label. You will end up with thousands of labels though you will only see the last ones created. It would also be better to have one function for any label update than a function for every label, but that's just my preference. Something like this maybe Create the label at the start and assign a variable name to it. When the data has to change use GuiCtrlSetData $gui = GUICreate("DataBase READER", 230, 170) $LabelA = GUICtrlCreateLabel($a, 50, 25);do this for each label Main() Local $a, $ta,$a,$tb,$c,$tc;reduce the number of global variables as much as possible While 1 $msg = GUIGetMsg() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '1' LIMIT 1;",$a) _FuncA($a[0],$LabelA,$ta) . _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '3' LIMIT 1;",$c) _FuncA($c[0],$LabelC,$tc) . . . Wend Func _FuncA($newtext, $labID,ByRef $OldText) If $OldText = $newtext then return GUICtrlSetDatal($labID,$newtext);update the label $OldText = $newtext EndFunc Edited March 6, 2011 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jchd Posted March 6, 2011 Share Posted March 6, 2011 I was about posting a similar remark as Martin did. Change your code and we'll see how far we get from a decent result. I can help wrt SQLite and its interface. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Luigi Posted March 8, 2011 Author Share Posted March 8, 2011 @Martin & jcd: thanks, I will try rewrite my script. I have some time today. ^^ ^^ ^^ Visit my repository Link to comment Share on other sites More sharing options...
martin Posted March 8, 2011 Share Posted March 8, 2011 (edited) @Martin & jcd: thanks, I will try rewrite my script. I have some time today. ^^ ^^ ^^ Good luck. The $OldText variable in my example is not really needed. This might be better. _FuncA($newtext, $labID) If GuiCtrlRead($labID) <> $newtext then GUICtrlSetDatal($labID,$newtext) EndIf EndFunc Edited March 8, 2011 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Luigi Posted March 17, 2011 Author Share Posted March 17, 2011 Greetings! @martin, I follow your advice, and write a new code. The final result from this last script is better. The fields is not re-writed all the time, but, one problem still happening. When I update some field, all fields are re-writed. This is my last script. expandcollapse popup#include <GUIConstantsEx.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Opt('MustDeclareVars', 1) Local $sSQliteDll, $Database Local $a Dim $Control[4] Local $gui, $filemenu, $exititem, $cancelbutton, $msg Local $a, $b, $c, $d Local $ta, $tb, $tc, $td, $tt, $tty Dim $query[4] Dim $tquery[4] $sSQliteDll = _SQLite_Startup () IF not FileExists ("base.db") Then $Database = _SQLite_Open("base.db") _SQLite_Exec (-1, "CREATE TABLE access (control, value);") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('1','5');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('2','10');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('3','15');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('4','20');") _SQLite_Close() _SQLite_Shutdown() EndIf If @error Then ConsoleWrite("SQLite Error: SQLite.dll Can't be Loaded!" & @CRLF) Exit - 1 EndIf _SQLite_Close() _SQLite_Shutdown () _Main() Func _Main() _SQLite_Startup () _SQLite_Open("base.db") $gui = GUICreate("DataBase READER", 230, 170) $filemenu = GUICtrlCreateMenu("File") $exititem = GUICtrlCreateMenuItem("E&xit", $filemenu) $cancelbutton = GUICtrlCreateButton("E&xit", 150, 125, 70, 20) $Control[0] = GUICtrlCreateLabel($query[0] & " ", 30, 25, 25) $Control[1] = GUICtrlCreateLabel($query[1] & " ", 150, 25, 25) $Control[2] = GUICtrlCreateLabel($query[2] & " ", 30, 80, 25) $Control[3] = GUICtrlCreateLabel($query[3] & " ", 150, 80, 25) GUICtrlCreateGroup("Control 1", 5, 5, 100, 50) GUICtrlCreateGroup("Control 3", 5, 60, 100, 50) GUICtrlCreateGroup("Control 2", 125, 5, 100, 50) GUICtrlCreateGroup("Control 4", 125, 60, 100, 50) GUISetState() While 1 $msg = GUIGetMsg() For $q = 1 to 4 _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '" & $q &"' LIMIT 1;",$tt) $query[$q - 1] = $tt[0] _SQLite_QueryFinalize($tt) IF $query[$q - 1] <> $tquery[$q - 1] Then GUICtrlSetData($Control[$q - 1],$query[$q - 1]) ConsoleWrite("Query: " & $q & @tab & "$query[]" & $query[$q - 1] & @tab & "$tquery[]" &$tquery[$q - 1] & @CRLF) $tquery[$q - 1] = $query[$q - 1] EndIf Next Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton OR $msg = $exititem _SQLite_Close() _SQLite_Shutdown() ExitLoop EndSelect WEnd EndFunc I try re-write the code again. Thanks! Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted March 18, 2011 Author Share Posted March 18, 2011 Greetings! The script above, is work, have less code lines, but have the same problem... I can't write one code to write or re-write only data was changed. In this script, I make a stupid thing... Case $b <> $tb IF $b <> $tb Then GUICtrlSetData($Control2,$B) $tb = $b ConsoleWrite($b & @CRLF) EndIf This is a part's algoritm what compare/identify if a data was changed, if it's changed... it rewrite the new data in the current control. Is this is problem, sometimes the algorithm write only de data was changed. Another times, the algorithm write the field 01 and field 02, or rewrite everything! I put a If...EndIf into the Case (I know... this is not necessary). I can't understand... Why the code rewrite more of one field? It rewrite fields when was not updated in the SQLite command. At the moment, is this the only way what I see for write this code... Someone see another way? Best regards! expandcollapse popup#include <GUIConstantsEx.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Opt('MustDeclareVars', 1) Local $sSQliteDll, $Database Local $a Local $Control1, $Control2, $Control3, $Control4 Local $gui, $filemenu, $exititem, $cancelbutton, $msg Local $a, $b, $c, $d Local $ta, $tb, $tc, $td $sSQliteDll = _SQLite_Startup () IF not FileExists ("base.db") Then $Database = _SQLite_Open("base.db") _SQLite_Exec (-1, "CREATE TABLE access (control, value);") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('1','5');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('2','10');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('3','15');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('4','20');") _SQLite_Close() _SQLite_Shutdown() EndIf If @error Then ConsoleWrite("SQLite Error: SQLite.dll Can't be Loaded!" & @CRLF) Exit - 1 EndIf _SQLite_Close() _SQLite_Shutdown () _Main() Func _Main() _SQLite_Startup () _SQLite_Open("base.db") $gui = GUICreate("DataBase READER", 230, 170) $filemenu = GUICtrlCreateMenu("File") $exititem = GUICtrlCreateMenuItem("E&xit", $filemenu) $cancelbutton = GUICtrlCreateButton("E&xit", 150, 125, 70, 20) $Control1 = GUICtrlCreateLabel($a & " ", 30, 25, 25) $Control2 = GUICtrlCreateLabel($b & " ", 150, 25, 25) $Control3 = GUICtrlCreateLabel($c & " ", 30, 80, 25) $Control4 = GUICtrlCreateLabel($d & " ", 150, 80, 25) GUICtrlCreateGroup("Control 1", 5, 5, 100, 50) GUICtrlCreateGroup("Control 3", 5, 60, 100, 50) GUICtrlCreateGroup("Control 2", 125, 5, 100, 50) GUICtrlCreateGroup("Control 4", 125, 60, 100, 50) GUISetState() While 1 $msg = GUIGetMsg() _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '1' LIMIT 1;",$a) $a = $a[0] _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '2' LIMIT 1;",$b) $b = $b[0] _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '3' LIMIT 1;",$c) $c = $c[0] _SQLite_QuerySingleRow(-1,"SELECT value FROM access WHERE control = '4' LIMIT 1;",$d) $d = $d[0] Select Case $a <> $ta IF $a <> $ta Then GUICtrlSetData($Control1,$a) ConsoleWrite($a & @CRLF) $ta = $a EndIf Case $b <> $tb IF $b <> $tb Then GUICtrlSetData($Control2,$b) $tb = $b ConsoleWrite($b & @CRLF) EndIf Case $c <> $tc IF $c <> $tc Then GUICtrlSetData($Control3,$c) $tc = $c ConsoleWrite($c & @CRLF) EndIf Case $d <> $td IF $d <> $td Then GUICtrlSetData($Control4,$d) $td = $d ConsoleWrite($d & @CRLF) EndIf Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton OR $msg = $exititem _SQLite_Close() _SQLite_Shutdown() ExitLoop EndSelect WEnd Exit EndFunc Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted March 18, 2011 Author Share Posted March 18, 2011 (edited) Greetings, I write this code and now working fine. *use _SQLite_FetchData() instead of _SQLite_QuerySingleRow(); *i charge all datas from database and save in $wer[]; *at the end, I compare the new data's from database with temporary's data in the memory; This is a best way to make this? Best regards! ^^ expandcollapse popup#include <GUIConstantsEx.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Opt('MustDeclareVars', 1) Local $sSQliteDll, $Database Local $Control1, $Control2, $Control3, $Control4 Local $gui, $filemenu, $exititem, $cancelbutton, $msg Local $Query, $Dados Dim $wer[4],$t Dim $Control[4] Dim $Data[4] $sSQliteDll = _SQLite_Startup () IF not FileExists ("base.db") Then $Database = _SQLite_Open("base.db") _SQLite_Exec (-1, "CREATE TABLE access (control, value);") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('1','5');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('2','10');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('3','15');") _SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('4','20');") ;_SQLite_Close() ;_SQLite_Shutdown() EndIf If @error Then ConsoleWrite("SQLite Error: SQLite.dll Can't be Loaded!" & @CRLF) Exit - 1 EndIf ;_SQLite_Close() ;_SQLite_Shutdown() ;_SQLite_Startup() _SQLite_Open("base.db") $gui = GUICreate("DataBase READER", 230, 170) $filemenu = GUICtrlCreateMenu("File") $exititem = GUICtrlCreateMenuItem("E&xit", $filemenu) $cancelbutton = GUICtrlCreateButton("E&xit", 150, 125, 70, 20) $Control[0] = GUICtrlCreateLabel($Data[0] & " ", 30, 25, 25) $Control[1] = GUICtrlCreateLabel($Data[1] & " ", 150, 25, 25) $Control[2] = GUICtrlCreateLabel($Data[2] & " ", 30, 80, 25) $Control[3] = GUICtrlCreateLabel($Data[3] & " ", 150, 80, 25) GUICtrlCreateGroup("Control 1", 5, 5, 100, 50) GUICtrlCreateGroup("Control 3", 5, 60, 100, 50) GUICtrlCreateGroup("Control 2", 125, 5, 100, 50) GUICtrlCreateGroup("Control 4", 125, 60, 100, 50) While 1 GUISetState() $msg = GUIGetMsg() Base() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton OR $msg = $exititem _SQLite_Close() _SQLite_Shutdown() ExitLoop EndSelect WEnd Exit Func Base() _SQlite_Query (-1, "SELECT value FROM access;", $Query) While _SQLite_FetchData ($Query, $Dados) = $SQLITE_OK $wer[$t] = $Dados[0] IF $wer[$t] <> $Data[$t] Then GUICtrlSetData($Control[$t],$wer[$t]) $Data[$t] = $wer[$t] ConsoleWrite($wer[$t] & @CRLF) EndIf $t = $t +1 WEnd _SQLite_QueryFinalize($Query) $t =0 EndFunc Edited March 18, 2011 by detefon Visit my repository Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now