Recent

Author Topic: I need help with msAccess database  (Read 5841 times)

magleft

  • Full Member
  • ***
  • Posts: 111
I need help with msAccess database
« on: September 15, 2014, 11:01:00 am »
Hi. In my application, my databases  must be update from msAccess.
I try to do this with ODBC connection but is very slow.
Is any other way to do this?

Thanks
 
windows 10 64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: I need help with msAccess database
« Reply #1 on: September 15, 2014, 11:03:45 am »
Are you sure it is the ODBC connection that is causing the slowness and not your code?
Is your code fast with other databases?

Perhaps you could fiddle with generating ADO bindings using the Lazarus ActiveX tools; IIRC there are some threads on the forum here.
Haven't tried that.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

magleft

  • Full Member
  • ***
  • Posts: 111
Re: I need help with msAccess database
« Reply #2 on: September 15, 2014, 11:14:56 am »
When tried with part (100 - 200) of records all is ok. if tried to work with all records (about 55000 records), my program need very long time to read the database.
 
windows 10 64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: I need help with msAccess database
« Reply #3 on: September 15, 2014, 11:34:20 am »
Thank you but I don't thank that answers my questions?

Why don't you post the relevant code (please format it using [ code ] tags (remove the spaces after [ and before ]) like this
Code: [Select]
writeln('hello world');

Thanks.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Jkey

  • New Member
  • *
  • Posts: 44
Re: I need help with msAccess database
« Reply #4 on: September 15, 2014, 01:33:14 pm »
If I try to read 55000 records (for example with 10 columns) from an MS Access DB table using ODBC, it takes usually 690-700ms  to perform it, so it's quite fast. Doesn't your source code slow down the reading?

magleft

  • Full Member
  • ***
  • Posts: 111
Re: I need help with msAccess database
« Reply #5 on: September 15, 2014, 01:58:26 pm »
The Access Database have the follwing structure:

   CODE_FYTA INTEGER,
   Crops VARCHAR(255),
   KOD_FARMAK INTEGER,
   EDR_COD_KAT VARCHAR(2),
   EIDOS VARCHAR(30),
   EMPORIKHON VARCHAR(50),
   GBONOMA VARCHAR(50),
   APOSYRSH VARCHAR(1),
   TELOS_EGRI DATE,
   UN_DELETE BOOLEAN,
   UN_DATE DATE, 
   SOIL BOOLEAN

the code who write is

Code: [Select]
Begin
   QAccessTable.SQL.Text := 'select * from FARMAKO_CROP_SKEYASMATA';
   QAccessTable.PacketRecords :=50;
   QAccessTable.Open;
   While not(QAccessTable.EOF) do
   begin
      QFarmaka.SQL.Text :='INSERT INTO FARMAKA_EGRISEIS ('
                  +'EMPORICO'
                  +', ID_KWDKAL'
                  +', INFO_KAL'
                  +') VALUES ('
                    + QAccessTable.FieldByName('KOD_FARMAK').AsString
                  +','+QAccessTable.FieldByName('CODE_FYTA').AsString
                  +','+QuotedStr(QAccessTable.FieldByName('Crops').AsString)
                  +')';
      QFarmaka.ExecSQL ;
      TransFarmaka.CommitRetaining  ;
       Panel1.Caption :=formatFloat('0',QAccessTable.RecNo)+' / '+   
                                   formatFloat('0',QAccessTable.RecordCount);
      QAccessTable.Next ;
  end;
   QAccessTable.close ;
End;

Any idea to do this more faster?
windows 10 64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: I need help with msAccess database
« Reply #6 on: September 15, 2014, 02:04:59 pm »
Yes,
Code: [Select]
QAccessTable.UniDirectional:=True;

see
http://wiki.lazarus.freepascal.org/Working_With_TSQLQuery#Out_of_memory_errors

Not sure about the packetrecords; perhaps tweaking that may help as well..
« Last Edit: September 15, 2014, 02:31:44 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

