Quando utilizzo la mia libreria in questo modo, applescript non analizzerà la riga display dialog
, trattando dialog
come identificatore!
Qualcuno può spiegare perché questo non viene compreso nel modo in cui voglio che sia? Grazie molto! ** AGGIORNAMENTO ** Entrambi gli script di seguito verranno ora compilati e funzionanti correttamente
use myLib : script "IHDatabase" -- the name of the library
-- UPDATE -- See also my answer below
use scripting additions
-- UPDATE -- without the above statement this script will not compile
set db to IHDatabase of myLib at "~/Desktop/TestDB.db"
-- IHDatabase handler returns an IHDB script object
tell db
add_sql("drop table if exists testtable;")
add_sql("create table testtable (firstname, lastname, country);")
add_sql("insert into testtable values('Ray', 'Barber', 'USA');")
add_sql("insert into testtable values('jj', 'Sancho', 'Spain');")
add_sql("insert into testtable values('Adam', 'Bell', 'Canada');")
add_sql("insert into testtable values('Bruce', 'Phillips', 'USA');")
add_sql("insert into testtable values('Kim', 'Hunter', 'USA');")
add_sql("insert into testtable values('Kevin', 'Bradley', 'USA');")
add_sql("select * from testtable;") -- columns are separated by pipes ("|") in the result.
set testtable_result to run_sql()
log testtable_result & return & return
set title to "So far, the table contents are: " & return & return
display dialog title & testtable_result buttons {"Done"} default button 1 with icon 1
end tell
Ma se lo scrivo così, con un livello extra di narrazione, funziona bene:
tell script "IHDatabase" -- the name of the library
set db to IHDatabase at "~/Desktop/TestDB.db"
-- IHDatabase handler returns an IHDB script object
tell db
add_sql("drop table if exists testtable;")
add_sql("create table testtable (firstname, lastname, country);")
add_sql("insert into testtable values('Ray', 'Barber', 'USA');")
add_sql("insert into testtable values('jj', 'Sancho', 'Spain');")
add_sql("insert into testtable values('Adam', 'Bell', 'Canada');")
add_sql("insert into testtable values('Bruce', 'Phillips', 'USA');")
add_sql("insert into testtable values('Kim', 'Hunter', 'USA');")
add_sql("insert into testtable values('Kevin', 'Bradley', 'USA');")
add_sql("select * from testtable;") -- columns are separated by pipes ("|") in the result.
set testtable_result to run_sql()
log testtable_result & return & return
set title to "So far, the table contents are: " & return & return
display dialog title & testtable_result buttons {"Done"} default button 1 with icon 1
end tell
end tell
FYI la libreria è:
property name : "IHDatabase"
property version : "1.0"
--IHDatabase class
on IHDatabase at dbname
script IHDB
property loc : missing value -- tells SQLite where to put our db if it doesn't exist, identifies it if it does.
property head : missing value -- the opening statement of every future command to our db.
property tail : missing value --ends every query started with "head".
property sql_stmt_list : missing value -- we build up a SQL program here
on init(dbname)
set loc to space & dbname & space
set head to "sqlite3" & loc & quote
set tail to quote
set sql_stmt_list to {}
return me
end init
on add_sql(stmt)
set stmt_space to stmt & space
set sql_stmt_list to sql_stmt_list & stmt_space
end add_sql
on run_sql()
set rows to do shell script head & sql_stmt_list & tail
set sql_stmt_list to {}
return rows
end run_sql
end script
return IHDB's init(dbname)
end IHDatabase