#1  
Old 9th June 2012, 08:39 AM
Enrico Enrico is offline
Junior Member
 
Join Date: Apr 2009
Posts: 11
Default Restructuretableex example on Manual does not work?

HI

Nexusdb 2 vers. 2.0803.

On the manual, there is an example "How to restructure a table?".
I made a simplified copy of the code (did not know what the Tablelist was, so I use directly the table name).
Everything seems to go smooth. I get no errors, and when I check the datetime stamp of the table (on disk) I see that it was accessed and somewhat modified.
But the new field is not added!
What am I missing?
In the example of the manual there is a variable NeedRestruct: Boolean;
which is never used. Maybe i should set something to true? but what, where?
Thanks for any help.
This is the code (the database is opened outside the procedure)

procedure restructuretable(nxDatabase1: Tnxdatabase);
var

NewDict, Dict: TnxDataDictionary;
TaskInfo: TnxAbstractTaskInfo;
Completed: Boolean;
TableMapper: TnxTableMapperDescriptor;
TaskStatus: TnxTaskStatus;

begin
Dict := TnxDataDictionary.Create;
TableMapper := TnxTableMapperDescriptor.Create;
try
nxDatabase1.GetDataDictionary('test', '', Dict);
NewDict := TnxDataDictionary.Create;
NewDict.Assign(Dict);
NewDict.fieldsdescriptor.ADDFIELD('NewFieldName',' ',nxtshortstring,10,0,false,nil);
TableMapper.MapAllTablesAndFieldsByName(Dict, NewDict);
nxCheck(nxDatabase1.RestructureTableEx('test', '', Dict, TableMapper, TaskInfo));
try
if Assigned(TaskInfo) then begin
repeat
TaskInfo.GetStatus(Completed, TaskStatus);
if not Completed then begin
Sleep(500)
end;
until Completed;
nxCheck(TaskStatus.tsErrorCode);
end;
finally
if Assigned(TaskInfo) then
TaskInfo.Free;
end;
finally
Dict.Free;
TableMapper.Free;
end;

end;
  #2  
Old 9th June 2012, 11:49 AM
Eivind Bakkestuen [NDD]
 
Posts: n/a
Default Re: Restructuretableex example on Manual does not work?

> nxCheck(nxDatabase1.RestructureTableEx('test', '', Dict,
> TableMapper, TaskInfo));


Pass the *new* dictionary in, not the old.


--
Eivind Bakkestuen [NDD]
  #3  
Old 9th June 2012, 05:04 PM
Enrico Enrico is offline
Junior Member
 
Join Date: Apr 2009
Posts: 11
Default Ok, thanks, but is this ok?

Thanks, Eivind
I will try that tomorrow (it's 1 AM here now).
In the meantime, while waiting for an answer, I tried the code shown below
and it seems to work fine.
Is that code ok? Why do I need to create a new Datadictionary and map the files/fields, if I can do anything using the current table data dictionary and modify it and then use tablerestructureEX passing the "empty" Table mapper (i.e. not mapped, just created)?
Thanks

procedure restructuretable(nxDatabase1: Tnxdatabase; t1:TnxTable);
var

NewDict, Dict: TnxDataDictionary;
TaskInfo: TnxAbstractTaskInfo;
Completed: Boolean;
TableMapper: TnxTableMapperDescriptor;
TaskStatus: TnxTaskStatus;
NeedRestruct: Boolean;
var AR : TnxResult;
begin
Dict := TnxDataDictionary.Create;
TableMapper := TnxTableMapperDescriptor.Create;
try
t1.Open;
dict := tnxDataDictionary.Create;
dict.Assign(t1._Dictionary);
t1.Close;
Dict.fieldsdescriptor.ADDFIELD('ddd','',nxtshortst ring,20,0,false,nil);
nxCheck(nxDatabase1.RestructureTableEx(t1.tablenam e, '', Dict, TableMapper, TaskInfo));
try
if Assigned(TaskInfo) then begin
repeat
TaskInfo.GetStatus(Completed, TaskStatus);
if not Completed then begin
Sleep(500)
end;
until Completed;
nxCheck(TaskStatus.tsErrorCode);
end;
finally
if Assigned(TaskInfo) then
TaskInfo.Free;
end;
finally
Dict.Free;
TableMapper.Free;
end;

end;
  #4  
Old 10th June 2012, 04:31 AM
Enrico Enrico is offline
Junior Member
 
Join Date: Apr 2009
Posts: 11
Default

Yes Eivind
Your solution worked.
Is the other version (the one that I posted with only Dict without NewDict)
safe? Why do we need a NewDict and MapAllTablesAndFieldsByName when
apparently the same things can be done making all the changes on Dict and not using MapAllTablesAndFieldsByName at all? Is there a disadvantange or a 'risk' doing it without NewDict and MapAllTablesAndFieldsByName?
Thanks
  #5  
Old 11th June 2012, 10:03 PM
Franz-Leo Chomse [NDX]
 
Posts: n/a
Default Re: Restructuretableex example on Manual does not work?

On Sun, 10 Jun 2012 03:31:29 +1000, Enrico
<Enrico.5dwkfi@nx-forums.nexusdb.com> wrote:

>
>Yes Eivind
>Your solution worked.
>Is the other version (the one that I posted with only Dict without
>NewDict)
>safe? Why do we need a NewDict and MapAllTablesAndFieldsByName when
>apparently the same things can be done making all the changes on Dict
>and not using MapAllTablesAndFieldsByName at all? Is there a
>disadvantange or a 'risk' doing it without NewDict and


This combination is needed when you remove or rename fields
during your restructure process.

Regards from Germany

Franz-Leo Chomse [NexusDB Expert]
franz.leo.chomse@ndx.nexusdb_x.com (please remove "_x" to reply)
  #6  
Old 11th June 2012, 05:40 PM
Bert Binnenmarsch
 
Posts: n/a
Default Re: Restructuretableex example on Manual does not work?

Eivind Bakkestuen [NDD] wrote:

> > nxCheck(nxDatabase1.RestructureTableEx('test', '', Dict,
> > TableMapper, TaskInfo));

>
> Pass the new dictionary in, not the old.


This error in the documentation was reported a long time ago, but it is
still present in the documentation for version 3! Download the latest
documentation from the website now and check it yourself.


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
ANN: Manual work-in-progress update Eivind Bakkestuen [NDD] nexusdb.public.announcements 0 6th February 2004 03:07 PM
ANN: Manual work-in-progress update Eivind Bakkestuen [NDD] nexusdb.public.support 0 6th February 2004 03:07 PM
work-in-progress manual too slow :) Roberto Nicchi nexusdb.public.support 10 7th August 2003 07:21 AM
ANN: Manual work-in-progress version now available. Hannes Danzl[NDD] nexusdb.public.support 15 7th August 2003 07:17 AM
ANN: Manual work-in-progress version now available. Hannes Danzl[NDD] nexusdb.public.announcements 0 6th August 2003 11:05 AM


All times are GMT +11. The time now is 03:45 AM.


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