|
Log in | ||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
> nxCheck(nxDatabase1.RestructureTableEx('test', '', Dict,
> TableMapper, TaskInfo)); Pass the *new* dictionary in, not the old. -- Eivind Bakkestuen [NDD] |
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | |
|
|
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 |