For usage notes, please see the chapter "Queries."
COMMIT
Perform a normal, short transaction commit.
A commit saves your actions to the databases involved and releases short locks. A commit also releases objects from cache memory, erases all savepoints, asserts persistent locks, and starts a new short transaction. A commit makes no changes to transient objects.
Changes made in a short transaction are not visible to other users until you commit them.
See the VERSANT Database Fundamentals Manual for a complete description of a commit.
DELETE FROM [ only ] class
[ predicate ]
Delete objects of a class that satisfy a predicate.
Specify the class in the class
parameter. To select objects to be deleted, specify a predicate in the predicate
parameter; otherwise, all instances of the class will be deleted. To exclude subclasses from evaluation, specify the keyword only
. See the "Usage Notes" section for information on how to specify a predicate.
DELETE ( oidval )
Delete the object with the logical object identifier specified in the oidval
parameter.
Examples
Delete a specified object:
Delete (9.0.3089)
delete from Employee where name like "*Jame*"
delete from only Employee where name like "*Jame*"
INSERT INTO class [ attrlist ]
VALUES ( constlist )
Elements
class
attrlist
If attrlist
is not specified, the values in the constlist
parameter are assumed to be in the same order in which attributes are defined in the class definition.
If attrlist
is specified, it should list attributes in the same order as values are supplied in the constlist
parameter.
The general syntax of a list of attribute names, each specified as and attr
parameter, is:
attr [, attr ...]
See the "Usage Notes" section for information on how to specify an attribute name.
You cannot use the keyword SELFOID
or the wildcard character *
in an attribute list.
constlist
The list of values will be applied to the attributes in attrlist
in the same order as the attribute names are specified. If attrlist
is not specified, values will be applied in the order in which attributes appear in the class definition.
Insert a new object with values for specified attributes:
insert into Employee (department, name)
values (9.0.3076, "Bill Li")
Insert into Employee
values ("Bill Li", 150000, 9.0.3076)
QUIT
Perform a normal application exit.
An exit ends a session if it has not already ended, terminates the application process, and commits the current short transaction.
See the VERSANT Database Fundamentals Manual for a complete description of an application exit.
ROLLBACK
Perform a normal, short transaction rollback.
A rollback abandons your actions, releases short locks, and restores databases to conditions at the last commit or checkpoint commit. A rollback also releases objects from cache memory, erases all savepoints, and starts a new short transaction. A rollback makes no changes to transient objects.
See the VERSANT Database Fundamentals Manual for a complete description of a rollback.
SELECT attrlist
FROM [ only ] class
[ predicate ]
Find attribute values for objects of a class.
Specify attribute names in attrlist
and a class name in class
. To select objects whose values are to be returned, specify a predicate in the predicate
parameter; otherwise, values for all instances of the class will be returned. To exclude subclasses from evaluation, specify the keyword only
.
SELECT attrlist
FROM ( oidval ) -> attr
[ predicate ]
Find attribute values for objects in a vstr.
Specify attribute names in attrlist
, the logical object identifier of the object containing the vstr in oidval
, and the name of the vstr attribute in attr
. To select objects whose values are to be returned, specifiy a predicate in the predicate
parameter; otherwise, values for all objects in the vstr will be returned.
SELECT attrlist
FROM ( oidval )
Find attribute values for a single object.
Specify attribute names in attrlist and the logical object identifier of the object in oidval
.
Elements
Following is an explanation of the elements of the various forms of the SELECT
statement.
attrlist
The general syntax is:
attr
[, attr.. ] [ SELFOID ] | *
To return values for all visible attributes of the class and its subclasses, use the wildcard character *
.
If you list individual attribute names, you can also use the keyword SELFOID
to get the logical object identifier for the returned object. You will not receive the logical object identifier if you use the wildcard character.
See the "Usage Notes" section for information on how to specify an attribute name.
class
only
only
.
oidval
predicate
If you do not specify a predicate in the forms of SELECT
that take an optional predicate, then all instances of the class or vstr are returned.
See the "Usage Notes" section for information on how to specify a predicate.
Select attribute from class and subclasses
name
from all instances of Person
and its subclasses:
select name from Person
name
from all instances of Person
:
select name from only Person
Employee
and its subclasses:
select selfoid from Employee
Employee
and its subclasses that satisfy a predicate:
select * from Employee where name like "*Jame*"
Select value of name
using a full attribute name in the predicate:
select * from Employee
where Person::name like "*James*"
name
from the instances of Employee
and its subclasses that satisfy multiple predicates:
select name from Employee
where salary > 45000.7 and name like "*Jame*"
name
from Employee
and subclasses where the department
link is not of type Department
(meaning that the link is null):
select name from Employee
where department not_isa Department
name
from the instances of Employee
and its subclasses that satisfy multiple predicates whose parameters $1
and $3
are substituted at runtime:
select name from Employee
where salary > $3 and name like $1
select * from (9.0.3076)
Employee
and subclasses whose department
attribute contains a link to a Department
object with a name
attribute that matches a predicate:
select * from Employee
where department -> name = "RD"
name
from objects in a vstr that satisfy a predicate. The vstr that will be searched is the employees
attribute of the Department
object whose loid is 9.0.3076
.
select name from (9.0.3076) -> employees
where salary > 30000.0
UPDATE [ only ] class
SET updatelist
[ predicate ]
Modify attributes of objects of a class.
Specify update expressions in updatelist
and a class name in class
. To select objects to be updated, specify a predicate in the predicate
parameter; otherwise, values for all instance of the class will be changed. To exclude subclasses from updating, specify the keyword only
.
UPDATE ( oidval )
SET updatelist
Modify attributes of a specified object.
Specify the logical object identifier of the object to be updated in oidval
and update expressions in updatelist
.
Elements
Following is an explanation of the elements of the various forms of the UPDATE
statement.
class
only
only
.
updatelist
The general syntax is:
update_expr [, update_expr ...]
predicate
See the "Usage Notes" section for information on how to specify a predicate.
oidval
The updatelist parameter consists of a list of update expressions. An update expression can modify object attributes.
Set value syntax
update_expr
:
attr = const
attr += const
attr
parameter. See the "Usage Notes" section for information on how to specify an attribute name.
In an update expression, specify a modified or new value in the const
parameter. A const
can be one of the following literal values:
float
float
.
int
int
.
string
oidval
nn.nn.nn
.
constaggr
{1.3, -3.05, 4.3}
const
or constaggr
parameter.Examples
Update attribute in specified object:
update (9.0.3089)
set employees += 9.0.3079,
name = "Marketing"
update Employee
set salary = 5.765e3
where name = "James"
update only Employee
set salary = 5765.7
where name = "James"
9.9.3079
to the vstr attribute employees
in all instances of Department
:
update Department
set employees += 9.0.3079
update Department
set employees += {9.0.3079, 9.0.3077}
1.0.3445
to the vstr attribute employees
in the instances of Department
whose name
attribute is "RD
":
update Department
set employees += 1.0.3445
where name = "RD"
employees
in the instances of Department
whose name
attribute is "RD
":
update Department
set employees += { 1.0.3445, 1.0.3446 }
where name = "RD"
void o_freequery( o_parseresult* parseresult );
Deallocate memory allocated in o_parsequery()
to hold a parse result.
See the chapter "VERSANT Query Language" in the Database Fundamentals Manual for usage notes.
This function does not release the memory of the o_parseresult
struct
itself.
If the parsing of a query result succeeds, o_parsequery()
returns O_OK
and places the parsed result in the output parameter of type o_parseresult
. Since o_parsequery()
allocates memory from the object cache to hold the parse results, you must call o_freequery()
to release the memory when the query result is no longer needed.
If the parsing of a query result fails, o_parsequery()
returns an error number of type o_errno
and places the parse error message and the offset of the token (where the error occurs) in the prs_err
field of the o_parseresult
structure. Since no memory is allocated in the case of a failure, in this case you do not need to call o_freequery()
.
o_err o_parsequery(
char* querystring,
o_parseresult* parseresult,
o_dbname dbname );
Parse a VQL statement string, place the results in an o_parseresult
structure, and return O_OK
if successful.
Following are the elements of o_parsequery()
.
querystring
parseresult
See the "Data Types" chapter for information about the o_parseresult
data type.
dbname
o_parsequery()
returns O_OK
and places the parsed result in the parseresult
output paramter.
If the parsing of any statement in the querystring
parameter fails, o_parsequery()
returns an o_errno
error number, and places the parser error message together with token offset (where the error occured) in the parseresult
parameter. In this case, no parse result of any statement is presented in the parseresult
output parameter, except for the error information.
The input statement can contain one or many VQL statements. After invoking this method, you can iterate through the parse result and use standard C/VERSANT functions to execute each VQL statement found in the input statement.
Usage
A parse result cannot be used across a session boundary.
You must allocate memory for the output parseresult
parameter before invoking this method.
o_freequery()
.
o_parsequery()
is serialized for threads within a process, which means at any given point of time, only one thread within a process can proceed with its o_parsequery()
execution. If there is any other thread of the same process invoking o_parsequery()
at the same time, this thread will wait until the ongoing execution of o_parsequery()
from the other thread completes.
The error messages may be returned by o_parsequery()
:
OM_PSR_ATTR_NOT_FOUND
OM_PSR_ATTR_NOT_FOUND_IN_DOMAIN
OM_PSR_ATTRCLASS_NOT_FOUND
OM_PSR_ATTRS_OUTBOUND
SELECT
, UPDATE
, INSERT
list goes beyond the limit.
OM_PSR_BCD_NOT_SUPPORT
BCD
type input value is not supported yet.
OM_PSR_CLASS_NOT_FOUND
OM_PSR_DOMAIN_NOT_FOUND
OM_PSR_FIND_ATTR_FAIL
OM_PSR_MIXED_TYPE
OM_PSR_NO_VALUE_INSERT
OM_PSR_NOMEM
OM_PSR_NOT_AGG_OF_CHAR
char
is not yet supported.
OM_PSR_NOT_AGG_TO_SCALAR
OM_PSR_NULL_RESULT
parseresult
pointer is passed in.
OM_PSR_NULLQUERY
OM_PSR_OBJCLASS_NOT_FOUND
OM_PSR_PARAMETER_TWICE
OM_PSR_PATHATTRS_OUTBOUND
OM_PSR_SET_PREDICATE_NOT_SUPPORTED
OM_PSR_SYNTAX_ERROR
OM_PSR_TYPE_MISMATCH
OM_PSR_TYPE_OVERFLOW
OM_PSR_UNSUPPORTED_DBTYPE
o_parsequery()
function may also return other VERSANT errors, which are documented in the VERSANT Database Administration Manual.
typedef enum o_cmdtype {
O_QRY_SELECT,
O_QRY_SELOBJ,
O_QRY_INSERT,
O_QRY_DELETE,
O_QRY_DELOBJ,
O_QRY_UPDATE,
O_QRY_UPDOBJ,
O_QRY_ROLLBACK,
O_QRY_COMMIT,
O_QRY_QUIT,
O_QRY_EMPTY
} o_cmdtype;
The statement type as returned to a parse block.
See o_parseblock
for further information.
typedef struct o_param {
o_4b prm_index;
o_predterm* prm_predterm;
} o_param;
Elements are:
prm_index
prm_predterm
o_predterm
predicate where the substitution occurs.
o_parsequery()
fills up an o_param
struct for each parameter, with the pointer in o_param
pointing to the o_predterm
where the parameter substitution should be applied at execution time.
Each parameter of type o_param
is inserted into a Vstr of o_param
parameters based on the value of the parameter index. The final Vstr of parameters pointed to by the prb_paramvstr
in the parse block is sorted based on the parameter index value in o_param
.
Parameter indexes need not be in a consecutive value range. For example, suppose that there are only two parameters, $100
and $3
, in the query. In the result Vstr of parmeters, $3
comes first and $100
sits in the second slot of the Vstr.
Suppose that you have the following query:
SELECT name
FROM Employee
WHERE salary > $4 or salary < $2 ;
In the above case, there will be two entries in prb_paramvstr
field of the parse block that correspond to the two parameters that are to be filled. Within the o_param
structure, there is a pointer prm_predterm
to the o_predterm
where the field key is null, which is where the parameter should be substituted. The index value of the parameter is also placed in the structure.
typedef struct o_parserr {
char prer_errmsg [ PSR_MAXP_ERRMSG ];
int prer_tokenpos;
} o_parserr;
Parser error information.
Elements are:
prer_errmsg
The maximum length of the error message, PSR_MAXP_ERRMSG
, is 256
bytes.
prer_tokenpos
typedef struct o_parseblock {
o_predblock* prb_predicate;
o_clsname prb_classname;
o_cmdtype prb_command;
o_vstr prb_prjvstr;
o_object prb_vstrobj;
o_attrname prb_vstrattr;
o_bool prb_options;
o_vstr* prb_paramvstr;
} o_parseblock;
The parse block for a VQL statement, which hold the parsed results for a VQL statement of a query string.
Elements are:
prb_predicate
prb_classname
prb_command
prb_prjvstr
o_projection
.
prb_vstrobj
If the prb_command
parameter is O_QRY_SELOBJ
, O_QRY_UPDOBJ
, or O_QRY_DELOBJ
, then the SELECT
, UPDATE
, or DELETE
statement specified a loid in the FROM
clause. In this case, the prb_vstrobj field will hold the loid of the input value oidval
.
prb_vstrattr
prb_options
o_pathselect()
.
prb_paramvstr
o_param
.
The prb_command
parameter will contain the type of statement performed as a value of type o_cmdtype
. Possible values are:
O_QRY_SELECT
SELECT
statement over a class or a vstr of objects contained in an attribute.
O_QRY_SELOBJ
SELECT
statement specifying a loid in the FROM
clause:
SELECT attrlist
FROM ( oidval );
In this case, the prb_vstrobj
field will hold the loid of the input value oidval
.
O_QRY_INSERT
INSERT
statement.
O_QRY_DELETE
DELETE
statement.
O_QRY_DELOBJ
DELETE
over an object statement.
O_QRY_UPDATE
UPDATE
statement.
O_QRY_UPDOBJ
UPDATE
over an object statement.
O_QRY_ROLLBACK
ROLLBACK
statement.
O_QRY_COMMIT
COMMIT
statement.
O_QRY_QUIT
SELECT
, UPDATE
or DELETE
statement has occurred, you can pass the following five fields into the o_pathselect()
function to execute the query:
prb_predicate
prb_classname
prb_vstrobj
prb_vstrattr
prb_options
SELOBJ
, UPDOBJ
, or DELOBJ
statement has occurred, the field prb_vstrobj
holds the object value for the input loid.
If a SELECT
, UPDATE
or INSERT
statement has occurred, the field prb_prjvstr
contains a vstr of pointers to structs of type o_projection
which describe which attributes to operate on and what the corresponding operand values are.
If there are parameter substitution values, the field prb_paramvstr
contains a vstr of pointers to parameter values of type o_param
.
typedef struct o_parseresult {
o_dbname prs_dbname;
o_vstr prs_pblkvstr;
o_parserr prs_err;
o_psrmem prs_memused;
} o_parseresult;
Structure to hold the result of parsing a VQL statement.
Elements are:
prs_dbname
prs_pblkvstr
o_parseblock
structs.
Each o_parseblock
holds the parsed result of a statement, if the parsing of all of the statements succeeded.
prs_err
prs_memused
typedef struct o_projection {
o_attrname prj_attrname;
o_setcmd prj_setcmd;
o_bufdesc prj_buf;
} o_projection;
Function parameters whose elements depend on the type of statement parsed.
A parse block will contain a prb_prjvstr
parameter, which is a vstr of pointers to structs of type o_projection
.
Elements are:
prj_attrname
prj_setcmd
prj_buf
o_projection
struct is filled depends on the value of the prb_command
parameter of the returned parse block. The prb_command
parameter is of type o_cmdtype
.
Following are possible values of the prb_command
parameter and the resulting values that will be placed in the o_projection
struct.
O_QRY_SELECT
prb_command
parameter contains O_QRY_SELECT
, only the prj_attrname
field of the o_projection
struct is filled. The remaining two field in the structure are meaningless and are zeroed out.
O_QRY_INSERT
prb_command
parameter contains O_QRY_INSERT
, the prj_attrname
and prj_buf
fields are filled. The prj_setcmd
field is meaningless.
O_QRY_UPDATE, O_QRY_UPDOBJ
prb_command
parameter contains O_QRY_UPDATE
, the prj_attrname
, prj_setcmd
, and prj_buf
fields are filled. The prj_setcmd
indicates what kind of SET
operation is to be applied.
typedef enum o_setcmd {
VQL_ASSIGN,
VQL_APPEND
} o_setcmd;
If the query is an UPDATE
statement, the parameter prj_setcmd
is of type o_setcmd
and indicates type of SET
operation to perform on the attribute.
VQL_ASSIGN
If the attribute is a single value attribute, prj_setcmd
parameter is always VQL_ASSIGN
.
VQL_APPEND
typedef struct o_psrmem {
o_vstr prm_memp;
o_vstr prm_vstrp;
} o_psrmem;
Memory that are allocated to hold the parse result:
Elements are:
prm_memp
prm_vstrp
o_psrmem
struct is an internal structure used only by the o_parsequery()
and o_freequery()
functions.
This online documentation is confidential and proprietary to Versant Corporation and is licensed to you, or to your organization, pursuant to the terms of an agreement between you and Versant that restricts the use of this documentation. Please refer to the agreement for more information or call Versant at 510-789-1500 with any questions.