|
Oracle9i Lite C and C++ Object Kernel API Reference
Release 5.0.1 Part No. A95263-01 |
|
This document details the functions of the Oracle Lite Object Kernel API (OKAPI). It includes the following topics:
In this release of Oracle Lite, OKAPI supports the following platforms:
Win32
Palm
EPOC
While almost all functions in the general OKAPI interface, as defined in this guide, are implemented on each platform, some do not have functioning code. Depending on the platform, functions are assigned to one of the following categories:
Although the internal processing for compatible functions may differ between a specific platform and the general OKAPI implementation, they are externally identical to the caller on all platforms. These functions are designated by the letter: "C".
These functions do nothing internally, but always return a positive result. Programs using these calls compile successfully and should not detect any abnormal behavior. These functions are designated by the letter: "P".
These functions do nothing internally and always return a negative result (OK_NOT_SUPPORTED). Programs with these calls compile successfully, but produce runtime errors when the calls are executed. These functions are designated by the letter: "N".
These functions do not exist in the library for the given platform. Programs using these functions do not compile. Calls to these functions should be commented out. These functions are designated by the letters: "NI".
|
Note: The OKAPI header file, okapi.h, includes data structure definitions and function prototypes that are not described in this document. They are provided for backward compatibility and should not be used. |
OKAPI defines persistent and runtime datatypes to ensure that OKAPI database applications are machine and compiler independent. OKAPI defines the following persistent datatypes.
| Datatype | Description |
|---|---|
ok4B
|
Signed 4-byte integer |
okU4B
|
Unsigned 4-byte integer |
ok2B
|
Signed 2-byte integer |
okU2B
|
Unsigned 2-byte integer |
ok1B
|
Signed 1-byte integer |
okU1B
|
Unsigned 1-byte integer |
okChar
|
Character |
okFloat
|
Single-precision floating-point |
okDouble
|
Double-precision floating-point |
OKAPI also defines the following basic datatypes for runtime use.
| Datatype | Definition |
|---|---|
okBool
|
Boolean |
okByte
|
Byte |
okError
|
Error code |
okLock
|
Lock mode |
okSize
|
Size type |
okPtr
|
Generic pointer |
okName
|
Name type |
okObjData
|
Pointer to the body of a persistent object |
In a typical object system, an object has an unchangeable unique identifier and an object body to hold its attribute values. Conceptually, an object A references another object B by using the unique identifier of B. In practice, an object reference is usually mapped into a memory pointer in a program, which points to an encapsulation of the unique identifier. This in turn contains information for locating the object body. The process of converting an object reference (which is often stored as an unique object identifier on secondary storage) into a memory pointer is commonly known as pointer swizzling.
A cached object generally has a descriptor, a header, and a body. A descriptor contains the ID of the object, a pointer to the object body, and other meta-information about the object. The header contains additional meta-information about the object. The body portion of an object contains data values of the object. An object reference (of type okRef) is a pointer to the descriptor of the object. When an object is fixed in the cache, the body of an object can be directly accessed through a pointer (of type okObjData). The Oracle Lite database uses object handles (of type okHandle) to indicate either an object reference or a direct pointer to the object body. For many OKAPI functions, you can use an object reference and an object body pointer interchangeably as input arguments.
You can convert an object pointer of one type to another, but such conversions should be done with care. Conversions between certain types of pointers may not yield valid results. For example, you should not convert an object reference (okRef) to okObjData, since an object reference points to the descriptor of the object and not the body of the object. An attempt to access the body of an object directly through an object reference returns erroneous results, and may even cause a memory protection fault.
The following table shows the validity of object pointer conversions. In the table:
"Auto" means that the conversion is not necessary or is performed automatically.
"Cast" means that you can safely cast between the pointer types.
"?" means that you should perform the conversion with care. The conversion may not produce correct results.
"X" indicates an incorrect conversion. Do not perform conversions between these pointer types.
okRef
|
okHandle
|
okObjData
|
Foo *
|
|
|---|---|---|---|---|
okRef
|
Auto | Auto | X | X |
okHandle
|
?/Auto | Auto | ? | ?/Cast |
okObjData
|
X | Cast | Auto | Cast |
Foo *
|
X | Cast | Cast | Auto |
Every database operation must be performed in the context of an environment object (okEnv). An environment object creates an independent environment (with object cache and memory heap) for the execution of database operations. An environment may have one current transaction or no transaction. Within an environment, you can connect to multiple databases simultaneously.
This table lists the OKAPI functions that manage environment objects.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okInit | Creates an object cache for an application and initializes the system. | C | C | C |
| okFinal | Terminates an environment. | C | C | C |
| okCleanup | Abnormally terminates an environment. | C | X | C |
| okGetEnvInfo | Gets information about the environment. | C | X | C |
Creates an object cache for an application and initializes the system.
okError okInit(const okEnvParams_s *EnvParams, okEnv *RetEnv);
The environment handle.
A database handle.
The okEnvParams_s structure specifies options for the environment. If EnvParams is NULL, the system uses default parameters for the environment. If EnvParams is not NULL, you can set individual parameters to 0 or NULL for the default for that parameter.
The okEnvParams_s structure has the following format:
typedef struct okEnvParams_s {
okU4B StructSize; /* caller fills in size of this structure */
okU4B CacheSize; /* Number of unfixed objects to keep */
okU4B NumObjRefs; /* optional estimated number of descriptors */
okU4B UserIDLen; /* optional length of user ID */
okName UserIDPtr; /* optional pointer to user ID */
okU4B PasswdLen; /* optional length of password */
okName PasswdPtr; /* optional pointer to password */
okPtr LocalHeap; /* optional local heap handle */
okPtr CacheHeap; /* optional cache heap handle */
okU4B Options; /* optional environment options */
okU1B CharacterSet; /* optional environment character set */
okU1B _Padding[3]; /* not used */
} okEnvParams_s;
Terminates an environment.
okError okFinal(okEnv Env);
An environment handle.
This function terminates an environment Env. It disconnects all outstanding database connections with the application and releases all runtime resources allocated by Env. This function commits the last transaction, if still active.
Abnormally terminates an environment.
void okCleanup(okEnv Env);
An environment handle.
This function abnormally terminates an environment. It disconnects all outstanding database connections with the application and releases all run-time resources allocated by Env. This function aborts the last transaction, if still active.
The okEnvInfo structure has the following format:
struct okEnvInfo {
okU4B StructSize; /* caller fills in size of this structure */
okU4B XactCount; /* currently not implemented */
okU4B MemoryUsed; /* currently not implemented */
okU4B MemoryFree; /* currently not implemented */
okU4B DescriptorsUsed; /* currently not implemented */
};
Gets information about the environment.
okError okGetEnvInfo(okEnv Env, okEnvInfo_s *RetEnvInfo);
An environment handle.
A buffer for returning environment information.
The following code demonstrates the use of the environment procedures:
#define OK_CS_ASCII 1
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okEnvParameters_s EnvParams; /* Env parameters */
okEnvInfo_s EnvInfo; /* Env information */
okEnv Env; /* Env handle */
okError e; /* for returned error code */
...
memset((char *)&EnvParams, 0, sizeof(okEnvParameters_s));
EnvParams.StructSize = sizeof(okEnvParameters_s);
EnvParams.CharacterSet = OK_CS_ASCII;
e = okInit(&EnvParams, &Env);
if (OK_IS_ERROR(e)) { /* error handling */ }
(void)okFinal(Env);
...
There are four Data Source Name (DSN) functions that you can use. They are described in the following sections.
Creates a DSN.
okError okCreateDsn(okName user, okName pub, okName path, okName dbName, ok1B drv);
The database user name.
The public part of the DSN name (see the example below).
The full path to the database file.
The name of the database file.
A flag that indicates whether an embedded (native) driver or a client driver is used. This parameter can take two values: DRV_NATIVE and DRV_CLIENT.
okCreateDsn creates a new DSN section in the odbc.ini file and also includes the new entry in the registry.
It gets default volume ID and default data directory (if the path parameter is NULL) from the polite.ini file. If polite.ini does not have a default datadirectory, okCreateDsn gets it from the system environment or from the registry.
the default value for the volume ID is 64. If dbName is NULL, okCreateDsn will use the DSN name as the database file name.
The DSN name will be user_pub or pub if no user name is given (that is, if the user is NULL).
If the datadirectory does not exist, it will be created.
okError e = okCreateDsn("yev","polite","d:\orant\oldb40", NULL,DRV_NATIVE);
The above statement will create the DSN named yev_polite with an ODBC native driver, the datadirectory D:\orant\oldb40\yev and the database file named yev_polite.odb.
Deletes a DSN.
okError okDeleteDsn(okName dsn);
DSN name.
okDeleteDsn deletes the DSN section from the odbc.ini file and from the registry.
Writes single attribute into a DSN section.
okError okSetDsnAttribute(okName dsn, okName attributeName, okChar * value);
DSN name.
The name of the DSN attribute (such as, database, datadirectory, and so on).
The attribute value.
If dsn is not given (NULL), the default dsn name will be taken from polite.ini.
If dsn does not exist, the dsn section will be created, but the attributes will not be filled in automatically.
Reads a single attribute from a DSN section.
okError okGetDsnAttribute(okName dsn, okName attributeName, okSize valueBufferSize, char * valueBuffer);
DSN name.
The name of the DSN attribute.
The size of the buffer receiving the value.
The buffer that receives the attribute value.
If no dsn name is given, the default dsn name will be taken from polite.ini.
A database is a collection of logically related objects. Before a database can store objects, it must be initialized (or formatted). During initialization, the underlying storage structures and storage allocation information are initialized on disk. In addition, the kernel creates system-maintained object groups to hold meta-objects it requires. After initializing the database, an application can create object groups for storing persistent objects. When the objects in a database are no longer needed, the application should delete the database to reclaim its storage space.
Before accessing objects in a database, the application must connect to the database. Connecting to the database involves either activating the database or setting up a communication link between the application (the client) and the server that manages the database.
Once connected, an application can access and update objects in the database in the context of transactions. When it no longer needs the objects in a database, the application can disconnect from the database.
A database connection can be established either inside or outside the context of a transaction. To ensure data integrity, however, a database should not be disconnected while a transaction is active.
This table lists the OKAPI database management functions.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateDatabase | Creates a database. | C | C | C |
| okDeleteDatabase | Deletes a database. | C | C | C |
| okConnect | Establishes a connection to a database. | C | C | C |
| okDisconnect | Breaks a connection to a database. | C | C | C |
Creates a database.
okError okCreateDatabase(okEnv Env, okSize DatabaseNameLen, okName DatabaseNamePtr, const okDatabaseParameters_s *DatabaseParams);
An environment handle.
The length of the database name.
A name for the new database.
Parameters for the creation of the database.
This function creates a database with the name DatabaseNamePtr. The underlying operating system or file system limits the length of the database name, since each database is mapped to a raw partition or file.
The okDatabaseParameters structure contains parameters for the new database. It has the following format:
typedef struct okDatabaseParameters okDatabaseParameters_s;
struct okDatabaseParameters {
okU4B StructSize; /* caller fills in size of this structure */
ok2B VolumeID; /* database volume ID */
okU2B ExtentSize; /* optional number of pages to cluster */
okU4B DatabaseSize; /* size of database in kilobytes */
okSize LabelLen; /* length of label for the database */
okName LabelPtr; /* pointer to label for the database */
okU4B Options; /* currently unused */
okU1B CharacterSet; /* character set */
okU1B _Padding[3]; /* not used */
};
Deletes a database.
okError okDeleteDatabase(okEnv Env, okSize DatabaseNameLen, okName DatabaseNamePtr);
An environment handle.
The length of the database name.
The name of the database to delete.
This function removes the database with the name DatabaseNamePtr and releases all resources allocated to the database. Since the objects in a deleted database cannot be recovered, you should be sure that the objects in the database are no longer needed before deleting the database.
On the Palm platform you must disconnect from the database before deleting it. See "okDisconnect" for more information.
Establishes a database connection.
okError okConnect(okEnv Env, okSize DatabaseNameLen, okName DatabaseNamePtr, const okConnOpt_s *Options, okRef *RetDatabase);
An environment handle.
The length of the database name.
The name of the database.
Options for the database connection. Possible value:
OK_CONNECT_READ_ONLY: connects to the database in read-only mode.
A buffer for returning a reference to a transient database object representing the connected database.
This function establishes a connection to the database with the name DatabaseNamePtr. It returns in RetDatabase a reference to a database object representing the connected database. An application must connect to the database before performing any operations on the objects in the database. Multiple okConnect calls to the same database by an application return the same database object.
Breaks a database connection.
okError okDisconnect(okEnv Env, okHandle Database);
An environment handle.
A database handle.
This function breaks a connection to the database pointed to by Database. It flushes all objects in the database and releases all control data structures for maintaining the connection. You must invoke okDisconnect outside of a transaction.
The following code demonstrates the use of the database procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okDatabaseParameters DatabaseParams; /* database parameters */
okRef Database; /* reference to database object */
okError e; /* for returned error code */
...
memset((char *)&DatabaseParams, 0, sizeof(okDatabaseParameters_s));
DatabaseParams.StructSize = sizeof(okDatabaseParameters_s);
e = okCreateDatabase(Env, sizeof("staff.odb"), "staff.odb", &DatabaseParam);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okConnect(Env, sizeof("staff.odb"), "staff.odb", 0, &Database);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDisconnect(Env, Database);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDeleteDatabase(Env, sizeof("staff.odb"), "staff.odb");
if (OK_IS_ERROR(e)) { /* error handling */ }
...
There is one object schema for each database. An object schema is similar to a class hierarchy in a programming language environment. A class has a unique name within a database and has zero or more attributes and methods. An attribute is similar to a column in a relational table or an instance variable in some programming languages. A method is a procedure or function that applies to individual instances of a class. Collectively, the attributes and methods of a class are called the properties of the class. A class can inherit properties from one or more classes. The class that inherits the properties is called a subclass, while the class from which the class inherits properties is called the superclass.
In the kernel, class objects represent classes, attribute objects represent attributes, and method objects represent methods. Collectively, the class, attribute, and method objects comprise the schema objects of a class. The kernel provides functions for creating and deleting classes and for locating schema objects by name.
To define a new class, you specify the attributes of the new class through the data structure okAttrDesc_s. You define methods by attaching a Java class to the kernel class.
The data structure for an attribute follows:
typedef struct okAttrDesc okAttrDesc_s;
struct okAttrDesc {
okU4B NameLen; /* length of attribute name */
okName NamePtr; /* pointer to attribute name */
okU4B DefinedInLen; /* optional length of defined-in class name */
okName DefinedInPtr; /* optional pointer to defined-in class name */
okU4B DomainLen; /* length of name of domain class */
okName DomainPtr; /* pointer to name of domain class */
okU4B Precision; /* optional precision of attribute value */
okU1B SdtScale; /* optional SDT scale */
okU1B SdtTypeCode; /* optional SDT type code */
okU1B SdtSubtypeCode; /* optional SDT subtype code */
okU1B DefCollate; /* optional default collating sequence */
ok4B Dimension; /* number of data units */
okU4B DefaultValSize; /* optional size of default value */
okByte *DefaultValPtr; /* optional pointer to default value */
okU4B ExtensionCount; /* optional number of extension objects */
okHandle *ExtensionHandles; /* optional array of extension handles */
okU4B Options; /* optional attribute options */
};
The field NamePtr specifies the name of the attribute in the class. Generally, the value for DefinedInPtr is either NULL or the name of the new class. Both values indicate that the attribute is a locally defined attribute. For more complex applications, such as a schema designer, the caller may bypass the default inheritance mechanism and explicitly specify from which superclass an attribute is inherited. DomainPtr specifies the class (type) name of the attribute value. For example, if the type of an attribute is okU4B, its domain is the string "okU4B".
Use the fields Precision, SdtScale, SdtTypeCode, and SdtSubtypeCode to store additional type information of the attribute. For example, you can use them to store type information for SQL datatypes. The kernel does not interpret the semantics of these fields directly.
|
Note: The prefix Sdt stands for Standard datatypes, which are extensions to SQL datatypes. These datatypes are defined to enable sharing of common datatypes among different languages, such as between C++ and SQL. |
For uniformity, the kernel views every attribute as an array. The field Dimension specifies the number of elements in the attribute. The dimension of a scale attribute, for example, is always OK_SCALE (with a value of 1), and the dimension of a dynamic attribute is OK_DYNAMIC. The field Default allows the caller to maintain default information for the attribute as a string. However, the kernel does not interpret or use this information. The field ExtensionHandles allows the application to store additional meta-information in objects. The kernel manages these extension objects on behalf of the application. However, the kernel does not interpret the semantics of extension objects. Finally, you can use the Options field to specify the following additional status flag bits.
| Flag | Description |
|---|---|
OK_PRIVATE_MEMBER
|
Private member attribute |
OK_PUBLIC_MEMBER
|
Public member attribute |
OK_PROTECTED_MEMBER
|
Protected member attribute |
OK_INHERITED_MEMBER
|
Attribute inherited from a superclass |
OK_COPIED_MEMBER
|
Attribute inherited as a copy |
OK_NULLABLE_ATTR
|
Attribute that can take a NULL value |
OK_RUNTIME_ATTR
|
Runtime attribute with no persistent storage |
This table lists the OKAPI functions that manage the schema.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateClass | Creates a new class in a database. | C | C | C |
| okAttachJavaClass | Attaches a Java class to an Oracle Lite class. | C | N | N |
| okDeleteClass | Deletes a class from a database. | C | C | C |
| okDetachJavaClass | Detaches a Java class from an Oracle Lite class. | C | N | N |
| okSetCallBacks | Specifies activator and deactivator functions for instances of a class. | C | X | C |
| okFindClass | Finds a class object. | C | C | C |
| okGetAttrCount | Returns the number of attributes in a class, excluding hidden attributes. | C | X | C |
| okFindAttr | Finds an attribute object in a class. | C | C | C |
| okFindMethod | Finds a method object in a class. | C | N | N |
| okGetSuClasses | Returns the superclasses or subclasses of a class. | C | C | C |
Creates a new class in a database.
okError okCreateClass(okEnv Env, okHandle Database, okSize ClassNameLen, okName ClassNamePtr, okSize SuperclassCount, const okHandle Superclasses[], okSize AttrCount, const okAttrDesc_s AttrDescs[], okSize MethCount, const okMethDesc_s MethDescs[], okU4B Options, okRef *RetClass);
An environment handle.
A database object.
The length of a class name.
Name of a class.
The number of superclasses from which to inherit.
An array of superclasses from which to inherit.
The number of attribute descriptions.
An array of attribute descriptions of type okAttrDesc_s.
The number of method descriptions. This parameter is always set to 0. It is currently not used.
An array of method descriptions of type okMethDesc_s. This parameter is always set to NULL. It is currently not used.
Additional information for creating the class.
The buffer for returning a class object.
This procedure creates a new class ClassNamePtr in a database represented by Database. The order of the attribute descriptions in the array AttrDescs determines the order of the corresponding attributes in the class. Currently, MethCount must be set to 0 and MethDescs must be set to NULL. The caller uses Options to pass in additional information about the class. The option OK_APP_DEF_INHERIT suppresses default class inheritance. If using this option, you should individually specify the properties that should be inherited in the attribute descriptions and method descriptions.
|
Caution: TheOK_APP_DEF_INHERIT option is intended for very specialized callers, such as C++ language bindings running on top of the kernel.
|
Each property of a class, inherited or not, is represented as a schema object, which you can look up by name in the context of the class.
Attaches a Java class to an Oracle Lite class.
okError okAttachJavaClass(okEnv Env, okHandle Database, okHandle ClassRef, okU4B ClassDef, okSize JavaClsOrSrcNameLen, okName JavaClsOrSrcName, okSize JavaClsOrSrcPthLen, okName JavaClsOrSrcPth, okSize ConsArgCount, okHandle *ConsArgs);
An environment handle.
A database object.
A class object.
Class definition. Possible values include:
CLS_IN_POLITE: specifies that the class is already in the Oracle Lite database (it is attached to another class prior to this call).
CLS_CLS_FILE: specifies that the file in the path JavaClsOrSrcPth is a class file. The kernel attaches the class file to the Oracle Lite class and stores the class file in the database.
CLS_SRC_FILE: specifies that the file in the path JavaClsOrSrcPth is a source file. The kernel compiles the Java class using the Java compiler specified in the class path set for the system.
The length of the Java class or source file name.
Name of the Java class. For fully qualified names that include package names, you must use dots to separate the name components.
The length of the path of the Java source or class file.
The directory path location of the Java class or source file.
The number of arguments in the constructor used to create a Java instance.
An array of attribute handles to pass as arguments to the class constructor.
This function attaches a Java class to an Oracle Lite class. After the function attaches the Java class, the methods of the Java class become the methods of the Oracle Lite class. Static methods of the Java class become class methods of the Oracle Lite class, while non-static methods become instance methods. Use the ClassDef argument to specify the class location.
When attaching a Java class, you can specify the constructor that the kernel should use to create instances of the class. The arguments ConsArgCount and ConsArgs specify the number of arguments the constructor takes and which attributes of the object should be passed to the constructor. Before an instance method executes (when invoked by the okExecMeth method described in section "Method Invocation"), the kernel constructs a Java object corresponding to the Oracle Lite object using the constructor that takes the attribute values passed in the ConsArgs argument.
Deletes a class from a database.
okError okDeleteClass(okEnv Env, okHandle Class);
An environment handle.
A class object.
This procedure deletes the class represented by the object Class. It deletes all the schema objects associated with the class. On the Palm platform, inheriting class objects are not automatically removed when you delete the super class. To prevent problems associated with dangling instances, every instance of a class should be deleted before you delete the class.
Detaches a Java class from an Oracle Lite class.
okError okDetachJavaClass(okEnv Env, okHandle Database,
okHandle ClassRef, okBool DeleteClassBody);
An environment handle.
A database object.
A class object.
A boolean flag to indicate whether to delete the Java class body from the database.
This procedure detaches the Java class from the Oracle Lite class specified by Class. If DeleteClassBody is TRUE, okDetachJavaClass deletes the class from the database.
Specifies runtime activator and deactivator functions for instances of a class.
okError okSetCallBacks(okEnv Env, okHandle Class, okPtr ActivatorData, okPtr DeactivatorData, okCallBack Activator, okCallBack Deactivator);
An environment handle.
A class object.
A pointer to data to pass to the activator function.
A pointer to data to pass to the deactivator function.
An activator function for instances of the class.
A deactivator function for instances of the class.
This procedure allows you to specify runtime activator and deactivator functions for instances of the class Class. Oracle Lite invokes the function Activator, if not NULL, when creating an instance of the class or bringing the instance into cache from disk. Oracle Lite invokes the function Deactivator, if not NULL, when deleting or swapping out an instance.
The kernel does not permanently store these functions in the class object. They must be set at runtime whenever a class object is brought in from disk.
The functions Activator and Deactivator each take two pointers as arguments. The first argument is a pointer given (as either ActivatorData or DeactivatorData) when okSetCallBacks is called. The second points to the body of a Class object.
Finds a class object in a database.
okError okFindClass(okEnv Env, okHandle Database, okSize ClassNameLen, okName ClassNamePtr, okRef *RetClass);
An environment handle.
A database object.
The length of a class name.
The name of a class.
A buffer for returning a class object.
This procedure finds the class object with the name ClassNamePtr in database Database and returns a reference to the class object in RetClass. If it does not find the class in the database, okFindClass returns a NULL reference. Returning NULL is not considered an error (that is, it does not return an error code).
Finds an attribute object in a class.
okError okFindAttr(okEnv Env, okHandle Class,
okSize AttrNameLen, okName AttrNamePtr, okHandle DefinedIn,
okRef *RetObj, okU4B *RetPos);
An environment handle.
A class object.
The length of an attribute name.
The name of an attribute.
The class from which an attribute or a method is inherited.
An optional buffer for returning the attribute or method object.
An optional buffer for returning the position of the attribute or method.
This function finds the attribute object for the attribute AttrName in the class represented by Class. If DefinedIn is NULL, it defaults to Class. The first attribute in a class is at position zero.
Returns the number of attributes in a class, excluding hidden attributes.
okError okGetAttrCount(okEnv Env, okHandle Class, okU4B *RetCount)
An environment handle.
A class object.
An optional buffer for returning the attribute count.
This function should be used in place of DAR_COUNT(class->Attributes) which does not exclude hidden attributes. This function will be available for Win32 in a future release.
Finds a method object in a class.
okError okFindMethod(okEnv Env, okHandle dbH, okHandle clsR, okU4B MethType, okSize MethNameLen, okName MethName, okSize MethSigLen, okName MethSig, okHandle *retMeth);
An environment handle.
A database object.
A class object.
The type of Java method to find. Possible values:
OK_CLASS_METHOD: to find a class method.
OK_INSTANCE_METHOD: to find an instance method.
The length of the method name.
The method name.
The length of the method signature as a string. If the method lookup should be based only on the name, set this value to 0.
A Java Native Interface (JNI) style method signature string.
An optional buffer for returning the attribute or method object.
This procedure finds the method object for the method MethName in the class represented by Class. The MethType argument specifies the type of method to find. Possible values are OK_CLASS_METHOD for class method and OK_INSTANCE_METHOD for instance method. Since more than one method may exist with the same name, the arguments MethSigLen and MethSig permit the caller to specify the method signature. You must specify the method signature as a string using the JNI format. For example, for the method String M (int, Date), the JNI signature is:
"(ILjava/sql/Date;)Ljava/lang/String;"
Returns the superclasses or subclasses of a class.
okError okGetSuClasses(okEnv Env, okHandle Class, okBool isSuper, okBool isImmediate, okArray *RetList);
An environment handle.
A class object.
A Boolean flag which is TRUE if the function should return superclasses, and FALSE if it should return subclasses.
A Boolean flag which is TRUE if the function should return all superclasses or subclasses, and FALSE if it should return only the immediate superclasses or subclasses.
An array for returning the results of the lookup.
This procedure returns the superclasses (when isSuper is TRUE) or subclasses (when isSuper is FALSE) of the class Class in RetList.
The following code demonstrates the schema procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okError e;
okEnv Env;
okHandle Database;
okRef PersonRef, StudentRef, DeptRef, MethRef, NameAttr;
okArray AttrDescs;
okU4B NamePos;
...
okAttrDesc_s DeptAttrs[] = {
{sizeof("Name"), "Name", 0, NULL, sizeof("okChar"), "okChar",
0, 0, 0, 0, 0, OK_DYNAMIC, 0, NULL, 0, NULL, 0},
{sizeof("Students"), "Students", 0, NULL,
sizeof("Student_s"),
"Student_s", 0, 0, 0, 0, 0, OK_DYNAMIC, 0, NULL, 0, NULL, 0},
{sizeof("Staff"), "Staff", 0, NULL, sizeof("Professor_s"),
"Professor_s", 0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0}
};
okAttrDesc_s PersonAttrs[] = {
{sizeof("ID"), "ID", 0, NULL, sizeof("okU4B"), "okU4B",
0,0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0},
{sizeof("Name"), "Name", 0, NULL, sizeof("okChar"), "okChar",
0, 0, 0, 0, 0, OK_DYNAMIC, 0, NULL, 0, NULL, 0},
{sizeof("Age"), "Age", 0, NULL, sizeof("okU2B"), "okU2B",
0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0},
{sizeof("Gender"), "Gender", 0, NULL, sizeof("okU2B"), "okU2B",
0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0},
{sizeof("Phone"), "Phone", 0, NULL, sizeof("okU1B"), "okU1B",
0, 0, 0, 0, 0, 8, 0, NULL, 0, NULL, 0},
{sizeof("Picture"), "Picture", 0, NULL, sizeof("okLong"),
"okLong", 0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0}
};
okAttrDesc_s StudentAttrs[] = {
{sizeof("Dept"), "Dept", 0, NULL, sizeof("Dept_s"), "Dept_s",
0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0},
{sizeof("Clock"), "Clock", 0, NULL, sizeof("okU4B"), "okU4B",
0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL,OK_RUNTIME_ATTR}
};
okAttrDesc_s ProfessorAttrs[] = {
{sizeof("Dept"), "Dept", 0, NULL, sizeof("Dept_s"), "Dept_s",
0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0}
};
#include <time.h>
/* constructor function for run-time attr of "Student" */
void GetTime(okPtr NotUsed, okObjData *StudentP)
{((Student_s *)StudentP)->Clock = (okU4B)clock(); }
e = okConnect(Env, 9, "staff.odb", FALSE, &Database);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* create class "Dept_s" */
e = okCreateClass(Env, Database, sizeof("Dept_s"), "Dept_s",
0, NULL, sizeof(DeptAttrs)/sizeof(okAttrDesc_s),
DeptAttrs, 0, NULL, 0, NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* creates class "Person_s" */
e = okCreateClass(Env, Database, sizeof("Person_s"),"Person_s",
0, NULL, sizeof(PersonAttrs)/sizeof(okAttrDesc_s),
PersonAttrs, 0, NULL, 0, &PersonRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* creates class "Student_s" */
e = okCreateClass(Env, Database, sizeof("Student_s"),
"Student_s", 1, &PersonRef,
sizeof(StudentAttrs)/sizeof(okAttrDesc_s), StudentAttrs,
0, NULL, 0, &StudentRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* creates class "Professor_s" */
e = okCreateClass(Env, Database, sizeof("Professor_s"),
"Professor_s", 1, &PersonRef,
sizeof(ProfessorAttrs)/sizeof(okAttrDesc_s),
ProfessorAttrs, 0, NULL, 0, NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* set constructor for run-time attr */
e = okSetCallBacks(Env, StudentRef, NULL, NULL, GetTime, NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindClass(Env, Database, sizeof("Dept_s"),
"Dept_s", &DeptRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindAttr(Env, DeptRef, sizeof("Name"),
"Name", NULL, &NameAttr, &NamePos);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* attach a Java class to class Dept_s. Assume that the Java
source file is c:\JavaSrc\DeptMeths. Use the Name
attribute of Dept_s as a constructor argument */
e = okAttachJavaClass(Env, Database, DeptRef, CLS_SRC_FILE,
9,"DeptMeths",10,
"c:\\JavaSrc",1,&NameAttr);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* find the void HireStaff(int ID, String Name) method */
e = okFindMethod(Env, Database, DeptRef, OK_INSTANCE_METHOD,
9, "HireStaff", 22,
"(ILjava/lang/String;)V", &MethRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
{okArrayBaseClasses;
e = okGetSuClasses(Env, StudentRef,
TRUE, TRUE, &BaseClasses);
if (OK_IS_ERROR(e)) { /* error handling */ }
}
e = okDeleteClass(Env, PersonRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
Object grouping is a powerful mechanism for placing and manipulating a collection of objects in a database. Specifically, object grouping supports:
clustering of objects on disk
group-level object locking
You create object groups in the context of a database. A group object represents each group. The group object has a name that must be unique within the database. When creating a new object, you can specify the group to which the object belongs. If you do not specify a group, the object is stored in a system-maintained default group, which can be changed by the application.
This table lists the OKAPI functions that manage groups.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateGroup | Creates an object group in a database. | C | C | C |
| okDeleteGroup | Deletes an object group from a database. | C | C | C |
| okFindGroup | Finds an object group in a database. | C | C | C |
| okSetDefaultGroup | Changes the current default object group maintained by the kernel. | C | C | C |
Creates a group object within a database.
okError okCreateGroup(okEnv Env, okHandle Database, okSize GroupNameLen, okName GroupNamePtr, okU4B Options, okRef *RetGroup);
An environment handle.
A database object.
The length of a group name.
The name of a new group.
Options for group operation.
A buffer for returning a group object.
This function creates an object group with the name GroupNamePtr in the database Database. It returns a reference to the new group object in RetGroup. Options is currently not used.
Deletes a group object from a database.
okError okDeleteGroup(okEnv Env, okHandle Group);
An environment handle.
The group object to delete.
This function deletes the group specified by Group. This function deletes the group object as well as all objects in the group.
Finds a group object in a database.
okError okFindGroup(okEnv Env, okHandle Database, okSize GroupNameLen, okName GroupNamePtr, okRef *RetGroup);
An environment handle.
A database object.
The length of the group name.
The name of the new group.
A buffer for returning a group object.
This function finds the group with the name GroupNamePtr in the database Database. If it does not find a group with the given name, the function returns a NULL reference. Returning NULL is not considered an error (that is, no error code is returned).
Changes the current default object group maintained by the kernel.
okError okSetDefaultGroup(okEnv Env, okHandle NewDefGroup,
okRef *RetOldDefGroup);
An environment handle.
The new default group.
A buffer for returning the group.
This function changes the current default object group to the group specified by NewDefGroup. If NewDefGroup is NULL, the default group reverts to the system-defined default group. If RetOldRefGroup is not NULL, this function makes NewDefGroup the default object group and returns a reference to the prior default group object in RetOldDefGroup.
The following code demonstrates the use of the group procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okRef FacultyRef;
okRef PrevDefGroup;
okError e;
...
e = okCreateGroup(Env, Database, sizeof("Faculty"),
"Faculty", 0, &FacultyRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindGroup(Env, Database, sizeof("Faculty"),
"Faculty", &FacultyRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okSetDefaultGroup(Env, FacultyRef, &PrevDefGroup);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDeleteGroup(Env, FacultyRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
The object is the fundamental unit in the kernel. All persistent entities are modeled and stored as objects. Several important meta-objects contain information about an object. First, since an object is an instantiation of a class, its class object defines the object. Second, since all objects are stored in a group, the group object determines the persistent storage for the object. The third meta-object associated with an object is its database object, which can be indirectly derived from its group object.
This table lists the OKAPI object functions.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateObj | Creates a new instance of a class. | C | C | C |
| okDeleteObj | Deletes an object from a database. | C | C | C |
| okFixObj | Fixes (or pins) an object in cache and returns a pointer to the object's body. | C | C | C |
| okUnfixObj | Unfixes an object. | C | C | C |
| okPrepForUpdate | Prepares an object for updating. | C | C | C |
| okSetShortLock | Acquires a lock on an object. | C | P | C |
| okCreateObjs | Creates an array of objects from a single class. | C | C | C |
| okDeleteObjs | Deletes an array of objects. | C | C | C |
| okSetShortLocks | Locks an array of objects. | C | P | C |
| okPrepForUpdates | Prepares an array of fixed objects for updating. | C | NI | C |
| okFixObjs | Fixes an array of objects and returns pointers to the body of each object. | C | C | C |
| okUnfixObjs | Unfixes an array of objects. | C | C | C |
Creates a new instance of a class.
okError okCreateObj(okEnv Env, okHandle Group, okHandle Class, const void *InitialVal, okU4B Options, void *RetHandle);
An environment handle.
The group in which to create the object.
The class object to instantiate.
The value of an object.
Options for object creation.
A buffer for returning the pointer to the body of the object.
This function creates a new instance of the class Class in the group Group. If Group is NULL, the kernel assigns the object to a system-maintained default group. Optionally, you can pass an initial value for the object in Val. The option OK_FIX_OBJ (passed in Options) specifies that the newly created object should be fixed in cache upon return from the function.
Deletes an object from a database.
okError okDeleteObj(okEnv Env, okHandle Obj);
An environment handle.
The object to delete.
This function removes the object obj from cache and reclaims its storage space on disk. After the function deletes the object, the kernel rejects attempts to access the object.
Fixes (or pins) an object in cache and returns a pointer to the object's body.
okError okFixObj(okEnv Env, okHandle Obj, okLock LockMode, void *RetObjData);
An environment handle.
The object to fix.
The type of lock to apply to the object. OKAPI defines the following lock modes:
| Lock | Description |
|---|---|
OK_NOLOCK
|
No lock |
OK_ISLOCK
|
Intent shared lock |
OK_IXLOCK
|
Intent exclusive lock |
OK_SIXLOCK
|
Shared-intent exclusive lock |
OK_SLOCK
|
Shared (read) lock |
OK_XLOCK
|
Exclusive (write) lock |
OK_ULOCK
|
Update lock |
A buffer for returning the pointer to the body of the object.
This function fixes (or pins) the object Obj in cache and returns a pointer to the object's body in RetObjData. The kernel guarantees that a fixed object is not swapped out. In other words, the memory pointer returned in RetObjData is valid as long as the object remains fixed. Mode specifies the lock mode to apply to the object. In single-user mode, all lock requests are ignored.
This function allows you to directly manipulate the contents of an object. By casting the returned memory pointer to the appropriate pointer type, you can access the object body in the same manner as a C structure. Accessing data through a memory pointer instead of through an OKAPI function may be efficient, but it can cause problems with the integrity of the data. If changing attribute values through a memory pointer, you must notify the kernel of your changes by calling okPrepForUpdate, or by passing the appropriate flag to okUnfixObj.
To avoid memory leaks, you should call okUnfixObj after calling okFixObj to unfix the object once it is no longer needed. However, if you are certain that the cache is large enough to hold the objects that the application directly or indirectly handles in a transaction, you can reduce function call overhead by leaving the objects fixed. At the end of each transaction, the kernel automatically unfixes all objects in the cache.
Unfixes an object.
okError okUnfixObj(okEnv Env, okHandle Obj, okBool isUpdated);
An environment handle.
The object handle.
A Boolean flag indicating whether the object has been updated while fixed in cache.
This function unfixes (or un-pins) the object Obj and, if isUpdated is TRUE, marks the object as dirty. An object can be fixed when created or through a call to okFixObj. After an object is unfixed, the kernel may swap the object out at any time. Usually, it swaps out the object when the cache is nearly full.
Since an object may be fixed several times (such as when different modules of an application fix the object), the kernel keeps a fix count for each object in the cache. The kernel increments the counter whenever the application fixes the object, and decrements the counter whenever the application unfixes the object with okUnfixObj. The kernel does not swap out an object unless its fix count is zero.
Prepares an object for updating.
okError okPrepForUpdate(okEnv Env, okHandle Obj);
An environment handle.
The object handle.
This function prepares an object Obj for updating. okPrepForUpdate acquires a write (or exclusive) lock on the object and marks the object as dirty. This function applies to objects that are fixed in cache. It makes no attempt to swap in an object if the object is not in the cache, and it does not increase the fix count of the object.
Acquires a lock on an object.
okError okSetShortLock(okEnv Env, okHandle Obj, okLock LockMode);
An environment handle.
The object handle.
The mode of the lock to apply to the object. OKAPI defines the following lock modes:
| Lock | Description |
|---|---|
OK_NOLOCK
|
No lock |
OK_ISLOCK
|
Intent shared lock |
OK_IXLOCK
|
Intent exclusive lock |
OK_SIXLOCK
|
Shared-intent exclusive lock |
OK_SLOCK
|
Shared (read) lock |
OK_XLOCK
|
Exclusive (write) lock |
OK_ULOCK
|
Update lock |
This function acquires a lock of the mode LockMode on the object Obj. If the lock request conflicts with an outstanding lock on the same object, the caller is blocked until the lock request is granted or rejected due to deadlock or time-out. In single-user mode, all lock requests are ignored.
Creates an array of objects from a single class.
okError okCreateObjs(okEnv Env, okHandle Group, okHandle Class, const okByte *InitialVal, okU4B Options, okU4B ObjCount, okHandle RetHandles[]);
An environment handle.
Group in which to create objects.
Class object to instantiate.
The value of objects.
Options for object creation.
Number of objects to create.
A buffer for returning the pointers to the bodies of the objects.
This function creates a specified number (ObjCount) of new instances of the class Class in the group Group. If Group is NULL, the kernel assigns the objects to a system-maintained default group. Optionally, you can pass an initial value for the objects in InitialVal. The option OK_FIX_OBJ (passed in Options) specifies that the newly created objects should be fixed in cache upon return from the function.
Deletes an array of objects from a database.
okError okDeleteObjs(okEnv Env, okU4B ObjCount, okHandle Objs[]);
An environment handle.
Number of objects to delete.
Handles of objects to delete.
This function removes the objects Objs[] from cache and reclaims the storage space on disk. After the function deletes the objects, the kernel rejects attempts to access the objects.
Acquires a lock on an array of objects.
okError okSetShortLocks(okEnv Env, okU4B ObjCount, okHandle Objs[], okLock LockMode);
An environment handle.
The number of objects to lock.
The handles of objects to lock.
The mode of the lock to apply to the objects. OKAPI defines the following lock modes:
| Lock | Description |
|---|---|
OK_NOLOCK
|
No lock |
OK_ISLOCK
|
Intent shared lock |
OK_IXLOCK
|
Intent exclusive lock |
OK_SIXLOCK
|
Shared-intent exclusive lock |
OK_SLOCK
|
Shared (read) lock |
OK_XLOCK
|
Exclusive (write) lock |
OK_ULOCK
|
Update lock |
This function acquires a lock of the mode LockMode on the objects Objs[]. If the lock request conflicts with an outstanding lock on the same object, the caller is blocked until the lock request is granted or rejected due to deadlock or time-out. In single-user mode, all lock requests are ignored.
Prepares an array of objects for updating.
okError okPrepForUpdates(okEnv Env, okU4B ObjCount, okHandle Objs[]);
An environment handle.
The number of objects to prepare.
The handles of the objects to prepare.
This function prepares an array of objects Objs for updating. okPrepForUpdates acquires a write (or exclusive) lock on the objects and marks the objects as dirty. This function applies to objects that are fixed in cache. It makes no attempt to swap in objects if the objects are not in the cache, and it does not increase the fix count of the objects.
Fixes (or pins) an array of objects in cache and returns a pointer to the body of each object.
okError okFixObjs(okEnv Env, okU4B ObjCount, okHandle Objs[], okLock LockMode, void *RetObjData[]);
An environment handle.
The number of objects to fix.
The objects to fix.
The type of lock to apply to the object. OKAPI defines the following lock modes:
| Lock | Description |
|---|---|
OK_NOLOCK
|
No lock |
OK_ISLOCK
|
Intent shared lock |
OK_IXLOCK
|
Intent exclusive lock |
OK_SIXLOCK
|
Shared-intent exclusive lock |
OK_SLOCK
|
Shared (read) lock |
OK_XLOCK
|
Exclusive (write) lock |
OK_ULOCK
|
Update lock |
A buffer for returning the pointer to the body of each object.
This function fixes (or pins) the objects Objs[] in cache and returns a pointer to the body of each object in RetObjData. The kernel guarantees that fixed objects are not swapped out. In other words, the memory pointer returned in RetObjData is valid as long as the objects remain fixed. Mode specifies the lock mode to apply to the objects. In single-user mode, all lock requests are ignored.
This function allows you to directly manipulate the contents of objects. By casting the returned memory pointer to the appropriate pointer type, you can access the object body in the same manner as a C structure. Accessing data through a memory pointer instead of through an OKAPI function may be efficient, but it can cause problems with the integrity of the data. If changing attribute values through a memory pointer, you must notify the kernel of your changes by calling okPrepForUpdates, or by passing the appropriate flag to okUnfixObjs.
To avoid memory leaks, you should call okUnfixObjs after calling okFixObjs to unfix the objects once they are no longer needed. However, if you are certain that the cache is large enough to hold the objects that the application directly or indirectly handles in a transaction, you can reduce function call overhead by leaving the objects fixed. At the end of each transaction, the kernel automatically unfixes all objects in the cache.
Unfixes an array of objects.
okError okUnfixObjs(okEnv Env, okU4B ObjCount, okHandle Objs[], okBool isUpdated);
An environment handle.
The number of objects to be unfixed.
The objects to unfix.
A Boolean flag indicating whether the objects have been updated while fixed in cache.
This function unfixes (or un-pins) the objects Objs[] and, if isUpdated is TRUE, marks the objects as dirty. A group of objects can be fixed when created or through a call to okFixObjs. After the objects are unfixed, the kernel may swap the objects out at any time. Usually, it swaps out the objects when the cache is nearly full.
Since an object may be fixed several times (such as when different modules of an application fix the object), the kernel keeps a fix count for each object in the cache. The kernel increments the counter whenever the application fixes the object, and decrements the counter whenever the application unfixes the object with okUnfixObj or OkUnfixObjs. The kernel does not swap out an object unless its fix count is zero.
The following code demonstrates the use of object functions:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okEnv Env;
okHandle Database, Object;
okRef Group, Class, ObjRef;
okObjData ClassObj;
okError e;
...
/* assume Env and Database are set up properly */
e = okFindGroup(Env, Database, sizeof("Faculty"),
"Faculty", &Group);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindClass(Env, Database, sizeof("Professor_s"), "Professor_s",
&Class);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* fix the class object then release it */
e = okFixObj(Env, Class, OK_NOLOCK, (okObjData *)&ClassObj);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okUnfixObj(Env, (okHandle)ClassObj, FALSE);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* create a new "Professor_s" object in "Faculty" group */
e = okCreateObj(Env, Group, Class, NULL, OK_FIX_OBJ, &Object);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* set an exclusive lock on the "Dept_s" object */
e = okSetShortLock(Env, Object, OK_XLOCK);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* release the new object then delete it */
e = okUnfixObj(Env, (okHandle)Object, FALSE);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDeleteObj(Env, Object);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
You can use the object information and control functions to query and control objects.
This table lists the OKAPI object information and control functions.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okGetObjRef | Acquires a reference to an object. | C | C | C |
| okIsInstanceOf | Determines whether an object is an instance of a particular class. | C | C | C |
| okGetObjInfo | Returns information about an object. | C | C | C |
| okIsObjEqual | Determines whether two object handles are equal. | C | C | C |
| okCtrlObjs | Enables the caller to apply control operations to an array of objects. | C | P | C |
| okGetObjRefs | Gets an array of handles to objects. | C | NI | C |
| okFindRefs | Finds an array of object references, given an array of object IDs. | C | C | C |
Acquires a reference to an object.
okError okGetObjRef(okEnv Env, okHandle Obj, okRef *RetRef);
An environment handle.
The object handle.
A buffer for returning the reference to the object.
This function returns a reference in RetRef to the object Obj. An object handle can be an object reference or a memory pointer to the body of the object. If Obj is already an object reference, the function returns the object reference in RetRef. If Obj is a memory pointer to the object body, okGetObjRef locates or creates an object reference to the object and returns it in RetRef.
Determines whether an object is an instance of a particular class.
okError okIsInstanceOf(okEnv Env, okHandle Obj, okHandle Class, okBool isImmediate, okBool *RetResult);
An environment handle.
The object handle.
The class object.
A Boolean flag indicating whether to consider superclasses.
A Boolean value to indicate whether the object is an instance of a class.
This function determines whether the object Obj is an instance of the class Class. It returns a Boolean result (either TRUE or FALSE) in RetResult. The argument isImmediate specifies whether the function should consider inheritance. If isImmediate is TRUE, the function returns TRUE only if Class is the class object of Obj. If isImmediate is FALSE, the function returns TRUE if Class is the class object or a superclass object of Obj.
On the Palm platform, if Class is the superclass object of obj, the function will return FALSE regardless of whether isImmediate is TRUE or FALSE.
Returns information about an object.
okError okGetObjInfo(okEnv Env, okHandle Obj, okOID_s *RetObjID, okRef *RetDatabase, okRef *RetGroup, okRef *RetClass, okObjInfo_s *RetInfo);
An environment handle.
The object handle.
An optional buffer for returning the object ID.
An optional buffer for returning the database of an object.
An optional buffer for returning the group of an object.
An optional buffer for returning the class of an object.
A buffer for returning object information.
This function returns information regarding an object Obj, including its unique ID (in RetObjID) and associated meta-objects. The meta-objects include the database object (in RefDatabase), group object (in RetGroup), and class object (in RetClass). RetInfo provides the version and lock mode of the object in the following format:
typedef struct {
okU4B Version;
wsLockMode LockMode;
} okObjInfo_s;
Determines whether two object handles are equal.
okError okIsObjEqual(okEnv Env, okHandle Obj1, okHandle Obj2, okBool *RetResult);
An environment handle.
The first object handle to compare.
The second object handle to compare.
A Boolean value to indicate the result.
This function determines whether two object handles, Obj1 and Obj2, are equal. It considers two object handles equal only if they point to the same object.
Applies control operations to an array of objects.
okError okCtrlObjs(okEnv Env, okU4B ObjCount, const okHandle ObjHandles[], okU4B Actions);
An environment handle.
The number of objects in the control operation.
The objects in the control operation.
The operations to apply to the objects. Actions can be any combination of the following:
OK_FLUSH_OBJECT: Writes a copy of the object to disk if marked dirty.
OK_FREE_OBJECT: Releases the memory space used by the body of an object. This option invalidates all direct memory pointers to the object body, but does not invalidate object references to the object. This is intended for use when the application no longer needs the object.
OK_FREE_DESC: Releases the descriptor of an object and the body of the object if it exists in the cache.
|
Important: Use of theOK_FREE_DESC option invalidates all existing object references, including those embedded in other cached objects. This is intended for use when memory is extremely scarce and the space used by object descriptors needs to be reclaimed.
|
This function allows you to apply the control operations specified in Actions to an array of objects ObjHandles.
Gets references to an array of objects.
okError okGetObjRef(okEnv Env, okU4B ObjCount, okHandle Objs[], okRef *RetRefs[]);
An environment handle.
The number of objects.
The object handle.
A buffer for returning the references to the objects.
This function returns references in RetRefs[] to the objects in Objs[]. An object handle can be an object reference or a memory pointer to the body of the object. If Objs[] is already an object reference, the function returns the object reference in RetRefs[]. If Objs[] is a memory pointer to the object bodies, okGetObjRefs locates or creates object references to the objects and returns them in RetRefs[].
Finds references to an array of objects, given an array of object IDs.
ok Error okFindRefs,( okEnv Env, okU4B ObjCount, okOID_s ObjIDs[], okRef RetObjRefs[]);
An environment handle.
The number of objects.
The Object IDs.
A buffer for returning the references to the objects.
This function returns references in RetObjRefs[] to the objects identified in ObjIDs[].
The following code demonstrates the use of the object information and control procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okRef Group, Class, ObjRef;
okHandle Object, NewObj;
Professor_s *Advisor;
okBool isa, isEqual;
okError e;
...
e = okFindGroup(Env, Database,
sizeof("Faculty"), "Faculty", &Group);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindClass(Env, Database,
sizeof("Professor_s"), "Professor_s", &Class);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* create a new "Professor_s" object in "Faculty" group */
e = okCreateObj(Env, Group, Class, NULL, OK_FIX_OBJ, &Object);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetObjRef(Env, Object, &ObjRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okIsInstanceOf(Env, Object, Class, TRUE, &isa);
if (OK_IS_ERROR(e)) { /* error handling */ }
{
okOID_sObjID;
okRefDatabase, Group, Class;
e = okGetObjInfo(Env, Object, &ObjID, &Database, &Group,
&Class, NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
}
e = okCtrlObjs(Env, 1, &Object, OK_FLUSH_OBJECT|OK_FREE_DESC);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* create a new "Dept_s" object */
e = okCreateObj(Env, Group, Class, NULL, OK_FIX_OBJ, &NewObj);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okIsObjEqual(Env, Object, NewObj, &isEqual);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
An object's attribute values collectively represent the object's internal state. As explained in the section "Schema", each attribute in a class is represented by an attribute object. The attribute object defines the attribute.
Functions that access or update attribute values also require attribute objects as parameters. For example, to execute an update operation or a search, you must provide a value for the update or for the search predicate. OKAPI provides the following structure to represent attribute values:
typedef struct okAttrVal_s { /* for holding attribute value */
okU4B BufSize; /* size of buffer in bytes */
okByte *BufPtr; /* pointer to buffer */
ok4B Indicator; /* data size if >= 0, NULL if < 0 */
} okAttrVal_s;
BufPtr points to a buffer for holding an attribute value. BufSize specifies the size of the buffer in bytes. Indicator contains the actual number of bytes in the attribute value. A negative number in Indicator indicates a NULL value (an undefined or not initialized value).
When manipulating an attribute that is a dynamic array, you should set BufSize to sizeof(okArray), and BufPtr should point to a variable of type okArray. When getting an attribute, the kernel sets the Indicator field to the actual size of the returned data. If the Indicator is negative, the attribute has a null value.
Optionally, you can set a flag within the attrVal.BufSize which indicates to OKAPI that a dynamic array should be created. You can then pass the string inside of attrVal.BuffPtr as follows:
attrVal.BufSize = attrVal.Indicator = OK_NEW_ARRAY | strlen((char *) attrVal.BufPtr);
|
Note: The flag,OK_NEW_ARRAY, is not supported or required on the Palm platform.
|
This table lists the OKAPI functions that manage attribute values.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okGetAttrVal | Extracts the value of an attribute and returns either a copy of the value or a direct memory pointer to the attribute value in the object body. | C | C | C |
| okSetAttrVal | Updates the value of an attribute. | C | C | C |
| okGetAttrValAt | Extracts the value of the attribute at a specified position and returns either a copy of the value or a direct memory pointer to the attribute value in the object body. | C | C | C |
| okSetAttrValAt | Updates the value of an attribute at a specified position. | C | C | C |
| okSetAttrVals | Updates the values of multiple attributes listed by their names. | C | C | C |
| okSetAttrValsAt | Updates the value of attributes at a specified position. | C | C | C |
Extracts the value of an attribute and returns either a copy of the value or a direct memory pointer to the attribute value in the object body.
okError okGetAttrVal(okEnv Env, okHandle Obj, okHandle AttrObj, okBool toCopy, okAttrVal_s *RetVal);
An environment handle.
An object handle.
An object representing the attribute to access.
A Boolean flag:
TRUE - On Win32 and EPOC platforms it returns a pointer to a pointer to the attribute. On the Palm platform it returns a pointer directly to the attribute.
FALSE - On Win32 and EPOC it returns a pointer directly to the attribute. The Palm platform does not support a FALSE value for this parameter.
A buffer for returning a value.
This function extracts the value of the attribute AttrObj and returns in RetVal either a copy of the value (if toCopy is TRUE) or a direct memory pointer to the attribute value in the object body (if toCopy is FALSE). If toCopy is FALSE, the function fixes the object in cache to ensure the validity of the returned memory pointer. As a result, you must explicitly unfix the object by calling okUnfixObj. You do not need to fix the object before calling this function.
If the size of the attribute is small, you should make a copy of the attribute value, and avoid the function call overhead of explicitly unfixing the object. However, if the attribute is large, such as a dynamic or an embedded array, it may be more efficient to obtain a memory pointer to the object and access the attribute value directly.
If the attribute contains a dynamic array, okGetAttrVal returns a pointer to the dynamic array. The type of the attribute value returned is okArray, which is a generic pointer type. The elements in the array are not returned in the buffer provided by RetVal. If toCopy is TRUE, okGetAttrVal creates a new copy of the dynamic array. You must explicitly release the copy of the array using okDeleteArray when it is no longer needed. However, you do not need to unfix the object itself. If toCopy is FALSE, you do not need to release the dynamic array the function returns, but you must unfix its containing object explicitly using okUnfixObj.
Updates the value of an attribute.
okError okSetAttrVal(okEnv Env, okHandle Obj,
okHandle AttrObj, const okAttrVal_s *NewVal);
An environment handle.
An object handle.
An object representing the attribute to access.
A buffer containing a new value.
This function updates the value of the attribute identified by AttrObj in object Obj with the new value specified in NewVal. You do not need to fix the object before calling this function. If the attribute contains a dynamic array, the NewVal buffer should point to a dynamic array. This function releases the original dynamic array in the attribute, creates the new dynamic array in NewVal, and places the new array in the object.
Extracts the value of the attribute at a specified position and returns either a copy of the value or a direct memory pointer to the attribute value in the object body.
okError okGetAttrValAt(okEnv Env, okHandle Obj,
okU4B Position, okBool toCopy, okAttrVal_s *RetVal);
An environment handle.
An object handle.
The position of the attribute to access.
A Boolean flag:
TRUE - On Win32 and EPOC platforms it returns a pointer to a pointer to the attribute. On the Palm platform it returns a pointer directly to the attribute.
FALSE - On Win32 and EPOC it returns a pointer directly to the attribute. The Palm platform does not support a FALSE value for this parameter.
A buffer for returning a value.
This function extracts the value of the attribute at position Position. It returns (in RetVal) either a copy of the value if toCopy is TRUE, or a direct memory pointer to the attribute value in the object body if toCopy is FALSE. If toCopy is FALSE, the object is implicitly fixed, which guarantees the validity of the returned memory pointer. Consequently, the caller must unfix the object with okUnfixObj. The object does not need to be fixed before a call to this function. See the preceding discussion of okGetAttrVal for more information.
Updates the value of an attribute at a specified position.
okError okSetAttrValAt(okEnv Env, okHandle Obj, okU4B Position, const okAttrVal_s *NewVal);
An environment handle.
An object handle.
The position of the attribute to access.
A buffer containing a new value.
This function updates the value of the attribute at position Position in object Obj with the new value specified in NewVal. The object does not need to be fixed before a call to this function. See the preceding discussion of okSetAttrVals for more information.
Updates the values of multiple attributes listed by their names.
okError okSetAttrVals(okEnv Env, okHandle ObjH, okSize AttrCnt,
okHandle AttrH, const okAttrVal_s *NewVal);
An environment handle.
An object handle.
The number of attributes to update.
The handles of the attributes to update.
A buffer containing the new values.
This function updates the value of the attributes identified by AttrObj in object ObjH with the new value specified in NewVal. You do not need to fix the object before calling this function. If the attribute contains a dynamic array, the NewVal buffer should point to a dynamic array. This function releases the original dynamic array in the attribute, creates the new dynamic array in NewVal, and places the new array in the object.
Updates the value of attributes at a specified position.
okError okSetAttrValsAt(okEnv Env, okHandle ObjH, okSize AttrPosCnt, okU4B *Position, const okAttrVal_s *NewVal);
An environment handle.
An object handle.
The number of attributes to update.
A buffer containing the positions of the attributes to access.
A buffer containing the new values.
This function updates the value of the attribute at position Position in object ObjH with the new value specified in NewVal. The object does not need to be fixed before a call to this function. See the preceding discussion of okSetAttrVal for more information.
The following code demonstrates the use of the attribute value procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
#define DEPT_NAME "Computer Science"
okEnv Env;
okHandle Object, Group;
okRef AttrRef, AttrRefs[2];
okArray DeptName;
okAttrVal_s Value, AttrVals[2];
okError e;
okU4B AttrPoss[2];
...
/* assume class "Dept_s" is in Class, find its attribute "Name" */
e = okFindAttr(Env, Class,
sizeof("Name"), "Name", NULL, &AttrRef, NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* create a new "Dept_s" object */
e = okCreateObj(Env, Group, Class, NULL, OK_FIX_OBJ, &Object);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* prepare the string "Computer Science" in Value */
e = okCreateArray(Env, &DeptName,
sizeof(DEPT_NAME), DEPT_NAME);
if (OK_IS_ERROR(e)) { /* error handling */ }
Value.BufSize = Value.Indicator = sizeof(okArray);
Value.BufPtr = (okByte *)&DeptName;
/* a silly sequence just to illustrate usage ... */
e = okSetAttrVal(Env, Object, AttrRef, &Value);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetAttrVal(Env, Object, AttrRef, FALSE, &Value);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okSetAttrValAt(Env, Object, 0, &Value);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetAttrValAt(Env, Object, 0, FALSE, &Value);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetAttrVals (Env, Object, Obj, 2, AttrRefs, AttrVals);
e = okGetAttrVals At (Env, Object, 2, AttrPoss, AttrVals);
...
The method invocation function, okExecMeth, invokes methods in a class.
This table shows the platform compatibility of okExecMeth.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okExecMeth | Executes a method. | X | X | X |
Executes a method.
okError okExecMeth (okEnv env, okHandle dbH, okHandle meth, okHandle obj, okSize argValCount, okAttrVal_s *argVals, okU1B *outFlag, okAttrVal_s *result );
An environment handle.
Handle to the database.
The method object to execute.
The handle to the object containing the method to execute.
The number of arguments passed to the method.
An array of arguments passed to the method.
A flag indicating IN/OUT parameters.
The result of the method.
This function executes the method meth. If the method is a class method, obj can be NULL. Otherwise, obj is a valid object handle. ArgValCount is the number of argument values provided in the argVals array. argVals is an array of okAttrVal_s structures, each containing an argument value. OutFlag is an array of ArgValCount bytes. A non-zero value in the n-th byte means that the n-th argument is an IN/OUT argument. Set outFlag to NULL if the method does not use IN/OUT arguments. The corresponding Java type of an IN/OUT argument must be a mutable type. The kernel returns the result in the okAttrVal_s structure pointed to by result.
The following code demonstrates the use of the method invocation procedure:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
#define DEPT_NAME "Computer Science"
...
okAttrVal_s argVals[2], res;
/* declare other variables here */
/* find the void HireStaff(int ID, String Name) method */
e = okFindMethod(Env, Database, DeptRef, OK_INSTANCE_METHOD,
9, "HireStaff", 22,
"(ILjava/lang/String;)V", &MethRef);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* use iterator to get a department object into variable dept */
/* initialize argVal2[0] and argVals[1] here */
e = okExecMeth(Env, Database, MethRef, dept, 2, argVals,NULL,&res);
...
The kernel supports queries against database objects using iterators. An iterator is similar to a scan in a relational database system. The scope of each query typically covers all instances of a class in an object group. Optionally, you can expand the scope of a query to include instances of all subclasses as well. The iterator only returns instances that satisfy the specified search conditions. A cursor associated with each iterator points to the current object in the iteration.
A query starts when you create the iterator and ends when you delete the iterator. During its lifetime, the iterator retrieves qualified objects one at a time from the database. The current object in the iteration establishes the cursor position, which can be saved or changed by the application. For each iteration, the application can set the cursor movement properties with one of the following:
OK_FIRST: move the cursor to the first qualified object.
OK_LAST: move the cursor to the last qualified object.
OK_NEXT: move the cursor to the next qualified object.
OK_PRIOR: move the cursor to the prior qualified object.
The kernel supports queries based on search conditions in the form <Connective, Attribute, Operator, Value>, where:
Connective is either a logical AND or OR operator.
Attribute is the attribute whose value is compared.
Operator is one of the comparators or nullity predicates (for testing NULL values).
Value is a constant value with which Attribute is compared.
Use the data structure okSearchCond_s to represent a search condition.
typedef struct okSearchCond okSearchCond_s;
struct okSearchCond {
okU4B AttrPos; /* relative position of attribute */
okU1B Operator; /* operator to compare with */
okU1B Connective; /* how to connect to next condition */
okU1B Collate; /* optional collating sequence */
okU1B _Padding; /* not used */
okAttrVal_s AttrVal; /* value to compare against */
};
To issue a query, you pass the search conditions in a dynamic array of okSearchCond_s to the kernel. The logical AND operator takes precedence over the logical OR operator during the evaluation of search conditions. In other words, when both the AND and OR operators appear, the kernel interprets the search conditions as a set of disjunctive (OR) expressions, each of which is composed of conjunctive (AND) terms.
This table lists the OKAPI iterator functions.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateIterator | Prepares a query against instances of a class and returns a transient iterator object. | C | C | C |
| okDeleteIterator | Terminates a query associated with an iterator. | C | C | C |
| okIterate | Advances the cursor associated with an iterator and returns a pointer to the body of the current object. | C | C | C |
| okGetCursor | Returns the current cursor position of an iterator. | C | C | C |
| okSetCursor | Sets the current cursor position of an iterator. | C | C | C |
Prepares a query against instances of a class and returns a transient iterator object.
okError okCreateIterator(okEnv Env, okHandle Group, okHandle Class, okBool isImmediate, okU4B CondCount, const okSearchCond_s SearchConds[], Reserved, okU4B UpdAttrCount, const okU4B UpdAttrPos[], okIterator *RetIter);
An environment handle.
A group object.
A class object.
A Boolean flag which is TRUE if subclasses should be included in the query, and FALSE if subclasses should not be included.
The number of search conditions.
An array of search conditions of type okSearchCond_s.
Reserved parameter. No value required.
The number of attributes to update.
The array of positions of the attributes the caller intends to update in the qualified instances.
A buffer for returning an iterator.
This function prepares a query against instances of the class Class in the object group Group. It returns a transient iterator object in RetIter. UpdAttrPos enables the kernel to avoid picking an access path whose scanning order may be affected by the updates.
Terminates a query associated with an iterator.
okError okDeleteIterator(okEnv Env, okIterator Iter);
An environment handle.
An iterator.
This function releases all system resources allocated to the iterator, including the iterator object.
Advances the cursor associated with an iterator and returns a pointer to the body of the current object.
okError okIterate(okEnv Env, okIterator Iter, okU4B Action, okObjData *RetObj);
An environment handle.
An iterator.
Specifies the direction in which the cursor should move:
OK_FIRST: move the cursor to the first qualified object.
OK_LAST: move the cursor to the last qualified object.
OK_NEXT: move the cursor to the next qualified object.
OK_PRIOR: move the cursor to the prior qualified object.
A buffer for returning a pointer to the object body.
This function advances the cursor associated with an iterator and returns (in RetObj) a pointer to the body of the current object. The kernel fixes the object returned by the function and automatically unfixes it when the cursor is moved. okIterate returns NULL in RetObj if:
The direction is OK_NEXT and the iterator reaches the end of the scan.
The direction is OK_PRIOR and the iterator reaches the beginning of the scan.
Neither event returns an error code.
Returns the current cursor position of an iterator.
okError okGetCursor(okEnv Env, okIterator Iter, okCursor *RetCursor);
An environment handle.
An iterator.
A buffer for returning the cursor.
This function returns in RetCursor the current cursor position of an iterator. A cursor returned by okGetCursor is a transient object. You can use the returned cursor to alter the cursor position of Iter.
After calling okSetCursor, the user must call okIterate to get the reference to the object. For example:
okSetCursor (env, iterHandle, &RetCursor); okIterate (env, iterHandle, OK_PRIOR, &foundRef); okIterate (env, iterHandle, OK_NEXT, &foundRef);
Changes the current cursor position of an iterator.
okError okSetCursor(okEnv Env, okIterator Iter, okCursor Cursor);
An environment handle.
An iterator.
The new cursor position.
This function changes the current cursor position of an iterator to that specified by Cursor, which you can obtain with okGetCursor. All cursors associated with an iterator are automatically deleted when okDeleteIterator deletes the iterator object. After calling okSetCursor, the user must call okIterate to get the reference of the object.
The following code demonstrates the use of the iterator procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okEnv Env;
okHandle Database;
okRef Group, Class;
okIterator Itor;
okCursor Cursor;
Professor_S *Advisor;
okError e;
okU4B MinID = 101;
okU2B MaxAge = 50;
...
okSearchCond_s Cond[2] = { /* ID >= 101 && Age < 50 */
{0, OK_GE, OK_AND, 0, 0,{sizeof(okU4B),
(unsigned char *)&MinID,sizeof(okU4B)}},
{2, OK_LT, OK_AND, 0, 0,{sizeof(okU2B),
(unsigned char *)&MaxAge,sizeof(okU2B)}}
};
e = okFindGroup(Env, Database, sizeof("Faculty"),
"Faculty", &Group);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindClass(Env, Database, sizeof("Professor_s"),
"Professor_s", &Class);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okCreateIterator(Env, Group, Class, TRUE, 2, Cond,
0, 0, NULL, &Itor);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okIterate(Env, Itor, OK_NEXT, (okObjData *)&Advisor);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetCursor(Env, Itor, &Cursor);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okSetCursor(Env, Itor, Cursor);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDeleteIterator(Env, Itor);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
To speed up query processing, the kernel supports indexes on instances of a class in an object group. The query optimizer in the kernel automatically picks an efficient access path when you create an iterator (that is, when you issue a query). The kernel maintains the index as objects are updated. The kernel currently supports only B-tree indexes.
You can obtain information about existing indexes using the okNextIndex function. okNextIndex returns information in the following data structure.
typedef struct {
okU2B IdxType;
okU2B IndexNo;
okU2B Options;
okArray AttrPos; /* Will be created/resized as necessary */
/* Used internally for iteration */
ok2B PrevIdx;
okU4B ClassNo;
okPtr Conx;
} okIdxInfo_s;
This table lists the OKAPI index management functions.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateIndex | Creates an index on a set of attributes. | C | C | C |
| okDeleteIndex | Deletes an index. | C | C | C |
| okGetIndexInfo | Returns index information. | C | N | C |
| okNextIndex | Returns the next index for a given group and class. | C | N | C |
Creates an index on a set of attributes.
okError okCreateIndex(okEnv Env, okHandle Group, okHandle Class, okU4B NumAttrs, okU4B AttrPos[], okU2B IndexType, okU2B Options, okU2B *RetIndexNo);
An environment handle.
A group object.
A class object.
The number of attributes on which the index is created.
The position of the attributes on which the index is created. Starts at 0.
The type of index to create. Currently OK_BTREE, for a B-tree index, is the only supported value for this parameter.
Additional options for index creation.
A buffer for returning the number of the new index.
This function creates an index on a set of attributes indicated by AttrPos. It creates the index on instances of Class in the object group Group. Options specifies key constraints on each constructed index. Valid key constraints include:
OK_UNIQUE_KEY: key values must be unique and NULL values are allowed.
OK_PRIMARY_KEY: key values must be unique and NULL values are not allowed.
After creating the index, the kernel automatically maintains the index whenever objects are created, updated, or deleted. If the specified index already exists, okCreateIndex does nothing. An error code is not returned.
Deletes an index.
okError okDeleteIndex(okEnv Env, okHandle Group, okHandle Class, okU4B IndexNo, okU2B IndexType);
An environment handle.
A group object.
A class object.
The index number or attribute position.
The type of index to delete. Currently OK_BTREE (for a b-tree index) is the only supported value for this parameter.
This function deletes the specified index. The arguments Group, Class, and IndexNo identify the index to delete. If the index is a multi-attribute index, IndexNo must be the index number returned by okCreateIndex. If the index is a single-attribute index, IndexNo can be the attribute position. If the index does not exist, okDeleteIndex does nothing. An error code is not returned.
Returns information pertaining to an index.
okError okGetIndexInfo(okEnv Env, okHandle Group, okHandle Class, okU4B AttrPos, okU2B IndexType, okU2B *RetInfo);
An environment handle.
A group object.
A class object.
The index number or attribute position.
The type of index on which to return information. Currently OK_BTREE (for a b-tree index) is the only supported value for this parameter.
The buffer for returning index information.
This function returns information in RetInfo pertaining to the index at attribute position AttrPos of Class instances in the group Group.
The returned bit map, which is placed in RefInfo, uses the following bit fields:
OK_INDEX_EXISTS: the index exists; if the index does not exist, the return value is zero.
OK_UNIQUE_KEY: key values must be unique and NULL values are allowed.
OK_PRIMARY_KEY: key values must be unique and NULL values are not allowed.
If you are getting an index on four attributes, for example:
attrpos[]={0,1,2,3}
You can call okGetIndexInfo on attribute 0 to return the index information. Calling okGetIndexInfo on any other attribute will return a value of 0.
Returns the next index for a given group and class.
okError okNextIndex(okEnv Env, okHandle Group, okHandle Class, okIdxInfo_s *Info);
An environment handle.
A group object.
A class object.
The index number or attribute position.
This function returns in Info the next index in the specified group and class. The first call should set the Group argument to the appropriate group and the Info.AttrPos array to NULL. Subsequent calls should set the group to NULL. After retrieving the information for all the indexes, you should delete the Info.AttrPos array. okError returns TRUE if the an index exists, and FALSE if no index exists.
The following code demonstrates the use of the index procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okRef Group, Class;
okU2B IndexType;
okError e;
...
e = okFindGroup(Env, Database, sizeof("Faculty"),
"Faculty", &Group);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindClass(Env, Database, sizeof("Professor_s"), "Professor_s",
&Class);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* create a B-Tree type of index on attribute ID */
e = okCreateIndex(Env, Group, Class, 0, OK_BTREE, OK_UNIQUE_KEY);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetIndexInfo(Env, Group, Class, 0, &IndexType);
if (!(RetInfo & OK_INDEX_EXISTS) { /* error handling */ }
e = okDeleteIndex(Env, Group, Class, 0, OK_BTREE);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
Object naming allows you to register a symbolic name for an object. After registering the object, you can look it up efficiently by name. You can assign any object a name, regardless of the object's class. Each database has its own name space organized as a hierarchy, which makes the names easier to manage.
As in the UNIX file system, directory objects implement the name hierarchy in a database. A root directory object describes the top-level objects in the name hierarchy. Each intermediate node in the hierarchy is a directory object that contains names and object references to objects at the next level in the sub-tree. The leaf nodes of the hierarchy are the named objects. When you create a new directory object and assign it a name within the hierarchy, a sub-hierarchy in a name space is created.
An object name is a character string that references an object relative to a directory object. You form the object name by concatenating the local names of all the directory objects, from the root to the target object, with the local name of the object. Components in an object name are separated by the backslash delimiter (\). The system-created root directory object is represented by a backslash (\).
The mechanism behind object naming is similar to "soft links" in the UNIX file system. The following rules apply to object naming:
An object may have several names (aliases).
The deletion of an object name does not imply the deletion of the object.
The deletion of an object does not imply the deletion of all its names. A dangling reference may remain in the name directory after an object is deleted.
This table lists the OKAPI functions that manage object names.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateName | Creates a name for an object. | C | C | C |
| okDeleteName | Deletes an object name. | C | C | C |
| okFindObj | Finds an object name. | C | C | C |
Creates a name for an object.
okError okCreateName(okEnv Env, okHandle Directory, okSize ObjNameLen, okName ObjNamePtr, okHandle Obj);
An environment handle.
A directory object.
The length of an object name.
A name for an object.
An object.
This function creates a name for the object Obj, relative to the directory object Directory. ObjNamePtr must be a NULL-terminated string. It cannot be empty. Instead of specifying the root directory object in a database, the caller can specify the database object. You can use the database object interchangeably with the root directory object in the Directory parameter for all object naming functions.
If you are using a one-level naming system, you need only to use the database reference for the Directory parameter value.
If you are using a multi-level naming system, you must create directory objects for each level. To create a directory object, use NULL as the obj parameter value and use the directory object for the Directory parameter value.
Deletes an object name.
okError okDeleteName(okEnv Env, okHandle Directory, okSize ObjNameLen, okName ObjNamePtr);
An environment handle.
A directory object.
The length of an object name.
A name for an object.
This function deletes the object name ObjNamePtr relative to the directory object Directory from the name hierarchy in the database. Instead of specifying the root directory object in a database, the caller can specify the database object. You can use the database object interchangeably with the root directory object in the Directory parameter for all object naming functions.
Finds an object name.
okError okFindObj(okEnv Env, okHandle Directory, okSize ObjNameLen, okName ObjNamePtr, okRef *RetObj, okBool *isDirectory);
An environment handle.
A directory object.
The length of an object name.
A name for an object.
A buffer for returning the object reference.
A buffer for returning a Boolean flag which is TRUE if the object found is a directory object.
This function locates the object with the name specified by ObjNamePtr relative to Directory. The function returns a reference to the object, if found, in RetObj. If the object cannot be found, the function returns a NULL reference in RetObj. This is not considered an error. A Boolean flag returned in isDirectory indicates whether the object found is a directory object. Instead of specifying the root directory object in a database, the caller can specify the database object. You can use the database object interchangeably with the root directory object in the Directory parameter for all object naming functions.
The following code demonstrates the use of the object naming procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okRef Group, Class;
Professor_s *Chairman;
okError e;
...
/* create a directory called "EECS" */
e = okCreateName(Env, Database /* to use root directory */, sizeof("EECS"),
"EECS", NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* create a new professor object in Chairman */
e = okFindGroup(Env, Database,
sizeof("Faculty"), "Faculty", &Group);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindClass(Env, Database,
sizeof("Professor_s"), "Professor_s", &Class);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okCreateObj(Env, Group, Class,
NULL, OK_FIX_OBJ, (okObjData *)&Chairman);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* assign "\EECS\CHAIRMAN" as name of a new "Professor_s" object */
e = okCreateName(Env, Database,
sizeof("\\EECS\\CHAIRMAN"), "\\EECS\\CHAIRMAN", Chairman);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindObj(Env, Database,
sizeof("\\EECS\\CHAIRMAN"), "\\EECS\\CHAIRMAN", &Chairman, NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDeleteName(Env, Database,
sizeof("\\EECS\\CHAIRMAN"), "\\EECS\\CHAIRMAN");
if (OK_IS_ERROR(e)) { /* error handling */ }
...
OKAPI supports relationships between objects of different classes or of the same class. Conceptually, each relationship between two objects consists of a pair of mutually dependent object references in an opposite direction. For example, a relationship between two objects A and B is represented by an object reference from A to B and a corresponding object reference from B to A.
OKAPI supports the following types of relationships:
| Relationship | Example |
|---|---|
| Referential integrity | If object A references object B and B is deleted, A's reference to B is nullified. If a reference in A is changed to be a reference to object C, references in both B and C must be updated accordingly. |
| Cascaded deletion | If object A is deleted, B is also deleted. If B references C in a cascaded deletion relationship, C is also deleted. |
| Restricted deletion | A cannot be deleted if B still exists. |
| Sole ownership | B can only be referenced by one object with which B has a sole-ownership relationship. |
A relationship by default implies referential integrity. Note, however, that an object reference need not be part of a relationship.
A relationship between two classes is represented by two attributes, one from each of the participating classes. A relationship is represented in the form <FromClass, FromAttribute, ToClass, ToAttribute>.
This table lists the OKAPI functions that manage relationships.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateRel | Establishes a relationship between two classes. | C | N | C |
| okDeleteRel | Deletes a relationship. | C | N | C |
Establishes a relationship between two classes.
okError okCreateRel(okEnv Env, okHandle FromClass, okHandle FromAttr, okHandle ToClass, okHandle ToAttr, okU4B Options);
An environment handle.
The first class involved in the relationship.
The attribute in the first class of the relationship.
The second class involved in the relationship.
The attribute in the second class of the relationship.
The type of relationship. Allowable values:
OK_REF_INTEGRITY: for referential integrity.
OK_CASCADE_DEL: for cascading deletion.
OK_RESTRICT_DEL: for restricted deletion.
OK_ONE_PARENT: for one parent only.
This function establishes a relationship between classes FromClass and ToClass. The relationship is maintained through the attribute FromAttr in FromClass and the attribute ToAttr in ToClass. Note that the kernel can maintain a relationship properly only if all object updates are made through the okCreateObj, okDeleteObj, okSetAttrVal, and okSetAttrValAt functions. Specifically, a direct modification to an attribute which participates in a relationship may cause a violation of the constraints required of the relationship. This function only works on the class attributes.
After creating the relationship between two classes and instantiating objects from those classes, you must update each objects class attribute with the reference to the related object using okSetAttrVal or okSetAttrValAt. The related object's class attribute will be updated automatically.
Deletes a relationship.
okError okDeleteRel(okEnv Env, okHandle FromClass, okHandle FromAttr, okHandle ToClass, okHandle ToAttr);
An environment handle.
The first class involved in the relationship.
The attribute in the first class of the relationship.
The second class involved in the relationship.
The attribute in the second class of the relationship.
This function deletes a previously established relationship maintained in the attribute FromAttr in FromClass and the attribute ToAttr in ToClass.
The following code demonstrates the use of the relationship procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okRef DeptClass, StaffAttr, ProfClass, DeptAttr;
okError e;
...
e = okFindClass(Env, Database, sizeof("Dept_s"), "Dept_s", &DeptClass);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindAttr(Env, DeptClass, sizeof("Staff"), "Staff",
NULL, &StaffAttr, NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindClass(Env, Database, sizeof("Professor_s"),
"Professor_s", &ProfClass);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okFindAttr(Env, ProfClass, sizeof("Dept"), "Dept",
NULL, &DeptAttr, NULL);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okCreateRel(Env, DeptClass, StaffAttr, ProfClass, DeptAttr,
OK_REF_INTEGRITY);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDeleteRel(Env, DeptClass, StaffAttr, ProfClass, DeptAttr);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
A binary large object (BLOB) stores unstructured binary data. BLOBS can be thought of as bitstreams with no character set semantics. BLOBs can store up to two gigabytes of binary data. They are intended for storing large pieces of raw data, such as a digitized image.
In general, a BLOB behaves the same way as other kernel objects. All BLOB objects belong to the class okLong. However, since a BLOB may be too big to fit into the address space of an application, OKAPI provides functions for retrieving and updating a portion of a BLOB object. In addition, OKAPI supplies functions for inquiring and changing the size of a BLOB object. Due to the size of a BLOB, the kernel does not allow a BLOB to be fixed in the cache.
This table lists the OKAPI functions that manage binary large objects (BLOBs).
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateBlob | Creates a BLOB. | C | C | C |
| okDeleteBlob | Deletes a BLOB. | C | C | C |
| okGetBlobVal | Retrieves a portion of a BLOB starting from a given byte offset. | C | C | C |
| okSetBlobVal | Modifies a portion of a BLOB. | C | C | C |
| okSetBlobSize | Adjusts the size of a BLOB. | C | C | C |
| okGetBlobSize | Returns the size of a BLOB. | C | C | C |
Creates a BLOB.
okError okCreateBlob(okEnv Env, okHandle Group, okU4B Size, okU4B EstimatedSize, okRef *RetBlobObj);
An environment handle.
A group object.
The size of BLOB data in bytes.
The estimated size of the large object in bytes.
A buffer for returning a reference to a BLOB object.
This function creates a new BLOB in the object group Group and returns a reference to it in RetBlobObj. After creating the BLOB, the kernel guarantees that the object can grow to at least EstimatedSize bytes, subject to the actual amount of space available on disk. On the Palm Computing Platform, the maximum allowable size for a BLOB is 64K. The argument Size specifies the initial size of the BLOB object. A large object can grow to at least two megabytes, regardless of the value specified in EstimatedSize. The maximum size allowable for a large object is two gigabytes.
Deletes a BLOB.
okError okDeleteBlob(okEnv Env, okHandle BlobObj);
An environment handle.
A handle to the BLOB object to delete.
This function deletes a BLOB and releases the space used by the BLOB.
Retrieves a portion of a BLOB starting from a given byte offset.
okError okGetBlobVal(okEnv Env, okHandle BlobObj, okU4B Offset, okU4B Size, okAttrVal_s *RetVal);
An environment handle.
A handle to the BLOB object to read from.
The byte offset into a BLOB object.
The size of BLOB data in bytes.
A buffer for returning the BLOB data in bytes.
This function retrieves a portion of a BLOB BlobObj, starting from a given byte offset. The value retrieved and its length are returned in the buffer and indicator specified in RetVal.
Modifies a portion of a BLOB.
okError okSetBlobVal(okEnv Env, okHandle BlobObj, okU4B Offset, okU4B Size, okAttrVal_s *NewVal);
An environment handle.
A handle to the BLOB to modify.
The byte offset into a BLOB.
The size of BLOB data in bytes.
A buffer containing the new data value.
This function modifies a portion of a BLOB. The new value and its length are specified in NewVal. You must adjust the size of the BLOB to accommodate the modification prior to calling okSetBlobVal. For example, to append new data to the end of a large object, the size of the large object must first be adjusted with a call to okSetBlobSize to ensure that the new data fits into the large object.
Adjusts the size of a BLOB.
okError okSetBlobSize(okEnv Env, okHandle BlobObj, okU4B Size);
An environment handle.
A handle to the BLOB object to modify.
The new size of the BLOB data in bytes.
This function adjusts the size of a BLOB. You can expand a large object by specifying a Size that is larger than the current size of BlobObj. Similarly, you can truncate a large object by specifying a Size that is smaller than the current size of BlobObj.
Returns the size of a BLOB.
okError okGetBlobSize(okEnv Env, okHandle BlobObj, okU4B *RetSize);
An environment handle.
A handle to a BLOB object.
The size of the BLOB in bytes.
This function returns in RetSize the current size in bytes of a BLOB BlobObj.
The following code demonstrates the use of the procedures that manage BLOBs:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
#define BUF_SIZE 1024
#define PICTURE_SIZE ((okU4B)10*BUF_SIZE)
okAttrVal_s BlobVal;
okByte Buffer[BUF_SIZE];
okRef Group, Blob;
okU4B BlobSize;
okError e;
...
/* create a blob in a group */
e = okCreateBlob(Env, Group, PICTURE_SIZE /* a hint */, &Blob);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okSetBlobSize(Env, Blob, sizeof(Buffer));
if (OK_IS_ERROR(e)) { /* error handling */ }
memset((void *)Buffer, 1, sizeof(Buffer));
memset((void *)&BlobVal, 0, sizeof(BlobVal));
BlobVal.BufSize = BlobVal.Indicator = BUF_SIZE;
BlobVal.BufPtr = Buffer;
e = okSetBlobVal(Env, Blob, 0, &BlobVal);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetBlobVal(Env, Blob, 0, BUF_SIZE, &BlobVal);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetBlobSize(Env, Blob, BUF_SIZE, &BlobSize);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDeleteBlob(Env, Blob);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
A transaction is an integral unit of work consisting of a sequence of operations on one or more databases. All operations of a transaction either succeed or fail together. The effects of a committed transaction persist even if the system crashes. The kernel uses logging to support the properties of transactions.
This table lists the OKAPI functions that manage transactions.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okTransact | Controls the outcome of the current transaction and optionally starts a new transaction. | C | C | C |
| okSetIsolationLevel | Sets the current isolation level. | C | X | C |
| okGetIsolationLevel | Gets the current isolation level. | C | X | C |
Controls the outcome of the current transaction and optionally starts a new transaction.
okError okTransact(okEnv Env, okU4B Action);
An environment handle.
Action to perform.
This function controls the outcome of the current transaction and, optionally, starts a new transaction, as specified by the flags in the bit map Action. Action can take the following flags:
| Flag | Description |
|---|---|
OK_BEGIN
|
Begin a new transaction. |
OK_COMMIT_END
|
Commit the current transaction. |
OK_ROLLBACK_END
|
Roll back the current transaction. |
OK_COMMIT_CONTINUE
|
Commit and start a new transaction at the same level. |
OK_ROLLBACK_CONTINUE
|
Roll back and start a new transaction at the same level. |
| OK_CHECKPOINT_COMMIT | Commit the current transaction but retain all locks. |
For most OKAPI functions that affect objects in a database, a transaction is automatically started if one is not already active.
Sets the current isolation level.
okError okSetIsolationLevel (okEnv Env, okU2B Level);
An environment handle.
Isolation level. Allowable values:
OK_TXN_SINGLE_USER: for single user.
OK_TXN_READ_COMMITTED: for read committed.
OK_TXN_REPEATABLE_READ: for repeatable read.
OK_TXN_SERIALIZABLE: for serializable.
Gets the current isolation level.
okError okGetIsolationLevel (okEnv Env, okU2B *Level);
An environment handle.
A buffer for returning the isolation level.
The following code demonstrates the okTransact procedure:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okError e;
...
e = okTransact(Env, OK_BEGIN);
if (OK_IS_ERROR(e)) { /* error handling */ }
/* do something ... */
e = okTransact(Env, OK_COMMIT_END);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
OKAPI's dynamic array library (okArray) extends the ANSI C memory allocation library. Like memory space allocated by malloc, the memory for a dynamic array is allocated at runtime. You can cast a dynamic array to a pointer type to access an element of the array directly. The application should explicitly release the dynamic array when it is no longer needed to prevent memory leaks. A function in the dynamic array library (similar to realloc) adjusts the size of a dynamic array.
Unlike space allocated by malloc, a dynamic array carries information about the size of the array, which the caller can query. The actual space taken by the dynamic array (its capacity) may be larger than the size of the array. The dynamic array library uses a predictive allocation algorithm to reduce memory fragmentation caused by small incremental expansions of an array. In addition, the library includes functions for appending and copying dynamic arrays.
The following shows the correspondence between the ANSI C memory allocation library and the OKAPI dynamic array library.
| ANSI C Function | OKAPI Dynamic Array Function |
|---|---|
malloc()
|
okCreateArray()
|
free()
|
okDeleteArray()
|
realloc()
|
okSetArraySize()
|
((UserType *)p)[i]
|
((UserType *)p)[i]
|
You can make a dynamic array persistent by embedding it in a persistent object. As such, dynamic arrays form the basis for supporting variable-length attributes in persistent objects. Once a dynamic array becomes a part of a persistent object, the kernel automatically manages storage allocation and de-allocation for the array. For example, when fetching an object with a variable-length attribute from disk, the kernel allocates a dynamic array to hold the values of the variable-length attribute in memory. Similarly, it releases space occupied by a variable-length attribute when the object that contains the attributes is swapped out or deleted.
This table lists the OKAPI functions that manage dynamic arrays.
| Function | Purpose | Win32 | Palm | EPOC |
|---|---|---|---|---|
| okCreateArray | Creates a dynamic array. | C | C | C |
| okDeleteArray | Deletes a dynamic array. | C | C | C |
| okGetArraySize | Returns the size of a dynamic array. | C | C | C |
| okSetArraySize | Sets the size of a dynamic array. | C | C | C |
| okAppendArray | Appends data to the end of a dynamic array. | C | C | C |
| okCopyArray | Creates a copy of a dynamic array. | C | C | C |
| okCreateMDArray | Creates a new multi-dimensional array. | C | C | C |
| okCopyMDArray | Copies a multi-dimensional array. | C | C | C |
| okFreeMDArray | Frees a multi-dimensional array. | C | C | C |
Creates a new dynamic array.
okError okCreateArray (okEnv Env, okArray *RetArray,
okU4B Size, const okByte *Data);
An environment handle.
A buffer for returning a pointer to the new dynamic array.
The size of data in a dynamic array.
Data value for a dynamic array.
This procedure creates an array and returns a pointer to the new array in RetArray. If Data is NULL, the initial value of the dynamic array is not initialized. This function assumes that RetArray does not point to a valid dynamic array before the call. To avoid a memory leak, the caller should release any valid dynamic array pointed to by RetArray before passing RetArray to okCreateArray. It is an error if RetArray is NULL.
Generally, you should call okCreateArray to initialize an array before performing any other operation on it. Alternatively, you can initialize it by setting it directly to NULL, as follows:
okArray anArray = NULL;
Deallocates the memory occupied by a dynamic array.
okError okDeleteArray(okEnv Env, okArray *Array);
An environment handle.
A pointer to a dynamic array.
This procedure deallocates the memory occupied by a dynamic array pointed to by Array. The function sets the value pointed to by Array to NULL. If Array is NULL prior to the call, okDeleteArray performs no action.
Retrieves the size, in bytes, of a dynamic array.
okError okGetArraySize(okEnv Env, const okArray *Array, okU4B *RetSize);
An environment handle.
A pointer to a dynamic array.
A buffer for returning the size of a dynamic array.
This procedure retrieves the size in bytes of a dynamic array pointed to by Array. It returns 0 if Array is NULL or if Array points to a NULL pointer.
Sets the size in bytes of a dynamic array.
okError okSetArraySize(okEnv Env, okArray *Array, okU4B NewSize);
An environment handle.
A pointer to a dynamic array.
The new size of the dynamic array.
This procedure adjusts the size of the dynamic array pointed to by Array. If Array points to a NULL pointer and NewSize is greater than zero, okSetArraySize creates a new array. If NewSize is larger than or equal to the original size of the dynamic array, the original value of the dynamic array remains intact. The newly added memory is not initialized. If NewSize is smaller than the original size of the dynamic array, the value in the array is truncated according to NewSize. You can use this function when you know how many bytes are to be added to a dynamic array. Instead of calling okAppendArray incrementally to append each data item to the dynamic array, you can adjust the size once and assign the data items directly into the array, treating it as a regular C array.
Appends data to the end of a dynamic array.
okError okAppendArray(okEnv Env, okArray *Array, okU4B Size, const okByte *Data);
An environment handle.
A pointer to a dynamic array.
The size of data in a dynamic array.
Data value for a dynamic array.
This procedure appends Size bytes of new data (pointed to by Data) to the end of a dynamic array pointed to by Array. If Array originally points to a NULL pointer and Size is greater than zero, okAppendArray creates a new array. If Data is NULL, it does not initialize the newly appended area. It is an error if Array is NULL.
Creates a copy of a dynamic array.
okError okCopyArray(okEnv NewEnv, okArray *RetNewArray, okEnv OldEnv, const okArray *OldArray);
The environment handle for the target array.
The target array.
The environment handle for the source array.
The source array.
This function creates a copy of a dynamic array pointed to by OldArray and returns a pointer to it in RetNewArray. It does not release a dynamic array pointed to by OldArray. To avoid memory leaks, you should release any valid dynamic array pointed to by RetNewArray before passing it to this function. If OldArray is NULL or points to a NULL pointer, the function returns a NULL pointer in RetNewArray. It is an error if RetNewArray is NULL.
Creates a new multi-dimensional array.
okError okCreateMDArray (okEnv Env, okSize Dim, const okSize *Size, okArray *d);
An environment handle.
Dimension. The number of elements.
The size of data in each element (bytes).
The array handle.
Copies a multi-dimensional array.
okError okCopyMDArray (okEnv Env, okSize Dim, okArray s, okArray *d);
An environment handle.
Dimension. The number of elements.
The source array.
The target array.
Frees a multi-dimensional array.
okError okFreeMDArray (okEnv Env, okSize Dim, okArray a);
An environment handle.
Dimension. The number of elements.
A handle to the array to free.
The following code demonstrates the use of the dynamic array procedures:
#include "okbasic.h"
#include "okerr.h"
#include "okapi.h"
okChar *CityName = "San Jose";
okU4B CityPopulation = 300000;
okU4B ArraySize; /* size of a dynamic array */
okArray City; /* dynamic array of okChar */
okArray Population; /* dynamic array of okU4B */
okArray NewArray; /* a new array */
okError e;
okEnv Env;
...
/* see okInit to initialize the environment here */
e = okCreateArray(Env, &City,
strlen(CityName)+1, (okByte *)CityName);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okCreateArray(Env, &Population,
sizeof(okU4B), (okByte *)&CityPopulation);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okGetArraySize(Env, &City, &ArraySize);
if (OK_IS_ERROR(e)) { /* error handling */ }
if (ArraySize != sizeof("San Jose")) { /* error handling */ }
e = okSetArraySize(Env, &Population, 2*sizeof(okU4B));
if (OK_IS_ERROR(e)) { /* error handling */ }
CityPopulation = 350000;
e = okAppendArray(Env, &Population,
sizeof(okU4B), (okByte *)CityPopulation);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okCopyArray(Env, &NewArray, Env, &City);
if (OK_IS_ERROR(e)) { /* error handling */ }
e = okDeleteArray(Env, &City);
if (OK_IS_ERROR(e)) { /* error handling */ }
...
|
![]() Copyright © 2002 Oracle Corporation All rights reserved |
|