Board index » delphi » tDBRichEdit and SQL insert and update statements

tDBRichEdit and SQL insert and update statements

I wated to perform an insert or update to a richedit field in a DB using an
SQL statement.  As far as I can figure out, the SQL property in a tquery can
not handle the control characters in the richedit field..  Is there anyway
to do an insert or update using an SQL statement

--
Gary W. Good

 

Re:tDBRichEdit and SQL insert and update statements


Use a parameterized query. What database are you using?

--
Bill
(TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


I am using paradox.

I thought the problem was in the SQL "string" with single quotes.  how will
parameterizing them help if that is the problem.

The control charcters, x10 and x 13 are surrounded by quotes in richedit and
strings.  Are the control charaters the problen and are they actually
represented differently internally?

I have replaced the queries with appends and inserts which work fine.

The problem was that I had writen some general methods which worked for
everything but the richedits and I was, and still am, looking for some way
to handle this.  parametrizing does not solve the general method problems.
(The general methods create SQL statements based on datatype)

"Bill Todd (TeamB)" <bill_nos...@dbginc.com> wrote in message
news:3cc873b2_1@dnews...

Quote
> Use a parameterized query. What database are you using?

> --
> Bill
> (TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


You have lost me. If you are using a TDBRichEdit you do not need to use SQL
to save the memo to the table. You need to use a Binary field in the Paradox
table. If you want to to insert the rich text with SQL use a TRichEdit and
assign its Text property to the query parameter.

--
Bill
(TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


I often hesitate to fully disclose what I am doing, simply because I do not
understand the implications of everything and I do not want to take up your
time with extraneous information.

I am using tClientDataset, tDatasetProvider and a tquery to show info.
there is one parent table "Test".  Tests has three child tables CondClas,
MeasClas, and PrepClas.  Each of the "Class" tables  has one child table,
collectively referred to as "Value" tables.  The value Tables are, in turn,
linked to yet other tables.  I am managing the links and not using
"MasterSource " etc.

The RichEdit field is in the "Tests" table.  A generalized comment field.  A
single form references the Test, Class, and Value tables.  I use tDBRichEdit
to "automatically" show the comments field.  Because of "joins" and "Order
By"s I use dspBeforeUpdateRecord methods in which I specifically perform the
updates via q, a tQuery component.  Because I use this approach in several
places, I wrote generalized methods to handle the updates using SQL Insert,
Update and Delete statements.  Everything worked fine until I ran up against
the Formatted Memos.  (Note that it works fine for "Straight Memos" as well
as Strings, Integers, Floats, Graphics, etc.).  When I used the "Comments"
field with SQL Update statement I ran into errors.  (I have not tried Insert
statements because I stopped when I ran into problems with the Update
statement.)

The error comes back as an error in the Set Comments = "" statements.  In
between the double quotes, there are formatted memo control characters in
single quotes.  For example, '#$D#$A'.  I did some simple testing and found
that this string of characters appear to be the problem,  I further assumed
then that the single quotes are the specific problem.  .

My goal was to only use tdbRichEdit and the SQL statements to handle my DB
updates.  From what you said, I do not believe this can be done.  Is this
correct?

"Bill Todd (TeamB)" <bill_nos...@dbginc.com> wrote in message
news:3cc89539$1_2@dnews...

Quote
> You have lost me. If you are using a TDBRichEdit you do not need to use
SQL
> to save the memo to the table. You need to use a Binary field in the
Paradox
> table. If you want to to insert the rich text with SQL use a TRichEdit and
> assign its Text property to the query parameter.

> --
> Bill
> (TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


Since you are using Paradox tables I would expect '#$D#$A' to work if
enclosed in double quotes. However, if you use a parameter to hold the value
in the update query it should certainly work. Once again, I assume you are
using a field of type Binary to hold the data in your Paradox table. If no,
that may be the problem.

--
Bill
(TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


Bill

The db datatype is Formatted Memo so it is a blob.

I tried the double quotes but that does not work.  The single quotes are
rich edit format control characters.  Replacing single quotes with double
quotes changes the meaning of the string.  I tried replacing the single
quotes with 2 single quotes, double quotes and 2 double quotes and nothing
works.

The problem is not with the DB.  The problem is with interpreting single and
double quotes in strings by the SQL property and how a rich edit treats
single and double quotes in its' format control characters.

I think we have beat on this one enough.  It is time for me to move on

Thanks for your time and help

"Bill Todd (TeamB)" <bill_nos...@dbginc.com> wrote in message
news:3cc965fb$1_1@dnews...

Quote
> Since you are using Paradox tables I would expect '#$D#$A' to work if
> enclosed in double quotes. However, if you use a parameter to hold the
value
> in the update query it should certainly work. Once again, I assume you are
> using a field of type Binary to hold the data in your Paradox table. If
no,
> that may be the problem.

> --
> Bill
> (TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


I don't know how to say this more clearly. You _must_ use the Binary field
type. You cannot use Formatted Memo, Memo or any other blob field type
except binary to store RTF. Formatted Memo is a field type that is supported
by the Paradox product only, not by Delphi. Formatted Memo fields expect and
check for a very specific proprietary undocumented data format that is used
only by the Paradox product marketed by Corel. If you try to put characters
that are not part of the proprietary formatted memo specification into a
formatted memo field you wil have errors.

--
Bill
(TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


Bill

I looked at your comment about binary as generic, that is binary as in
Binary Large OBjecs fields not specifically as BLOB type 2 fields.

thank you for the clarification.

"Bill Todd (TeamB)" <bill_nos...@dbginc.com> wrote in message
news:3cc97e76_1@dnews...

Quote
> I don't know how to say this more clearly. You _must_ use the Binary field
> type. You cannot use Formatted Memo, Memo or any other blob field type
> except binary to store RTF. Formatted Memo is a field type that is
supported
> by the Paradox product only, not by Delphi. Formatted Memo fields expect
and
> check for a very specific proprietary undocumented data format that is
used
> only by the Paradox product marketed by Corel. If you try to put
characters
> that are not part of the proprietary formatted memo specification into a
> formatted memo field you wil have errors.

> --
> Bill
> (TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


Bill

I switched the field type to Binary in the paradox db as you suggested and
it did not work.  This is the string as generated by the rich text
component:

"{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans
Serif;}{\f1\fnil MS Sans
Serif;}}'#$D#$A'\viewkind4\uc1\pard\lang1033\b\f0\fs16
gary\f1\par'#$D#$A'}'#$D#$A#0'

and the sql statement is

update Test SET Test."Comments" =
"{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans
Serif;}{\f1\fnil MS Sans
Serif;}}'#$D#$A'\viewkind4\uc1\pard\lang1033\b\f0\fs16
gary\f1\par'#$D#$A'}'#$D#$A#0'" where Test_Key=18

When I try to update the DB I get an "Invalid Use of Keyword" error
regardless of the type of field in my table.  I have tried it with formatted
memo and binary.

However both data types have no difficulty handling the string in a tTable
or tQuery "edit - post" block

  tblTest.Edit;
  for i := 1 to aDeltaDS.FieldCount-1 do
    begin
    if NOT varisempty(aDeltaDS.Fields[i].NewValue) then
      begin
      if CompareText(aDeltaDS.Fields[i].DisplayName, 'TEST')=0 then
        tblTestTest.AsString := aDeltaDS.FieldByName('Test').AsString
      else if CompareText(aDeltaDS.Fields[i].DisplayName, 'CODE')=0 then
        tblTestCode.AsString := aDeltaDS.FieldByName('Code').AsString
      else if CompareText(aDeltaDS.Fields[i].DisplayName, 'COMMENTS')=0 then
        tblTestComments.AsString :=
aDeltaDS.FieldByName('Comments').AsString;
      end;
    end;
  tblTest.Post;

This leads me to believe that the type of field in the database is not where
my problem is.  I am not challenging your comment about binary versus
"formatted memo".  It just appears that something else is going on here.

Quote
"lrgood" <g...@lrgood.com> wrote in message news:3cc9a193_1@dnews...
> Bill

> I looked at your comment about binary as generic, that is binary as in
> Binary Large OBjecs fields not specifically as BLOB type 2 fields.

> thank you for the clarification.

> "Bill Todd (TeamB)" <bill_nos...@dbginc.com> wrote in message
> news:3cc97e76_1@dnews...
> > I don't know how to say this more clearly. You _must_ use the Binary
field
> > type. You cannot use Formatted Memo, Memo or any other blob field type
> > except binary to store RTF. Formatted Memo is a field type that is
> supported
> > by the Paradox product only, not by Delphi. Formatted Memo fields expect
> and
> > check for a very specific proprietary undocumented data format that is
> used
> > only by the Paradox product marketed by Corel. If you try to put
> characters
> > that are not part of the proprietary formatted memo specification into a
> > formatted memo field you wil have errors.

> > --
> > Bill
> > (TeamB cannot answer questions received via email)

Re:tDBRichEdit and SQL insert and update statements


My only other suggestion is to try a parameterized query.

--
Bill
(TeamB cannot answer questions received via email)

Other Threads