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