Database Events & Yosemite - Treating databases as if they were empty

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

Model: iMac 5k Yosemite 10.10.3
AppleScript: 2.4
Browser: Safari 537.36
Operating System: Other

Hi joconner,

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.

gl,
kel

Another thing, not sure if using ‘copy’ is good. Maybe use ‘set’ instead. I need to do some review on Database Events.

Come to think of it, you don’t mention what the script is supposed to do! That would help also.

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?

Hi joconner,

Thanks for the info. Sounds interesting. Maybe someone has experienced this problem.

Edited: or can duplicate it.

Later,
kel

Darn, some of the old examples are from power pcs and don’t work.

Ok created one database.

I got one error in creating the db from the old code. Checking it out. Thinking it might be a security thing. Not sure.

It might have something to do with your references. Check that out. Maybe it doesn’t use posix paths anymore. Not sure.

Edited: try just using the colon delimited path.

Edited: darn, I need to rewrite my scripts also. Getting errors with the posix path I think. Anyway, gotta go for now. Hope you find your answer.

Later,
kel

Hi,

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.

Later,
kel

Think I have an idea with a database that already works.

Edited: I can get a preexisting database, but can’t make a new one.

Hi joconner,

Try running this:

tell application "Database Events"
	every database
end tell

and see if you get something but an empty list.

gl,
kel

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.

Hi joconner,

That’s great! Maybe we can get something and compare it with your program.

Later,
kel

Next step, try this:

tell application "Database Events"
	set the_dbs to every database
	set first_db to item 1 of the_dbs
	every record of first_db
end tell

What do you get?

returns an empty list. - Returns an empty list for all databases in the list as well.

Hi joconner,

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



gl,
kel

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?