magleft

  • Full Member
  • ***
  • Posts: 111
Re: I need help with msAccess database
« Reply #7 on: September 15, 2014, 02:31:06 pm »
Thanks. I wil try.
windows 10 64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: I need help with msAccess database
« Reply #8 on: September 15, 2014, 02:31:18 pm »
Oh, and moving the insert query SQL definition out of the loop and making it a parameterized query could help as well.
This way, Access can prepare the query once and run it within the loop instead of having to evaluate the SQL again each loop iteration.

See e.g.
http://wiki.lazarus.freepascal.org/SQLdb_Tutorial3#Parameterized_queries
« Last Edit: September 15, 2014, 03:01:03 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Jkey

  • New Member
  • *
  • Posts: 44
Re: I need help with msAccess database
« Reply #9 on: September 15, 2014, 03:46:23 pm »
I would make two separate transactions: one for the SELECT, and one for the mass of INSERTs. Now it takes me 11,7 seconds to copy 3 columns of 55000 records from one table to another. Is it better than your speed?
Code: [Select]
const c = ''''; 
var StrLists: array of TStringList;
    i: integer;
begin
  SetLength(StrLists, 3);
  for i := 0 to Length(StrLists) - 1 do StrLists[i] := TStringList.Create;
  SQLTransaction.StartTransaction;
  SQLQuery.SQL.Text := 'SELECT KOD_FARMAK, CODE_FYTA, Crops  FROM FARMAKO_CROP_SKEYASMATA;';  // Open only as many columns as necessary
  SQLQuery.Open;
  SQLQuery.First;
  while not SQLQuery.EOF do
  begin
    for i := 0 to Length(StrLists) - 1 do  StrLists[i].Add(SQLQuery.Fields[i].AsString);
    SQLQuery.Next;
  end;
  SQLQuery.Close;
  SQLTransaction.Commit;
  SQLTransaction.StartTransaction;
  for i := 0 to StrLists[0].Count - 1 do
  begin
    SQLQuery.SQL.Text :='INSERT INTO FARMAKA_EGRISEIS (EMPORICO, ID_KWDKAL, INFO_KAL) VALUES ('+c+StrLists[0].Strings[i]+c+','+c+StrLists[1].Strings[i]+c+','+c+StrLists[2].Strings[i]+c+');';
    SQLQuery.ExecSQL;
  end;
  SQLTransaction.Commit;
  for i := 0 to Length(StrLists) - 1 do StrLists[i].Free;
end;

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: I need help with msAccess database
« Reply #10 on: September 15, 2014, 04:10:30 pm »
Thanks. I wil try.
Can I ask a simple question? are those 2 tables in the same database? Using the same connection and all? If yes then I would suggest to cut of the middle man (ee the network and your program) altogether use the
Code: [Select]
insert into <DestTable> select (<nil or desttable.field1>, <sourcetable.field2>, ..... from SourceTable where source conditions required; sql command to instruct the database to move data from one table the other internally.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Jkey

  • New Member
  • *
  • Posts: 44
Re: I need help with msAccess database
« Reply #11 on: September 15, 2014, 04:35:20 pm »
I would suggest to cut of the middle man (ee the network and your program) altogether use the
Code: [Select]
insert into <DestTable> select (<nil or desttable.field1>, <sourcetable.field2>, ..... from SourceTable where source conditions required; sql command to instruct the database to move data from one table the other internally.
Your suggestion results less than 300ms... :) This can be the quickest method, if appropriate for magleft.

magleft

  • Full Member
  • ***
  • Posts: 111
Re: I need help with msAccess database
« Reply #12 on: September 15, 2014, 09:16:47 pm »
Jkey:
     It really is what I was looking for. It is much faster.

taazz:
    No. The tables are in different database.


Thanks to all for help!!!
 :)
windows 10 64

 

TinyPortal © 2005-2018