#1  
Old 19th June 2012, 02:42 PM
JimGilmour JimGilmour is offline
Junior Member
 
Join Date: Jun 2011
Posts: 8
Default Delphi AddIndex to Memory Table

I am updating a Delphi App that used Paradox Tables to now use NexusDb Tables.
In Paradox I used a lot of Private Tables for Temporary storage and have emulated this using NexusDb memory Tables.
However, I used a lot of BatchMoves (which I have working OK) and then an AddIndex to add any Indexes (usually a primary)
This works fine the first time I use the table but upon any subsequent uses of the table AddIndex gives me an 'Index already Exists Error'
A cant seem to find the equivilent of an IndexExists command. Does anybody know how to test if an Index alreay exists ?

Jim
__________________
Jim Gilmour
Border Rivers Computer Services
  #2  
Old 19th June 2012, 04:18 PM
Wolfgang
 
Posts: n/a
Default Re: Delphi AddIndex to Memory Table

Have you tried

"nxMemTable1.Active := False;"

before using it again?

On 19.06.2012 5:42 AM, JimGilmour wrote:
> I am updating a Delphi App that used Paradox Tables to now use NexusDb
> Tables.
> In Paradox I used a lot of Private Tables for Temporary storage and have
> emulated this using NexusDb memory Tables.
> However, I used a lot of BatchMoves (which I have working OK) and then
> an AddIndex to add any Indexes (usually a primary)
> This works fine the first time I use the table but upon any subsequent
> uses of the table AddIndex gives me an 'Index already Exists Error'
> A cant seem to find the equivilent of an IndexExists command. Does
> anybody know how to test if an Index alreay exists ?
>
> Jim
>
>

  #3  
Old 19th June 2012, 04:31 PM
Wolfgang
 
Posts: n/a
Default Re: Delphi AddIndex to Memory Table

Here is an Example:

EmpMem.IndexDefs.Clear;
EmpMem.FieldDefs.Clear;
EmpMem.FieldDefs.Add('Department', ftString, 25);
EmpMem.FieldDefs.Add('Name', ftString, 25);
EmpMem.FieldDefs.Add('Capacity', ftFloat);
for i := StartDt to EndDt do EmpMem.FieldDefs.Add(DateToStr(i), ftFloat);
with EmpMem.IndexDefs.AddIndexDef do begin
Name := 'DeptIx';
Fields := 'Department';
end;
EmpMem.IndexName := 'DeptIx';
EmpMem.MasterSource := CapMemSc;
EmpMem.MasterFields := 'Department';
CapMem.Active := True;
for i := 0 to CapMem.Fields.Count - 1 do begin
if CapMem.Fields[i].DataType = ftFloat then begin
(CapMem.FieldByName(CapMem.Fields[i].FieldName) as
TNumericField).DisplayFormat := '0.00';
end;
end;

EmpMem.Active := True;
On 19.06.2012 5:42 AM, JimGilmour wrote:
> I am updating a Delphi App that used Paradox Tables to now use NexusDb
> Tables.
> In Paradox I used a lot of Private Tables for Temporary storage and have
> emulated this using NexusDb memory Tables.
> However, I used a lot of BatchMoves (which I have working OK) and then
> an AddIndex to add any Indexes (usually a primary)
> This works fine the first time I use the table but upon any subsequent
> uses of the table AddIndex gives me an 'Index already Exists Error'
> A cant seem to find the equivilent of an IndexExists command. Does
> anybody know how to test if an Index alreay exists ?
>
> Jim
>
>

  #4  
Old 19th June 2012, 04:32 PM
Wolfgang
 
Posts: n/a
Default Re: Delphi AddIndex to Memory Table

Forgot first line :

EmpMem.Active := False;
EmpMem.IndexDefs.Clear;
EmpMem.FieldDefs.Clear;
EmpMem.FieldDefs.Add('Department', ftString, 25);
EmpMem.FieldDefs.Add('Name', ftString, 25);
EmpMem.FieldDefs.Add('Capacity', ftFloat);
for i := StartDt to EndDt do EmpMem.FieldDefs.Add(DateToStr(i), ftFloat);
with EmpMem.IndexDefs.AddIndexDef do begin
Name := 'DeptIx';
Fields := 'Department';
end;
EmpMem.IndexName := 'DeptIx';
EmpMem.MasterSource := CapMemSc;
EmpMem.MasterFields := 'Department';
CapMem.Active := True;
for i := 0 to CapMem.Fields.Count - 1 do begin
if CapMem.Fields[i].DataType = ftFloat then begin
(CapMem.FieldByName(CapMem.Fields[i].FieldName) as
TNumericField).DisplayFormat := '0.00';
end;
end;

