• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScript access to databases
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript access to databases


  • Subject: Re: AppleScript access to databases
  • From: Vittorio <email@hidden>
  • Date: Tue, 23 Mar 2010 14:43:16 +0100




Here you are my contribution (of an AS absolute beginner) to the discussion ignited by myself.
I'm profitably using a PostgreSQL DB to consult thousands of meteorological data. 
psql is the shell commmand to deal with this db. I noticed that is much better to simplify the otherwise neat and nice-looking output adding the following option to the command line:
-A = doesn't align the output
-t = I want tuples only without headers
-R = character(s) for the end of each record (I chose the unfrequent '§')
-F = character(s) field separator (in my case "," according to the standard CSV style)
-c = command to be executed as a string

the subroutine returns a list

For me it works and I think that with small adjustement the same routine can be used for MySQL. 

Ciao
Vittorio


property psqlCommand : "/sw/bin/psql"

on SQLExecute(DatabaseName, sqlCommand)
set resultText to (do shell script psqlCommand & space & DatabaseName & space & ¬
"-A -t -R '§' -F ',' -c " & (quoted form of sqlCommand))
if length of resultText = 0 then
return resultText
end if
set text item delimiters to "§"
set these_items to the text items of resultText
set text item delimiters to ","
repeat with i from 1 to count of items of these_items
set item i of these_items to text items of item i of these_items
end repeat
return these_items


end SQLExecute


on run
set DBName to "meteodm"
set resultList to SQLExecute(DBName, "
select * from regioni where id > 115 order by id;")
..................................  
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: A bit of philosophy about Database events (From: Rob Lewis <email@hidden>)
 >AppleScript access to databases (was: A bit of philosophy about Database events) (From: BareFeet <email@hidden>)
 >Re: AppleScript access to databases (was: A bit of philosophy about Database events) (From: Axel Luttgens <email@hidden>)
 >Re: AppleScript access to databases (From: BareFeet <email@hidden>)
 >Re: AppleScript access to databases (From: Axel Luttgens <email@hidden>)
 >Re: AppleScript access to databases (From: BareFeet <email@hidden>)

  • Prev by Date: Re: How to disable the -- comment
  • Next by Date: new line when writing to text file
  • Previous by thread: Re: AppleScript access to databases
  • Next by thread: Re: AppleScript access to databases (was: A bit of philosophy about Database events)
  • Index(es):
    • Date
    • Thread