Re: Trouble with Database(EDS)

new topic     » goto parent     » topic index » view thread      » older message » newer message

The cause of your problem is the documentation, sorry.

Here is a start of what needs to be covered about key:value pairs.

As you will see Greg has packaged these ideas into one routine.

_tom


Error Status Constants

Constant Value Meaning
DB_OK 0 Database is OK, not error has occurred
DB_OPEN_FAIL -1 The database could not be opened
DB_EXISTS_ALREADY -2 The database could not be created, it already exists
DB_LOCK_FAIL -3, A lock could not be gained on the database
DB_BAD_NAME -4 An invalid name suppled when creating a table
DB_FATAL_FAIL -404 A fatal error has occurred



Constant Value Meaning
DB_LOCK_NO 0 Do not lock the file.
DB_LOCK_SHARED 1 Open the database with read-only access but allow others to update it.
DB_LOCK_EXCLUSIVE 2 Open the database with read and write access
DB_LOCK_READ_ONLY 3 Open the database with read-only access and ignore others updating it

Key:Value

A common way to organize data is to create a sequence of Key:Value pairs. The Key is used as an index to access the Value. A Key is often unique, small, easy to remember, and easy to search. A Value may be anything, and does not have to be unique.

-- simple example of Key:Value data pairs 
 
sequence colors = { {"red",{255,0,0}}, {"green", {0,255,0}}, {"blue",{0,0,255}}, $ } 

Since the idea of Key:Value data pairs is so useful there are many ways of working with large datasets.

  • associative list
  • std/map.e
  • std/eds.e
  • [Phix] dictionary

The choices differ in convenience and speed; they all provide Key:Value pairs.

A eds database is convenient when:

  • a table has many records
  • a database has many tables
  • you have many databases
  • finaly, you want to save the database as a disk file

EDS Euphoria Database System

The eds database uses standard database language:

  • An eds database is "as collection of tables; inside a directory of files."
  • An eds table is "a collection of records ( key:data pairs); inside a database."
  • An eds record is "one key:data pair; inside a table."
  • The eds key is "an index to the record."
  • The eds data is "the cargo (value) of the record."

To work with eds you:

  • db_select) to get a database
  • db_select_table) to get a table
  • proceed to read|write records (key:value pairs)

Before you can select you must open. Before you can open you must create.

The full viewpoint of working with eds is:

  • db_create) a database
  • db_open) the database
  • db_select) the database
  • db_create_table) a table
  • db_select_table) the table
  • proceed to read|write records (key:value pairs) When finished you db_close) the database.

Note that eds has a few safeguards:

  • once you db_create) you can not create again; else you erase the database
  • once you db_create_table) you can not create again; else you erase the table

The eds database has a few one time only conveniences:

  • when you db_create) a database it is also open and selected
  • when you db_create_table) it is also selected

The eds system is designed so you can work with many databases each containing many tables. Databases are good for working with large amounts of data.

Example

include std/eds.e 
atom db_msg 
 
-- first level of thinking is "database" 
 
db_msg = db_select( "GameDatabase" ) 
 
	if db_msg = DB_OK then 
		puts(1, "GameDatabase is selected for use" ) 
	 
	else db_msg = db_open( "GameDatabase" ) 
 
		if db_msg = DB_OK then 
			puts(1, "GameDatabase opened and selected for use" ) 
		 
		else db_msg = db_create( "GameDatabase" ) 
			if db_msg = DB_OK then 
				puts(1, "GameDatabase created, opened, and selected for use" ) 
			else 
				puts(1, "Database Failure" )			 
			end if 
		end if 
	end if 
 
-- second level of thinking is "table" 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu