Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 52159 invoked from network); 4 Jun 2009 15:26:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Jun 2009 15:26:05 -0000 Received: (qmail 35471 invoked by uid 500); 4 Jun 2009 15:26:17 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 35437 invoked by uid 500); 4 Jun 2009 15:26:17 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 35429 invoked by uid 99); 4 Jun 2009 15:26:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jun 2009 15:26:17 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [192.18.43.132] (HELO sca-es-mail-1.sun.com) (192.18.43.132) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jun 2009 15:26:05 +0000 Received: from fe-sfbay-10.sun.com ([192.18.43.129]) by sca-es-mail-1.sun.com (8.13.7+Sun/8.12.9) with ESMTP id n54FPWe9010878 for ; Thu, 4 Jun 2009 08:25:44 -0700 (PDT) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII; format=flowed Received: from conversion-daemon.fe-sfbay-10.sun.com by fe-sfbay-10.sun.com (Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)) id <0KKQ0080001M9C00@fe-sfbay-10.sun.com> for derby-user@db.apache.org; Thu, 04 Jun 2009 08:25:32 -0700 (PDT) Received: from richard-hillegas-computer.local ([unknown] [129.150.241.239]) by fe-sfbay-10.sun.com (Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)) with ESMTPSA id <0KKQ00MS606HNHA0@fe-sfbay-10.sun.com> for derby-user@db.apache.org; Thu, 04 Jun 2009 08:25:29 -0700 (PDT) Date: Thu, 04 Jun 2009 08:25:34 -0700 From: Rick Hillegas Subject: Re: Inserting into BLOB field In-reply-to: <4A27E626.1080706@sun.com> Sender: Richard.Hillegas@Sun.COM To: Derby Discussion Message-id: <4A27E76E.2080203@sun.com> References: <23841004.post@talk.nabble.com> <4A25BB2D.3090700@Sun.COM> <23855280.post@talk.nabble.com> <4A27E626.1080706@sun.com> User-Agent: Thunderbird 2.0.0.21 (Macintosh/20090302) X-Virus-Checked: Checked by ClamAV on apache.org I forgot to mention that you this will only work on 10.5, which includes the fix for DERBY-2201. Regards, -Rick Rick Hillegas wrote: > Often these coercion problems can be finessed by writing your own cast > function. You might try the following: > > 1) Write a public static method which takes a String argument and > returns a java.sql.Blob value. > > 2) Register that method as a Derby function which takes a VARCHAR > argument and returns a BLOB. > > 3) Then use the function to coerce string values to Blobs in your > insert statements. > > Here's some code which shows how to do this. First the static method: > > import java.sql.Blob; > import org.apache.derbyTesting.functionTests.tests.lang.StringColumnVTI; > > public class z > { > public static Blob makeBlob( String seed ) > { > return new StringColumnVTI.SimpleBlob( seed.getBytes() ); > } } > > Then a little ij script which exercises the function: > > connect 'jdbc:derby:memory:dummy;create=true'; > > create function makeBlob( seed varchar( 32672 ) ) > returns blob > language java > parameter style java > no sql > external name 'z.makeBlob'; > > create table t( a blob ); > > insert into t( a ) values ( makeBlob( 'xyz' ) ); > > select * from t; > > > Hope this helps, > -Rick > > cmathrusse wrote: >> I had read that post prior and it would require me converting the >> text that I >> am attempting to insert, an xslt file, into a hex representation. >> Only then >> could I attempt to do this. I did actually attempt this. (not very >> friendly) >> I did convert the contents of my file into a hex representation and >> attempted the insert by performing a CAST( X'text content' AS BLOB), >> but it >> complained when I executed the SQL. While this would be a viable >> approach, I >> think you would agree that this is far from desirable. >> What would be optimal would be the ability to have Derby allow >> inserts of >> TEXT into BLOB fields. I know that this is how Sybase ASE operates, >> (Yes, I >> know Derby is not ASE) and I don't know if this is ANSI standard, but it >> sure makes life less complicated. >> >