DuroDBMS API  1.7
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_set_str_obj_len (RDB_object *objp, size_t len, RDB_exec_context *ecp)
 
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

◆ RDB_alloc()

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_create_ro_op_version(), RDB_dup_nonscalar_type(), RDB_new_array_type(), RDB_new_relation_type_from_base(), RDB_new_scalar_type(), RDB_new_tuple_type(), RDB_set_array_length(), RDB_set_cleanup(), RDB_set_op_cleanup_fn(), and RDB_tx_db().

◆ RDB_append_char()

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.

References RDB_set_str_obj_len().

◆ RDB_append_string()

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.

References RDB_set_str_obj_len().

◆ RDB_binary_get()

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.

◆ RDB_binary_length()

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.

◆ RDB_binary_resize()

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().

◆ RDB_binary_set()

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.

◆ RDB_bool_to_obj()

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(), and RDB_tuple_set_bool().

◆ RDB_copy_obj()

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_evaluate(), RDB_tuple_set(), and RDB_union_tuples().

◆ RDB_copy_obj_data()

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_destroy_obj(), RDB_dup_nonscalar_type(), RDB_init_obj(), and RDB_new_relation_type().

Referenced by RDB_evaluate().

◆ RDB_destroy_obj()

int RDB_destroy_obj ( RDB_object *  objp,
RDB_exec_context *  ecp 
)

RDB_destroy_obj releases all resources associated with a RDB_object structure. If an error occurred, RDB_ERROR is returned and an error valued is stored in *ecp. On success, RDB_OK is returned and *ecp is not modified.

Returns

RDB_OK on success, RDB_ERROR if an error occurred.

References RDB_del_nonscalar_type(), RDB_free(), and RDB_type_is_scalar().

Referenced by Duro_destroy_interp(), Duro_init_interp(), Duro_print_error_f(), RDB_cardinality(), RDB_clear_err(), RDB_copy_obj_data(), RDB_destroy_exec_context(), RDB_expr_is_table_ref(), RDB_irep_to_obj(), RDB_obj_equals(), RDB_raise_err(), RDB_set_array_length(), RDB_set_op_cleanup_fn(), RDB_table_is_empty(), RDB_tuple_set(), and RDB_wrap_tuple().

◆ RDB_float_to_obj()

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().

◆ RDB_free()

void RDB_free ( void *  p)

◆ RDB_init_builtin()

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.

◆ RDB_init_obj()

void RDB_init_obj ( RDB_object *  valp)

RDB_init_obj initializes the RDB_object structure pointed to by valp. RDB_init_obj must be called before any other operation can be performed on a RDB_object variable.

Referenced by Duro_dt_execute(), Duro_init_interp(), Duro_print_error_f(), RDB_cardinality(), RDB_copy_obj_data(), RDB_extend_tuple(), RDB_extract_tuple(), RDB_irep_to_obj(), RDB_move_tuples(), RDB_obj_equals(), RDB_parse_expr(), RDB_raise_err(), RDB_set_array_length(), RDB_set_op_cleanup_fn(), RDB_table_is_empty(), RDB_tuple_set(), and RDB_wrap_tuple().

◆ RDB_int_to_obj()

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_tuple_set_int().

◆ RDB_multi_assign()

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.

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

◆ RDB_obj_bool()

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_obj_equals(), RDB_obj_set_typeinfo(), and RDB_table_is_empty().

◆ RDB_obj_equals()

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_obj_float()

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_obj_set_typeinfo().

◆ RDB_obj_int()

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_cardinality(), and RDB_obj_set_typeinfo().

◆ RDB_obj_matches_type()

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().

◆ RDB_obj_property()

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 to *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_type_is_scalar().

Referenced by Duro_print_error_f().

◆ RDB_obj_set_property()

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.

◆ RDB_obj_set_typeinfo()

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_obj_bool(), RDB_obj_float(), RDB_obj_int(), RDB_obj_string(), RDB_string_n_to_obj(), RDB_string_to_obj(), and RDB_type_is_scalar().

Referenced by RDB_set_init_value().

◆ RDB_obj_string()

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_obj_set_typeinfo(), and RDB_operator_source().

◆ RDB_obj_type()

RDB_type* RDB_obj_type ( const RDB_object *  objp)

RDB_obj_type returns a pointer to the type of *objp.

Returns

A pointer to the type of the RDB_object.

Referenced by Duro_print_error_f(), RDB_call_update_op_by_name(), RDB_expr_type(), RDB_extract_tuple(), RDB_get_update_op(), RDB_get_update_op_by_args(), RDB_move_tuples(), and RDB_table_attrs().

◆ RDB_realloc()

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(), and RDB_set_array_length().

◆ RDB_set_init_value()

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_del_nonscalar_type(), RDB_dup_nonscalar_type(), RDB_init_table_from_type(), RDB_obj_set_typeinfo(), 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().

◆ RDB_set_str_obj_len()

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

Converts *objp to a string of size len.

Referenced by RDB_append_char(), RDB_append_string(), RDB_string_n_to_obj(), and RDB_string_to_obj().

◆ RDB_string_n_to_obj()

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.

References RDB_set_str_obj_len().

Referenced by RDB_obj_set_typeinfo().

◆ RDB_string_to_obj()

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.

References RDB_set_str_obj_len().

Referenced by Duro_init_interp(), RDB_expr_attr_qid(), RDB_obj_set_typeinfo(), and RDB_tuple_set_string().

◆ RDB_tm_to_obj()

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.