• 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: Database events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Database events


  • Subject: Re: Database events
  • From: Deivy Petrescu <email@hidden>
  • Date: Wed, 07 Jan 2015 14:51:43 -0500

Fred is my first foray into DB Events.

I made some changes in your script, among other things it avoids the problem you mentioned  by trapping the error.
Apparently not all records had a field “Year”, so this would throw an error in your script

I left a bunch of logs around so you (and I) could see what was going on.


I do think there is a bug with DB Events, it does not see the database after it is created, you have to explicitly tell the who path of the db.
I believed you should be able to use only the_db but it says it can’t find database “cars”.

<script>
set lokatie to (path to "desk") as alias

tell application "Database Events"
	-- close every database
	delete every database
	-- aanmaak datbase. Naam en pad naar de naam, de database heet hier the_db
	set the_db to make new database with properties {name:"cars", location:lokatie}
	tell the_db
		-- aanmaken eerste nieuwe record in de database
		set the_record to make new record with properties {name:"Renault"}
		-- aanmaken volgende nieuwe record in de database
		make new record with properties {name:"Toyota"}
	end tell
	tell the_record
		-- aanmaken van velden in een record. Hier het eerste record
		make new field with properties {name:"Merk", value:"Renault"}
		make new field with properties {name:"Model", value:"Espace"}
		make new field with properties {name:"Year", value:"2008"}
	end tell
	-- aanamaken van velden bij het volgende record
	tell record "Toyota" of the_db
		make new field with properties {name:"Merk", value:"Toyota"}
		make new field with properties {name:"Model", value:"Yaris"}
		make new field with properties {name:"Year", value:"2010"}
	end tell
	-- opslaan van de wijzigingen. Hier met expliciete naam, anders werkt het niet lekker
	save the_db
	-- sluiten van de database. Hier met expliciete naam, anders werkt het niet lekker
	close the_db
end tell

-- lokatie is het relatieve pad naar de database, naam van het pad wordt gebruikt om database aan te wijzen
set lokatie to get POSIX path of (lokatie as string) & "cars.dbev"
--return lokatie


-- dit is om dubbele databases onder de zelfde naam te voorkomen
tell application "System Events" to if (exists file lokatie) then

	tell application "Database Events"
		-- dit is om te controleren of database bestaat

		tell database lokatie
			log "count of records   " & (count its records)
			-- op halen gegevens uit veld van record
			set p to properties of field "Year" of record 1
			log p
			-- toewijzen van veld van record aan een variabele
			set car_model to value of field "Year" of record "Renault"
			tell record "Renault"
				-- 2 manieren om een veld te wijzigingen van record Renault
				-- set value of first field where its name is "Year" and its value is "2008" to "2010"
				-- set value of field "Year" to "2013"
			end tell
			set ry to value of field "Year" of record "Renault"
			log "year:   " & ry
			-- bepalen id van een record. 3 manieren
			set refRecord1 to record 1
			log refRecord1
			set refRecord3 to record "Renault"
			log refRecord3
			--set refRecord2 to record id 439912014

			-- Controleren of een veld bestaat in een record. Eigen tell per record nodig
			tell record "Toyota" to if (field "Merk" exists) = true then say "yes"


			-- contoleren of een record bestaat. Hier dus opgehanden onder tell van database events
			if (record "BMW" exists) then say "no"

			-- haal waardes op uit een record
			tell record "Renault" to set aval to value of every field whose name is "Year"
			log aval
			-- every record whose value is "Model"
			-- every record whose value of field "Year" = " Espace"
			set theRecord to the first record whose name = "Renault"
			log theRecord
			set theRecord to the last record whose name = "Renault"
			log theRecord
			set theRecord to every record whose name = "Renault"
			log theRecord


			set everec to every record
			-- set theRecord to every record whose value of field "Year" is "2008")
			-- set theRecord to every record whose value of the field "Year" is "2008"
			repeat with arec in everec
				try
					set arec to contents of arec
					if arec's (field "Year")'s value = "2008" then log "arec   " & arec's (field "Year")'s value
					--	set evrec to its every record whose value of the field "Year" is "2008"
				on error e
					log e
					log arec
				end try
			end repeat
			--get name of every record where value of field "Model" contains "Espace"

			-- get name of every record where (value of field "Year" of it is "2008")
		end tell
		save lokatie
		quit
	end tell

end if
</script>


Deivy Petrescu
email@hidden




 _______________________________________________
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


  • Follow-Ups:
    • Re: Database events
      • From: Shane Stanley <email@hidden>
References: 
 >Database events (From: Fred Diepeveen <email@hidden>)

  • Prev by Date: Re: Database events
  • Next by Date: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Previous by thread: Re: Database events
  • Next by thread: Re: Database events
  • Index(es):
    • Date
    • Thread