X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id D1130D1E06B for ; Sat, 29 Nov 2003 07:52:46 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 78031-04 for ; Sat, 29 Nov 2003 03:52:17 -0400 (AST) Received: from smtp.covadmail.net (mx05.covadmail.net [63.65.120.65]) by svr1.postgresql.org (Postfix) with SMTP id 3EF0AD1DF16 for ; Sat, 29 Nov 2003 03:52:15 -0400 (AST) Received: (covad.net 30530 invoked from network); 29 Nov 2003 07:52:11 -0000 Received: from unknown (HELO covad.net) (rncombs@68.165.41.64) by sun-qmail10 with SMTP; 29 Nov 2003 07:52:10 -0000 Message-ID: <3FC8502D.7060805@covad.net> Date: Sat, 29 Nov 2003 01:52:13 -0600 From: Richard Combs User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Cristian Custodio Cc: pgsql-odbc@postgresql.org Subject: Re: Character invalid saving memo with UpdateSQL References: <005d01c3b50d$f1328c90$b301a8c0@ttcristian> <3FC6FD17.4020300@covad.net> <001d01c3b5ae$38a28da0$b301a8c0@ttcristian> In-Reply-To: <001d01c3b5ae$38a28da0$b301a8c0@ttcristian> Content-Type: multipart/alternative; boundary="------------020400090803070603010700" X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/134 X-Sequence-Number: 3536 This is a multi-part message in MIME format. --------------020400090803070603010700 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Since you mentioned update as the root of the problem, I retried my experiment. Same setup as before, however table1 was changed to the following bigtest=# \d table1 idnumber | integer | not null default nextval('public.table1_id number_seq'::text) c1 | character(40) | v2 | character varying(4000) | Sample Delphi code type TForm1 = class(TForm) Table1: TTable; DataSource1: TDataSource; DBGrid1: TDBGrid; Query1: TQuery; procedure DBGrid1DblClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.DBGrid1DblClick(Sender: TObject); begin { query is update table1 set v2 = :v2 where idnumber = :idnumber } // query1.Params[0].AsMemo := 'mod '+table1.Fields[2].AsString; // this gives invalid characters query1.Params[0].AsString := 'mod '+table1.Fields[2].AsString; // this gives only valid characters query1.Params[1].AsInteger := table1.Fields[0].AsInteger; query1.ExecSQL; table1.Refresh; end; end. Table before any updates bigtest=# select * from table1; 1 | one | var one 2 | two | var two 3 | three | var three Table after updates using asMemo bigtest=# select * from table1; idnumber | c1 | v2 ----------+------------------------------------------+-------------------------- - 1 | one | var one 2 | two | mod var twoER 3 | three | mod mod mod var three[i? idnumber 2 errored after 1 modify idnumber 3 errored after 3 modifies Table after updates using asString bigtest=# select * from table1; 1 | one | var one 3 | three | mod mod mod var three 2 | two | mod mod mod mod mod mod mod var two As you said, the problem seems to be in using asMemo. Borland docs say Note: Some servers support string field types that are too long to fit in the record buffer. These fields are represented as memo fields, although they are not actually Blob fields. When working with such "pseudo-Blob" fields, use the AsString property instead. Also Memo fields are a form of binary large object (BLOB) field where the data consists of simple text. Use AsString to assign the BLOB field value to a string or to assign a string value to the BLOB field. Typically, using AsString makes sense only if the BLOB contains text, such as that in a memo field. The string data (Delphi) or AnsiString (C++) type can, however, store binary data as well. Thus, even BLOB fields for nontextual BLOB types such as ftGraphic or ftTypedBinary can use the AsString property. This would seem to be the case with varchar in PostgreSQL. Perhaps the best thing to do is use asString for all char and varchar columns unless you find an indication to the contrary. There are some mentions in the Borland newsgroups to having to use asMemo with Oracle. Check those out by searching the old archives, you may still have to use asMemo to get your Oracle data. HTH Feel free to send me your code, and I will take a look at it. Cristian Custodio wrote: > > Sorry, I forget to say that the problem occur just in Upate, not in > Insert. > And not in first time. You sometimes need update two or tree times > until see the error. > --------------020400090803070603010700 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Since you mentioned update as the root of the problem, I retried my
experiment.  Same setup as before, however table1 was changed to the
following

bigtest=# \d table1
 idnumber | integer                 | not null default nextval('public.table1_id
number_seq'::text)
 c1       | character(40)           |
 v2       | character varying(4000) |


Sample Delphi code

type
  TForm1 = class(TForm)
     Table1: TTable;
     DataSource1: TDataSource;
    DBGrid1: TDBGrid;
     Query1: TQuery;
     procedure DBGrid1DblClick(Sender: TObject);
  private
     { Private declarations }
  public
     { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DBGrid1DblClick(Sender: TObject);
begin
    { query is
        update table1
        set v2 = :v2
        where idnumber = :idnumber
    }
//    query1.Params[0].AsMemo := 'mod '+table1.Fields[2].AsString;    // this gives invalid characters
    query1.Params[0].AsString := 'mod '+table1.Fields[2].AsString;    // this gives only valid characters
    query1.Params[1].AsInteger := table1.Fields[0].AsInteger;
    query1.ExecSQL;
    table1.Refresh;
end;

end.


Table before any updates

bigtest=# select * from table1;
        1 | one                                      | var one
        2 | two                                      | var two
        3 | three                                    | var three

Table after updates using asMemo

bigtest=# select * from table1;
 idnumber |                    c1                    |            v2

----------+------------------------------------------+--------------------------
-
        1 | one                                      | var one
        2 | two                                      | mod var twoER
        3 | three                                    | mod mod mod var three[i?

idnumber 2 errored after 1 modify
idnumber 3 errored after 3 modifies


Table after updates using asString

bigtest=# select * from table1;
        1 | one                                      | var one
        3 | three                                    | mod mod mod var three
        2 | two                                      | mod mod mod mod mod mod mod var two


As you said, the problem seems to be in using asMemo.
Borland docs say
Note:    Some servers support string field types
that are too long to fit in the record buffer.
These fields are represented as memo fields,
although they are not actually Blob fields.
When working with such “pseudo-Blob” fields,
use the AsString property instead.

Also

Memo fields are a form of binary large object (BLOB) field where the data consists of simple text.
Use AsString to assign the BLOB field value to a string or to assign a string value to the BLOB field.
Typically, using AsString makes sense only if the BLOB contains text, such as that in a memo field. The string data (Delphi) or AnsiString (C++) type can, however, store binary data as well. Thus, even BLOB fields for nontextual BLOB types such as ftGraphic or ftTypedBinary can use the AsString property.


This would seem to be the case with varchar in PostgreSQL.  Perhaps
the best thing to do is use asString for all char and varchar columns
unless you find an indication to the contrary.

There are some mentions in the Borland newsgroups to having to use
asMemo with Oracle.  Check those out by searching the old archives,
you may still have to use asMemo to get your Oracle data.


HTH

Feel free to send me your code, and I will take a look at it.


Cristian Custodio wrote:
 
Sorry, I forget to say that the problem occur just in Upate, not in Insert.
And not in first time. You sometimes need update two or tree times
until see the error.

--------------020400090803070603010700--