00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _terimber_memdbacc_h_
00029 #define _terimber_memdbacc_h_
00030
00031 #include "db/dbaccess.h"
00032 #include "dbtypes.h"
00033 #include "log.h"
00034
00035 #pragma pack(4)
00038 enum terimber_db_row_status
00039 {
00040 status_lookup = 0,
00041 status_original,
00042 status_new,
00043 status_updated,
00044 status_deleted
00045 };
00046
00049 class terimber_index_column_info
00050 {
00051 public:
00052 size_t _index;
00053 bool _asc_sort;
00054 bool _case_insensitive;
00055 };
00056
00059 class terimber_table_column_desc
00060 {
00061 public:
00062 dbtypes _type;
00063 const char* _name;
00064 size_t _scale;
00065 size_t _precision;
00066 size_t _max_length;
00067 bool _nullable;
00068 };
00069
00071
00072 class terimber_db_value_vector
00073 {
00074 protected:
00076 virtual
00077 ~terimber_db_value_vector()
00078 {
00079 }
00080
00081 public:
00083 virtual
00084 size_t
00085 get_size() const = 0;
00086
00089 virtual
00090 bool
00091 set_value_as_null(size_t index,
00092 dbtypes type
00093 ) = 0;
00095 virtual
00096 bool
00097 set_value_as_bool(size_t index,
00098 bool val
00099 ) = 0;
00101 virtual
00102 bool
00103 set_value_as_char(size_t index,
00104 sb1_t val
00105 ) = 0;
00107 virtual
00108 bool
00109 set_value_as_byte(size_t index,
00110 ub1_t val
00111 ) = 0;
00113 virtual
00114 bool
00115 set_value_as_short(size_t index,
00116 sb2_t val
00117 ) = 0;
00119 virtual
00120 bool
00121 set_value_as_word(size_t index,
00122 ub2_t val
00123 ) = 0;
00125 virtual
00126 bool
00127 set_value_as_long(size_t index,
00128 sb4_t val
00129 ) = 0;
00131 virtual
00132 bool
00133 set_value_as_dword(size_t index,
00134 ub4_t val
00135 ) = 0;
00137 virtual
00138 bool
00139 set_value_as_float(size_t index,
00140 float val
00141 ) = 0;
00143 virtual
00144 bool
00145 set_value_as_double(size_t index,
00146 double val
00147 ) = 0;
00149 virtual
00150 bool
00151 set_value_as_long64(size_t index,
00152 sb8_t val
00153 ) = 0;
00155 virtual
00156 bool
00157 set_value_as_dword64(size_t index,
00158 ub8_t val
00159 ) = 0;
00161 virtual
00162 bool
00163 set_value_as_guid(size_t index,
00164 const guid_t& val
00165 ) = 0;
00166
00167
00168
00169
00170
00171
00173 virtual
00174 bool
00175 set_value_as_numeric(size_t index,
00176 const char* val,
00177 char delimeter
00178 ) = 0;
00180 virtual
00181 bool
00182 set_value_as_decimal(size_t index,
00183 const char* val,
00184 char delimeter
00185 ) = 0;
00186
00187
00188
00189
00190
00191
00192
00193
00194
00196 virtual
00197 bool
00198 set_value_as_date(size_t index,
00199 ub4_t year,
00200 ub1_t month,
00201 ub1_t day,
00202 ub1_t hour,
00203 ub1_t minute,
00204 ub1_t second,
00205 ub2_t millisec
00206 ) = 0;
00207
00210 virtual
00211 bool
00212 set_value_as_string(size_t index,
00213 const char* val,
00214 size_t len
00215 ) = 0;
00216
00222 virtual
00223 bool
00224 set_value_as_string_ptr(size_t index,
00225 const char* val
00226 ) = 0;
00227
00230 virtual
00231 bool
00232 set_value_as_wstring(size_t index,
00233 const wchar_t* val,
00234 size_t len
00235 ) = 0;
00240 virtual
00241 bool
00242 set_value_as_wstring_ptr(size_t index,
00243 const wchar_t* val
00244 ) = 0;
00247 virtual
00248 bool
00249 set_value_as_binary(size_t index,
00250 const ub1_t* val,
00251 size_t len
00252 ) = 0;
00261 virtual
00262 bool
00263 set_value_as_binary_ptr(size_t index,
00264 const ub1_t* val
00265 ) = 0;
00266
00267
00270 virtual
00271 bool
00272 get_value_is_null(size_t index
00273 ) const = 0;
00274
00276 virtual
00277 bool
00278 get_value_as_bool(size_t index
00279 ) const = 0;
00281 virtual
00282 sb1_t
00283 get_value_as_char(size_t index
00284 ) const = 0;
00286 virtual
00287 ub1_t
00288 get_value_as_byte(size_t index
00289 ) const = 0;
00291 virtual
00292 sb2_t
00293 get_value_as_short(size_t index
00294 ) const = 0;
00296 virtual
00297 ub2_t
00298 get_value_as_word(size_t index
00299 ) const = 0;
00301 virtual
00302 sb4_t
00303 get_value_as_long(size_t index
00304 ) const = 0;
00306 virtual
00307 ub4_t
00308 get_value_as_dword(size_t index
00309 ) const = 0;
00311 virtual
00312 float
00313 get_value_as_float(size_t index
00314 ) const = 0;
00316 virtual
00317 double
00318 get_value_as_double(size_t index
00319 ) const = 0;
00321 virtual
00322 sb8_t
00323 get_value_as_long64(size_t index
00324 ) const = 0;
00326 virtual
00327 ub8_t
00328 get_value_as_dword64(size_t index
00329 ) const = 0;
00332 virtual
00333 bool
00334 get_value_as_guid(size_t index,
00335 guid_t& val
00336 ) const = 0;
00337
00339 virtual
00340 const char*
00341 get_value_as_numeric(size_t index,
00342 char delimeter
00343 ) const = 0;
00344
00346 virtual
00347 const char*
00348 get_value_as_decimal(size_t index,
00349 char delimeter
00350 ) const = 0;
00351
00353 virtual
00354 bool
00355 get_value_as_date(size_t index,
00356 ub4_t& year,
00357 ub1_t& month,
00358 ub1_t& day,
00359 ub1_t& hour,
00360 ub1_t& minute,
00361 ub1_t& second,
00362 ub2_t& millisec,
00363 ub1_t& wday,
00364 ub2_t& yday
00365 ) const = 0;
00366
00369 virtual
00370 const char*
00371 get_value_as_string(size_t index
00372 ) const = 0;
00375 virtual
00376 const wchar_t*
00377 get_value_as_wstring(size_t index
00378 ) const = 0;
00379
00383 virtual
00384 const ub1_t*
00385 get_value_as_binary(size_t index,
00386 size_t& len
00387 ) const = 0;
00393 virtual
00394 const ub1_t*
00395 get_value_as_binary_ptr(size_t index
00396 ) const = 0;
00397
00398 };
00399
00400
00401 class terimber_memindex;
00402 class terimber_memlookup;
00403
00406 class terimber_memtable : public terimber_log_helper
00407 {
00408 public:
00411 virtual
00412 ~terimber_memtable()
00413 {
00414 }
00415
00417 virtual
00418 const char*
00419 get_last_error() = 0;
00420
00433
00434 virtual
00435 bool
00436 populate( dbserver* server,
00437 size_t start_row,
00438 size_t max_rows
00439 ) = 0;
00440
00443 virtual
00444 bool
00445 create( size_t columns,
00446 const terimber_table_column_desc desc[]
00447 ) = 0;
00448
00449
00452 virtual
00453 void
00454 refresh() = 0;
00456 virtual
00457 size_t
00458 get_row_count() = 0;
00459
00461
00463 virtual
00464 size_t
00465 get_column_count() const = 0;
00467 virtual
00468 dbtypes
00469 get_column_type(size_t index
00470 ) const = 0;
00472 virtual
00473 const char*
00474 get_column_name(size_t index
00475 ) const = 0;
00477 virtual
00478 bool
00479 get_column_nullable(size_t index
00480 ) const = 0;
00482 virtual
00483 size_t
00484 get_column_scale(size_t index
00485 ) const = 0;
00487 virtual
00488 size_t
00489 get_column_precision(size_t index
00490 ) const = 0;
00492 virtual
00493 size_t
00494 get_column_max_length(size_t index
00495 ) const = 0;
00496
00499
00507 virtual
00508 terimber_memindex*
00509 add_index( size_t columns,
00510 const terimber_index_column_info info[]
00511 ) = 0;
00512
00516 virtual
00517 bool
00518 remove_index( terimber_memindex* obj
00519 ) = 0;
00520
00521
00523 virtual
00524 terimber_db_value_vector*
00525 allocate_db_values(size_t count
00526 ) = 0;
00527
00529 virtual
00530 void
00531 destroy_db_values(terimber_db_value_vector* obj
00532 ) = 0;
00533 };
00534
00537 class terimber_memindex
00538 {
00539 protected:
00542 virtual
00543 ~terimber_memindex()
00544 {
00545 }
00546 public:
00547
00558 virtual
00559 terimber_memlookup*
00560 add_lookup( const terimber_db_value_vector* info
00561 ) = 0;
00562
00564 virtual
00565 bool
00566 remove_lookup( terimber_memlookup* obj
00567 ) = 0;
00568 };
00569
00572 class terimber_memlookup
00573 {
00574 protected:
00577 virtual
00578 ~terimber_memlookup()
00579 {
00580 }
00581 public:
00582
00585 virtual
00586 bool
00587 assign( const terimber_memlookup& x
00588 ) = 0;
00589
00591
00594 virtual
00595 bool
00596 reset( const terimber_db_value_vector* info
00597 ) = 0;
00598
00601 virtual
00602 bool
00603 next() const = 0;
00604
00607 virtual
00608 bool
00609 prev() const = 0;
00610
00619
00621 virtual
00622 bool
00623 get_value_is_null(size_t index
00624 ) const = 0;
00626 virtual
00627 bool
00628 get_value_as_bool(size_t index
00629 ) const = 0;
00631 virtual
00632 sb1_t
00633 get_value_as_char(size_t index
00634 ) const = 0;
00636 virtual
00637 ub1_t
00638 get_value_as_byte(size_t index
00639 ) const = 0;
00641 virtual
00642 sb2_t
00643 get_value_as_short(size_t index
00644 ) const = 0;
00646 virtual
00647 ub2_t
00648 get_value_as_word(size_t index
00649 ) const = 0;
00651 virtual
00652 sb4_t
00653 get_value_as_long(size_t index
00654 ) const = 0;
00656 virtual
00657 ub4_t
00658 get_value_as_dword(size_t index
00659 ) const = 0;
00661 virtual
00662 float
00663 get_value_as_float(size_t index
00664 ) const = 0;
00666 virtual
00667 double
00668 get_value_as_double(size_t index
00669 ) const = 0;
00671 virtual
00672 sb8_t
00673 get_value_as_long64(size_t index
00674 ) const = 0;
00676 virtual
00677 ub8_t
00678 get_value_as_dword64(size_t index
00679 ) const = 0;
00680
00683 virtual
00684 bool
00685 get_value_as_guid(size_t index,
00686 guid_t& val
00687 ) const = 0;
00690 virtual
00691 const char*
00692 get_value_as_numeric(size_t index,
00693 char delimeter
00694 ) const = 0;
00697 virtual
00698 const char*
00699 get_value_as_decimal(size_t index,
00700 char delimeter
00701 ) const = 0;
00704 virtual
00705 bool
00706 get_value_as_date(size_t index,
00707 ub4_t& year,
00708 ub1_t& month,
00709 ub1_t& day,
00710 ub1_t& hour,
00711 ub1_t& minute,
00712 ub1_t& second,
00713 ub2_t& millisec,
00714 ub1_t& wday,
00715 ub2_t& yday
00716 ) const = 0;
00719 virtual
00720 const char*
00721 get_value_as_string(size_t index
00722 ) const = 0;
00725 virtual
00726 const wchar_t*
00727 get_value_as_wstring(size_t index
00728 ) const = 0;
00729
00733 virtual
00734 const ub1_t*
00735 get_value_as_binary(size_t index,
00736 size_t& len
00737 ) const = 0;
00743 virtual
00744 const ub1_t*
00745 get_value_as_binary_ptr(size_t index
00746 ) const = 0;
00747
00748
00755
00760 virtual
00761 bool
00762 insert_row( const terimber_db_value_vector* info
00763 ) = 0;
00764
00765
00769 virtual
00770 bool
00771 delete_row() = 0;
00772
00776 virtual
00777 bool
00778 update_row( const terimber_db_value_vector* info
00779 ) = 0;
00780
00786
00791 virtual
00792 terimber_db_row_status
00793 get_row_status() = 0;
00794 };
00795
00797
00798
00799 class terimber_memtable_factory
00800 {
00801 public:
00804 terimber_memtable*
00805 get_memtable();
00806 };
00807
00808 #pragma pack()
00809
00810 #endif // _terimber_memdbacc_h_
00811