Database suggestions?

Pierre Sahores psahores at easynet.fr
Sat May 14 06:18:10 EDT 2005


Hello Ken, Richard an All,

Just see how simple it can be to connect PostgreSQL 7.xx or 8.xx from 
within Rev 2.xx (Mac OS X and Linux, Win32 untested) or Rev 2.xx and 
Metacard 2.3 and above (Linux, Win32 untested) :

to stick in the main stack's script :

> on preopenstack
>     ...
>   if the platform is not "MacOS" then put "psql -h localhost dpim -U 
> postgres" into PgPath
>   else
>     repeat for each item i in revOpenDatabases()
>       get revdb_disconnect(i)
>     end repeat
>     put 
> revOpenDatabase("PostgreSQL","localhost","dpim","postgres","postgres") 
> into PGLinkOpen
>   end if
>     ...
> end preopenstack
>
>
> function presave r
>   set itemdel to "¶"
>   put item 1 of r into s
>   put item 2 of r into t
>
>   set itemdel to "&"
>   replace numtochar(10) with "##10;#" in s
>   replace "\'" with "##11;#" in s
>   replace numtochar(34) with "##34;#" in s
>   replace "##11;###11;#" with "" in s
>
>   if the platform is "macos" then put mactoiso(isotomac(s)) into s
>
>   if "&CCL=insert&" is in s then put item itemoffset("personid=",s) of 
> s & return into datatosave
>   else put item itemoffset("recordid=",s) of s & return into datatosave
>
>   if itemoffset("credatid=",s) is not "0" then
>     put item itemoffset("credatid=",s) of s & return after datatosave
>     put item itemoffset("creserid=",s) of s & return after datatosave
>   end if
>
>   put item itemoffset("derdatid=",s) of s & return & \
>       item itemoffset("modserid=",s) of s & return after datatosave
>
>   repeat for each item i in s
>     if char 1 to 4 of i is t then put i & return after datatosave
>   end repeat
>
>   repeat for each char c in datatosave
>     try
>       if c is "_"
>       then put " " after datatosavec
>       else if chartonum(c) > 223
>       then put "&#" & chartonum(c) & ";" after datatosavec
>       else if chartonum(c) > 191
>       then put "&#" & chartonum(c) & ";" after datatosavec
>       else if chartonum(c) = 39
>       then put "&#" & chartonum(c) & ";" after datatosavec
>       else put c after datatosavec
>     catch errornum
>       if c is not char 1 of datatosave
>       then if c is not char -1 of datatosave
>       then put "_" after datatosavec
>     end try
>   end repeat
>
>   put char 1 to 8 of line -1 of datatosavec && "RECORDED" into aa
>
>   if "&CCL=insert&" is in s then
>     put " ( " into insertcolnames
>     put " values ( " into insertcoldatas
>     repeat for each line l in datatosavec
>       if l is line -1 of datatosavec then
>         put char 1 to 8 of l && " ) " after insertcolnames
>         put "'" & aa & "' ) " after insertcoldatas
>       else
>         put char 1 to 8 of l && " , " after insertcolnames
>         put "'" & char 10 to -1 of l & "' , " after insertcoldatas
>       end if
>     end repeat
>     put insertcolnames & insertcoldatas into updatecols
>   else
>     repeat for each line l in datatosavec
>       if l is line -1 of datatosavec then put char 1 to 8 of l && "= 
> '" & aa & "'" after updatecols
>       else put char 1 to 8 of l && "= '" & char 10 to -1 of l & "' , " 
> after updatecols
>     end repeat
>   end if
>
>   put updatecols
>
>   return updatecols
> end presave
>
>
> function parsesql s
>   repeat for each char c in s
>     try
>       if chartonum(c) > 223
>       then put "&#" & chartonum(c) & ";" after t
>       else if chartonum(c) > 191
>       then put "&#" & chartonum(c) & ";" after t
>       else put c after t
>     catch errornum
>       if c is not char 1 of s
>       then if c is not char -1 of s
>       then put "_" after t
>     end try
>   end repeat
>   replace "\" with "" in t
>   replace "[" with "&" in t
>   replace "]" with "\" in t
>   if the platform is "MacOS" then
>     if "select" is not in t then get revdb_QueryBLOB(PGLinkOpen,t)
>     else
>       put revdb_QueryList("|",return,PGLinkOpen,t) into pgreply
>       repeat for each line l in pgreply
>         put char 1 to -1+offset("|",l) of l && char offset("|",l) to 
> -1 of l & return after d
>       end repeat
>       return d & "(" & the num of lines in pgreply && "rows)"
>     end if
>   else return shell("echo" && quote && t && quote && "|" && PgPath)
> end parsesql


to stick where you want in the transcript/metatalk code to catch your 
SQL requests results (the four basic SQL queries) :

> get parsesql("insert into dpim0001" && presave(PostIn & "¶0001"))

> get parsesql("update dpim0001 set" && presave(PostIn & "¶0001 where 
> recordid='" & \
> char 5 to -1 of item itemoffset("CCL=",PostIn) of PostIn & "'")

> get parsesql("delete from dpim0001 where recordid='" & char 5 to -1 of 
> item itemoffset("CCL=",PostIn) of PostIn & "'")

> get parsesql("select * from" && k && "where" && word 1 to -2 of 
> lesclauses)
> if word 1 to -1 of it is not "(0 rows)" then put line 1 to -2 of it & 
> return after lareply


Have fun, Friends ! Rev is just most usable than any other language 
(Java and .NET included) in about databases access too ;-)

All the best,

Pierre


Le 14 mai 05, à 07:51, Ken Ray a écrit :

> On 5/14/05 12:28 AM, "Chipp Walters" <chipp at chipp.com> wrote:
>
>> Hi Ken,
>>
>> Here's a couple of things you may want to consider.
>
> Thanks, Chipp... yes, we'll have multiple concurrent users so I guess 
> it's
> MySQL or PostgreSQL. My understanding is that in general, MySQL has 
> better
> performance than PostgreSQL, does that jibe with your take on the two 
> DBs?
>
>
> Ken Ray
> Sons of Thunder Software
> Web site: http://www.sonsothunder.com/
> Email: kray at sonsothunder.com
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>


More information about the use-livecode mailing list