guinness Posted December 16, 2013 Posted December 16, 2013 My understanding of proper usage of Local declaration in "Global scope". #include <Constants.au3> Local $sVar = 'This variable is only used in the scope it''s declared in, therefore imagine if this scope was wrapped in a function called "Main".' Global $g_sString = 'This variable is used not only in this scope ("Main") but also inside other functions e.g. SomeFunc()' SomeFunc() MsgBox($MB_SYSTEMMODAL, '', $sVar) ; Display in a MsgBox(). $sVar = '' SomeOtherFunc() Func Example() Local $sText = 'This is some text.' ; The variable is Local and is declared and initialised when required. ConsoleWrite($sText & @CRLF) ; Display in the console. $sText = 'Change the variable which is local to the scope it''s declared in.' ; Change the variable's contents. ConsoleWrite($sText & @CRLF) ; Display in the console. EndFunc Func SomeFunc() $g_sString &= @CRLF ; Append CRLF to the string. ConsoleWrite($g_sString) ; Display in the console. EndFunc Func SomeOtherFunc() $g_sString = '' ; Clear the contents of the Global variable. EndFunc UDF List: Reveal hidden contents _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
JohnOne Posted December 16, 2013 Posted December 16, 2013 On 12/16/2013 at 4:35 PM, michaelslamet said: Could you please explain more detail about the "queue control script on the server machine"? Which server? the MySQL server? Wherever the the MYSQL server is located. A script which handles a queue of queries from clients, only that 1 script passes those queries on the MYSQL at timed intervals. That script is a whole other kettle of fish, but you'll probably find one on the forums. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
markyrocks Posted December 16, 2013 Posted December 16, 2013 (edited) On 12/16/2013 at 4:30 PM, michaelslamet said: No, it is not saved on a separate .au3 file and I dont think this is the issue I don't think you're understanding what I meant. Not saying it would be an issue. Saying that if say 2 pcs press "functionbutton" 100ms apart pc 1 would run say function.au3 pc2 checks if processexists (funtion.au3) then wait till process does not exist plus 200ms. Not formatted exactly that way but gets my point across. If a few people need to use it this maybe small time solution. If 100's are trying to use it then you'd have issues. Would mainly be luck as to who was next to use it. There would be no rhythm or reason to it. Edited December 16, 2013 by markyrocks Reveal hidden contents "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
kylomas Posted December 16, 2013 Posted December 16, 2013 michaelslamet, I would do as BrewmanNH suggested and let the DB do the work. I don't understand it offhand but it seems like table locking/unlocking and/or transactions should be all you need to ensure the integrity of your DB. Perhaps a DB programmer wll weigh in on this? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
michaelslamet Posted December 17, 2013 Author Posted December 17, 2013 On 12/16/2013 at 7:44 PM, kylomas said: michaelslamet, I would do as BrewmanNH suggested and let the DB do the work. I don't understand it offhand but it seems like table locking/unlocking and/or transactions should be all you need to ensure the integrity of your DB. Perhaps a DB programmer wll weigh in on this? kylomas Thank you, kylomas What I've done for now is changing the table engine from InnoDB to MyISAM since I read that InnoDB doesn't support table locking. What I need to figure out is now where to put the LOCK and UNLOCK TABLES command
AutID Posted December 17, 2013 Posted December 17, 2013 If you are between using lock/unlock and your function then take the 1st solution. You are reading milliseconds. Your function will take definitely more than 200 milliseconds to return since you are using array delete function twice so it would be something more than useless... https://iblockify.wordpress.com/
michaelslamet Posted December 17, 2013 Author Posted December 17, 2013 On 12/17/2013 at 12:43 AM, AutID said: If you are between using lock/unlock and your function then take the 1st solution. You are reading milliseconds. Your function will take definitely more than 200 milliseconds to return since you are using array delete function twice so it would be something more than useless... This is really a good idea, I should try speed up the process, including try to remove the array delete function, thanks for that! What is 1st solution anyway?
AutID Posted December 17, 2013 Posted December 17, 2013 What BrewManNH suggested is the 1st solution https://iblockify.wordpress.com/
BrewManNH Posted December 17, 2013 Posted December 17, 2013 If you're looking to lock the table, you put the lock command just before the update/commit commands. http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
kylomas Posted December 17, 2013 Posted December 17, 2013 (edited) <delete> incorrect response to AutID michaelslamet, The first function is the DB solution. 1 - construct Log record 2 - lock table (or whatever the appropriate terminology is) 3 - write table record 4 - unlock table I would figure out how connections, transactions and locking work in whatever DB solution I use and implement it that way. kylomas edit: deleted response noted above Edited December 17, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
jchd Posted December 17, 2013 Posted December 17, 2013 Rather than locking the DB (or part of it, depending on the DB engine capabilities), I'd rather use standard SQL-way to implement a kind of IPC. Create a table `Timer` with only one row and one column `lasttime` where you store the time of last access within a transaction. Now in your access function, start an immediate transaction, select the difference between the current time and `lasttime` and either wait loop until it is > 200ms. Once the delay has elapsed, grab the rows you need then update `lasttime`, all within the transaction. This way, you can be sure that only one process can access the precious row within any 200ms period. I'm not familiar enough with the terrible intricacies of MySQL to offer working code but I don't see why it wouldn't work. Reveal hidden contents 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)
JohnOne Posted December 17, 2013 Posted December 17, 2013 May I ask what the logic behind wanting this 200ms limit is? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
kylomas Posted December 17, 2013 Posted December 17, 2013 Hi jchd, I don't think the OP is trying to implement IPC. I think his concern is writing log records from multiple places to a single table (please correct me if I'm wrong michaelslamet). I don't understand transactions, locking and unlocking in enough detail to offer anything more than the technique as a possiblilty. It seems better to let the DB handle serialization of writing records, if it can. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
jchd Posted December 17, 2013 Posted December 17, 2013 Want it or not it's a kind of IPC centralized and deported to the DB side. ClientA says "last time written is T0", clients B thru Z have to wait until T0 + 200ms. That can be translated to a pure IPC communication: client A broadcasts message "I just wrote a record" (e.g. MailSlot or UDP or whatever) and all other clients have to wait 200ms from receiving that to be allowed to compete for reading said record. This even makes it more subtle: clients just launched have to wait 200ms inconditionnally for that scheme to work reliably (may not have received a previous message). Reveal hidden contents 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)
michaelslamet Posted December 18, 2013 Author Posted December 18, 2013 On 12/17/2013 at 8:32 AM, jchd said: Rather than locking the DB (or part of it, depending on the DB engine capabilities), I'd rather use standard SQL-way to implement a kind of IPC. Create a table `Timer` with only one row and one column `lasttime` where you store the time of last access within a transaction. Now in your access function, start an immediate transaction, select the difference between the current time and `lasttime` and either wait loop until it is > 200ms. Once the delay has elapsed, grab the rows you need then update `lasttime`, all within the transaction. This way, you can be sure that only one process can access the precious row within any 200ms period. I'm not familiar enough with the terrible intricacies of MySQL to offer working code but I don't see why it wouldn't work. Thank you, jchd. This is the first time I heard word "IPC". Googling bring me some great explanation at wikipedia. Interesting. I had a chance to escape from a tight loop at my script, so right now (I think) the database lock solution working great. I will not really sure until it's put to run in the production environment, but I think it's enough for now, so I'm going to mark this as solved. Thanks everybody!
michaelslamet Posted December 18, 2013 Author Posted December 18, 2013 On 12/17/2013 at 9:42 AM, JohnOne said: May I ask what the logic behind wanting this 200ms limit is? That 200ms can be any number
michaelslamet Posted December 18, 2013 Author Posted December 18, 2013 On 12/17/2013 at 2:15 AM, kylomas said: <delete> incorrect response to AutID michaelslamet, The first function is the DB solution. 1 - construct Log record 2 - lock table (or whatever the appropriate terminology is) 3 - write table record 4 - unlock table I would figure out how connections, transactions and locking work in whatever DB solution I use and implement it that way. kylomas edit: deleted response noted above Thank you, kylomas. This is what exactly I'm doing as a solution for this problem (see my previous post). Thanks again!
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