DuroDBMS API  1.2
Data Structures | Enumerations | Functions
Scalar and generic functions

Data Structures

struct  RDB_ma_insert
 
struct  RDB_attr_update
 
struct  RDB_ma_update
 
struct  RDB_ma_delete
 
struct  RDB_ma_vdelete
 
struct  RDB_ma_copy
 

Enumerations

enum  { RDB_DISTINCT = 1, RDB_INCLUDED = 2 }
 

Functions

void * RDB_alloc (size_t size, RDB_exec_context *ecp)
 
void * RDB_realloc (void *p, size_t size, RDB_exec_context *ecp)
 
void RDB_free (void *p)
 
RDB_object * RDB_new_obj (RDB_exec_context *ecp)
 
int RDB_free_obj (RDB_object *objp, RDB_exec_context *ecp)
 
void RDB_init_obj (RDB_object *valp)
 
int RDB_destroy_obj (RDB_object *objp, RDB_exec_context *ecp)
 
void RDB_bool_to_obj (RDB_object *valp, RDB_bool v)
 
void RDB_int_to_obj (RDB_object *valp, RDB_int v)
 
void RDB_float_to_obj (RDB_object *valp, RDB_float v)
 
void RDB_tm_to_obj (RDB_object *objp, const struct tm *tm)
 
int RDB_string_to_obj (RDB_object *valp, const char *str, RDB_exec_context *ecp)
 
int RDB_string_n_to_obj (RDB_object *valp, const char *str, size_t n, RDB_exec_context *ecp)
 
int RDB_append_string (RDB_object *objp, const char *str, RDB_exec_context *ecp)
 
int RDB_append_char (RDB_object *objp, char ch, RDB_exec_context *ecp)
 
RDB_bool RDB_obj_bool (const RDB_object *valp)
 
RDB_int RDB_obj_int (const RDB_object *valp)
 
RDB_float RDB_obj_float (const RDB_object *valp)
 
char * RDB_obj_string (const RDB_object *valp)
 
int RDB_binary_set (RDB_object *valp, size_t pos, const void *srcp, size_t len, RDB_exec_context *ecp)
 
int RDB_binary_get (const RDB_object *objp, size_t pos, size_t len, RDB_exec_context *ecp, void **pp, size_t *alenp)
 
size_t RDB_binary_length (const RDB_object *objp)
 
int RDB_binary_resize (RDB_object *objp, size_t len, RDB_exec_context *ecp)
 
RDB_typeRDB_obj_type (const RDB_object *objp)
 
void RDB_obj_set_typeinfo (RDB_object *objp, RDB_type *typ)
 
RDB_bool RDB_obj_matches_type (const RDB_object *objp, const RDB_type *typ)
 
RDB_int RDB_multi_assign (int insc, const RDB_ma_insert insv[], int updc, const RDB_ma_update updv[], int delc, const RDB_ma_delete delv[], int vdelc, const RDB_ma_vdelete vdelv[], int copyc, const RDB_ma_copy copyv[], RDB_getobjfn *getfn, void *getarg, RDB_exec_context *ecp, RDB_transaction *txp)
 
int RDB_copy_obj (RDB_object *dstvalp, const RDB_object *srcvalp, RDB_exec_context *ecp)
 
int RDB_init_builtin (RDB_exec_context *ecp)
 
int RDB_obj_equals (const RDB_object *val1p, const RDB_object *val2p, RDB_exec_context *ecp, RDB_transaction *txp, RDB_bool *resp)
 
int RDB_obj_property (const RDB_object *objp, const char *propname, RDB_object *propvalp, RDB_environment *envp, RDB_exec_context *ecp, RDB_transaction *txp)
 
int RDB_obj_set_property (RDB_object *objp, const char *propname, const RDB_object *propvalp, RDB_environment *envp, RDB_exec_context *ecp, RDB_transaction *txp)
 
int RDB_set_init_value (RDB_object *objp, RDB_type *typ, RDB_environment *envp, RDB_exec_context *ecp)
 
int RDB_copy_obj_data (RDB_object *dstvalp, const RDB_object *srcvalp, RDB_exec_context *ecp, RDB_transaction *txp)
 

Detailed Description

Function Documentation

void* RDB_alloc ( size_t  size,
RDB_exec_context *  ecp 
)

Allocates size bytes of memory.

If allocation fails, NULL is returned and an error valued is stored in *ecp.

