TABLE_COPY & ATTACH_TABLE TROUBLE (OpenInsight Specific)
At 05 JUN 2001 10:54:03AM S Bell wrote:
THIS IS CODE FROM A CLICK EVENT ON A FORM NOT CONNECTED
TO ANY TABLE. I CANT SEEM TO GET THE TABLE COPY,ATTACH'
AND CLEAR TO WORK.THE COPY_TABLE GETS NO DEBUG FILE ERROR
BUT THE ATTACH GETS A FILE ERROR 401(FILE NOT ATTACHED).
HISTORYFILES IS JUST A FILE I KEEP SO A POPUP CAN BE USED
IN ANOTHER COLLECTOR FORM WHERE THE USER SELECTS A COPYTO
HISTORY FILE NAME THEN INPUTS A GAME NUMBER TO USE IN A
READ WRITE ROUTINE IN ANOTHER PROGRAM THAT WRITES RECORDS
WITH THAT GAME NUMBER TO THE NEW HISTORY FILE. THE USER
WANTED TO BE ABLE TO NAME AND CREATE THEIR OWN HISTORYFILES.
THIS ALL WORKED VERY WELL IN OLD AREV.
DECLARE FUNCTION GET_PROPERTY, SET_PROPERTY, SLIST_97
DECLARE SUBROUTINE COPY_TABLE
DECLARE SUBROUTINE CLEAR_TABLE
DECLARE SUBROUTINE ATTACH_TABLE
DECLARE FUNCTION MESSAGE_BOX
DECLARE FUNCTION Send_Event
$INSERT MESSAGE_BOX_EQUATES
debug
NEW_FILE_NAME='
thisone='
OK=0
Program=RTCW002.000 - BUTTON_1(CLICK)"
input_new_file_name=GET_PROPERTY(@WINDOW:".NEW_FILE_NAME","TEXT")
NEW_FILE_NAME=input_new_file_name
IF NEW_FILE_NAME=' THEN
Line_no=19MESSAGE=PLEASE ENTER A NEW HISTORY FILE NAME ...'GOSUB PRINT_MSGGOTO OUTEND
OPEN
,'HISTORYFILES' TO HISTORYFILES ELSE Line_no=26 MESSAGE=COULD NOT OPEN HISTORYFILES' GOSUB PRINT_MSG END OPEN
,'RTC_FILE' TO RTC_FILE ELSELine_no=32MESSAGE=COULD NOT OPEN RTC_FILE'GOSUB PRINT_MSGEND
OPEN 'DICT','RTC_FILE' TO @DICT ELSE
Line_no=38MESSAGE=COULD NOT OPEN DICTIONARY TO RTC_FILE'GOSUB PRINT_MSGEND
READ THISONE FROM HISTORYFILES,NEW_FILE_NAME ELSE
OK=1END
IF THISONE=NEW_FILE_NAME THEN
Line_no=48MESSAGE=This NEW_FILE_NAME Already exist ...'GOSUB PRINT_MSGGOTO OUTEND ELSE
HISTREC='HISTREC=NEW_FILE_NAMEWRITE HISTREC ON HISTORYFILES,NEW_FILE_NAME THENLine_no=56MESSAGE=NEW HISTORY FILE NAME **':NEW_FILE_NAME:'** HAS BEEN WRITTEN TO HISTORYFILES.'GOSUB PRINT_MSGEND
NEW_FILE=QUOTE(NEW_FILE_NAME)
IF OK THEN
COPY_TABLE("RTC_FILE", "S:\AREV\RTC", "RTC", ":NEW_FILE:", "1", "0", "0", "0", "1", "1")ATTACH_TABLE("S:\AREV\RTC", ":NEW_FILE:", "", "")Clear_Table(NEW_FILE)END
GOTO OUT
OUT:
RETURN 1
PRINT_MSG:
text=*":Program:\0D0A\:\0D0A\:"Program Information From Line #":line_no:\0D0A\:\0D0A\:MESSAGE
m=Message_Box(@window,text," Program Information ",MSG_BTN_OK$)
the_message="
RETURN
At 05 JUN 2001 11:57AM Oystein Reigem wrote:
S,
… … … IF THISONE=NEW_FILE_NAME THEN Line_no=48 MESSAGE=This NEW_FILE_NAME Already exist …' GOSUB PRINT_MSG GOTO OUT END ELSE
(This ELSE hasn't got any END.)
HISTREC=' HISTREC=NEW_FILE_NAME WRITE HISTREC ON HISTORYFILES,NEW_FILE_NAME THEN Line_no=56 MESSAGE=NEW HISTORY FILE NAME ':NEW_FILE_NAME:' HAS BEEN WRITTEN TO HISTORYFILES.' GOSUB PRINT_MSG END NEW_FILE=QUOTE(NEW_FILE_NAME)
What do you need the quotes for?
IF OK THEN COPY_TABLE("RTC_FILE", "S:\AREV\RTC", "RTC", ":NEW_FILE:", "1", "0", "0", "0", "1", "1") ATTACH_TABLE("S:\AREV\RTC", ":NEW_FILE:", "", "")
What's that ":NEW_FILE:"? Shouldn't it be NEW_FILE_NAME?
Clear_Table(NEW_FILE)
Why clear the target table?
END GOTO OUT OUT: RETURN 1 PRINT_MSG: text=*":Program:\0D0A\:\0D0A\:"Program Information From Line #":line_no:\0D0A\:\0D0A\:MESSAGE m=Message_Box(@window,text," Program Information ",MSG_BTN_OK$) the_message=" RETURN
- Oystein -
At 05 JUN 2001 01:47PM S Bell wrote:
Sorry about the "END". I fixed that and took the quotes
off the file name. I thought that when the file name was
in a variable called new_file_name, it would think that
was the actual file name which it is not. All the book
examples put "" around the actual file name. Any way, I
thought this would be the way to get the quotes around the
actual file name each time. The actual file name in this case
was HISTORY_13.
What I was doing was coping the original file "RTC_FILE" with
Dictionary and DATA to the NEW_FILE_NAME, what ever it may be,
clear out all the data, then read say game 12 records off the
"RTC_FILE" and write them to the new file. This way all the new
historyfiles have the same dict and layout as the "RTC_FILE".
In Arev, this was done with a select with game=13 then copy the
list. Any way as far as I can see, this needs to be done with a
read_row write_row in OI.
At 05 JUN 2001 04:24PM Oystein Reigem wrote:
S,
Unless I'm mistaken about what you try to do - you have to do the copying row by row.
But I recommend you use plain old open/read/write instead of read_row and write_row.
Also you might have to save the new database definition with a call to Define_Database.
- Oystein -
At 05 JUN 2001 09:15PM J Scott wrote:
Hi All
I use the copy table a lot where manipulation of data would be too slow on the whole file and I only need a selected bit of data. Hopefully the licencing problem for this kind of use of copy_table in the latest releases of OI will be resolved (in my code's favour) soon.
Scott, LMS
]
]Source_Table_Name=CHARGES"
]Dest_Table_Name=CHARGES_" : User_ID : "_" : Date() ]Location=C:\TEMP"
]void=SET_STATUS(0)
]CALL COPY_TABLE(Source_Table_Name, Location, 'GLOBAL', Dest_Table_Name,
,
,'1',,
,) ]stat=GET_STATUS(err_code) ]void=SET_STATUS(0) ]CALL ATTACH_TABLE (Location, Dest_Table_Name,
,) ]stat2=GET_STATUS(err_code2) ]CALL CLEAR_TABLE(Dest_Table_Name) ]Open Dest_Table_Name to Dest_Table Else ]]Mesg=Unable to open " : Dest_Table_Name ]]Gosub DISPLAY_ERROR ]End ]Open Source_Table_Name to Source_Table Else ]]Mesg=Unable to open " : Source_Table_Name ]]Gosub DISPLAY_ERROR ]End ]If @LIST_ACTIVE Then ClearSelect ]Sel=SELECT " : Source_Table_Name * usually have a pile of criteria with this ]Call RLIST( sel, 5,
,,
)]Done=0
]Counter=0
]Loop
]]ReadNext Source_Key Else Done=1
]Until Done
]]Read This_Rec from Source_Table, Source_Key Then
]]]Write This_Rec to Dest_Table, Source_Key Else
]]]]Mesg=Unable to write " : Source_Key
]]]End
]]End
]]Counter += 1
]]If counter ] 10 then
]]]Done=1]
]]End
]Repeat
]* to get rid of the new table
]
* Placed 'DATA.' in front of table name
* to stop the FS100 error occuring.
* not sure why this makes a difference but
* it may have to do with the original code
* using a create table instead of the copy.
* Maybe I should be running a second delete with the DICT. part
]del_status ]=
]temp_table_name ]= 'DATA.': Dest_Table_Name ]void ]]= SET_STATUS(0) ]Call DELETE_TABLE(temp_table_name,
, del_status)]stat3 ]]= GET_STATUS(err_code3)
]IF err_code3 Then
]]mesg =prog_id :'|Unable to Delete the Temporary Table ' :temp_table_name
]]mesg := '|Error Code : (' :err_code3 :')'
]]void =VICTEC_MSG( wname, 'BO', mesg, 'H')
]End
At 07 JUN 2001 09:40AM S Bell wrote:
THANKS FOR THE SAMPLE CODE. I USED EVERY THING EXCEPT THE
GET_STATUS THING.
I STILL GET A 401 'TABLE NOT ATTACHED' WHEN I TRY TO CLEAR
THE NEW TABLE.
I LEAVE THE DATABASE NULL BECAUSE EVERYTHING NEEDS TO STAY
IN THE SAME LOCATION.
I DONT KNOW WHAT THE DEAL IS. WHEN I STEP THRUE THE CALL
ATTACH_TABLE LINE I GET NO FILE ERROR IN THE SYSTEM VAR'S IN
THE DEBUGER. THEN WHEN I STEP THRUE THE CALL CLEAR_TABLE I GET
THE 401 ERROR.
??????
At 08 JUN 2001 02:18AM Scott, LMS wrote:
Hi
Ok we are down to the little things now.
I think if you put in the status stuff, it makes tracking where things went wrong a lot easier. If the err_code bits stay unassigned or null (if you init them first) then everything is ok.
By the way, does your caps lock key turn off? Your posts are giving me nasty flashbacks to a time on COBOL and Cybers and IBM 9000's.
I tried my own sample code and altered a few things.
1. I did init the err_codes eg
err_code='
err_code2='
2. I changed the source table to point at a table with much less data. I think this may have been a significant factor. I don't know why this should make a difference.
3. I put a GLOBAL into the attach bit
CALL ATTACH_TABLE (Location, Dest_Table_Name,'GLOBAL',
) I don't think this was crucial as I didn't have it in the original which works. You may need to change the GLOBAL to match your source database if it is not GLOBAL but I'd only try that if nothing else works ie I think you should be able to copy from 'MY_APP' to 'GLOBAL'. I could be wrong. 4. I added time() to the dest table name to make it more unique so I could run over again. I still think things went wrong first in the copy though. Dest_Table_Name=CHARGES_" : "JSS" : "_" : Date() : Time() So the stuff in my click event now looks like: declare function message_box, GET_STATUS, SET_STATUS, VICTEC_MSG debug * test copy table Source_Table_Name=CHARGES_TEMP" Dest_Table_Name=CHARGES_" : "JSS" : "_" : Date() : Time() Location=C:\TEMP" err_code=' err_code2=' void=SET_STATUS(0) CALL COPY_TABLE(Source_Table_Name, Location, 'GLOBAL', Dest_Table_Name,
,,'1',
,,
)stat=GET_STATUS(err_code)void=SET_STATUS(0)CALL ATTACH_TABLE (Location, Dest_Table_Name,'GLOBAL','')stat2=GET_STATUS(err_code2)void=SET_STATUS(0)CALL CLEAR_TABLE(Dest_Table_Name)stat2=GET_STATUS(err_code2)Open Dest_Table_Name to Dest_Table ElseMesg=Unable to open " : Dest_Table_NameGosub DISPLAY_ERROREndOpen Source_Table_Name to Source_Table ElseMesg=Unable to open " : Source_Table_NameGosub DISPLAY_ERROREndRETURN 0
DISPLAY_ERROR:
void=message_box(@WINDOW, mesg, "error message", 0)RETURN
At 08 JUN 2001 10:18AM S Bell wrote:
Still not working.
Here's what I have now …
DECLARE FUNCTION GET_PROPERTY, SET_PROPERTY, SLIST_97
DECLARE SUBROUTINE COPY_TABLE, DEFINE_DATABASE
DECLARE SUBROUTINE CLEAR_TABLE
DECLARE SUBROUTINE ATTACH_TABLE
DECLARE FUNCTION MESSAGE_BOX, GET_STATUS, SET_STATUS, VICTEC_MSG
DECLARE FUNCTION SEND_EVENT
$INSERT MESSAGE_BOX_EQUATES
debug
NEW_FILE_NAME='
thisone='
OK=0
Program=RTCW002.000 - BUTTON_1(CLICK)"
input_new_file_name=GET_PROPERTY(@WINDOW:".NEW_FILE_NAME","TEXT")
NEW_FILE_NAME=input_new_file_name
IF NEW_FILE_NAME=' THEN
Line_no=21MESSAGE=PLEASE ENTER A NEW HISTORY FILE NAME ...'GOSUB PRINT_MSGGOTO OUTEND
OPEN
,'HISTORYFILES' TO HISTORYFILES ELSE Line_no=28 MESSAGE=COULD NOT OPEN HISTORYFILES' GOSUB PRINT_MSG END READ THISONE FROM HISTORYFILES,NEW_FILE_NAME ELSE OK=1 END IF THISONE=NEW_FILE_NAME THEN Line_no=38 MESSAGE=This NEW_FILE_NAME Already exist …' GOSUB PRINT_MSG GOTO OUT END ELSE HISTREC=' HISTREC=NEW_FILE_NAME WRITE HISTREC ON HISTORYFILES,NEW_FILE_NAME THEN Line_no=46 MESSAGE=NEW HISTORY FILE NAME ':NEW_FILE_NAME:' HAS BEEN WRITTEN TO HISTORYFILES.' GOSUB PRINT_MSG END END SOURCE_TABLE_NAME=RTC_FILE" DEST_TABLE_NAME=QUOTE(NEW_FILE_NAME) LOCATION=S:\AREV\RTC" IF OK THEN err_code=' err_code2=' void=SET_STATUS(0) CALL COPY_TABLE(SOURCE_TABLE_NAME,LOCATION,
,DEST_TABLE_NAME,"1","0","0","0","1","1")stat=GET_STATUS(err_code) **this gets err_code 'fs272void=SET_STATUS(0)CALL ATTACH_TABLE(LOCATION,DEST_TABLDECLARE FUNCTION GET_PROPERTY, SET_PROPERTY, SLIST_97DECLARE SUBROUTINE COPY_TABLE, DEFINE_DATABASE
DECLARE SUBROUTINE CLEAR_TABLE
DECLARE SUBROUTINE ATTACH_TABLE
DECLARE FUNCTION MESSAGE_BOX, GET_STATUS, SET_STATUS, VICTEC_MSG
DECLARE FUNCTION SEND_EVENT
$INSERT MESSAGE_BOX_EQUATES
debug
NEW_FILE_NAME='
thisone='
OK=0
Program=RTCW002.000 - BUTTON_1(CLICK)"
input_new_file_name=GET_PROPERTY(@WINDOW:".NEW_FILE_NAME","TEXT")
NEW_FILE_NAME=input_new_file_name
IF NEW_FILE_NAME=' THEN
Line_no=21MESSAGE=PLEASE ENTER A NEW HISTORY FILE NAME ...'GOSUB PRINT_MSGGOTO OUTEND
OPEN
,'HISTORYFILES' TO HISTORYFILES ELSE Line_no=28 MESSAGE=COULD NOT OPEN HISTORYFILES' GOSUB PRINT_MSG END READ THISONE FROM HISTORYFILES,NEW_FILE_NAME ELSE OK=1 END IF THISONE=NEW_FILE_NAME THEN Line_no=38 MESSAGE=This NEW_FILE_NAME Already exist …' GOSUB PRINT_MSG GOTO OUT END ELSE HISTREC=' HISTREC=NEW_FILE_NAME WRITE HISTREC ON HISTORYFILES,NEW_FILE_NAME THEN Line_no=46 MESSAGE=NEW HISTORY FILE NAME ':NEW_FILE_NAME:' HAS BEEN WRITTEN TO HISTORYFILES.' GOSUB PRINT_MSG END END SOURCE_TABLE_NAME=RTC_FILE" DEST_TABLE_NAME=QUOTE(NEW_FILE_NAME) LOCATION=S:\AREV\RTC" IF OK THEN err_code=' err_code2=' void=SET_STATUS(0) CALL COPY_TABLE(SOURCE_TABLE_NAME,LOCATION,
,DEST_TABLE_NAME,"1","0","0","0","1","1")stat=GET_STATUS(err_code) */* this gets err_code 'fs272void=SET_STATUS(0)CALL ATTACH_TABLE(LOCATION,DEST_TABLE_NAME,'','')stat=GET_STATUS(err_code2) */* this gets err_code2 'sp280void=SET_STATUS(0)CALL CLEAR_TABLE(DEST_TABLE_NAME)stat=GET_STATUS(err_code2) */* this gets err_code2 'fs200Open SOURCE_TABLE_NAME to Source_Table ElseMesg=Unable to open ":SOURCE_TABLE_NAMEGosub DISPLAY_ERROR */* stops here cant open this fileEndOpen DEST_TABLE_NAME to Dest_Table ElseMesg=Unable to open ":SOURCE_TABLE_NAMEGosub DISPLAY_ERROREndEND
OUT:
RETURN 1
DISPLAY_ERROR:
void=message_box(@WINDOW,mesg,"error message",0)
RETURN
PRINT_MSG:
text=*":Program:\0D0A\:\0D0A\:"Program Information From Line #":line_no:\0D0A\:\0D0A\:MESSAGE
m=Message_Box(@window,text," Program Information ",MSG_BTN_OK$)
the_message="
RETURNE_NAME,
,
)stat=GET_STATUS(err_code2)void=SET_STATUS(0)CALL CLEAR_TABLE(DEST_TABLE_NAME)stat=GET_STATUS(err_code2)Open SOURCE_TABLE_NAME to Source_Table ElseMesg=Unable to open ":SOURCE_TABLE_NAMEGosub DISPLAY_ERROREndOpen DEST_TABLE_NAME to Dest_Table ElseMesg=Unable to open ":SOURCE_TABLE_NAMEGosub DISPLAY_ERROREndEND
OUT:
RETURN 1
DISPLAY_ERROR:
void=message_box(@WINDOW,mesg,"error message",0)
RETURN
PRINT_MSG:
text=*":Program:\0D0A\:\0D0A\:"Program Information From Line #":line_no:\0D0A\:\0D0A\:MESSAGE
m=Message_Box(@window,text," Program Information ",MSG_BTN_OK$)
the_message="
RETURN
At 08 JUN 2001 10:59AM Simon Wilmot wrote:
What error messages do you get if you replace
Dest_Table_Name=Quote(New_File_Name)
with
Dest_Table_Name=New_File_Name
I would also prefer to use @DBID within the Copy_Table call rather than a default null for the database (param 4)
Simon
RebusHR
At 08 JUN 2001 01:07PM S Bell wrote:
OK! Thanks for joining in to help me.
I put the @DBID in the 3rd pram of the COPY_TABLE.
I'm hoping when you said pram 4 it was a type O error.
now err_code=SSP214(vm)DICT.DOG*RTC
DOG is the name of the Dest_Table_Name I typed into
my collector form so that looks good to me.
RTC=the @DBID so I hope. In Arev this was the Account name
This time I got no err_code2 on both Open Dest & Source files.
Only thing is, there is no table DOG there. Even when I log out
and back IN.
???? more help please.
At 11 JUN 2001 03:37AM Simon Wilmot wrote:
S,
SSP214 indicates that the table already exists. Is 'DOG' a test table name you have used before ??
Try attaching the REVMEDIA table for that area and listing the contents. You may need to attach and delete the dictionary portions of tables that have been part created.
Simon
RebusHR
At 11 JUN 2001 09:13AM S Bell wrote:
Yes! I found a CAT & a DOG out there. I attached them and their Dictionaties look OK. Now I just need to learn why the programms
attach line doesn't work right. The input filenames DOG & CAT had
been tried several times. When running the program I didn't see any
errors on the ATTACT_TABLE line only on the CLEAR_TABLE line.
The source file RTC_FILE is kind of large. 90,000 + records.
Any way to copy the file and dictionary and no records. Then I
wouldn't need to CLEAR_FILE.
At 11 JUN 2001 10:47AM Oystein Reigem wrote:
S,
Any way to copy the file and dictionary and no records. Then I wouldn't need to CLEAR_FILE.
There is a Create_Table function. You could perhaps create the new table with Create_Table, then copy all the dict rows from the old table's dict to the new one's.
I have a function that does something similar: Creates a new, empty table from a text file description of all the fields. It goes something like this (I've omitted stuff like OSOpen/OSRead text file):
Delete_Table( … New_Table_Name … )
Define_Database( … )
DictFlag=true$
Create_Table( … New_Table_Name, DictFlag … )
open "DICT." : New_Table_Name to New_Dict_Var
loop
while …
Dict_Item=…
write Dict_Item to New_Dict_Var, …
repeat
DictFlag=false$
Create_Table( … New_Table_Name, DictFlag … )
Define_Database( … )
I'm not brilliant when it comes to stuff like this. I don't remember why it was I created the dictionary part separately from the data part. But it least it works.
My function only creates the dict rows for each field, not the special rows. They are created automatically when... ...don't remember. :-) I think it'd be a matter of taste if you wanted to copy over the rows or let them be created automatically.
I can supply more details if you're interested.
- Oystein -
At 11 JUN 2001 11:02AM Simon Wilmot wrote:
The problem I think is that sometime in the past you had an errored run that created the Dict parts of the table but failed on the data part. That is why you can't attach both parts from the attach_table(data table',..) statement. I would suggest that if you were to delete all the part bits you have and try again from scratch, it may all work OK.
But use the code without the 'Quote' statement (@DBID not necessary, but recommended)
Simon
RebusHR