Appending Data in BLOB fields

ckndr47
Member Posts: 100
Hi Gurus,
I have a BLOB field where i am importing a txt file;
Next i have to create append mechansim that is when i select any other file, the system should not overwrite my existing data found BLOB field but it should append it.
Any quick trick to get this thing done apart from reading the blob field, createinstream and then read the data and thn put it somwhere.
I have done this copy stream trick but this isint working. Any trick or help
This code is called at the IMPORT button on Form:
I have a BLOB field where i am importing a txt file;
Next i have to create append mechansim that is when i select any other file, the system should not overwrite my existing data found BLOB field but it should append it.
Any quick trick to get this thing done apart from reading the blob field, createinstream and then read the data and thn put it somwhere.
I have done this copy stream trick but this isint working. Any trick or help
This code is called at the IMPORT button on Form:
Rec.CALCFIELDS(Comments); IF Rec.Comments.HASVALUE THEN BEGIN RMCommentLine.Comments.IMPORT('*.txt',TRUE); RMCommentLine.Comments.CREATEINSTREAM(StreamInObj); Rec.Comments.CREATEOUTSTREAM(StreamOutObj); COPYSTREAM(StreamOutObj,StreamInObj); CurrForm.UPDATE; END ELSE BEGIN Rec.Comments.IMPORT('*.txt',TRUE); CurrForm.UPDATE; END;
0
Answers
-
I doubt you can append data to existing data in a BLOB-field.
You'll have to export the contents of the BLOB-field to a file on disk, append the new data to this file and finally import this new file into the BLOB-field and thus overwriting the old data.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
Luc Van Dyck wrote:I doubt you can append data to existing data in a BLOB-field.
You'll have to export the contents of the BLOB-field to a file on disk, append the new data to this file and finally import this new file into the BLOB-field and thus overwriting the old data.
1.) save the BLOB in on ther BLOB field (COYPSTREAM)
2.) clear the original BLOB field
3.) use a INSTREAM from the tempBLOB and wriite to the original field with WRITE
4.) once INSTREAM (tempBLOB) is EOS, read from INSTREAM containing the data to append and use the same OUTSTREAM to write the data
COPYSTREAM always seeks to position 0 within the OUTSTREAM. As you can not move the stream pointer, you can not simply use COPYSTREAM to append.Torsten
MCP+I, MCSE NT, Navision MCT (2004,2005)0 -
Thanks todro and Luc Van for your valuable feedback.
Yeah this thing can be done in 2 ways;
a) either through exporting the files and merging them through Shell command
b) Manipulation with streams.
I have selected option b) and its working fine here at my end.
Here is the code so that it can be useful for everybody:
The code is written on the IMPORT button of form:IF NOT Rec.ISEMPTY THEN Rec.CALCFIELDS(Comments); IF Rec.Comments.HASVALUE THEN BEGIN // if data exists in BLOB RMCommentLine.Comments := Rec.Comments; // copy the BLOB field to temp1 Rec.Comments.CREATEOUTSTREAM(StreamOutObj); // Move data from Temp1 stream to the original BLOB field RMCommentLine.Comments.CREATEINSTREAM(StreamInObj); WHILE NOT (StreamInObj.EOS()) DO BEGIN StreamInObj.READTEXT(Txt); StreamOutObj.WRITE(COPYSTR(Txt,1,STRLEN(Txt))); END; // Get the new file (for the second file i m using a sep Rec) RMCommentLinetemp.Comments.IMPORT('*.txt',TRUE); // Append the data from Temp2 to original RMCommentLinetemp.Comments.CREATEINSTREAM(StreamInObj); WHILE NOT (StreamInObj.EOS()) DO BEGIN StreamInObj.READTEXT(Txt); StreamOutObj.WRITE(COPYSTR(Txt,1,STRLEN(Txt))); END; CurrForm.UPDATE; END ELSE BEGIN Rec.Comments.IMPORT('*.txt',TRUE); CurrForm.UPDATE; END; // Both Temp1 (RMCommentLine) and Temp2 (RMCommentLinetemp) are temporary tables Thanks and Regards,
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions