NIL codb_close(<oDB>) oDB codb_connect() oRes codb_execute(<oDB>,<sQuery>,[<sDatabase>],[<aFiles>]) '' | 'ERROR' codb_get_answer(<oRes>) sName codb_get_column(<oRes>, <nIndex>) sError | NIL codb_get_error(<oRes>) oMetaobject codb_get_metaobject(<oDB>,<sID>,[<sDatabase>]) oObject codb_get_object(<oDB>,<sID>,[<sDatabase>]) aResult codb_get_result(<oRes>) nColumns codb_num_columns(<oRes>) nRows codb_num_rows(<oRes>) oResult codb_put_metaobject(<oDB>,<oContent>,[<sDatabase>],<sClass>) oResult codb_put_object(<oDB>,<oContent>,[<sDatabase>],<sClass>)
codb-query library provides unified access to CODB databases by queries instead call of methods of classes CODBDEPOSITORY, CODBDICTIONARY, CODBLIST and CODBIDLIST.
Queries are written on CQL language (SQL dialect adapted for CODB). You can use this library in own CLIP program or use console program called codb.
Using In Programs.
For use codb-query library in programs you should build program with this library. Just append '-lcodb-query' to build command.
Typical session of work with database contains following steps:
db := codb_connect() // Connect to databases e := codb_get_error( db ) // Check error if e != NIL ?? "ERROR codb_connect(): " + e + chr(10) return 1 endif // Query execution oRes := codb_execute( db, 'show databases' ) // Process result aResult := codb_get_result( oRes ) codb_close( db ) // Close databases
Connect to databases is provided by function codb_connect(). This function opens all available databases. Function codb_close() closes all databases.
Real operations with databases are provided by functions: codb_execute(), codb_get_metaobject(), codb_get_object(), codb_put_metaobject(), codb_put_object().
The difference between these functions is codb_execute() returns object, from which you can extract data by function codb_get_result(), but other functions operate only real objects.
For error check use codb_get_answer() and codb_get_error().
Query result returned from codb_execute(), you can processed by codb_get_result(), codb_num_columns(), codb_num_rows() and codb_get_column().
Besides you can get result as formatted string. Just pass result object in CODBFormatter() method show.
Using codb.
codb [options] [database[:depository]]
On start codb without any parameters it will be work in interactive mode.
codb options:
-c 'command' - Execute query and exit.
--hide-titles - Suppress column names.
--delim='DELIM' - Set columns delimiter.
Complete list of options is available on run codb -h.
Examples:
codb ETC01 -c 'show classes;'Show all classes in database ETC01.
codb ETC01:ETC0101 -c 'select * from mng_vendor,mng_author;' --delim='|'Show all fields from all objects of classes mng_vendor and mng_author from database ETC01 and depository ETC0101 with delimiter '|'.
Note: All data outputs in formatted mode so fields are accompanied with spaces to maximum width of element in each column.
CQL Commands.
Each CODB command should be ended by semicolon. You can write comments begin with '#' character and end with line end ('\n'). String are delimited by single quote ('). If single quote is part of string it should be escaped by backslash (\').
You can pass several commands in -c parameter and through pipe:
echo 'show classes;show indexes;' | codb ETC01
Brief CQL Commands Description.
help - Help about database commands;
create - Create metaobject;
delete - Delete object or metaobject;
describe - Show class structure;
drop - Delete metaobject by its name;
get - Get object from depository;
metaget - Get metaobject;
metaput - Create or update metaobject;
put - Create or update object in depository;
select - Query object attributes;
show - Show list of metaobjects;
use - Open database.
There is command quit - quits the program in interactive mode. You can quit from codb to press Esc key.
Verbose CQL Command Description.
help [<command>] Help on command. If 'help' call without command name show all available commands.
create <metaclass> (<attr1>=<value1>[,...]) or create database <db_name> <path>[<description>] Create database or metaobject. Examples: create database EAS01 /var/lib/db 'E/AS Database'; create attribute (name='phone',type='C',len=20);
Supported metaclasses:
depository - depository;
extent - namespace;
attribute - attribute;
counter - counter;
index - index;
class - class;
tcolumn - view column;
tview - view;
report - report;
plugin - plugin;
user - user;
group - group of users.
delete <id> Delete object or metaobject by its id.
describe <class_name> Show class structure by its name.
drop <metaclass> <metaobject_name> Delete metaobject by its name.
Supported metaclasses:
depository - depository;
extent - namespace;
attribute - attribute;
counter - counter;
index - index;
class - class;
tcolumn - view column;
tview - view;
report - report;
plugin - plugin;
user - user;
group - group of users.
get <id> Get object content from depository by its id.
metaget <id> Get metaobject content from dictionary by its id.
metaput (<attr1>=<value1>[, ...]) Create or change metaobject in dictionary. If 'id' is defined in attributes list, exist object will be replaced by new values.
put (<attr1>=<value1>[, ...]) Create or change metaobject in depository. If 'id' is defined in attributes list, exist object will be replaced by new values.
select <attributes> from <class> [where <condition>] Get list of attribute values matched condition.
<attributes> - list of attribute names delimited by comma. Names with spaces put in single quotes. You can use * for all attribute names for all specified classes.
<class> - list of class names delimited by comma. Names with spaces put in single quotes.
<condition> - condition by CLIP rules. There are supported operators: '==', '!=', '>', '>=', '<=', '<' and logical operators '.not.', '.and.', '.or.'. Value should be put in double quotes and there are no spaces between operators.
Example:
select id,author_name,email from mng_author where code=="Uri";
show <metaclass> Show metaobject list.
Supported metaclasses:
databases - databases;
depositories - depositories;
extents - namespaces;
attributes - attributes;
counters - counters;
indexes - indices;
classes - classes;
tcolumns - view columns;
tviews - views;
reports - reports;
plugins - plugins;
users - users;
groups - user groups;
statistics - total statistics with number metaobjects in each metaclass.
use <db> [<depository>] Change current work database and depository.
codb_close(<oDB>) --> NIL
<oDB> | - Object. Database connection object returned from codb_connect(). |
Returns : | NIL |
codb_execute(<oDB>,<sQuery>,[<sDatabase>],[<aFiles>]) --> oRes
<oDB> | - Object. Database connection object returned from codb_connect(). |
<sQuery> | - String. Query on CQL (dialect of SQL adapted for CODB). |
<sDatabase> | - String. Name of work dictionary:depository (eg. ETC01:ETC0101). Optional parameter. |
<aFiles> | - Array. Array of files attached to this query. Each element is array: { <fileName>, <content> }. Optional parameter. |
Returns : | codb_execute() returns result as object. Real data shoult be retrieved by codb_get_result(). |
codb_get_answer(<oRes>) --> '' | 'ERROR'
<oRes> | - Object. Object returned by codb_execute() function. |
Returns : | Returns empty string if query executed successful or 'ERROR' if error is ocurred. |
codb_get_column(<oRes>, <nIndex>) --> sName
<oRes> | - Object. Object returned by codb_execute() function. |
<nIndex> | - Number. Column number from 1. |
Returns : | Returns column name from result or NIL if column number does not exist. |
codb_get_error(<oRes>) --> sError | NIL
<oRes> | - Object. Object returned by codb_execute() function. |
Returns : | Returns NIL if query executed successful or error description if error is ocurred. |
codb_get_metaobject(<oDB>,<sID>,[<sDatabase>]) --> oMetaobject
<oDB> | - Object. Database connection object returned from codb_connect(). |
<sID> | - String. ID of metaobject. |
<sDatabase> | - String. Name of work dictionary:depository (eg. ETC01:ETC0101). Optional parameter. |
Returns : | Returns metaobject content. |
codb_get_object(<oDB>,<sID>,[<sDatabase>]) --> oObject
<oDB> | - Object. Database connection object returned from codb_connect(). |
<sID> | - String. ID of object. |
<sDatabase> | - String. Name of work dictionary:depository (eg. ETC01:ETC0101). Optional parameter. |
Returns : | Returns object content. |
codb_get_result(<oRes>) --> aResult
<oRes> | - Object. Object returned by codb_execute() function. |
Returns : | Returns query result as array. |
codb_num_columns(<oRes>) --> nColumns
<oRes> | - Object. Object returned by codb_execute() function. |
Returns : | Number of columns in query result. |
codb_num_rows(<oRes>) --> nRows
<oRes> | - Object. Object returned by codb_execute() function. |
Returns : | Number of rows in query result. |
codb_put_metaobject(<oDB>,<oContent>,[<sDatabase>],<sClass>) --> oResult
<oDB> | - Object. Database connection object returned from codb_connect(). |
<oConent> | - Object. Metaobject content. |
<sDatabase> | - String. Name of work dictionary:depository (eg. ETC01:ETC0101). Optional parameter. |
<sClass> | - String. Class name. |
Returns : | Result object. |
codb_put_object(<oDB>,<oContent>,[<sDatabase>],<sClass>) --> oResult
<oDB> | - Object. Database connection object returned from codb_connect(). |
<oConent> | - Object. ïbject content. |
<sDatabase> | - String. Name of work dictionary:depository (eg. ETC01:ETC0101). Optional parameter. |
<sClass> | - String. Class name. |
Returns : | Result object. |
See also : | CODBFORMATTER |