Returns
A pointer to the memory allocated, or NULL if the allocation failed.

References RDB_raise_no_memory().

Referenced by Duro_init_interp(), RDB_binary_set(), RDB_copy_obj_data(), RDB_create_constraint(), RDB_create_ro_op_version(), RDB_create_table_index(), RDB_dup_nonscalar_type(), RDB_irep_to_obj(), RDB_new_array_type(), RDB_new_relation_type_from_base(), RDB_new_scalar_type(), RDB_new_tuple_type(), RDB_obj_property(), RDB_obj_set_property(), and RDB_set_array_length().

int RDB_append_char ( RDB_object *  objp,
char  ch,
RDB_exec_context *  ecp 
)

Appends the 1-byte character ch to *objp.

objp must be of type string.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

Errors:

The call may fail for a system error.

int RDB_append_string ( RDB_object *  objp,
const char *  str,
RDB_exec_context *  ecp 
)

Appends the string str to *objp.

objp must be of type string.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

Errors:

The call may fail for a system error.

Referenced by RDB_create_table_from_type(), and RDB_expr_attr_qid().

int RDB_binary_get ( const RDB_object *  objp,
size_t  pos,
size_t  len,
RDB_exec_context *  ecp,
void **  pp,
size_t *  alenp 
)

RDB_binary_get obtains a pointer to len bytes starting at position pos of the RDB_object pointed to by objp and stores this pointer at the location pointed to by pp. If the sum of pos and len exceeds the length of the object, the length of the byte block will be lower than requested.

If alenp is not NULL, the actual length of the byte block is stored at the location pointed to by alenp.

valp must point to a RDB_object of type BINARY.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

Errors:

The call may fail for a system error.

References RDB_raise_invalid_argument().

size_t RDB_binary_length ( const RDB_object *  objp)

RDB_binary_length returns the number of bytes stored in the RDB_object pointed to by objp. The RDB_object must be of type BINARY.

Returns

The length of the RDB_object.

int RDB_binary_resize ( RDB_object *  objp,
size_t  len,
RDB_exec_context *  ecp 
)

RDB_binary_resize sets the returns the number of bytes stored in the RDB_object pointed to by objp to len. If len is greater than the original length, the value of the bytes added is undefined.

Returns

The length of the RDB_object.

References RDB_free(), and RDB_realloc().

int RDB_binary_set ( RDB_object *  valp,
size_t  pos,
const void *  srcp,
size_t  len,
RDB_exec_context *  ecp 
)

RDB_binary_set copies len bytes from srcp to the position pos in the RDB_object pointed to by valp. valp must point either to a new initialized RDB_object or to a RDB_object of type BINARY.

If an error occurs, an error value is left in *ecp.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

Errors:

The call may fail for a system error.

References RDB_alloc(), RDB_raise_invalid_argument(), and RDB_realloc().

Referenced by RDB_define_subtype().

void RDB_bool_to_obj ( RDB_object *  valp,
RDB_bool  v 
)

RDB_bool_to_obj sets the RDB_object pointed to by valp to the boolean value specified by v.

The RDB_object must either be newly initialized or of type boolean.

Referenced by Duro_dt_execute(), Duro_init_interp(), RDB_call_ro_op_by_name_e(), and RDB_tuple_set_bool().

int RDB_copy_obj ( RDB_object *  dstvalp,
const RDB_object *  srcvalp,
RDB_exec_context *  ecp 
)

RDB_copy_obj copies the value of the RDB_object pointed to by srcvalp to the RDB_object pointed to by dstvalp.

The source RDB_object must either be newly initialized or of the same type as the destination.

If both the source and the target are a table, the tuples are copied from the source to the target. In this case, both tables must be local, because otherwise a transaction would be required. RDB_copy_table() or RDB_multi_assign() can be used to copy global tables.

Currently, RDB_copy_obj is not supported for targets which hold a virtual table.

If an error occurs, an error value is left in *ecp.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

Errors:
rdb_type_mismatch_error
*dstvalp is not newly initialized and its type does not match the type of the RDB_object specified by srcvalp.

The call may also fail for a system error.

References RDB_multi_assign().

Referenced by RDB_array_set(), RDB_call_ro_op_by_name_e(), RDB_evaluate(), RDB_obj_property(), RDB_obj_to_expr(), RDB_tuple_set(), and RDB_union_tuples().

