Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Storing Documents in the database

3 posts in General Discussion Last posting was on 2009-03-11 20:43:21.0Z
Herman Miller Posted on 2009-03-11 17:12:07.0Z
Sender: 2b93.49b7f098.1804289383@sybase.com
From: Herman Miller
Newsgroups: ianywhere.public.general
Subject: Storing Documents in the database
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <49b7f0e7.2ba7.1681692777@sybase.com>
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 11 Mar 2009 09:12:07 -0800
X-Trace: forums-1-dub 1236791527 10.22.241.41 (11 Mar 2009 09:12:07 -0800)
X-Original-Trace: 11 Mar 2009 09:12:07 -0800, 10.22.241.41
Lines: 4
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:7405
Article PK: 5823

Sybase Version 9.0.2.3534

How can I write and retrieve documents in the database.
Please include sample code and database if possible.


Breck Carter [TeamSybase] Posted on 2009-03-11 20:43:21.0Z
From: "Breck Carter [TeamSybase]" <NOSPAM__breck.carter@gmail.com>
Newsgroups: ianywhere.public.general
Subject: Re: Storing Documents in the database
Organization: RisingRoad Professional Services
Reply-To: NOSPAM__breck.carter@gmail.com
Message-ID: <vb8gr492m1dt0enaji56h8mfemg5g4s6hq@4ax.com>
References: <49b7f0e7.2ba7.1681692777@sybase.com>
X-Newsreader: Forte Agent 2.0/32.640
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Date: 11 Mar 2009 12:43:21 -0800
X-Trace: forums-1-dub 1236804201 10.22.241.152 (11 Mar 2009 12:43:21 -0800)
X-Original-Trace: 11 Mar 2009 12:43:21 -0800, vip152.sybase.com
Lines: 54
X-Authenticated-User: TeamSybase
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:7407
Article PK: 5819

In addition to the streamlined code Jeff posted, if you want to do
error checking the following templates may be of interest:

-----------------------------------------------------------

BEGIN

DECLARE @contents LONG BINARY;

SET @contents = xp_read_file ( 'full file specification' );

IF COALESCE ( @contents, '' ) = '' THEN

-- error

END IF;

END;

-----------------------------------------------------------

BEGIN

DECLARE @return_code INTEGER;
DECLARE @contents LONG BINARY;

@return_code = CALL xp_write_file (
'full file specification', @contents );

IF @return_code <> 0 THEN

-- error

END IF;

END;

On 11 Mar 2009 09:12:07 -0800, Herman Miller wrote:

>Sybase Version 9.0.2.3534
>
>How can I write and retrieve documents in the database.
>Please include sample code and database if possible.

--
Breck Carter http://sqlanywhere.blogspot.com/

RisingRoad SQL Anywhere and MobiLink Professional Services
breck.carter@risingroad.com


Jeff Albion [Sybase iAnywhere] Posted on 2009-03-11 18:23:35.0Z
From: "Jeff Albion [Sybase iAnywhere]" <firstname.lastname@ianywhere.com>
User-Agent: Thunderbird 2.0.0.19 (Windows/20081209)
MIME-Version: 1.0
Newsgroups: ianywhere.public.general
Subject: Re: Storing Documents in the database
References: <49b7f0e7.2ba7.1681692777@sybase.com>
In-Reply-To: <49b7f0e7.2ba7.1681692777@sybase.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <49b801a7$1@forums-1-dub>
Date: 11 Mar 2009 10:23:35 -0800
X-Trace: forums-1-dub 1236795815 10.22.241.152 (11 Mar 2009 10:23:35 -0800)
X-Original-Trace: 11 Mar 2009 10:23:35 -0800, vip152.sybase.com
Lines: 37
X-Authenticated-User: techsupp
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:7406
Article PK: 5821

Herman,

I assume by storing "documents" you mean "binary files" and not just
"plain text".

=====
CREATE TABLE documents (
doc_id BIGINT PRIMARY KEY DEFAULT AUTOINCREMENT,
document LONG BINARY
);

INSERT INTO documents (document) VALUES
(xp_read_file('c:\\folder\\mydocument.doc'));

COMMIT;

SELECT xp_write_file( 'c:\\newfolder\\mynewdocument.doc' , document)
FROM documents WHERE doc_id = 1;
=====

Regards,

Herman Miller wrote:
> Sybase Version 9.0.2.3534
>
> How can I write and retrieve documents in the database.
> Please include sample code and database if possible.

--
Jeff Albion, Sybase iAnywhere

iAnywhere Developer Community :
http://www.sybase.com/developer/library/sql-anywhere-techcorner
iAnywhere Documentation : http://www.ianywhere.com/developer/product_manuals
SQL Anywhere Patches and EBFs :
http://downloads.sybase.com/swd/summary.do?baseprod=144&client=ianywhere&timeframe=0
Report a Bug/Open a Case : http://case-express.sybase.com/cx/