#51 mORMot 1 » Quick to check if keyfields exist... » 2011-08-25 20:09:48

jonsafi
Replies: 6

Hello,

I have a Table where the key consists of 2 fields. Prior
to adding a new record (am using batch insertion)
I'd like to check that no previous identical key exists.

So am looking for a quick way to test if the given 2 key values
already exist in the table.

I used a multiindex method to setup the index,
but instead of using validate I tried the following,
which does work, although it's a bit slow.

Is there a better way to do this?
Much obliged for any help.


Const QTS= '''';
Var 
 Tbl_Classe:TSQLRecordClass;
 TableEssaie :  TSQLmytbl;
   parenth1,   parenth2,
 where_str :RawUTF8;

  parenth1     := '=:(';   
  parenth2     := '):';
    where_str := G_CRSTBL_INDEXES_Ar[0] + parenth1 +
        QTS       +   TableEssaie.KeyField1 +QTS + parenth2    + ' AND ' +
        G_CRSTBL_INDEXES_Ar[1] +parenth1  +
            QTS +  TableEssaie.KeyField2 + QTS + parenth2;

     
Tbl_Classe :=  model.Table[Tname];
   
If globalClient.MultiFieldValue(Tbl_Classe,
      G_CRSTBL_INDEXES_Ar, Fld_vals,where_str) Then
       Begin
           Showmessage("Key violation!");
      End
     Else
       globalClient.BatchAdd(TableEssaie, true);

#52 mORMot 1 » Slow performance with multiple inserts » 2011-08-23 08:54:20

jonsafi
Replies: 1

Hello,

Am getting a little bit the hang of this great framework
and was trying to add a couple of thousands of rows
to a simple stand alone application.

Seems though, that each row insertion is generating
a disk access and the whole process is quite slow,
at least 25 seconds/1000 rows.

The table has around 15 fields
and was using :

CourseId       := StringToUTF8(Courseid_);
StudentId      := StringToUTF8(StudentId_);
ID                  := globalClient.Add(myrec, true);

Also tried swithing to the synBigTable but with D2009,
compiling the following example code gives an error
for the AddField, saying:

E2010 Incompatible types: 'TSynTableFieldProperties' and 'Boolean'

Var FieldText : TSynTableFieldProperties;
TableBig:TSynBigTableRecord;
BEGIN
  TableBig  := TSynBigTableRecord.Create('DB.big','Mytable');
  FieldText := Table.AddField('text',tftWinAnsi,[tfoIndex]); // error!
   ...
END;

Any ideas? Your help is much appreciated,
thanks, Sami

#53 mORMot 1 » How to add rows to 2 different tables with Identical structures? » 2011-08-06 11:09:08

jonsafi
Replies: 1

Hello,

Assuming the mybaby example in the documentation
was implemented so that Male babies go to a separate table
and Females to their own table.

Since both TSQLBabyMale and TSQLBabyFeMale
have a similar structure, one would like to write
generic code to add a baby to the correct
table depending on its gender.

However, in the call:

 myBaby.add_Baby (myBaby, Name_,Address_,BirthDate_);

the whole instance of the table, myBaby, is sent as a parameter.
Is this the way to do it?
Or am I missing something...

Much obliged for your kind help,
Sami
---
Here's the full simplified code:

TSQLBaby = class(TSQLRecord)
private
fName: RawUTF8;
fAddress: RawUTF8;
fBirthDate: TDateTime;
published
property Name: RawUTF8 read fName write fName;
property Address: RawUTF8 read fAddress write fAddress;
property BirthDate: TDateTime read fBirthDate write fBirthDate;

Procedure add_Baby (Const Name_,Address_:String;Const BirthDate_: TDateTime);
end;

TSQLBabyMale = class(TSQLBaby)
end;

TSQLBabyFeMale = class(TSQLBaby)
end;

Procedure TSQLBaby.add_Baby (Const myBaby:TSQLBaby;
   Const Name_,Address_:String;Const BirthDate_: TDateTime);
BEGIN

  myBaby.Name:       :=  Name_;
  myBaby.Address:   := Address_;

 // now can add record
  globalClient.Add(myBaby, true);
END;

Procedure add_new_baby (Const Gender_, Name_,Address_:String;Const BirthDate_: TDateTime);
Var
myBaby :TSQLBaby ;

BEGIN
If Gender ='Male' Then
  myBaby := TSQLBabyMale
Else
 myBaby := TSQLBabyFeMale;

 myBaby.add_Baby (myBaby, Name_,Address_,BirthDate_);

 FreeAndNil(myBaby);
END;

#54 mORMot 1 » Access violation when running MainDemo with D2009 » 2011-07-26 09:26:10

jonsafi
Replies: 1

Hello,

This Framework looks great! Downloaded latest source,
run the TestProject, only 1 failure in Pdf module which
I figure was minor.

However, when running 'MainDemo' on D2009 (Win XP)
get an access violation  in  unit SQLite3ToolBar, traced to line 2476, where the error occurs on the 2nd pass
of the loop:
---

for aPage := 0 to PagesCount-1 do begin 
    if TP^.CustomHint<>nil then  // error! 

---------------
So the stmt:
if TP^.CustomHint<>nil then 
seems to fail the 2nd time it's executed.

Thanks for any help,
Regards Sami

Board footer

Powered by FluxBB