int RDB_copy_obj_data ( RDB_object *  dstvalp,
const RDB_object *  srcvalp,
RDB_exec_context *  ecp,
RDB_transaction *  txp 
)

Copy RDB_object, but not the type information, except for tables. If the RDB_object wraps a table, it must be a real table. No type checking takes place.

References RDB_alloc(), RDB_destroy_obj(), RDB_dup_nonscalar_type(), RDB_free(), RDB_init_obj(), RDB_move_tuples(), RDB_new_relation_type(), RDB_raise_type_mismatch(), RDB_realloc(), and RDB_table_is_persistent().

Referenced by RDB_evaluate(), RDB_obj_property(), RDB_obj_set_property(), and RDB_set_init_value().

int RDB_destroy_obj ( RDB_object *  objp,
RDB_exec_context *  ecp 
)
void RDB_float_to_obj ( RDB_object *  valp,
RDB_float  v 
)

RDB_float_to_obj sets the RDB_object pointed to by valp to the RDB_float value specified by v.

The RDB_object must either be newly initialized or of type float.

Referenced by RDB_tuple_set_float().

void RDB_free ( void *  p)
int RDB_init_builtin ( RDB_exec_context *  ecp)

Initialize built-in types and operators. May be called more than once.

It is called by RDB_create_db_from_env() and RDB_get_db_from_env(). If neither of these functions have been called, RDB_init_builtin() must be called to make built-in types and operators available.

void RDB_init_obj ( RDB_object *  valp)
void RDB_int_to_obj ( RDB_object *  valp,
RDB_int  v 
)

RDB_int_to_obj sets the RDB_object pointed to by valp to the integer value specified by v.

The RDB_object must either be newly initialized or of type integer.

Referenced by RDB_call_ro_op_by_name_e(), and RDB_tuple_set_int().

RDB_int RDB_multi_assign ( int  insc,
const RDB_ma_insert  insv[],
int  updc,
const RDB_ma_update  updv[],
int  delc,
const RDB_ma_delete  delv[],
int  vdelc,
const RDB_ma_vdelete  vdelv[],
int  copyc,
const RDB_ma_copy  copyv[],
RDB_getobjfn *  getfn,
void *  getarg,
RDB_exec_context *  ecp,
RDB_transaction *  txp 
)

Performs a number of insert, update, delete, and copy operations in a single call.

For each of the RDB_ma_insert elements given by insc and insv, the tuple or relation *insv[i]->objp is inserted into *insv[i]->tbp. If *insv[i].flags is zero, inserting a tuple which is already an element of the table succeeds. If *insv[i].flags is RDB_DISTINCT, such an insert will result in an element_exists_error.

For each of the RDB_ma_update elements given by updc and updv, the attributes given by updv[i]->updc and updv[i]->updv of the tuples of *updv[i]->tbp for which *updv[i]->condp evaluates to RDB_TRUE are updated.

For each of the RDB_ma_delete elements given by delc and delv, the tuples for which *delv[i]->condp evaluates to RDB_TRUE are deleted from *delv[i]->tbp.

For each of the RDB_ma_vdelete elements given by vdelc and vdelv, the tuples given by *insv[i]->objp (may be a tuple or a table) are deleted from *vdelv[i]->tbp. If *vdelv[i].flags is zero, deleting a tuple which is not already an element of the table succeeds. If *insv[i].flags is RDB_DISTINCT, such a delete will result in an not_found_error.

For each of the RDB_ma_copy elements given by copyc and copyv, copyv[i]->scrp is copied to *copyv[i]->dstp.

If getfn is not NULL, the function it points to will be called to resolve variable names in expressions passed using the updv and delv arguments.

A RDB_multi_assign call is atomic with respect to constraint checking; a constraint violation error can only occur if the result of all operations violates a constraint.

A table may not appear twice as a target in the arguments to RDB_multi_assign(), and it may not appear as a source if it appears as a target in a previous assignment.

This means that an assignment like the following:

UPDATE S WHERE S# = S#('S2') STATUS := 15, UPDATE S WHERE S# = S#('S3') STATUS := 25;

(taken from TTM, chapter 6) cannot be performed directly. It can, however, be converted to an equivalent form like the following:

