00001 /*-< CLI.H >---------------------------------------------------------*--------* 00002 * FastDB Version 1.0 (c) 1999 GARRET * ? * 00003 * (Main Memory Database Management System) * /\| * 00004 * * / \ * 00005 * Created: 13-Jan-2000 K.A. Knizhnik * / [] \ * 00006 * Last update: 13-Jan-2000 K.A. Knizhnik * GARRET * 00007 *-------------------------------------------------------------------*--------* 00008 * Call level interface to FastDB server 00009 *-------------------------------------------------------------------*--------*/ 00010 00011 #ifndef __CLI_H__ 00012 #define __CLI_H__ 00013 00014 #include <stdlib.h> 00015 00016 #ifndef FASTDB_DLL_ENTRY 00017 #ifdef FASTDB_DLL 00018 #ifdef INSIDE_FASTDB 00019 #define FASTDB_DLL_ENTRY __declspec(dllexport) 00020 #else 00021 #define FASTDB_DLL_ENTRY __declspec(dllimport) 00022 #endif 00023 #else 00024 #define FASTDB_DLL_ENTRY 00025 #endif 00026 #endif 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00032 enum cli_result_code { 00033 cli_ok = 0, 00034 cli_bad_address = -1, 00035 cli_connection_refused = -2, 00036 cli_database_not_found = -3, 00037 cli_bad_statement = -4, 00038 cli_parameter_not_found = -5, 00039 cli_unbound_parameter = -6, 00040 cli_column_not_found = -7, 00041 cli_incompatible_type = -8, 00042 cli_network_error = -9, 00043 cli_runtime_error = -10, 00044 cli_bad_descriptor = -11, 00045 cli_unsupported_type = -12, 00046 cli_not_found = -13, 00047 cli_not_update_mode = -14, 00048 cli_table_not_found = -15, 00049 cli_not_all_columns_specified = -16, 00050 cli_not_fetched = -17, 00051 cli_already_updated = -18, 00052 cli_table_already_exists = -19, 00053 cli_not_implemented = -20 00054 }; 00055 00056 enum cli_var_type { 00057 cli_oid, 00058 cli_bool, 00059 cli_int1, 00060 cli_int2, 00061 cli_int4, 00062 cli_int8, 00063 cli_real4, 00064 cli_real8, 00065 cli_decimal, /* not supported */ 00066 cli_asciiz, /* zero terminated string */ 00067 cli_pasciiz, /* pointer to zero terminated string */ 00068 cli_cstring, /* not supported */ 00069 cli_array_of_oid, 00070 cli_array_of_bool, 00071 cli_array_of_int1, 00072 cli_array_of_int2, 00073 cli_array_of_int4, 00074 cli_array_of_int8, 00075 cli_array_of_real4, 00076 cli_array_of_real8, 00077 cli_array_of_decimal, 00078 cli_array_of_string, 00079 cli_any, /* not supported */ 00080 cli_datetime, /* not supported */ 00081 cli_autoincrement, 00082 cli_rectangle,/* not supported */ 00083 cli_unknown 00084 }; 00085 00086 typedef char cli_bool_t; 00087 typedef signed char cli_int1_t; 00088 typedef signed short cli_int2_t; 00089 typedef signed int cli_int4_t; 00090 typedef float cli_real4_t; 00091 typedef double cli_real8_t; 00092 00093 #if (defined(_WIN32) || defined(__BORLANDC__)) && !defined(__MINGW32__) 00094 typedef __int64 cli_int8_t; 00095 #else 00096 #if defined(__osf__ ) 00097 typedef signed long cli_int8_t; 00098 #else 00099 #if defined(__GNUC__) || defined(__SUNPRO_CC) 00100 typedef signed long long cli_int8_t; 00101 #else 00102 #error "integer 8 byte type is not defined" 00103 #endif 00104 #endif 00105 #endif 00106 00107 #ifndef CLI_OID_DEFINED 00108 typedef long cli_oid_t; 00109 #endif 00110 00111 // structure used to represent array field in structure extracted by cli_execute_query 00112 typedef struct cli_array_t { 00113 size_t size; // number of elements in the array 00114 void* data; // pointer to the array elements 00115 size_t allocated; // internal field: size of allocated buffer 00116 } cli_array_t; 00117 00118 /********************************************************************* 00119 * cli_open 00120 * Establish connection with the server 00121 * Parameters: 00122 * server_url - zero terminated string with server address and port, 00123 * for example "localhost:5101", "195.239.208.240:6100",... 00124 * max_connect_attempts - number of attempts to establish connection 00125 * reconnect_timeout_sec - timeput in seconds between connection attempts 00126 * Returns: 00127 * >= 0 - connectiondescriptor to be used in all other cli calls 00128 * < 0 - error code as described in cli_result_code enum 00129 */ 00130 int FASTDB_DLL_ENTRY cli_open(char const* server_url, 00131 int max_connect_attempts, 00132 int reconnect_timeout_sec); 00133 00134 enum cli_open_attributes { 00135 cli_open_default = 0x0, 00136 cli_open_readonly = 0x1, 00137 cli_open_truncate = 0x2, 00138 cli_open_concurrent = 0x4 00139 }; 00140 /********************************************************************* 00141 * cli_create 00142 * Create connection to the local database 00143 * Parameters: 00144 * databaseName - name of the database 00145 * fileName - path to the database file 00146 * transactionCommitDelay - trasnaction commit delay (specify 0 to disable) 00147 * openAttr - mask of cli_open_attributes 00148 * initDatabaseSize - initial size of the database 00149 * extensionQuantum - database extension quantum 00150 * initIndexSize - initial size of object index 00151 * fileSizeLimit - limit for file size (0 - unlimited) 00152 * Returns: 00153 * >= 0 - connection descriptor to be used in all other cli calls 00154 * < 0 - error code as described in cli_result_code enum 00155 */ 00156 00157 int FASTDB_DLL_ENTRY cli_create(char const* databaseName, 00158 char const* filePath, 00159 unsigned transactionCommitDelay, 00160 int openAttr, 00161 size_t initDatabaseSize, 00162 size_t extensionQuantum, 00163 size_t initIndexSize, 00164 size_t fileSizeLimit); 00165 00166 /********************************************************************* 00167 * cli_create_replication_node 00168 * Create connection to the local database with support of replication 00169 * Parameters: 00170 * nodeId - node identifier: 0 <= nodeId < nServers 00171 * nServers - number of replication nodes (primary + standby) 00172 * nodeNames - array with URLs of the nodes (address:port) 00173 * databaseName - name of the database 00174 * fileName - path to the database file 00175 * transactionCommitDelay - trasnaction commit delay (specify 0 to disable) 00176 * openAttr - mask of cli_open_attributes (to allow concurrent read access to replication node, 00177 * cli_open_concurrent attribute should be set) 00178 * initDatabaseSize - initial size of the database 00179 * extensionQuantum - database extension quantum 00180 * initIndexSize - initial size of object index 00181 * fileSizeLimit - limit for file size (0 - unlimited) 00182 * Returns: 00183 * >= 0 - connection descriptor to be used in all other cli calls 00184 * < 0 - error code as described in cli_result_code enum 00185 */ 00186 00187 int FASTDB_DLL_ENTRY cli_create_replication_node(int nodeId, 00188 int nServers, 00189 char* nodeNames[], 00190 char const* databaseName, 00191 char const* filePath, 00192 int openAttr, 00193 size_t initDatabaseSize, 00194 size_t extensionQuantum, 00195 size_t initIndexSize, 00196 size_t fileSizeLimit); 00197 00198 /********************************************************************* 00199 * cli_close 00200 * Close session 00201 * Parameters: 00202 * session - session descriptor returned by cli_open 00203 * Returns: 00204 * result code as described in cli_result_code enum 00205 */ 00206 int FASTDB_DLL_ENTRY cli_close(int session); 00207 00208 /********************************************************************* 00209 * cli_statement 00210 * Specify SubSQL statement to be executed at server 00211 * Binding to the parameters and columns can be established 00212 * Parameters: 00213 * session - session descriptor returned by cli_open 00214 * stmt - zero terminated string with SubSQL statement 00215 * Returns: 00216 * >= 0 - statement descriptor 00217 * < 0 - error code as described in cli_result_code enum 00218 */ 00219 int FASTDB_DLL_ENTRY cli_statement(int session, char const* stmt); 00220 00221 /********************************************************************* 00222 * cli_parameter 00223 * Bind parameter to the statement 00224 * Parameters: 00225 * statement - statememt descriptor returned by cli_statement 00226 * param_name - zero terminated string with parameter name 00227 * Paramter name should start with '%' 00228 * var_type - type of variable as described in cli_var_type enum. 00229 * Only scalar and zero terminated string types are supported. 00230 * var_ptr - pointer to the variable 00231 * Returns: 00232 * result code as described in cli_result_code enum 00233 */ 00234 int FASTDB_DLL_ENTRY cli_parameter(int statement, 00235 char const* param_name, 00236 int var_type, 00237 void* var_ptr); 00238 00239 /********************************************************************* 00240 * cli_column 00241 * Bind extracted column of select or insert statement 00242 * Parameters: 00243 * statement - statememt descriptor returned by cli_statement 00244 * column_name - zero terminated string with column name 00245 * var_type - type of variable as described in cli_var_type enum 00246 * var_len - pointer to the variable to hold length of array variable. 00247 * This variable should be assigned the maximal length 00248 * of the array/string buffer, pointed by var_ptr. 00249 * After the execution of the statement it is assigned the 00250 * real length of the fetched array/string. If it is large 00251 * than length of the buffer, then only part of the array 00252 * will be placed in the buffer, but var_len still will 00253 * contain the actual array length. 00254 * var_ptr - pointer to the variable 00255 * Returns: 00256 * result code as described in cli_result_code enum 00257 */ 00258 int FASTDB_DLL_ENTRY cli_column(int statement, 00259 char const* column_name, 00260 int var_type, 00261 int* var_len, 00262 void* var_ptr); 00263 00264 00265 typedef void* (*cli_column_set)(int var_type, void* var_ptr, int len); 00266 typedef void* (*cli_column_get)(int var_type, void* var_ptr, int* len); 00267 00268 typedef void* (*cli_column_set_ex)(int var_type, void* var_ptr, int len, 00269 char const* column_name, int statement, void const* data_ptr); 00270 typedef void* (*cli_column_get_ex)(int var_type, void* var_ptr, int* len, 00271 char const* column_name, int statemen); 00272 00273 /********************************************************************* 00274 * cli_array_column 00275 * Specify get/set functions for the array column 00276 * Parameters: 00277 * statement - statememt descriptor returned by cli_statement 00278 * column_name - zero terminated string with column name 00279 * var_type - type of variable as described in cli_var_type enum 00280 * var_ptr - pointer to the variable 00281 * set - function which will be called to construct fetched 00282 * field. It receives pointer to the variable, 00283 * length of the fetched array and returns pointer to th 00284 * array's elements 00285 * get - function which will be called to update the field in the 00286 * database. Given pointer to the variable, it should return 00287 * pointer to the array elements and store length of the 00288 * array to the variable pointer by len parameter 00289 * Returns: 00290 * result code as described in cli_result_code enum 00291 */ 00292 int FASTDB_DLL_ENTRY cli_array_column(int statement, 00293 char const* column_name, 00294 int var_type, 00295 void* var_ptr, 00296 cli_column_set set, 00297 cli_column_get get); 00298 00299 int FASTDB_DLL_ENTRY cli_array_column_ex(int statement, 00300 char const* column_name, 00301 int var_type, 00302 void* var_ptr, 00303 cli_column_set_ex set, 00304 cli_column_get_ex get); 00305 00306 enum { 00307 cli_view_only, 00308 cli_for_update 00309 }; 00310 00311 /********************************************************************* 00312 * cli_fetch 00313 * Execute select statement. 00314 * Parameters: 00315 * statement - statememt descriptor returned by cli_statement 00316 * for_update - not zero if fetched rows will be updated 00317 * Returns: 00318 * >= 0 - success, for select statements number of fetched rows is returned 00319 * < 0 - error code as described in cli_result_code enum 00320 */ 00321 int FASTDB_DLL_ENTRY cli_fetch(int statement, int for_update); 00322 00323 /********************************************************************* 00324 * cli_insert 00325 * Execute insert statement. 00326 * Parameters: 00327 * statement - statememt descriptor returned by cli_statement 00328 * oid - object identifier of created record. 00329 * Returns: 00330 * status code as described in cli_result_code enum 00331 */ 00332 int FASTDB_DLL_ENTRY cli_insert(int statement, cli_oid_t* oid); 00333 00334 /********************************************************************* 00335 * cli_get_first 00336 * Get first row of the selection. 00337 * Parameters: 00338 * statement - statememt descriptor returned by cli_statement 00339 * Returns: 00340 * result code as described in cli_result_code enum 00341 */ 00342 int FASTDB_DLL_ENTRY cli_get_first(int statement); 00343 00344 /********************************************************************* 00345 * cli_get_last 00346 * Get last row of the selection. 00347 * Parameters: 00348 * statement - statememt descriptor returned by cli_statement 00349 * Returns: 00350 * result code as described in cli_result_code enum 00351 */ 00352 int FASTDB_DLL_ENTRY cli_get_last(int statement); 00353 00354 /********************************************************************* 00355 * cli_get_next 00356 * Get next row of the selection. If get_next records is called 00357 * exactly after cli_fetch function call, is will fetch the first record 00358 * in selection. 00359 * Parameters: 00360 * statement - statememt descriptor returned by cli_statement 00361 * Returns: 00362 * result code as described in cli_result_code enum 00363 */ 00364 int FASTDB_DLL_ENTRY cli_get_next(int statement); 00365 00366 /********************************************************************* 00367 * cli_get_prev 00368 * Get previous row of the selection. If get_next records is called 00369 * exactly after cli_fetch function call, is will fetch the last record 00370 * in selection. 00371 * Parameters: 00372 * statement - statememt descriptor returned by cli_statement 00373 * Returns: 00374 * result code as described in cli_result_code enum 00375 */ 00376 int FASTDB_DLL_ENTRY cli_get_prev(int statement); 00377 00378 /********************************************************************* 00379 * cli_skip 00380 * Skip specified number of rows. 00381 * Parameters: 00382 * statement - statememt descriptor returned by cli_statement 00383 * n - number of objects to be skipped 00384 * - if "n" is positive, then this function has the same effect as 00385 * executing cli_get_next() function "n" times. 00386 * - if "n" is negative, then this function has the same effect as 00387 * executing cli_get_prev() function "-n" times. 00388 * - if "n" is zero, this method just reloads current record 00389 * Returns: 00390 * result code as described in cli_result_code enum 00391 */ 00392 int FASTDB_DLL_ENTRY cli_skip(int statement, int n); 00393 00394 /********************************************************************* 00395 * cli_seek 00396 * Position cursor to the record with specified OID 00397 * Parameters: 00398 * statement - statememt descriptor returned by cli_statement 00399 * oid - object identifier of the record to which cursor should be positioned 00400 * Returns: 00401 * >= 0 - success, position of the record in the selection 00402 * < 0 - error code as described in cli_result_code enum 00403 */ 00404 int FASTDB_DLL_ENTRY cli_seek(int statement, cli_oid_t oid); 00405 00406 00407 /********************************************************************* 00408 * cli_get_oid 00409 * Get object identifier of the current record 00410 * Parameters: 00411 * statement - statememt descriptor returned by cli_statement 00412 * Returns: 00413 * object identifier or 0 if no object is seleected 00414 */ 00415 cli_oid_t FASTDB_DLL_ENTRY cli_get_oid(int statement); 00416 00417 /********************************************************************* 00418 * cli_update 00419 * Update the current row in the selection. You have to set 00420 * for_update parameter of cli_fetch to 1 in order to be able 00421 * to perform updates. Updated value of row fields will be taken 00422 * from bound column variables. 00423 * Parameters: 00424 * statement - statememt descriptor returned by cli_statement 00425 * Returns: 00426 * result code as described in cli_result_code enum 00427 */ 00428 int FASTDB_DLL_ENTRY cli_update(int statement); 00429 00430 /********************************************************************* 00431 * cli_remove 00432 * Remove all selected records. You have to set 00433 * for_update parameter of cli_fetch to 1 in order to be able 00434 * to remove records. 00435 * Parameters: 00436 * statement - statememt descriptor returned by cli_statement 00437 * Returns: 00438 * result code as described in cli_result_code enum 00439 */ 00440 int FASTDB_DLL_ENTRY cli_remove(int statement); 00441 00442 /********************************************************************* 00443 * cli_free 00444 * Deallocate statement and all associated data 00445 * Parameters: 00446 * statement - statememt descriptor returned by cli_statement 00447 * Returns: 00448 * result code as described in cli_result_code enum 00449 */ 00450 int FASTDB_DLL_ENTRY cli_free(int statement); 00451 00452 /********************************************************************* 00453 * cli_commit 00454 * Commit current database transaction 00455 * Parameters: 00456 * session - session descriptor as returned by cli_open 00457 * Returns: 00458 * result code as described in cli_result_code enum 00459 */ 00460 int FASTDB_DLL_ENTRY cli_commit(int session); 00461 00462 /********************************************************************* 00463 * cli_precommit 00464 * Release all locks set by transaction. This methods allows other clients 00465 * to proceed, but it doesn't flush transaction to the disk. 00466 * Parameters: 00467 * session - session descriptor as returned by cli_open 00468 * Returns: 00469 * result code as described in cli_result_code enum 00470 */ 00471 int FASTDB_DLL_ENTRY cli_precommit(int session); 00472 00473 /********************************************************************* 00474 * cli_abort 00475 * Abort current database transaction 00476 * Parameters: 00477 * session - session descriptor as returned by cli_open 00478 * Returns: 00479 * result code as described in cli_result_code enum 00480 */ 00481 int FASTDB_DLL_ENTRY cli_abort(int session); 00482 00483 00484 enum cli_field_flags { 00485 cli_hashed = 1, /* field should be indexed usnig hash table */ 00486 cli_indexed = 2 /* field should be indexed using B-Tree */ 00487 }; 00488 00489 typedef struct cli_field_descriptor { 00490 enum cli_var_type type; 00491 int flags; 00492 char const* name; 00493 char const* refTableName; 00494 char const* inverseRefFieldName; 00495 } cli_field_descriptor; 00496 00497 /********************************************************************* 00498 * cli_describe 00499 * Describe fileds of specified table 00500 * Parameters: 00501 * session - session descriptor as returned by cli_open 00502 * table - name of the table 00503 * fields - address of the pointer to the array of fields descriptors, 00504 * this array should be later deallocated by application by cli_free_memory() 00505 * Returns: 00506 * >= 0 - number of fields in the table 00507 * < 0 - result code as described in cli_result_code enum 00508 */ 00509 int FASTDB_DLL_ENTRY cli_describe(int session, char const* table, cli_field_descriptor** fields); 00510 00511 00512 /********************************************************************* 00513 * cli_get_field_size 00514 * Calculate field size 00515 * Parameters: 00516 * fields - array with fields descriptors obtained using cli_describe function 00517 * field_no - number of the field 00518 */ 00519 int FASTDB_DLL_ENTRY cli_get_field_size(cli_field_descriptor* fields, int field_no); 00520 00521 /********************************************************************* 00522 * cli_get_field_offset 00523 * Calculate offset of the field 00524 * Parameters: 00525 * fields - array with fields descriptors obtained using cli_describe function 00526 * field_no - number of the field 00527 */ 00528 int FASTDB_DLL_ENTRY cli_get_field_offset(cli_field_descriptor* fields, int field_no); 00529 00530 00531 typedef struct cli_table_descriptor { 00532 char const* name; 00533 } cli_table_descriptor; 00534 00535 /********************************************************************* 00536 * cli_show_tables 00537 * Show all tables of specified database 00538 * Parameters: 00539 * session - session descriptor as returned by cli_open 00540 * tables - address of the pointer to the array of tables descriptors, 00541 * this array should be later deallocated by application by cli_free_memory() 00542 * Returns: 00543 * >= 0 - number of tables in the database (Metatable is not returned/counted) 00544 * < 0 - result code as described in cli_result_code enum 00545 */ 00546 int FASTDB_DLL_ENTRY cli_show_tables(int session, cli_table_descriptor** tables); 00547 00548 00549 /********************************************************************* 00550 * cli_create_table 00551 * Create new table 00552 * Parameters: 00553 * session - session descriptor as returned by cli_open 00554 * tableName - name of new table 00555 * nFields - number of columns in the table 00556 * fields - array with table columns descriptors 00557 * Returns: 00558 * result code as described in cli_result_code enum 00559 */ 00560 int FASTDB_DLL_ENTRY cli_create_table(int session, char const* tableName, int nFields, 00561 cli_field_descriptor* fields); 00562 00563 /********************************************************************* 00564 * cli_alter_table 00565 * Change table format 00566 * Parameters: 00567 * session - session descriptor as returned by cli_open 00568 * tableName - name of existing table 00569 * nFields - number of columns in the table 00570 * fields - array with new table columns descriptors 00571 * Returns: 00572 * result code as described in cli_result_code enum 00573 */ 00574 int FASTDB_DLL_ENTRY cli_alter_table(int session, char const* tableName, int nFields, 00575 cli_field_descriptor* fields); 00576 00577 /********************************************************************* 00578 * cli_drop_table 00579 * drop the table 00580 * Parameters: 00581 * session - session descriptor as returned by cli_open 00582 * tableName - name of deleted table 00583 * Returns: 00584 * result code as described in cli_result_code enum 00585 */ 00586 int FASTDB_DLL_ENTRY cli_drop_table(int session, char const* tableName); 00587 00588 00589 /********************************************************************* 00590 * cli_alter_index 00591 * add or remove column index 00592 * Parameters: 00593 * session - session descriptor as returned by cli_open 00594 * tableName - name of the table 00595 * fieldName - name of field 00596 * newFlags - new flags of the field, if index exists for this field, but is not specified in 00597 * <code>newFlags</code> mask, then it will be removed; if index not exists, but is 00598 * specified in <code>newFlags</code> mask, then it will be created. * 00599 * Returns: 00600 * result code as described in cli_result_code enum 00601 */ 00602 int FASTDB_DLL_ENTRY cli_alter_index(int session, char const* tableName, char const* fieldName, 00603 int newFlags); 00604 00605 00606 /********************************************************************* 00607 * cli_set_error_handler 00608 * Set FastDB erro handler. Handler should be no-return function which perform stack unwind. 00609 * Parameters: 00610 * session - session descriptor as returned by cli_open 00611 * handler - error handler 00612 * Returns: 00613 * previous handler 00614 */ 00615 enum cli_error_class { 00616 cli_no_error, 00617 cli_query_error, 00618 cli_arithmetic_error, 00619 cli_index_out_of_range_error, 00620 cli_database_open_error, 00621 cli_file_error, 00622 cli_out_of_memory_error, 00623 cli_deadlock, 00624 cli_null_reference_error, 00625 cli_lock_revoked, 00626 cli_file_limit_exeeded 00627 }; 00628 typedef void (*cli_error_handler)(int error, char const* msg, int msgarg); 00629 cli_error_handler FASTDB_DLL_ENTRY cli_set_error_handler(int session, cli_error_handler new_handler); 00630 00631 /********************************************************************* 00632 * cli_freeze 00633 * Freeze cursor. Make it possible to reused cursor after commit of the current transaction. 00634 * Parameters: 00635 * statement - statememt descriptor returned by cli_statement 00636 * Returns: 00637 * result code as described in cli_result_code enum 00638 */ 00639 int FASTDB_DLL_ENTRY cli_freeze(int statement); 00640 00641 /********************************************************************* 00642 * cli_unfreeze 00643 * Unfreeze cursor. Reuse previously frozen cursor. 00644 * Parameters: 00645 * statement - statememt descriptor returned by cli_statement 00646 * Returns: 00647 * result code as described in cli_result_code enum 00648 */ 00649 int FASTDB_DLL_ENTRY cli_unfreeze(int statement); 00650 00651 00652 /********************************************************************* 00653 * cli_attach 00654 * Attach thread to the database. Each thread except one opened the database should first 00655 * attach to the database before any access to the database, and detach after end of the work with database 00656 * Parameters: 00657 * session - session descriptor returned by cli_open 00658 * Returns: 00659 * result code as described in cli_result_code enum 00660 */ 00661 int FASTDB_DLL_ENTRY cli_attach(int session); 00662 00663 /********************************************************************* 00664 * cli_detach 00665 * Detach thread from the database. Each thread except one opened the database should perform 00666 * attach to the database before any access to the database, and detach after end of the work with database 00667 * Parameters: 00668 * session - session descriptor returned by cli_open 00669 * detach_mode - bit mask representing detach mode 00670 * Returns: 00671 * result code as described in cli_result_code enum 00672 */ 00673 enum cli_detach_mode { 00674 cli_commit_on_detach = 1, 00675 cli_destroy_context_on_detach = 2 00676 }; 00677 00678 int FASTDB_DLL_ENTRY cli_detach(int session, int detach_mode); 00679 00680 00681 /********************************************************************* 00682 * cli_free_memory 00683 * Free memory allocated by cli_show_tables and cli_describe 00684 * Parameters: 00685 * session - session descriptor returned by cli_open 00686 * ptr - pointer to the allocated buffer 00687 */ 00688 void FASTDB_DLL_ENTRY cli_free_memory(int session, void* ptr); 00689 00690 00691 typedef struct cli_database_monitor { 00692 int n_readers; 00693 int n_writers; 00694 int n_blocked_readers; 00695 int n_blocked_writers; 00696 int n_users; 00697 } cli_database_monitor; 00698 00699 /********************************************************************* 00700 * cli_get_database_state 00701 * Obtain information about current state of the database 00702 * Parameters: 00703 * session - session descriptor returned by cli_open 00704 * monitor - pointer to the monitor structure. The folloing fields are set: 00705 * n_readers: number of granted shared locks 00706 * n_writers: number of granted exclusive locks 00707 * n_blocked_reader: number of threads which shared lock request was blocked 00708 * n_blocked_writers: number of threads which exclusive lock request was blocked 00709 * n_users: number of processes openned the database 00710 * Returns: 00711 * result code as described in cli_result_code enum 00712 */ 00713 int FASTDB_DLL_ENTRY cli_get_database_state(int session, cli_database_monitor* monitor); 00714 00715 00716 00717 /********************************************************************* 00718 * cli_set_trace_function 00719 * Set trace function which will be used to output FastDB trace messages 00720 * Parameters: 00721 * func - pointer to trace function which receives trace message terminated with new line character 00722 */ 00723 typedef void (*cli_trace_function_t)(char* msg); 00724 void FASTDB_DLL_ENTRY cli_set_trace_function(cli_trace_function_t func); 00725 00726 00727 /********************************************************************* 00728 * cli_prepare_query 00729 * Prepare SubSQL query statement. 00730 * Parameters: 00731 * session - session descriptor returned by cli_open 00732 * query - query string with optional parameters. Parameters are specified 00733 * as '%T' where T is one or two character code of parameter type using the same notation 00734 * as in printf: %d or %i - int, %f - float or double, %ld - int8, %s - string, %p - oid... 00735 * Returns: 00736 * >= 0 - statement descriptor 00737 * < 0 - error code as described in cli_result_code enum 00738 */ 00739 int FASTDB_DLL_ENTRY cli_prepare_query(int session, char const* query); 00740 00753 int FASTDB_DLL_ENTRY cli_execute_query(int statement, int for_update, void* record_struct, ...); 00754 00766 int FASTDB_DLL_ENTRY cli_insert_struct(int session, char const* table_name, void* record_struct, cli_oid_t* oid); 00767 00768 #ifdef __cplusplus 00769 } 00770 #endif 00771 00772 #endif 00773 00774