Recent

Author Topic: In Memory DB and working indexes.  (Read 4652 times)

liewald

  • Full Member
  • ***
  • Posts: 142
In Memory DB and working indexes.
« on: February 28, 2012, 03:08:42 pm »
I feel I'm going round in circles and getting no where. Can anyone come up with a working suggestion. What I want to do is actually very simple. I want to create a simple in memory database that I can index to enable me to do either a quick lookup or a sql select to return one row of data that I can use to complete my task.

Current state of affairs

Tbufdataset and all decendants : Broken  (numerous reports in bug tracking

SQLLite : I'm stuck. Can create database and store data without a problem, Locate is extremely slow and if I try a SQL statement then all data lost as need to activae select sql using "SQL.open" to get returned dataset

I'm out of Ideas!

HELP!

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: In Memory DB and working indexes.
« Reply #1 on: February 28, 2012, 03:29:00 pm »
zmsql.
indexing for sorting are being created automatically. There is SortDataSet method available.
Locate works.
SQL included.

liewald

  • Full Member
  • ***
  • Posts: 142
Re: In Memory DB and working indexes.
« Reply #2 on: February 28, 2012, 03:42:43 pm »
Sorry but it's suffering from the same problems being a decendant

http://bugs.freepascal.org/view.php?id=19631

http://bugs.freepascal.org/view.php?id=20514


denver

  • Jr. Member
  • **
  • Posts: 67
Re: In Memory DB and working indexes.
« Reply #3 on: February 28, 2012, 04:56:14 pm »
I am using kbmMemTable version 5.6 , so far so good.

liewald

  • Full Member
  • ***
  • Posts: 142
Re: In Memory DB and working indexes.
« Reply #4 on: February 28, 2012, 05:01:09 pm »
I'm on linux unfortunately!

I haven't found an installable version. Any Ideas?
« Last Edit: February 28, 2012, 05:05:59 pm by liewald »

denver

  • Jr. Member
  • **
  • Posts: 67
Re: In Memory DB and working indexes.
« Reply #5 on: February 28, 2012, 05:22:17 pm »
It work on both linux and window. I found a bug kbmMemTable.Locate in linux and fixed with the following code :

Code: [Select]

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Dialogs,Menus,
  kbmMemTable, kbmMemBinaryStreamFormat,kbmMemCSVStreamFormat, db,
  StdCtrls, ComCtrls, ExtCtrls, Variants ;

 
  TMyMemTable = class( TkbmMemTable )
     function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; override;
  published
    Constructor Create(AOwner:TComponent); override;
    Destructor Destroy; override;
  private
    function _LocateMemDataSet( FieldNames:String; aValues:String): Boolean;
  public
    BinaryFormat : TkbmBinaryStreamFormat ;
    CSVFormat : TkbmCSVStreamFormat ;
  end;
 
  function dgStrSeg(Str ,SegSymbol: String ; SegIndex: integer): String;
  function dgStrSegCount(Str,SegSymbol: String): integer;

implementation


function dgStrSeg(Str, SegSymbol: String; SegIndex: integer): String;
var
   r,c,s,sTmp : String;
   i:integer;
begin
  r:='';

  if ((Str='') or (SegIndex<1)) then
     begin
       result:=r;
       exit;
     end;

  c:=UTF8ToAnsi(SegSymbol);
  if (c='') then c:=',';

  i:=0;
  s:=UTF8ToAnsi(Str);
  sTmp:='';
  while Pos(c,s)>0 do
        begin
          i:=i+1;
          sTmp := Copy(s,1,Pos(c,s)-1);
          if (SegIndex=i) then
             begin
               r:=AnsiToUTF8(sTmp);
               break;
             end;

          s:=Copy(s , Pos(c,s)+Length(c) , Length(s)-(Pos(c,s)+Length(c))+1);
        end;

  if SegIndex=(i+1) then
     begin
       r:=AnsiToUTF8(s);
     end;

  result:=r;
end;

function dgStrSegCount(Str, SegSymbol: String): integer;
var r,i:integer;
    c,s,sTmp : String;
begin
  r:=0;

  if (Str='') then
     begin
       result:=r;
       exit;
     end;

  c:=UTF8ToAnsi(SegSymbol);
  if (c='') then c:=',';

  i:=0;
  s:=UTF8ToAnsi(Str);
  sTmp:='';
  while Pos(c,s)>0 do
        begin
          i:=i+1;
          sTmp := Copy(s,1,Pos(c,s)-1);
          s:=Copy(s , Pos(c,s)+Length(c) , Length(s)-(Pos(c,s)+Length(c))+1);
        end;

  r:=i+1;

  result:=r;
end;


 
function TMyMemTable.Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean;
begin
 {$IFDEF win32}
  Result := inherited Locate(KeyFields, KeyValues, Options) ;
 {$ELSE}
  Result := _LocateMemDataSet( KeyFields, KeyValues ) ;
{$ENDIF}
end;

constructor TMyMemTable.Create(AOwner: TComponent);
begin
  BinaryFormat := TkbmBinaryStreamFormat.Create( AOwner ) ;
  CSVFormat := TkbmCSVStreamFormat.Create( AOwner ) ;
  inherited Create(AOwner);
  AllDataFormat := BinaryFormat ;
  DefaultFormat := BinaryFormat ;
end;

destructor TMyMemTable.Destroy;
begin
 CSVFormat.Free ;
 BinaryFormat.Free ;
 inherited Destroy;
end;

function TMyMemTable._LocateMemDataSet(FieldNames: String; aValues: String ): Boolean;
var
  field_count:integer;
  i,j:integer;
  is_find:boolean;
begin
  is_find:=false;
  First;
  while not Eof do
  begin
    is_find:=true;
    for i:=1 to dgStrSegCount(FieldNames,';') do
    begin
      if ( FieldByName( dgStrSeg(FieldNames,';',i)).AsString<> dgStrSeg( aValues,';',i)) then is_find:=false;
    end;
    if is_find then break;
    Next;
  end;
  result:=is_find;
end;


and working fine for years ......  :)

99Percent

  • Full Member
  • ***
  • Posts: 160
Re: In Memory DB and working indexes.
« Reply #6 on: March 10, 2012, 11:05:49 pm »
I am using kbmMemTable version 5.6 , so far so good.
Where can I find it for Linux 64?

 

TinyPortal © 2005-2018