Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

How does one persist data?

 [1/9] from: sharriff:aina:med-iq at: 11-Oct-2000 7:56


Does anyone have a soultion of persisting data across HTML pages? I want data submitted through a CGI from a HTML form to be usable in other pages. Many thanks for the anticipated help guys Sharriff Aina med.iq information & quality in healthcare AG

 [2/9] from: al:bri:xtra at: 11-Oct-2000 1:09


Sharriff wrote:
> Does anyone have a solution of persisting data across HTML pages? I want
data submitted through a CGI from a HTML form to be usable in other pages. Why not have a Rebol cgi script that outputs the HTML form, another one that responds to the form and then writes the information as a file, then another one that reads the file and writes the information as html again? Or, failing that, have the Rebol script on the site FTP the data to the site? I hope that helps somewhat. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [3/9] from: sharriff:aina:med-iq at: 11-Oct-2000 9:51


Thanks Andrew, I´ll try that out. Sharriff Aina med.iq information & quality in healthcare AG [Al--Bri--xtra--c] o.nz An: [list--rebol--com] Kopie: 11.10.00 Thema: [REBOL] How does one persist data? Re: 10:09 Bitte antworten an list Sharriff wrote:
> Does anyone have a solution of persisting data across HTML pages? I want
data submitted through a CGI from a HTML form to be usable in other pages. Why not have a Rebol cgi script that outputs the HTML form, another one that responds to the form and then writes the information as a file, then another one that reads the file and writes the information as html again? Or, failing that, have the Rebol script on the site FTP the data to the site? I hope that helps somewhat. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [4/9] from: cybarite:sympatico:ca at: 11-Oct-2000 5:37


For storing the post or get data, I added a key and a timestamp and stored the name=value pairs on a file (%journal.txt). Then I could use the same approach for fields whether they came from the journal for a previous post or a new record from a user write/append %journal.txt reduce [ {confirmation-number=} confirmation-number "&timestamp=" now "&status=new" "&" system/options/cgi/query-string newline ] When I wanted to look it up in another script, requests: read/lines %journal.txt Find the requests that matches the confirmation-number or other criteria and instantiate a cgi object using the same approach: selected-query-string: pick requests some-key ; some-key is used to pick off one of the journal entries data-record-object: make object! [ ;-- Default form values. status: "None" timestamp: "None" confirmation-number: "None" name-last: "No name entered" name-first: "Not entered" card-number: "Not entered" special-instructions: "None entered" customer-request: "None entered" email: "None entered" refer-to: "None specified" special-instructions: "None" ] record-object: make data-record-object decode-cgi-query selected-query-string Now use the record-object data in your script such as record-object/status Worked for me!

 [5/9] from: joel:neely:fedex at: 11-Oct-2000 8:37


[Sharriff--Aina--med-iq--de] wrote:
> Does anyone have a soultion of persisting data across HTML pages? I want > data submitted through a CGI from a HTML form to be usable in other pages. > > Many thanks for the anticipated help guys > > Sharriff Aina > med.iq information & quality in healthcare AG
Two standard techniques: 1) return from the CGI script another form with the data as hidden fields; 2) within the CGI script, save the data (e.g. to a disk file) so that subsequent scripts can read it. -jn-

 [6/9] from: coussement::c::itc::mil::be at: 11-Oct-2000 16:15


Those solution works find but it can become buggy to manage the files (location, versions, ...) The solution I used with precisely the same problem you mentionned is to use the form hidden field element to pass the global vars. My first HTMLpage calls a REBOL-cgi script, passing some args this script uses to generate another page which in turn contains a form with some hidden field containing the global data. <form action='http://127.0.0.1/cat_task_manager.r'> "<input name='id' type='hidden' value='0'>" "<input name='RLI' type='hidden' value='F'>" "<input name='test' type='hidden' value='0'>" "<input name='question' type='hidden' value='1'>" "<input name='navigation' type='hidden' value='next'>" "<input name='answer' type='hidden' value='next'>" "<input type='submit' value=' >> ' class='longbutton'>" </form> You can so pass your args through your app, and call them when you need it... I hope it will work for you ! Do not hesitate to ask I there is any problem. C. COUSSEMENT e-mail: [coussement--c--itc--mil--be]

 [7/9] from: kracik:mbox:dkm:cz at: 11-Oct-2000 22:56


Hi Sharriff, be careful when saving to a file and reading it later, as many users may run your CGI programs simultaneously. You should use some form of inter-process synchronization to serialize access to your file. AFAIK from REBOL you can reliably synchronize by opening TCP sockets or renaming a file. I use these two functions: obtain-semaphore: func [] [ loop 100 [ if not error? try [ rename %lockdir/lock %lock.locked ] [ return ] wait ( random 5 ) / 10 ] print "Could not obtain semaphore" quit ] release-semaphore: func [] [ loop 100 [ if not error? try [ rename %lockdir/lock.locked %lock ] [ return ] wait ( random 5 ) / 10 ] print "Could not release semaphore" quit ] -- Michal Kracik [Sharriff--Aina--med-iq--de] wrote:

 [8/9] from: sharriff:aina:med-iq at: 12-Oct-2000 7:33


Thank you Mr. Kracik! If only I undersatood completely whats going on in the script. Please correct me if I´m wrong: 1.Files in use are flagged with "semaphore" 2. The files in use are renamed as "%lock.locked" The script loops, continues to "Try" to rename, if it encounters an error then it "waits". Wonßt I get an error anyway if the file is directly renamed when I CGI script user requests a file? Excuse my newbie question Best regards Sharriff Aina med.iq information & quality in healthcare AG Gutenbergstr. 42 [kracik--mbox--d] km.cz An: [list--rebol--com] Kopie: 11.10.00 Thema: [REBOL] How does one persist data? Re: 21:56 Bitte antworten an list Hi Sharriff, be careful when saving to a file and reading it later, as many users may run your CGI programs simultaneously. You should use some form of inter-process synchronization to serialize access to your file. AFAIK from REBOL you can reliably synchronize by opening TCP sockets or renaming a file. I use these two functions: obtain-semaphore: func [] [ loop 100 [ if not error? try [ rename %lockdir/lock %lock.locked ] [ return ] wait ( random 5 ) / 10 ] print "Could not obtain semaphore" quit ] release-semaphore: func [] [ loop 100 [ if not error? try [ rename %lockdir/lock.locked %lock ] [ return ] wait ( random 5 ) / 10 ] print "Could not release semaphore" quit ] -- Michal Kracik [Sharriff--Aina--med-iq--de] wrote:

 [9/9] from: kracik:mbox:dkm:cz at: 12-Oct-2000 18:59


Hi, I forgot to include some description how it should work. The guarded file is not %lockdir/lock, but any other file - because read-only accesses to the file don't need to be guarded, and would fail if the guarded file is currently renamed. You should make a directory %lockdir/ with an empty file %lock then you should use: obtain-semaphore something: read %my-guarded-file.txt write %my-guarded-file.txt "something new" release-semaphore If you want to only read from your file, you can use just something: read %my-guarded-file.txt print something If I remember correctly, you must only guard one situation, read-modify-write , because two simultaneous reads do not interfere, and two simultaneous writes are a logic error of your program. obtain-semaphore function uses loop and random wait interval to have a better chance of succeeding if several processes run it simultaneously. release-semaphore function should be simpler, loop is not necessary: release-semaphore: func [] [ if not error? try [ rename %lockdir/lock.locked %lock ] [ return ] print "Could not release semaphore" quit ] -- Michal Kracik [Sharriff--Aina--med-iq--de] wrote: