Solved

Saving string > 2000 chars to oracle long varchar

Posted on 1998-07-28
8
437 Views
Last Modified: 2010-04-04
How can I save a string >2000 to an oracle long varchar field?  I keep getting and oracle error ora-01704 string literal too long messsage.
0
Comment
Question by:blitz051697
  • 3
  • 3
  • 2
8 Comments
 
LVL 2

Expert Comment

by:duneram
ID: 1358871
I don't know oracle, so I don't know what a long varchar field is, but in other db's, try to see if you can have a field of type memo or of type blob    If oracle permits 'blob' or 'memo' that is probably a better field type to use.
0
 
LVL 3

Accepted Solution

by:
vladika earned 100 total points
ID: 1358872
I create such table

SQL> describe test
 Name                            Null?    Type
 ------------------------------- -------- ----
 LONGSTR                                  LONG

then I create simple form with Button, OpenDialog, Database and Query component

in the Query.SQL I wrote
INSERT INTO TEST(LONGSTR) VALUES(:LONGSTR)

then I wrote Button.OnClick handler
procedure TForm1.Button1Click(Sender: TObject);
var FileStream: TFileStream;
    Size: Integer;
    S: string;
begin
  if OpenDialog1.Execute then
  begin
    FileStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
    try
      Size := FileStream.Size;
      SetString(S, nil, Size);
      FileStream.Read(PChar(S)^, Size);
    finally
      FileStream.Free;
    end;
    Query1.ParamByName('longstr').AsMemo := S; // or AsString
    Query1.ExecSQL;
  end;
end;

I run program and there is no problem with it.
(I save 10K, 50K files - no problem)

Explain your problem in more detail

0
 

Author Comment

by:blitz051697
ID: 1358873
The problem is that when I do the exact same thing, I get garbage in the field if the string
i'm saving is larger than 255 characters.  why?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:vladika
ID: 1358874
Maybe you write your code? I check it on my computer.

What langdriver do you use?
When you use AsString or AsMemo delphi
translates strings from ANSI to the language driver's native character set.
Try use another langdriver.
Try write in my code ParamByName().AsBlob (not translate)

Reject my answer in order to other experts can comment/answer

0
 

Author Comment

by:blitz051697
ID: 1358875
I've switched my code to use AsMemo.  It appears to work.  However, I remember trying this before and I had another problem.  I can't remember what it was.  We support SQLServer and Oracle in our application.  I need to test it against SQLServer Text field and see if it works there too.  After I've tested, I'll get back to you. Thanks

0
 
LVL 2

Expert Comment

by:duneram
ID: 1358876
Memo fields generally work well for this sort of stuff.
0
 
LVL 3

Expert Comment

by:vladika
ID: 1358877

0
 

Author Comment

by:blitz051697
ID: 1358878
thanks...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question