Applescript - how do I use the result of a library return value

Hello. Been using applescript for about a week. Very new.


I'm using the following script below using an external libarary to query mysql database on external server. works. gives results. How do I save them to do something with the.


when I run it, the results of the call to the library show up in the results window. that makes sense.


ie


{rows:1, cols:1, record_data:{{"85016 "}}}




I want to assign the results to a variable to use it later, particularly the 85016.


I try "set testVariable to tell db_link to do_select(theDBCommand)"


no good. Not sure how to do this.


Help appreciated.




Script follows:



-- links to the mysql tools - thanks to http://www.j-schell.de/node/80


set library_path to "js_aux_scripts:mysql_objects.scptd"


set app_support to (path toapplication support folder) as string

set DB_Library to (load scriptfile (app_support & library_path))


set db_link to new_link("lala.yadayada.com", "user", "pass", "db") of DB_Library


-- collect the job number you want to run

-- Get the Number

set displayString to "Enter Job Number"

set the theIcon to 1

set theJobNumber to ""

repeat


display dialogdisplayStringdefault answertheJobNumberwith icontheIcon

set theJobNumber to text returned of result

try

if theJobNumber = "" then error

set theJobNumber to theJobNumber as number

exit repeat

on error

set displayString to "INVALID ENTRY! " & displayString

set theIcon to 0

end try

end repeat


-- Query the database and get the other informtion from the ticket file.


set theDBCommand to "SELECT BaseId from SfComp where JobNo = " & theJobNumber


tell db_link to do_select(theDBCommand)

applescript-OTHER, Mac OS X (10.7.3)

Posted on Apr 26, 2012 5:54 PM

Reply
2 replies

Apr 26, 2012 6:23 PM in response to good_nature

Usually you would assign the variable to the results of the command/function, which are inside the tell statement -for example:


telldb_linktosettestVariabletodo_select(theDBCommand)


The results are a record, where it looks like record_data is a list of lists (although your example only has one item), so for that you can specify the particular property you are intereste in, for example:


getfirstitemoffirstitemofrecord_dataoftestVariable

Apr 26, 2012 6:26 PM in response to good_nature

Without having the library in question, it's hard to be specific, but according to the standard AppleScript rules you have a couple of options.


First, you're close on your existing attempt, but you need to shift the 'set' to inside the 'tell' statement. e.g.:


tell db_link to set testVariable to do_select(theDBCommand)


In this way the result of the do_select command should be stored in the variable.


If that doesn't work, the alternative is to use AppleScript's result property. The result is always the result of the last-executed command, so:


tell db_link to do_select(theDBCommand)

set testVariable to the result

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript - how do I use the result of a library return value

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.