UPDATE S WHERE (S# = S#('S2')) OR (S# = S#('S3')) STATUS := IF (S# = S#('S2')) THEN 15 ELSE 25;

The restrictions of RDB_insert(), RDB_update(), RDB_delete(), and RDB_copy_obj() regarding virtual target tables apply to RDB_multi_assign, too.

txp must point to a running transaction if a persistent table is involved.

Returns

On success, the number of tuples inserted, deleted, and updated as specified by the arguments insc, insv, updc, updv, delc, delv, vdelc and vdelv, plus objc. If an error occurred, (RDB_int) RDB_ERROR is returned.

Errors:
no_running_tx_error
txp must point to a running transaction (see above) but does not.
invalid_argument_error
A table appears twice as a target.
A table does not exist. (e.g. after a rollback)
not_supported_error
A table is both source and target. A virtual table appears as a target in copyv.
predicate_violation_error
A constraint has been violated.
not_found_error
A tuple given by *vdelv[i]->objp was not found.

The errors that can be raised by RDB_insert(), RDB_update(), RDB_delete() and RDB_copy_obj() can also be raised.

References RDB_begin_tx(), RDB_commit(), RDB_free(), RDB_raise_no_running_tx(), RDB_rollback(), RDB_tx_db(), and RDB_tx_is_running().

Referenced by RDB_copy_obj(), RDB_copy_table(), RDB_delete(), RDB_insert(), and RDB_update().

RDB_bool RDB_obj_bool ( const RDB_object *  valp)

RDB_obj_bool returns the value of the RDB_object pointed to by valp as a RDB_bool. The RDB_object must be of type BOOLEAN.

Returns

The value of the RDB_object.

Referenced by RDB_all(), RDB_any(), RDB_obj_equals(), and RDB_table_is_empty().

int RDB_obj_equals ( const RDB_object *  val1p,
const RDB_object *  val2p,
RDB_exec_context *  ecp,
RDB_transaction *  txp,
RDB_bool *  resp 
)

Check two RDB_object variables for equality and store the result in the variable pointed to by resp.

If an error occurs, an error value is left in *ecp.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

References RDB_call_ro_op_by_name(), RDB_destroy_obj(), RDB_init_obj(), and RDB_obj_bool().

Referenced by RDB_expr_equals().

RDB_float RDB_obj_float ( const RDB_object *  valp)

RDB_obj_float returns the value of the RDB_object pointed to by valp as a RDB_float. The RDB_object must be of type FLOAT.

Returns

The value of the RDB_object.

Referenced by RDB_avg(), RDB_max(), RDB_min(), and RDB_sum().

RDB_int RDB_obj_int ( const RDB_object *  valp)

RDB_obj_int returns the value of the RDB_object pointed to by valp as a RDB_int. The RDB_object must be of type INTEGER.

Returns

The value of the RDB_object.

Referenced by RDB_avg(), RDB_cardinality(), RDB_max(), RDB_min(), and RDB_sum().

RDB_bool RDB_obj_matches_type ( const RDB_object *  objp,
const RDB_type typ 
)

Determines if the DST of *objp matches *typ. *typ may be a generic tuple type. In this case, *objp must carry type information. *objp may not carry type information if it is an array or tuple. In this case, *typ must not be generic.

References RDB_tuple_get(), and RDB_tuple_size().

Referenced by RDB_table_contains().

int RDB_obj_property ( const RDB_object *  objp,
const char *  propname,
RDB_object *  propvalp,
RDB_environment *  envp,
RDB_exec_context *  ecp,
RDB_transaction *  txp 
)

Copy the value of property propname of *objp *propvalp.

There must be type information associated with *objp.

If txp is NULL and envp is not, envp is used to look up the getter operator from memory. If txp is not NULL, envp is ignored.

*propvalp will carry type information. If the property type is non-scalar and not a relation type, it is managed by the type of *objp.

If an error occurs, an error value is left in *ecp.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

Errors:
invalid_argument_error
The type of *valp does not have any properties.
name_error
The property propname could not be found.
operator_not_found_error
The getter method for property propname has not been created.

RDB_obj_property may also raise an error raised by a user-provided getter function.

The call may also fail for a system error.

References RDB_alloc(), RDB_call_ro_op_by_name_e(), RDB_copy_obj(), RDB_copy_obj_data(), RDB_del_nonscalar_type(), RDB_dup_nonscalar_type(), RDB_free(), RDB_raise_invalid_argument(), RDB_raise_name(), RDB_raise_type_mismatch(), RDB_tuple_get(), RDB_type_equals(), RDB_type_is_relation(), and RDB_type_is_scalar().

Referenced by Duro_print_error_f(), and RDB_drop_table_index().

int RDB_obj_set_property ( RDB_object *  objp,
const char *  propname,
const RDB_object *  propvalp,
RDB_environment *  envp,
RDB_exec_context *  ecp,
RDB_transaction *  txp 
)

Set the the value of property propname of the RDB_object specified to by objp to the value of *propvalp.

The RDB_object must be of a type which has a property propname.

If txp is NULL and envp is not, envp is used to look up the getter operator from memory. If txp is not NULL, envp is ignored.

If an error occurs, an error value is left in *ecp.

If the call fails with a type_constraint_violation_error, the value of *dst may be replaced by the init value of the type of *dst.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

References RDB_alloc(), RDB_call_update_op(), RDB_copy_obj_data(), RDB_free(), RDB_get_update_op(), RDB_obj_type(), RDB_raise_internal(), RDB_raise_invalid_argument(), RDB_raise_name(), RDB_raise_type_mismatch(), RDB_tuple_set(), RDB_type_equals(), and RDB_attr::typ.

void RDB_obj_set_typeinfo ( RDB_object *  objp,
RDB_type typ 
)

Set the type information for *objp to *typ. This can be used only for tuples and arrays, which, unlike scalars and tables, do not to carry explicit type information by default. The caller must manage the type; it is not automatically destroyed when *objp is destroyed (except if *objp is embedded in an expression, in which case the expression takes responsibility for destroying the type).

If *typ is a dummy type and the existing type is not a dummy type, the existing type becomes the implemented type.

References RDB_type_is_scalar().

Referenced by RDB_set_init_value().

char* RDB_obj_string ( const RDB_object *  valp)

RDB_obj_string returns a pointer to the value of the RDB_object pointed to by valp as a char *. The RDB_object must be of type string.

Returns

The string value of the RDB_object.

Referenced by Duro_dt_prompt(), Duro_print_error_f(), RDB_create_table_from_type(), RDB_drop_table_index(), RDB_drop_type(), RDB_drop_typeimpl_ops(), RDB_operator_source(), RDB_parse_expr(), and RDB_set_table_name().

RDB_type* RDB_obj_type ( const RDB_object *  objp)
void* RDB_realloc ( void *  p,
size_t  size,
RDB_exec_context *  ecp 
)

Changes the sie of the memory block pointed to by p by size bytes.

If the operation fails, NULL is returned and an error valued is stored in *ecp.

Returns
A pointer to the allocated memory.

References RDB_raise_no_memory().

Referenced by RDB_binary_resize(), RDB_binary_set(), RDB_copy_obj_data(), RDB_create_table_index(), RDB_drop_table_index(), and RDB_set_array_length().

int RDB_set_init_value ( RDB_object *  objp,
RDB_type typ,
RDB_environment *  envp,
RDB_exec_context *  ecp 
)

Set *objp to the initial value of type *typ.

A user-defined type may have no INIT value if it has only one possrep. In this case, the selector is called, and txp or, if txp is NULL, envp is used to look up the selector.

References RDB_copy_obj_data(), RDB_del_nonscalar_type(), RDB_dup_nonscalar_type(), RDB_init_table_from_type(), RDB_obj_set_typeinfo(), RDB_raise_internal(), RDB_raise_invalid_argument(), RDB_set_array_length(), RDB_set_init_value(), RDB_tuple_get(), RDB_tuple_set(), and RDB_type_is_relation().

Referenced by RDB_set_init_value().

int RDB_string_n_to_obj ( RDB_object *  valp,
const char *  str,
size_t  n,
RDB_exec_context *  ecp 
)

Sets *valp to the string that begins at str limited to a length of n bytes. valp must either be newly initialized or of type string.

int RDB_string_to_obj ( RDB_object *  valp,
const char *  str,
RDB_exec_context *  ecp 
)

RDB_string_to_obj sets the RDB_object pointed to by valp to the string value specified by str.

The RDB_object must either be newly initialized or of type string.

Referenced by Duro_init_interp(), RDB_create_table_from_type(), RDB_expr_attr_qid(), RDB_parse_expr(), and RDB_tuple_set_string().

void RDB_tm_to_obj ( RDB_object *  objp,
const struct tm *  tm 
)

Sets the RDB_object *objp to the datetime value specified by the argument tm. *objp must either be newly initialized or of type datetime.