EmpMem.Active := True;

On 19.06.2012 5:42 AM, JimGilmour wrote:
> I am updating a Delphi App that used Paradox Tables to now use NexusDb
> Tables.
> In Paradox I used a lot of Private Tables for Temporary storage and have
> emulated this using NexusDb memory Tables.
> However, I used a lot of BatchMoves (which I have working OK) and then
> an AddIndex to add any Indexes (usually a primary)
> This works fine the first time I use the table but upon any subsequent
> uses of the table AddIndex gives me an 'Index already Exists Error'
> A cant seem to find the equivilent of an IndexExists command. Does
> anybody know how to test if an Index alreay exists ?
>
> Jim
>
>

  #5  
Old 19th June 2012, 04:56 PM
Thorsten Engler [NDA]
 
Posts: n/a
Default Re: Delphi AddIndex to Memory Table

It sounds as if you would be better of using a TnxCachedDataSet

It will automatically take it's fields and indices from the attached source
dataset, adding any indices you have defined in AddIndexDefs, and use batch
read operations to copy all visible records from the source dataset (visible
means that you can apply a range and filter to the source dataset before
opening the cached dataset).

JimGilmour wrote:

>
> I am updating a Delphi App that used Paradox Tables to now use NexusDb
> Tables.
> In Paradox I used a lot of Private Tables for Temporary storage and have
> emulated this using NexusDb memory Tables.
> However, I used a lot of BatchMoves (which I have working OK) and then
> an AddIndex to add any Indexes (usually a primary)
> This works fine the first time I use the table but upon any subsequent
> uses of the table AddIndex gives me an 'Index already Exists Error'
> A cant seem to find the equivilent of an IndexExists command. Does
> anybody know how to test if an Index alreay exists ?
>
> Jim


  #6  
Old 20th June 2012, 03:27 PM
JimGilmour JimGilmour is offline
Junior Member
 
Join Date: Jun 2011
Posts: 8
Default

Thank you all,
This is typical of what is being done :

qryGetHeldLoads.Open;
{Copy}
BatchMove(qryGetHeldLoads, dmGinProg.tblHeldMote, batCopy);
dmGinProg.tblHeldMote.AddIndex('Load No','Mote Load',[ixprimary]);

ie. Execute a query, copy results to a Memory Tables (Used to be a Private Table in Paradox) and add an Index.

The BatchMove is some code that I copied from somewhere, but did not have an 'IndexDefs.Clear' which I have added thanks to your responses.

Also - thanks for the info about CachedDataSets I will give this a go for stuff in the future.
__________________
Jim Gilmour
Border Rivers Computer Services
  #7  
Old 20th June 2012, 04:30 PM
Wolfgang
 
Posts: n/a
Default Re: Delphi AddIndex to Memory Table

It seems to me, that you could do much better as follows:

Use a normal TnxTable and set the TableName property to ##Temp;

Use a TnxQuery to retrieve data from a Table into a Temporary Table like so:

nxTable1.Active := False;
with nxQuery1 do begin
Active := False;
SQL.Clear;
SQL.Add('select * into ##Temp from aTable');
SQL.Add('where (selectioncriteria);');
SQL.Add('create index ix on ##Temp (Field);');
Active := True;
end;
nxTable1.Active := True;
nxTable1.IndexName := 'ix';

On 20.06.2012 6:27 AM, JimGilmour wrote:
> Thank you all,
> This is typical of what is being done :
>
> qryGetHeldLoads.Open;
> {Copy}
> BatchMove(qryGetHeldLoads, dmGinProg.tblHeldMote, batCopy);
> dmGinProg.tblHeldMote.AddIndex('Load No','Mote Load',[ixprimary]);
>
> ie. Execute a query, copy results to a Memory Tables (Used to be a
> Private Table in Paradox) and add an Index.
>
> The BatchMove is some code that I copied from somewhere, but did not
> have an 'IndexDefs.Clear' which I have added thanks to your responses.
>
> Also - thanks for the info about CachedDataSets I will give this a go
> for stuff in the future.
>
>



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create an in-memory database in delphi code kgday nexusdb.public.support 4 25th January 2012 11:59 PM
setup in memory table in Delphi 2009 IDE - TnxMemTable Scott H nexusdb.public.support 18 27th September 2009 12:41 PM
AddIndex slow Luke Johnston nexusdb.public.support 2 31st August 2006 09:46 AM
AddIndex problem Richard Light nexusdb.public.support 4 3rd February 2006 02:39 AM
in-memory table Diniz nexusdb.public.support 8 12th September 2003 03:09 AM


All times are GMT +11. The time now is 11:52 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.