#!/bin/sh # MetaCard 2.4 stack # The following is not ASCII text, # so now would be a good time to q out of more exec mc $0 "$@" MySQL 3 on doLog pData put pData & cr after fld "Data" set the scroll of fld "Data" to 30000 end doLog on makeConnection put the dbConnectName of this stack into dbName put the dbConnectAddr of this stack into dbHost put the dbConnectUser of this stack into dbUser put the dbConnectPass of this stack into dbPass get revOpenDatabase("MySQL",dbHost,dbName,dbUser,dbPass) if it is a number then set the dbConnectID of this stack to it doLog "Connected to " & dbName & ", ID = " & it set the label of btn "Connect" to "Disconnect" else set the dbConnect of this stack to empty answer it end if end makeConnection on closeConnections set the dbConnectID of this stack to empty put revOpenDatabases() into dbList repeat for each item d in dbList revCloseDatabase d doLog "Disconnected from ID = " & d end repeat end closeConnections on showCursor curID put "-" into tDiv put revDatabaseColumnCount(curID) into colNum repeat colNum times put "--------------|" after tDiv end repeat put revDatabaseColumnNames(curID) into colNames replace comma with tab & "|" in colNames put tDiv & cr & colNames & tab & "|" & cr & tDiv & cr into curDisplay put revNumberOfRecords(curID) into recNum if recNum > 0 then repeat repeat with c = 1 to colNum put revDatabaseColumnNumbered(curID, c) into temp if temp is empty then put "NULL" into temp put temp & tab & "|" after curDisplay end repeat put cr after curDisplay revMoveToNextRecord curID if the result = false then exit repeat end repeat end if put tDiv after curDisplay revCloseCursor curID doLog curDisplay end showCursor function formatSQL pQuery put the mySQLreservedWords of this stack into tWords put empty into newQuery replace cr with space in pQuery if last char of pQuery = ";" then delete last char of pQuery repeat for each word W in pQuery if tWords contains W then put toUpper(W) & space after newQuery else put W & space after newQuery end if end repeat delete last char of newQuery if word 1 of newQuery is in "SELECT,DESCRIBE,SHOW" then put ";" after newQuery return newQuery end formatSQL on executeSQL put formatSQL(fld "Query") into fld "Query" put fld "Query" into dbSQL doLog "> " & dbSQL revExecuteSQL the dbConnectID of this stack, dbSQL if the result is a number then doLog "Query OK: " & the result & " record(s) altered." else doLog the result end if end executeSQL on querySQL put formatSQL(fld "Query") into fld "Query" put fld "Query" into dbSQL doLog "> " & dbSQL put revQueryDatabase(the dbConnectID of this stack, dbSQL) into curID if curID is a number then showCursor curID else doLog curID end if end querySQL @ e& dbConnect dbConnectName dbConnectAddr MySQLreservedWords ADD ALL ALTER ANALYZE AND AS ASC ASENSITIVE AUTO_INCREMENT BDB BEFORE BERKELEYDB BETWEEN BIGINT BINARY BLOB BOTH BTREE BY CALL CASCADE CASE CHANGE CHAR CHARACTER CHECK COLLATE COLUMN COLUMNS CONNECTION CONSTRAINT CREATE CROSS CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP CURSOR DATABASE DATABASES DAY_HOUR DAY_MINUTE DAY_SECOND DEC DECIMAL DECLARE DEFAULT DELAYED DELETE DESC DESCRIBE DISTINCT DISTINCTROW DIV DOUBLE DROP ELSE ELSEIF ENCLOSED ERRORS ESCAPED EXISTS EXPLAIN FALSE FIELDS FLOAT FOR FORCE FOREIGN FROM FULLTEXT GRANT GROUP HASH HAVING HIGH_PRIORITY HOUR_MINUTE HOUR_SECOND IF IGNORE IN INDEX INFILE INNER INNODB INOUT INSENSITIVE INSERT INT INTEGER INTERVAL INTO IS ITERATE JOIN KEY KEYS KILL LEADING LEAVE LEFT LIKE LIMIT LINES LOAD LOCALTIME LOCALTIMESTAMP LOCK LONG LONGBLOB LONGTEXT LOOP LOW_PRIORITY MASTER_SERVER_ID MATCH MEDIUMBLOB MEDIUMINT MEDIUMTEXT MIDDLEINT MINUTE_SECOND MOD MRG_MYISAM NATURAL NOT NULL NUMERIC ON OPTIMIZE OPTION OPTIONALLY OR ORDER OUT OUTER OUTFILE PRECISION PRIMARY PRIVILEGES PROCEDURE PURGE READ REAL REFERENCES REGEXP RENAME REPEAT REPLACE REQUIRE RESTRICT RETURN RETURNS REVOKE RIGHT RLIKE RTREE SELECT SENSITIVE SEPARATOR SET SHOW SMALLINT SOME SONAME SPATIAL SPECIFIC SQL_BIG_RESULT SQL_CALC_FOUND_ROWS SQL_SMALL_RESULT SSL STARTING STRAIGHT_JOIN STRIPED TABLE TABLES TERMINATED THEN TINYBLOB TINYINT TINYTEXT TO TRAILING TRUE TYPES UNION UNIQUE UNLOCK UNSIGNED UNTIL UPDATE USAGE USE USER_RESOURCES USING VALUES VARBINARY VARCHAR VARCHARACTER VARYING WARNINGS WHEN WHERE WHILE WITH WRITE XOR YEAR_MONTH ZEROFILLdbConnectID dbConnectPass dbConnectUser MySQL Client U Lucida Grande U Monaco W Monaco U Arial U Arial U Verdana U Verdana U Verdana @U Verdana U Monaco W Monaco W Arial @U Verdana cREVGeometryCache stackID 1016 cREVGeneral scriptChecksum jF ,19 debugObjects breakPoints handlerList NdoLog makeConnection closeConnections showCursor formatSQL executeSQL querySQLscriptSelection char 2556 to 2555 bookmarks tempScript prevHandler doLogscript 4
on doLog pData
put pData & cr after fld "Data"
set the scroll of fld "Data" to 30000
end doLog
on makeConnection
put the dbConnectName of this stack into dbName
put the dbConnectAddr of this stack into dbHost
put the dbConnectUser of this stack into dbUser
put the dbConnectPass of this stack into dbPass
get revOpenDatabase("MySQL",dbHost,dbName,dbUser,dbPass)
if it is a number then
set the dbConnectID of this stack to it
doLog "Connected to " & dbName & ", ID = " & it
set the label of btn "Connect" to "Disconnect"
else
set the dbConnect of this stack to empty
answer it
end if
end makeConnection
on closeConnections
set the dbConnectID of this stack to empty
put revOpenDatabases() into dbList
repeat for each item d in dbList
revCloseDatabase d
doLog "Disconnected from ID = " & d
end repeat
end closeConnections
on showCursor curID
put "-" into tDiv
put revDatabaseColumnCount(curID) into colNum
repeat colNum times
put "--------------|" after tDiv
end repeat
put revDatabaseColumnNames(curID) into colNames
replace comma with tab & "|" in colNames
put tDiv & cr & colNames & tab & "|" & cr & tDiv & cr into curDisplay
put revNumberOfRecords(curID) into recNum
if recNum > 0 then
repeat
repeat with c = 1 to colNum
put revDatabaseColumnNumbered(curID, c) into temp
if temp is empty then put "NULL" into temp
put temp & tab & "|" after curDisplay
end repeat
put cr after curDisplay
revMoveToNextRecord curID
if the result = false then exit repeat
end repeat
end if
put tDiv after curDisplay
revCloseCursor curID
doLog curDisplay
end showCursor
function formatSQL pQuery
put the mySQLreservedWords of this stack into tWords
put empty into newQuery
replace cr with space in pQuery
if last char of pQuery = ";" then delete last char of pQuery
repeat for each word W in pQuery
if tWords contains W then
put toUpper(W) & space after newQuery
else
put W & space after newQuery
end if
end repeat
delete last char of newQuery
if word 1 of newQuery is in "SELECT,DESCRIBE,SHOW" then put ";" after newQuery
return newQuery
end formatSQL
on executeSQL
put formatSQL(fld "Query") into fld "Query"
put fld "Query" into dbSQL
doLog "> " & dbSQL
revExecuteSQL the dbConnectID of this stack, dbSQL
if the result is a number then
doLog "Query OK: " & the result & " record(s) altered."
else
doLog the result
end if
end executeSQL
on querySQL
put formatSQL(fld "Query") into fld "Query"
put fld "Query" into dbSQL
doLog "> " & dbSQL
put revQueryDatabase(the dbConnectID of this stack, dbSQL) into curID
if curID is a number then
showCursor curID
else
doLog curID
end if
end querySQL
@ & cREVGeometryCacheIDs 1056696974030 10101056695578571 10081056695553166 10051056695545166 10031057444991862 10161057444950635 10151057444727319 1014 cREVGeometrycache order b1056695545166 1057444991862 1056695553166 1056695578571 1056696974030 1057444727319 1057444950635 total 7 cREVGeneral bookmarks handlerList tempScript prevHandler scriptSelection char 1 to 0script Data )p on mouseUp if word 1 of the selectedText of me = ">" then put word 2 to -1 of the selectedText of me into fld "Query" end if end mouseUp i cREVGeometry Master,scalebottomObjectSide BottomMaster,movehDistance falseMaster,scaleBottomscaleBottom trueMaster trueMaster,scaleLeftObjectRef cardMaster,scaleTopObjectRef cardMaster,scalebottomObjectRef cardMaster,scalebottomAbsolute trueMaster,scalebottom trueMaster,scaleLeftObjectSide LeftMaster,scaleTopObjectSide TopMaster,movevDistance falseMaster,scalebottomDistance -92Master,expectedRect 8,8,440,338Master,scaleRightAbsolute trueMaster,scaleRight trueMaster,scalerightDistance -10Master,scaleLeftAbsolute trueMaster,scaleTopAbsolute trueMaster,scaleRightObjectSide RightMaster,scaleRightObjectRef cardMaster,scaleLeft trueMaster,scaleTop trueMaster,cardRanking 4Master,scaletopDistance 8Master,scaleleftDistance 8 cREVGeneral scriptChecksum rH~SjJyW bookmarks revUniqueID 1056695545166handlerList mouseUpscriptSelection char 133 to 132prevHandler tempScript scripton mouseUp
if word 1 of the selectedText of me = ">" then
put word 2 to -1 of the selectedText of me into fld "Query"
end if
end mouseUp
` n a v Connect ep on mouseUp if the label of me = "Connect" then go to stack "Connect" as sheet else closeConnections set the label of me to "Connect" end if end mouseUp R Connect cREVGeometry Master,scaleBottomObjectSide BottomMaster,moveVObjectSide bottomMaster,movehDistance -0.903846Master,scaleBottomscaleBottom trueMaster trueMaster,scaleBottomObjectRef cardMaster,moveVObjectRef cardMaster,movehObjectRef cardMaster,scaleBottomAbsolute falseMaster,moveVAbsolute trueMaster,scaleBottom false Master,moveV trueMaster,movevDistance -15Master,scalebottomDistance -0.006135Master,expectedRect 8,469,90,492Master,movehObjectSide rightMaster,scalerightDistance Master,cardRanking 2Master,scaletopDistance Master,scaleleftDistance Master,movehAbsolute false Master,moveh true cREVGeneral scriptChecksum ubf>z76OrevUniqueID 1056695578571 bookmarks handlerList mouseUptempScript prevHandler mouseUpscriptSelection char 144 to 143script ron mouseUp
if the label of me = "Connect" then
go to stack "Connect" as sheet
else
closeConnections
set the label of me to "Connect"
end if
end mouseUp
Clear Ep oon mouseUp put empty into fld "Data" if the optionKey is down then put empty into fld "Query" end mouseUp R cREVGeometry Master,moveVObjectSide bottomMaster,movehDistance -0.641026Master trueMaster,moveVObjectRef cardMaster,movehObjectRef cardMaster,moveVAbsolute true Master,moveV trueMaster,expectedRect 141,469,223,492Master,scalebottomDistance Master,movevDistance -15Master,movehObjectSide rightMaster,scalerightDistance Master,cardRanking 2Master,scaleleftDistance Master,scaletopDistance Master,movehAbsolute false Master,moveh true cREVGeneral scriptChecksum ,bzrevUniqueID 1056696974030 bookmarks handlerList mouseUptempScript prevHandler mouseUpscriptSelection char 98 to 97scripton mouseUp
put empty into fld "Data"
if the optionKey is down then put empty into fld "Query"
end mouseUp
Query )p Aon enterInField send mouseUp to btn "Do It" end enterInField / cREVGeometry Master,scaleBottomObjectSide BottomMaster,moveVObjectSide bottomMaster,movehDistance falseMaster,scaleBottomscaleBottom trueMaster trueMaster,scaleLeftObjectRef cardMaster,scaleTopObjectRef cardMaster,scaleBottomObjectRef cardMaster,moveVObjectRef cardMaster,scaleBottomAbsolute falseMaster,moveVAbsolute trueMaster,scaleBottom false Master,moveV trueMaster,scaleLeftObjectSide LeftMaster,scaleTopObjectSide TopMaster,movevDistance -55Master,scalebottomDistance -0.063395Master,expectedRect 8,352,440,399Master,scaleRightAbsolute trueMaster,scaleRight trueMaster,scalerightDistance -10Master,scaleLeftAbsolute trueMaster,scaleRightObjectSide RightMaster,scaleRightObjectRef cardMaster,scaleTopAbsolute trueMaster,scaleLeft trueMaster,scaleTop falseMaster,cardRanking 3Master,scaletopDistance 411Master,scaleleftDistance 8 cREVGeneral scriptChecksum (ORRJr7 ژ\ bookmarks revUniqueID 1056695553166handlerList enterInFieldscriptSelection char 47 to 46prevHandler enterInFieldtempScript script qon enterInField
send mouseUp to btn "Do It"
end enterInField
` - Do It p on mouseUp if word 1 of fld "Query" is in "SELECT,DESCRIBE,SHOW" then querySQL else executeSQL end if end mouseUp R cREVGeometry Master,moveVObjectSide bottomMaster,scaleBottomObjectSide BottomMaster,scaleBottomscaleBottom trueMaster,movehDistance -0.113782Master,scaleRightscaleBottom trueMaster trueMaster,moveVObjectRef cardMaster,scaleBottomObjectRef cardMaster,moveHObjectRef cardMaster,moveVAbsolute trueMaster,scaleBottomAbsolute false Master,moveV trueMaster,scaleBottom falseMaster,expectedRect 512,463,594,486Master,scalebottomDistance -0.006135Master,movevDistance -15Master,moveHObjectSide rightMaster,scaleRightAbsolute falseMaster,scaleRight falseMaster,scalerightDistance -0.048077Master,scaleRightObjectSide RightMaster,scaleRightObjectRef cardMaster,cardRanking 2Master,moveHAbsolute falseMaster,scaleleftDistance Master,scaletopDistance Master,moveH true cREVGeneral scriptChecksum {S-*F{b bookmarks revUniqueID 1057444727319handlerList mouseUpscriptSelection char 38 to 37prevHandler mouseUptempScript script ^on mouseUp
if word 1 of fld "Query" is in "SELECT,DESCRIBE,SHOW" then
querySQL
else
executeSQL
end if
end mouseUp
Help p Won mouseUp set the visible of fld "Help" to not the visible of fld "Help" end mouseUp . R cREVGeometry Master,moveVObjectSide bottomMaster,scaleBottomObjectSide BottomMaster,scaleBottomscaleBottom trueMaster,movehDistance -0.376603Master,scaleRightscaleBottom trueMaster trueMaster,moveVObjectRef cardMaster,scaleBottomObjectRef cardMaster,moveHObjectRef cardMaster,moveVAbsolute trueMaster,scaleBottomAbsolute false Master,moveV trueMaster,scaleBottom falseMaster,expectedRect 348,463,430,486Master,scalebottomDistance -0.006135Master,movevDistance -15Master,moveHObjectSide rightMaster,scaleRightAbsolute falseMaster,scaleRight falseMaster,scalerightDistance -0.310897Master,scaleRightObjectSide RightMaster,scaleRightObjectRef cardMaster,cardRanking 2Master,moveHAbsolute falseMaster,scaleleftDistance Master,scaletopDistance Master,moveH true cREVGeneral scriptChecksum $8nbTֹꚱrevUniqueID 1057444950635 bookmarks handlerList mouseUptempScript prevHandler mouseUpscriptSelection char 74 to 73scripton mouseUp
set the visible of fld "Help" to not the visible of fld "Help"
end mouseUp
Help !x on linkClicked pLink if pLink contains "@" then revGoURL "mailto:" & pLink else revGoURL pLink end if end linkClicked on mouseUp hide me end mouseUp cREVGeometry Master,scaleBottomObjectSide BottomMaster,movehDistance falseMaster trueMaster,scaleLeftObjectRef cardMaster,scaleTopObjectRef cardMaster,scaleBottomObjectRef cardMaster,scaleBottomAbsolute trueMaster,scaleBottom trueMaster,scaleLeftObjectSide LeftMaster,scaleTopObjectSide TopMaster,expectedRect 8,8,614,458Master,scalebottomDistance -31Master,movevDistance falseMaster,scaleRightAbsolute trueMaster,scaleRight trueMaster,scalerightDistance -10Master,scaleRightObjectRef cardMaster,scaleRightObjectSide RightMaster,scaleLeftAbsolute trueMaster,scaleTopAbsolute trueMaster,scaleLeft trueMaster,scaleTop trueMaster,cardRanking 4Master,scaleleftDistance 8Master,scaletopDistance 8 cREVGeneral scriptChecksum ADHn >,M bookmarks revUniqueID 1057444991862handlerList linkClicked mouseUpscriptSelection char 154 to 153prevHandler linkClickedtempScript scripton linkClicked pLink
if pLink contains "@" then
revGoURL "mailto:" & pLink
else
revGoURL pLink
end if
end linkClicked
on mouseUp
hide me
end mouseUp
MySQL Client: This stack is a client for MySQL which is designed to be very like the client that can be used from the OS X Terminal. Since I am now using MySQL on a remote server, I didn't have the client installed on my desktop computer, so I needed a way to interact directly with the MySQL Server. Connecting to the Server: 2Click 'Connect' to enter your connection details. 7The last connection will be remembered for future use. `If you are connecting to a MySQL Server on your own computer, type 'localhost' for the address. Querying the Server: TType any SQL command in the field at the bottom and press 'Enter' or click 'Do It'. MySQL reserved words will be changed to upper-case, a semi-colon will be added if required and the command will be checked to see whether it is a query or an executable command. _The relevant Revolution database handler or function will be called and the results displayed. `For a query, the results are displayed in table form with dividers like those used in Terminal. DFor executable commands, the number of rows affected will be shown. Disconnecting: SWhen you have finished, click 'Disconnect' to break your connection to the Server. Other information: - Clicking on any line in the results display that starts with a '>', will bring the selected command back into the command field at the bottom, where it can be edited or re-run. - 'Clear' will normally only clear the results display, but if you Option-click, it will also clear the command field at the bottom. - This has only been tested on Mac OS X 10.2.6, Rev 2.0.1 and with MySQL 4.0, but I would be interested to hear if anyone uses it on other systems. - If you want a more structured method of interacting with a MySQL Server, then you might be interested in my other MySQL utility stack: MySQL tests.rev which is also available on my web site. h- Feel free to use or modify this stack in any way, but anything you do with it is your responsibility. 7Sarah Reichelt sarah@troz.net http://www.troz.net/Rev/ ` Connect R z U Lucida Grande cREVGeometryCache stackID 1015 cREVGeneral scriptChecksum ُ B~ bookmarks handlerList tempScript prevHandler preOpenStackscriptSelection char 1 to 0script Pon preOpenStack put the dbConnectName of stack "MySQL" into fld "dbName" put the dbConnectAddr of stack "MySQL" into fld "dbAddr" put the dbConnectUser of stack "MySQL" into fld "dbUser" put the dbConnectPass of stack "MySQL" into dbPass put dbPass into fld "hiddenPass" put the length of dbPass into lenPass put char 1 to lenPass of "" into fld "dbPass" end preOpenStack on clearFields put empty into fld "dbName" put empty into fld "dbAddr" put empty into fld "dbUser" put empty into fld "dbPass" put empty into fld "hiddenPass" end clearFields on openField put the target select the text of the target end openField cREVGeometryCacheIDs 1056952038548 10131057025449661 10151056951898520 10061056951978389 10101056951967941 10081056951975614 10091056951895505 10051056952027718 10121056951902421 10071056952060318 10141056951980515 10111056951870346 1004 cREVGeometrycache total 12order cREVGeneral scriptChecksum r[r\[ bookmarks handlerList "preOpenStack clearFields openFieldscriptSelection char 636 to 635prevHandler clearFieldstempScript scripton preOpenStack
put the dbConnectName of stack "MySQL" into fld "dbName"
put the dbConnectAddr of stack "MySQL" into fld "dbAddr"
put the dbConnectUser of stack "MySQL" into fld "dbUser"
put the dbConnectPass of stack "MySQL" into dbPass
put dbPass into fld "hiddenPass"
put the length of dbPass into lenPass
put char 1 to lenPass of "" into fld "dbPass"
end preOpenStack
on clearFields
put empty into fld "dbName"
put empty into fld "dbAddr"
put empty into fld "dbUser"
put empty into fld "dbPass"
put empty into fld "hiddenPass"
end clearFields
on openField
put the target
select the text of the target
end openField
Field 1 ' cREVGeneral revUniqueID 1056951870346 Database name: Field 1 B cREVGeneral revUniqueID 1056951895505 Database address: Field 1 \ cREVGeneral revUniqueID 1056951898520 Login name: Field 1 w cREVGeneral revUniqueID 1056951902421 Password: dbName i` ) cREVGeneral revUniqueID 1056951967941 dbAddr i` D cREVGeneral revUniqueID 1056951975614 dbUser i` ^ cREVGeneral revUniqueID 1056951978389 dbPass ip on closeField put me into fld "hiddenPass" put the length of me into lenPass put char 1 to lenPass of "" into me end closeField y cREVGeneral scriptChecksum 0 Id MY bookmarks revUniqueID 1056951980515handlerList closeFieldscriptSelection char 151 to 150prevHandler tempScript script Pon closeField
put me into fld "hiddenPass"
put the length of me into lenPass
put char 1 to lenPass of "" into me
end closeField
Cancel Ep Kon mouseUp clearFields save this stack close this stack end mouseUp R cREVGeneral scriptChecksum ;@5 ;revUniqueID 1056952027718 bookmarks handlerList mouseUptempScript prevHandler scriptSelection char 62 to 61script lon mouseUp
clearFields
save this stack
close this stack
end mouseUp
Connect MpKon mouseUp set the dbConnectName of stack "MySQL" to fld "dbName" set the dbConnectAddr of stack "MySQL" to fld "dbAddr" set the dbConnectUser of stack "MySQL" to fld "dbUser" set the dbConnectPass of stack "MySQL" to fld "hiddenPass" clearFields close this stack send makeConnection to stack "MySQL" end mouseUp " R cREVGeneral scriptChecksum \XBbrevUniqueID 1056952038548 bookmarks handlerList mouseUptempScript prevHandler mouseUpscriptSelection char 238 to 237scripton mouseUp
set the dbConnectName of stack "MySQL" to fld "dbName"
set the dbConnectAddr of stack "MySQL" to fld "dbAddr"
set the dbConnectUser of stack "MySQL" to fld "dbUser"
set the dbConnectPass of stack "MySQL" to fld "hiddenPass"
clearFields
close this stack
send makeConnection to stack "MySQL"
end mouseUp
Field 2 P cREVGeneral revUniqueID 1056952060318 Enter the connection settings. hiddenPass ` @ j cREVGeneral revUniqueID 1057025449661