Note: The following help should be used in conjunction with the
available examples Vietnam etc.
| |
| 1 |
Install AccessObject-JavascriptDatabase |
|
|
| 1.1 |
Install client side on HTML page |
|
|
| 1.2 |
Install server side on ASP page |
|
|
| 2 |
Create a Database Object |
|
|
| 3 |
Database Object Methods |
|
databaseObject.Method() |
| 3.1 |
database.CreateRecordset(name) |
|
Create a recordset |
| 3.2 |
database.ResetRecordset(id) |
|
Resets a recordset where id is ordinal position or name |
| 4 |
Recordset Object Methods |
|
databaseObject.recordsetObject.Method() |
| 4.1 |
.A([values])/AddRec([values]) |
|
Add a record where values are comma separated |
| 4.2 |
.Count({query}) |
|
Count how many records satisfy query or all records without query |
| 4.3 |
.CreateField(name) |
|
Create a field |
| 4.4 |
.CreateQueryArrays(query{,pagesize}) |
|
Sets RecordsArray and PagesArray, see container RsetProperties |
| 4.5 |
.DeleteRec() |
|
Deletes the current record |
| 4.6 |
.DumpRecordset(options) |
|
Returns a string dump of the recordset |
| 4.7 |
.FindFirst(query) |
|
Find first record that matches query and make current |
| 4.8 |
.FindLast(query) |
|
Find last record that matches query and make current |
| 4.9 |
.FindNext(query) |
|
Find next record that matches query and make current |
| 4.10 |
.FindPrevious(query) |
|
Find previous record that matches query and make current |
| 4.11 |
.Get(record array id) |
|
Get a record and make current, see also CreateQueryArrays() |
| 4.12 |
.MoveFirst() |
|
Move to first record and make current |
| 4.13 |
.MoveLast() |
|
Move to last record and make current |
| 4.14 |
.MoveNext() |
|
Move to next record and make current |
| 4.15 |
.MovePrevious() |
|
Move to previous record and make current |
| 4.16 |
.Seek(dbPrimaryKey1,dbPrimaryKey2...) |
|
Seek a record using primary key(s) and make current |
| 4.17 |
.Sort('fieldnames','ascend/descend') |
|
Sort a recordset |
| 4.18 |
.UpdateField(fieldname,fieldvalue) |
|
Update the 'fieldname' with the 'fieldvalue' of current record |
| 5 |
Container Property Objects |
|
|
| 5.1 |
database.DBaseProperties |
|
Holds properties for a database object |
| 5.2 |
database.recordset.RsetProperties |
|
Holds properties for the recordset object |
| 5.3 |
database.recordset.field.FieldProperties |
|
Holds properties for the fields object |
| 5.4 |
db.recordset.RsetProperties.RecordProperties |
|
A pointer to an object that holds properties for the current record |
| 6 |
Database Collection Functions |
|
Allow you to reference objects using ordinal
position and name |
| 6.1 |
database.Recordsets(id) |
|
Returns a recordset object where id is ordinal position or name |
| 6.2 |
database.recordset.Fields(id) |
|
Returns a field object where id is ordinal position or name |
| 7 |
Collection Properties |
|
|
| 7.1 |
database.Recordsets.Count |
|
Holds how many recordsets in database/collection |
| 7.2 |
database.recordset.Fields.Count |
|
Holds how many fields are in a recordset |
|
|
|
| ^ | < > |
1 |
Install AccessObject-JavascriptDatabase (AO-JD) |
| |
|
AO-JD was created initially for client side data processing. After working with server side ASP pages I wanted to know if AO-JD
could run server side on an ASP page which it does.
AO-JD cookie methods also work server side and can be used to pass cookie databases about a website. |
| ^ | <
> |
1.1 |
Install client side on HTML page |
| |
|
<script language="JavaScript" src="AccessObject-JavascriptDatabaseV3_47.js"></script> |
| ^ | <
> |
1.2 |
Install server side on ASP page |
| |
|
<!--#include file="AccessObject-JavascriptDatabaseV3_47.inc"-->
Note:
1) rename file to .inc
2) alter two lines at top and bottom of AO-JD files, see AO-JD code for instructions.
|
| ^ | <
> |
2 |
Create a Database Object |
| |
|
Create a database.
Database names can be alphanumeric and include underscores.
var DB = new Database('DB')
var myDB = new Database('myDB')
var menus = new Database('menus') |
| ^ | <
> |
3 |
Database Object Methods |
| |
|
databaseObject.Method() |
| ^ | <
> |
3.1 |
database.CreateRecordset(name) |
| |
|
Create a recordset.
Database and recordset names can be alphanumeric and include underscores.
var DB = new Database('DB')
DB.CreateRecordset('MENU_PRICES')
DB.CreateRecordset('MENUS')
DB.CreateRecordset('ORDERS')
with (DB) {
CreateRecordset('MENU_PRICES')
CreateRecordset('MENUS')
CreateRecordset('ORDERS')
} |
| ^ | <
> |
3.2 |
database.ResetRecordset(id) |
| |
|
Resets a recordset where id is ordinal position or name. Records are
removed though structure (fields) are left intact.
DB.ResetRecordset('MENUS')
DB.ResetRecordset(1) |
| ^ | <
> |
4 |
Recordset Object Methods |
| |
|
databaseObject.recordsetObject.Method() |
| ^ | <
> |
4.1 |
database.recordset.A([values])/AddRec([values]) |
| |
|
Add a record to a recordset.
Both these methods do exactly the same thing. A([]) was introduced to
reduce the size of record files.
DB.MENUS.A(['Apples',3])
DB.MENUS.AddRec(['Apples',3])
DB.Recordsets('MENUS').A(['Apples',3]) //using Recordsets collection
function
with (DB.MENUS) {
A(['Apples',3])
A(['Oranges and lemons',2.4])
} |
| ^ | <
> |
4.2 |
database.recordset.Count({query}) |
| |
|
Count how many records there are in a recordset. If query is used all
records that satisfy query are counted.
DB.MENUS.Count() //counts all records in recordset
query = "PRICE != 2" //see query definition
DB.MENUS.Count(query) //counts all records that satisfy query
|
| ^ | <
> |
4.3 |
database.recordset.CreateField(name) |
| |
|
Create a field within the given recordset.
Database, recordset and field names can be alphanumeric and include underscores.
DB.MENUS.CreateField('MENU_TITLE')
DB.MENUS.CreateField('PRICE')
with (DB.MENUS) {
CreateField('MENU_TITLE')
CreateField('PRICE')
}
If you intend to use the Seek method then you need to specify the field
as a primary key field:
DB.MENUS.CreateField('MENU_ID',dbPrimaryKey) //dbPrimaryKey is a
database global variable
Note: See dbPrimaryKey Definitions |
| ^ | <
> |
4.4 |
database.recordset.CreateQueryArrays(query{,pagesize}) |
| |
|
CreateQueryArrays(query{,pagesize}) searches a recordset for records
satisfying a query and creates RecordsArray and PagesArray.
The property
RecordsArray of the property container RsetProperties is an array that
holds record array indexes of every record that satisfies the query. Also,
if pagesize is specified, PagesArray is created that holds every pagesize
record array index that satisfies the query, relative to the first record
found. You can use the Get method in conjunction with PagesArray and
RecordsArray to set current records - see 4.10
Note: PagesArray can be useful for creating record navigations systems as
shown in the Vietnam example. |
| ^ | <
> |
4.5 |
database.recordset.DeleteRec() |
| |
|
Deletes the current record
DB.MENUS.MoveFirst() //moves to first record and sets as current record
DB.MENUS.DeleteRec() //deletes the current record in MENUS recordset
Note: after deleting the current record no record is current so you
must set another record as current |
| ^ | <
> |
4.6 |
database.recordset.DumpRecordset(['fieldnames'],fieldDelimiter,recordDelimiter) |
| |
|
var fieldDelimiter = '*F*'
var recordDelimiter = '*R*'
var s = DB.MENUS.DumpRecordset(['MENU_TITLE','PRICE'],fieldDelimiter,recordDelimiter)
//DumpRecordset returns a string of the dumped recordset |
| ^ | <
> |
4.7 |
database.recordset.FindFirst(query) |
| |
|
Find the first record that satisfies the query and if found set as
current record.
var query = 'MENU_TITLE == ' + sTitleName
DB.MENUS.FindFirst(query) //if record found NoMatch=false else NoMatch=true
while (!DB.MENUS.RsetProperties.NoMatch) {
//do whatever
alert(DB.MENUS.MENU_TITLE) //same as:
alert(DB.MENUS.MENU_TITLE.FieldProperties.Value)
DB.MENUS.FindNext(query) //starts from next record after the
current record
}
Note: with the Find Methods use the NoMatch property to test whether
record has been found |
| ^ | <
> |
4.8 |
database.recordset.FindLast(query) |
| |
|
Find the last record that satisfies the query and if found set as
current record. var query = 'MENU_TITLE == ' + sTitleName
DB.MENUS.FindLast(query) //if record found NoMatch=false else NoMatch=true
while (!DB.MENUS.RsetProperties.NoMatch) {
//do whatever
alert(DB.MENUS.MENU_TITLE) //same as:
alert(DB.MENUS.MENU_TITLE.FieldProperties.Value)
DB.MENUS.FindPrevious(query) //starts from previous record
before the
current record
}
Note: with the Find Methods use the NoMatch property to test whether
record has been found
|
| ^ | <
> |
4.9 |
database.recordset.FindNext(query) |
| |
|
Find the next record that satisfies the query and if found set as
current record.
Note: generally used with FindFirst(query), see 4.6 for example
|
| ^ | <
> |
4.10 |
database.recordset.FindPrevious(query) |
| |
|
Find the previous record that satisfies the query and if found set as
current record.
Note: generally used with FindLast(query), see 4.7 for example
|
| ^ | <
> |
4.11 |
database.recordset.Get(record array id) |
| |
|
This is the latest method to AO-JD and can be used in conjunction with
CreateQueryArrays(query{,pageSize}) another new method. Basically all records
in AO-JD are stored in arrays and if you know the array index of a record
you can use the Get method to set that record as the current record. The
CreateQueryArrays(query{,pageSize}) method is a very fast way to build a list
of record indexes (stored in RecordsArray & PagesArray) that satisfy a
query, see 4.11 for more information.
var query = 'MENU_TITLE == ' + sTitleName
var pageSize = 10 //optional
database.recordset.CreateQueryArrays(query,pageSize) //sets both
RecordsArray & PagesArray
for (var i=0;i<database.recordset.RsetProperties.RecordsArray.length;i++.)
{
database.recordset.Get(database.recordset.RsetProperties.RecordsArray[i])
//set current record
//do whatever
}
var pRset = database.recordset //pointer
var pPA = pRP.RsetProperties.PagesArray //pointer
var iPageArrayLength = pPA.length
for (var i=0;i<iPageArrayLength;i++) {
pRset.Get(pPA[i]) //set current record
//do whatever
}
The two ways to find array indexes of records:
1) database.recordset.RsetProperties.CurrentRecord holds the array index
value of the current record.
2) database.recordset.CreateQueryArrays(query{,pageSize}), see 4.11
Note: Vietnam example has a good example of using Seek method and Get
method in getHTML_Display_Records() function.
|
| ^ | <
> |
4.12 |
database.recordset.MoveFirst() |
| |
|
Move to first record and make current record. Use Move methods with Eof
(End of recordset) and Bof (Beginning of recordset) properties which are
either true or false.
database.recordset.MoveFirst()
while (!database.recordset.RsetProperties.Eof) {
//do whatever
alert(database.recordset.field) //same as:
alert(database.recordset.field.FieldProperties.Value)
database.recordset.MoveNext()
} |
| ^ | <
> |
4.13 |
database.recordset.MoveLast() |
| |
|
Move to last record and make current record. Use Move methods with Eof
(End of recordset) and Bof (Beginning of recordset) properties which are
either true or false. database.recordset.MoveLast()
while (!database.recordset.RsetProperties.Bof) {
//do whatever
alert(database.recordset.field) //same:
alert(database.recordset.field.FieldProperties.Value)
database.recordset.MovePrevious()
} |
| ^ | <
> |
4.14 |
database.recordset.MoveNext() |
| |
|
Move to next record and make current record, see example in 4.12 |
| ^ | <
> |
4.15 |
database.recordset.MovePrevious() |
| |
|
Move to previous record and make current record, see example in 4.13 |
| ^ | <
> |
4.16 |
database.recordset.Seek(dbPrimaryKey1,dbPrimaryKey2...) |
| |
|
Seek a record and make it the current record using a primary key or
primary keys if a recordset has more than one primary key field. The Seek
method is a fast way to access a record based on primary key and is
used to pull together information from related tables.
To use this method you must have one or more fields in the recordset
created as dbPrimaryKey, see CreateField method.
DB.ITEMS.Seek(menu_id) //ITEMS has one primary key
Or,
DB.ORDERS.Seek(user_id,item_id) //ORDERS has two primary keys
If recordset2 has a foreign key in recordset1:
DB.rset1.MoveFirst()
while (!DB.rset1.RsetProperties.Eof) {
prKeyRset2 = DB.rset1.FK_RSET2_ID
DB.rset2.Seek(prKeyRset2) //sets current record for rset2
//do whatever
DB.rset1.MoveNext()
}
Note:
See dbPrimaryKey Definitions
See Control Panel example for more information: view 'properties
display' and select 'IndexedField' value from RsetProperties. Also Vietnam
example has a good example of using Seek method and Get method in getHTML_Display_Records()
function.
|
| ^ | <
> |
4.17 |
database.recordset.Sort('fieldnames','ascend/descend') |
| |
|
Sort a recordset by fieldnames and corresponding options of
ascend or descend.
DB.recordset.Sort('fieldname1','ascend')
DB.recordset.Sort('fieldname1','descend')
DB.recordset.Sort('fieldname3,fieldname6,fieldname1','ascend,descend,ascend') |
| ^ | <
> |
4.18 |
database.recordset.UpdateField(fieldname,fieldvalue) |
| |
|
Update the 'fieldname' with the 'fieldvalue' of current record
DB.recordset.UpdateField('MENUS','Food is good')
DB.BASKET.UpdateField('QUANTITY',newQuantity) |
| ^ | <
> |
5 |
Container Property Objects |
| |
|
The container property objects contain properties that
reflect various states of the database.
Note: if you wished you could add your own properties to these objects
in AO-JD code, very simple, just follow what is already there. |
| ^ | <
> |
5.1 |
database.DBaseProperties |
| |
|
DBaseProperties contains the following properties:
| property name |
read/write |
type |
information |
| AOJDVersion |
r |
string |
current version of AO-JD |
| AOJDLastUpdated |
r |
string |
last update |
| Name |
r |
string |
name that you give database |
|
| ^ | <
> |
5.2 |
database.recordset.RsetProperties |
| |
|
RsetProperties contains the following properties (each
recordset in the database has its own RsetProperties):
| property name |
read/write |
type |
information |
| BadQuery |
r |
boolean |
any query method can set this. true if no recordset field in query |
| Bof |
r |
boolean |
true if current record pointer before first record |
| CookieOn |
r/w |
boolean |
used by cookie methods. turn recordset into cookie if set true |
| CurrentRecord |
r |
integer |
holds the array index of the current record |
| CurrentQuery |
r |
string |
string you pass as query to any query method |
| CurrentQueryChanged |
r |
string |
parsed query |
| Eof |
r |
boolean |
true if current record pointer after last record |
| IndexedField |
r |
object |
holds all primary key values with array indexes. used by Seek() |
| Name |
r |
string |
name of recordset |
| NoMatch |
r |
boolean |
true in no record found for query |
| OrdinalPosition |
r |
integer |
order in which recordset was created within database |
| PagesArray |
r |
array |
created by CreateQueryArrays(query). Array of all record array
indexes by pagesize satisfying query. Used in conjunction with Get() |
| RecordsArray |
r |
array |
created by CreateQueryArrays(query). Array of all record array
indexes satisfying query. Used in conjunction with Get() |
| RecsDeleted |
r |
integer |
number of records deleted in recordset |
| RecsUndeleted |
r |
integer |
number of records not deleted in recordset |
| MyDatabase |
r |
pointer |
points to the database object. maybe useful if you wish to create
your own recordset methods. |
| RecordProperties |
r |
pointer |
each record array has a RecordProperties object. When a record
becomes current this property points to that object. |
|
| ^ | <
> |
5.3 |
database.recordset.field.FieldProperties |
| |
|
FieldProperties contains the following properties (each
field in a recordset has its own FieldProperties):
| property name |
read/write |
type |
information |
| Indexed |
r |
boolean |
true if field is dbPrimaryKey |
| Name |
r |
string |
name of field |
| OrdinalPosition |
r |
integer |
order in which field was created within recordset |
| Type |
r |
integer |
this field can be used by yourself to define your own kinds of
fields. dbPrimaryKey is of type=1. |
| Value |
r |
whatever |
when a record becomes current the values from the array record are
copied into each field.FieldProperties.Value |
|
| ^ | <
> |
5.4 |
db.recordset.RsetProperties.RecordProperties |
| |
|
RecordProperties contains the following properties (every
record in the database has its own RecordProperties):
| property name |
read/write |
type |
information |
| Deleted |
r |
boolean |
set by DeleteRec(). true if deleted |
| PrimaryKeyName |
r |
string |
this is taken from the value(s) of the primary key field(s) |
|
| ^ | <
> |
6 |
Database Collection Functions |
| |
|
Allow you to reference objects using ordinal
position and name |
| ^ | <
> |
6.1 |
database.Recordsets(id) |
| |
|
Returns a recordset object where id is ordinal position or name
//both these return the MENUS recordset.
DB.Recordsets('MENUS') //by recordsetname
DB.Recordsets(2) //by ordinal - MENUS was the third recordset
created in the database
//the following are the same
name = DB.Recordsets('MENUS').RsetProperties.Name
name = DB.Recordsets(2).RsetProperties.Name
name = DB.MENUS.RsetProperties.Name var pMRP = DB.MENUS.RsetProperties
name = pMRP.Name //in a loop this is fastest |
| ^ | <
> |
6.2 |
database.recordset.Fields(id) |
| |
|
Returns a field object where id is ordinal position or name DB.recordset.Fields('MENU_ID') //by fieldname
DB.recordset.Fields(0) //by ordinal - MENUS was the first field
created in the database
//the following are the same
name = DB.Recordsets('MENUS').MENU_ID.FieldProperties.Name
name = DB.Recordsets(2).Fields(0).FieldProperties.Name
name = DB.MENUS.MENU_ID.FieldProperties.Name |
| ^ | <
> |
7 |
Collection Properties |
| |
|
These are properties that are available for Recordsets and
Fields Collection functions. |
| ^ | <
> |
7.1 |
database.Recordsets.Count |
| |
|
How many recordsets are in database.
alert(database.Recordsets.Count)
|
| ^ | <
> |
7.2 |
database.recordset.Fields.Count |
| |
|
How many fields are in a recordset.
alert(database.recordset.Fields.Count) |
| |
|
|
| ^ | <
> |
AA |
Appendix A - Definitions |
| |
|
| Collection |
|
A collection such as Recordsets and Fields
allow you to reference objects by ordinal position or name. |
| Container |
|
Containers are javascript objects that contain
properties. |
| Current record |
|
The following methods set a record as
current:
All Move methods, all Find methods, Get method and Seek method. |
| dbPrimaryKey |
|
All data within a field created with
dbPrimaryKey in a recordset can contain any character except '_'.
see Control Panel example RsetProperties.IndexedField for more
information. IMPORTANT: the data MUST be unique for the primary key
field or if more than one primary key field the combined data from
both fields must be unique.
Use Seek method on foreign key fields within a recordset for
setting a current record in a related table and make sure the
related table has the given field set as dbPrimaryField. see CreateField
method
This is how AO-JD can be used to replicate relational databases. |
| Ordinal position |
|
The numerical position (array position) of where a recordset
or field has been created starting at 0. Some methods and the
collections allow you to specify ordinal position instead of object
name. |
| query |
|
A query is any valid javascript statement
that contains one or more fieldnames of the recordset the query is
being applied to. The query must return a true or false value.
Similar to sql WHERE.
From Vietnam example:
(FK_COUNTRY_ID == 2) && (LASTNAME.charAt(0) == 'B')
|
|
| ^ | <
> |
AB |
Appendix B - About Latest Version (V3_47) |
| |
|
- Addition of recordset CreateQueryArrays(query{,pagesize}) method for
generating RecordsArray and PagesArray - used by Get method
- Addition of recordset Get(id) method for setting a record as current
- Separation of cookie code and main database into two separate files,
giving you the option of including cookie code if required.
- General code changes to improve performance, notable being
AddRec/A method to improve record load speed
|
| |
|
|