📄 fastdbcli.pas
字号:
{-< CLI.H >--------------------------------------------------------*
Main Memory Database Management System
FastDbCLI - Delphi/Kylix FastDB API
Call level interface to FastDB Main Memory DBMS
Serge Aleynikov <serge@hq.idt.net>
Created:
11/11/2002 Serge Aleynikov (serge@hq.idt.net)
Last update:
Version 3.01
6/24/2004 Verified compliance with FastDB 2.88
Added a context parameter to callback functions of
cli_column_set_ex, cli_column_get_ex
Version 2.88
1/08/2004 Verified compliance with FastDB 2.88
Added cli_get_field_size(), cli_get_field_offset()
Version 2.86
12/22/2003 Verified compliance with FastDB 2.86
Added cli_alter_table(), TFastDbSession.AlterTable()
Version 2.74
8/8/2003 Verified compliance with FastDB 2.74
Version 2.72
7/14/2003 Verified compliance with FastDB 2.72
Added functions: cli_prepare_query(),
cli_execute_query(),
cli_insert_struct()
Version 2.69
6/20/2003 Verified compliance with FastDB 2.69
Version 2.68
6/12/2003 Added compliance with FastDB 2.68 and Gigabase 2.90
Version 2.66
6/4/2003 Added compliance with FastDB 2.65
Introduced cli_set_trace_function()
Version 2.65
5/28/2003 Added compliance with FastDB 2.65
Introduced cli_get_database_state
Version 2.61.2:
5/11/2003 Fixed a problem with
TFastDbVar:TFieldBufferItem.GetArrayAsSingle/Double
fetching wrong data from array and occasuonally
causing index out of bounds error.
Also, TFieldBufferItem.FetchData now defaults to True
5/09/2003 Fixed a compilation issue on Linux/Kylix3
It turns out that Kylix3 doesn't like Pointer of Object
declarations.
Fixed an AV when using library with a FastDb DLL of wrong
version.
Version 2.61:
4/20/2003 Added compatibility with FastDB 2.61
3/31/2003 Added compatibility with GigaBase
3/30/2003 Added compatibility with FastDB 2.59
Fixed an AV in case of loading a DLL that's not found in the path.
2/4/2003 Added EFastDbError.Create(Msg: string) constructor
1/22/2003 Added support for cli_attach and cli_detach
1/3/2003 Fixed the Access Violation problem with
cli_set_error_handler
12/24/2002 fixed bug in cli_set_error_handler()
12/20/2002 Added new FastDb 2.56 features.
cli_freeze()
cli_unfreeze()
11/20/2002 Included all new FastDb 2.54 features. Changes:
cli_create_replication_node()
cli_create()
cli_skip()
FastDB Version 2.59 (c) 1999 GARRET
Konstantin Knizhnik <knizhnik@garret.ru>
-------------------------------------------------------------------*}
unit FastDbCLI;
{$I FastDbConfig.inc}
interface
uses
{$IFDEF CLR}Borland.Delphi.SysUtils{$ELSE}SysUtils{$ENDIF},
{$IFDEF CODESITE_DEBUG}
CSIntf,
{$ENDIF}
{$IFDEF MSWINDOWS}
{$IFDEF CLR}Borland.Win32.Windows{$ELSE}Windows{$ENDIF}
{$ENDIF}
{$IFDEF LINUX}
Libc,
Types
{$ENDIF}
;
const
Version = '2.88';
{$IFDEF GIGABASE}
{$IFDEF LINUX}
libname = 'libgigabase_r.so';
{$ENDIF}
{$IFDEF MSWINDOWS}
libname = 'GigaBase.dll';
{$ENDIF}
{$ELSE}
{$IFDEF LINUX}
libname = 'libfastdb_r.so'{'libFastDB.so'};
{$ENDIF}
{$IFDEF MSWINDOWS}
libname = 'FastDB.dll';
{$ENDIF}
{$ENDIF}
FastDbDefaultInitDatabaseSize = 4*1024*1024; // Defaukt initial db size (number of objects)
FastDbDefaultInitIndexSize = 512*1024; // Defaukt initial index size (number of objects)
FastDbDefaultExtensionQuantum = 4*1024*1024; // Quantum of extension of allocated memory
FastDbMaxParallelSearchThreads = 64; // Maximal number of threads which can be spawned to perform parallel sequentila search
FastDbDefaultDatabasePort = 6010;
FastDbDefReconnectTimeoutSec = 120; // Reconnect timeout seconds
//-----------------------------------------
// cli_result_code
//-----------------------------------------
cli_ok = 0;
cli_bad_address = -1;
cli_connection_refused = -2;
cli_database_not_found = -3;
cli_bad_statement = -4;
cli_parameter_not_found = -5;
cli_unbound_parameter = -6;
cli_column_not_found = -7;
cli_incompatible_type = -8;
cli_network_error = -9;
cli_runtime_error = -10;
cli_bad_descriptor = -11;
cli_unsupported_type = -12;
cli_not_found = -13;
cli_not_update_mode = -14;
cli_table_not_found = -15;
cli_not_all_columns_specified = -16;
cli_not_fetched = -17;
cli_already_updated = -18;
cli_table_already_exists = -19;
cli_not_implemented = -20;
{$IFDEF GIGABASE}
cli_login_failed = -21;
cli_empty_parameter = -22; cli_closed_connection = -23; {$ENDIF}
//-----------------------------------------
// cli_error_class
// Note: When calling CliErrorToStr in TCliErrorHandler subtract 100 from the
// code passed as ErrorClassCode in order to get correct description
//-----------------------------------------
cli_query_error = 1 -100;
cli_arithmetic_error = 2 -100;
cli_index_out_of_range_error = 3 -100;
cli_database_open_error = 4 -100;
cli_file_error = 5 -100;
cli_out_of_memory_error = 6 -100;
cli_deadlock = 7 -100;
cli_null_reference_error = 8 -100;
cli_lock_revoked = 9 -100;
cli_file_limit_exeeded = 10 -100;
//-----------------------------------------
// Extended Error Codes
//-----------------------------------------
cli_error_loading_library = -200;
cli_session_not_assigned = -201;
cli_database_already_open = -202;
cli_invalid_field_size = -203;
cli_empty_query = -204;
cli_item_already_defined = -205;
cli_wrong_inverse_reference = -206;
cli_no_fields_defined = -207;
cli_access_violation = -208;
//-----------------------------------------
// Field Types
//-----------------------------------------
cli_oid = 0;
cli_bool = 1;
cli_int1 = 2;
cli_int2 = 3;
cli_int4 = 4;
cli_int8 = 5;
cli_real4 = 6;
cli_real8 = 7;
cli_decimal = 8; { not supported in FastDB }
cli_asciiz = 9; { zero terminated string (Get/Set function can be used) }
cli_pasciiz = 10; { pointer to zero terminated string }
cli_cstring = 11; { not supported in FastDB }
cli_array_of_oid = 12;
cli_array_of_bool = 13;
cli_array_of_int1 = 14;
cli_array_of_int2 = 15;
cli_array_of_int4 = 16;
cli_array_of_int8 = 17;
cli_array_of_real4 = 18;
cli_array_of_real8 = 19;
cli_array_of_decimal = 20; { not supported in FastDB }
cli_array_of_string = 21;
cli_any = 22; { not supported in FastDB }
cli_datetime = 23; { not supported in FastDB }
cli_autoincrement = 24;
cli_rectangle = 25; { not supported in FastDB }
cli_unknown = 26;
function CliErrorToStr(Code: Integer): string; // translate error code to string
function CliCheck(Code: Integer; Msg: string=''): Integer; // raises an exception in case of an error result
{$IFDEF CLI_DEBUG}
type
TTraceDebugProcedure = procedure(Message: string; const BeforeCall: Boolean) of object;
var
TraceDebugProcedure: TTraceDebugProcedure;
{$ENDIF}
type
TStrArray = array of string;
EFastDbError = class(Exception)
public
ErrorCode: Integer;
constructor Create(Code: Integer; Msg: string=''); overload;
constructor Create(Msg: string=''); overload;
end;
size_t = LongWord;
TCliVarType = (
ctOID,
ctBOOL,
ctInt1,
ctInt2,
ctInt4,
ctInt8,
ctReal4,
ctReal8,
ctDecimal, // not supported in FastDB
ctString,
ctPString,
ctCString, // not supported in FastDB
ctArrayOfOID,
ctArrayOfBool,
ctArrayOfInt1,
ctArrayOfInt2,
ctArrayOfInt4,
ctArrayOfInt8,
ctArrayOfReal4,
ctArrayOfReal8,
ctArrayOfDemical, // not supported in FastDB
ctArrayOfString,
ctAny, // not supported in FastDB
ctDateTime,
ctAutoInc,
ctRectangle, // not supported in FastDB
ctUnknown,
//--- Custom types not supported by the database directly -----
ctSubst // Reserved for substitution variables
);
type
cli_bool_t = Char;
cli_int1_t = Char;
cli_int2_t = SmallInt;
cli_int4_t = Integer;
cli_real4_t = Single;
cli_real8_t = Double;
cli_int8_t = INT64;
cli_oid_t = LongInt;
TClibool = cli_bool_t;
TCliInt1 = cli_int1_t;
TCliInt2 = cli_int2_t;
TCliInt4 = cli_int4_t;
TCliReal4 = cli_real4_t;
TCliReal8 = cli_real8_t;
TCliInt8 = cli_int8_t;
TCliOid = cli_oid_t;
PCliOid = ^cli_oid_t;
PCliReal4 = ^cli_real4_t;
PCliReal8 = ^cli_real8_t;
PCliBool = ^cli_bool_t;
PCliInt1 = ^cli_int1_t;
PCliInt2 = ^cli_int2_t;
PCliInt4 = ^cli_int4_t;
PCliInt8 = ^cli_int8_t;
TCliBoolArray = array of TCliBool;
TCliOidArray = array of TCliOid;
TCliInt1Array = array of TCliInt1;
TCliInt2Array = array of TCliInt2;
TCliInt4Array = array of TCliInt4;
TCliInt8Array = array of TCliInt8;
TCliReal4Array = array of TCliReal4;
TCliReal8Array = array of TCliReal8;
var
SizeOfCliType : array[TCliVarType] of Integer = (
sizeof(cli_oid_t),
sizeof(cli_bool_t),
sizeof(cli_int1_t),
sizeof(cli_int2_t),
sizeof(cli_int4_t),
sizeof(cli_int8_t),
sizeof(cli_real4_t),
sizeof(cli_real8_t),
0, // cli_decimal
0, // cli_asciiz,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -