Picked up a new iMac at home and wanted to improve some scripts that I use for work. I’m having problems with the most basic database functions, like opening one and getting a record count. It states that there are 0 records available. The exact same code & file on a 10.7.5 machine doesn’t have a problem.
The script editor is also getting hung when I ‘close database x saving no’
Any idea what I’m missing here? Below is just a snippet example of the code. Please let me know if there is anything else i can do or provide to help find a solution. Thank you!
global userName
set userName to short user name of (system info)
global basePath
tell application "Finder"
set current_path to container of (path to me) as alias
set basePath to container of current_path as text
end tell
global garmentDB
set garmentDB to basePath & "Databases:GARMENTCOLORS.dbev"
set garmentDB to POSIX path of garmentDB
global gcList
set gcList to {}
tell application "Database Events"
open database garmentDB
tell database garmentDB
set recordCount to count records of garmentDB
repeat with x from 1 to recordCount
copy value of field "name" of record x to the end of gcList
copy value of field "PMSMATCH" of record x to the end of gcPMSMatchList
try
copy value of field "TONAL" of record x to the end of gcTonalList
on error
copy " " to the end of gcTonalList
end try
try
copy value of field "DESCRIPTION" of record x to the end of gcDescList
on error
copy " " to the end of gcDescList
end try
end repeat
end tell
close database garmentDB saving no
end tell
For one thing, you should place all the global variables at the beginning, so you don’t get them mixed up and it’s easier to read also.
Edited: come to think of it, you don’t need to declare global variables, but it’s ok if you declare it at the beginning just to know what variable labels you used.
Edited: also declaring global variables will make the values of the variable persistent from run to run in an application. I haven’t gone beyond that in your script, but this could cause problems if you didn’t know that.
The script itself is actually a database management tool so I provide the user with a number of options. Each option, for instance adding a new garment color to the database is done with a handler. I also pull in a dozen or so subroutines into each of my scripting files & pass the database info through them sometimes so it does have to be global.
I really just pulled out a few snippets of the code out so you could see my variables and basically what I was working with.
I watered down to only the most basic lines of code without globals, subroutines, etc. and I still have two fundamental problems. For whatever reason, Yosemite 10.10.3 is treating the database file as if it were empty even though I am positive the file is not corrupt. I am able to access it with the exact same code on a machine running 10.7.5 no problem.
I also receive a timeout error with the close database command. Any ideas?
Can’t even make a database now. Tried not using the posix path with:
tell application "Database Events"
launch
set quit delay to 0
end tell
set desk_ref to (path to desktop as string)
--set db_ref to (desk_ref & "MyDb") as alias
tell application "Database Events"
make new database at desk_ref with properties {name:"Mydb"}
end tell
Getting error. with both posix path and AppleScript references.
It shows that i have two open databases in that list. The one from the example I provided earlier & another one from the same script program. I don’t get any errors opening the file other than not being able to see the content.
Sounds like you lost your data. But it could be residing somewhere else in the machine. Wouldn’t know how to get that
You could try looking in second database although I doubt it> Anyway, next steps was to try to get the data:
[applescripttell application “Database Events”
set the_dbs to every database
set first_db to item 1 of the_dbs
set the_recs to every record of first_db
set first_rec to item 1 of the_recs
set the_fields to every field of first_rec
set first_field to item 1 of the_fields
set the_value to value of first_field
end tell
The data can’t be lost. I can run this script from a flash drive, and if I plug it into a different machine everything works fine. It’s only on the 10.10.3 OS it doesn’t read it. It’s the same file, on the same flash drive. All my database files are also showing at normal file size, so the content must be in there. I would be happy to send you a .dbev to experiment with.
I’m thinking I either have two options as database alternatives. Either breaking out into text files or compiling the databases as excel spreadsheets or something and getting it that way. None of my databases contain more than 1000 records… would it just be better to hard code the information? Any suggestings for database events alternatives?