Pieter van Heerden
2008-11-05 03:44:07 UTC
I have found that if data is added to a table, with a unique index, after the table has been emptied by local SQL delete, the unique index fails on the newly added data. When the following commands are used:
//Test_U_Index
// Create a table for out origional data
set safety off
// Set the database name to whatever is convenient
d = new database()
d.databasename = "sapwat"
d.active = true
// Delete existing tables
if d.tableExists("ws_crop")
d.dropTable("ws_crop")
endif
if d.tableExists("ws_temp1")
d.dropTable("ws_temp1")
endif
// Create a table for holding the origionla data
create table ":sapwat:ws_crop.dbf"(;
WStation character(10), ;
Crop character(10))
// Fill the table with data
aWs = {"WS1", "WS2"}
aCrop = {"Apples", "Pears", "Prunes"}
q = new query()
q.database = d
q.sql = "select * from ws_crop"
q.active = true
for i = 1 to 2
for j = 1 to 3
q.rowset.beginappend()
q.rowset.fields["WStation"].value = aWs[i]
q.rowset.fields["Crop"].value = aCrop[j]
q.rowset.save()
endfor
endfor
q.active = false
// Now copy the structure of the table to another table
use ws_crop
copy structure to ws_temp1
use ws_temp1 exclusive
index on WStation tag wstationu unique
for i = 1 to 2
use ws_temp1
append from ws_crop
if i = 1
browse
use
delete from ws_temp1
else
set order to wstationu
browse
use
endif
endfor
d.active = false
set safety on
the table is shown as being empty, even though the newly added data shows if the index is not active.
If the table is packed, and the above commands are used, the relevant rows show as expected.
//Test_U_Index
// Create a table for out origional data
set safety off
// Set the database name to whatever is convenient
d = new database()
d.databasename = "sapwat"
d.active = true
// Delete existing tables
if d.tableExists("ws_crop")
d.dropTable("ws_crop")
endif
if d.tableExists("ws_temp1")
d.dropTable("ws_temp1")
endif
// Create a table for holding the origionla data
create table ":sapwat:ws_crop.dbf"(;
WStation character(10), ;
Crop character(10))
// Fill the table with data
aWs = {"WS1", "WS2"}
aCrop = {"Apples", "Pears", "Prunes"}
q = new query()
q.database = d
q.sql = "select * from ws_crop"
q.active = true
for i = 1 to 2
for j = 1 to 3
q.rowset.beginappend()
q.rowset.fields["WStation"].value = aWs[i]
q.rowset.fields["Crop"].value = aCrop[j]
q.rowset.save()
endfor
endfor
q.active = false
// Now copy the structure of the table to another table
use ws_crop
copy structure to ws_temp1
use ws_temp1 exclusive
index on WStation tag wstationu unique
for i = 1 to 2
use ws_temp1
append from ws_crop
if i = 1
browse
use
delete from ws_temp1
else
set order to wstationu
browse
use
endif
endfor
d.active = false
set safety on
the table is shown as being empty, even though the newly added data shows if the index is not active.
If the table is packed, and the above commands are used, the relevant rows show as expected.