How to "set define off" using dbExpress ?

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for Oracle in Delphi and C++Builder
Post Reply
Michel Nolard

How to "set define off" using dbExpress ?

Post by Michel Nolard » Sat 01 Oct 2005 08:30

Hi !

I've tried to insert data in an Oracle database using the dbExpress driver for Builder C++. The data contain an XML string which escapes the "<" using "<". Too bad for us, the ampersand character is the default substitution character when using Oracle.

I _REALLY_ need to disable this default Oracle behavior very quickly. Sorry to urge you this way.

Thank you by advance.

Michel Nolard
Ares Developer

Posts: 725
Joined: Thu 28 Oct 2004 14:06

Post by Paul » Mon 03 Oct 2005 06:55

I suppose you wrote incorrect string expression in your SQL. Possibly you wrote it in double quotes. Please check your query in SQL*Plus, try the following example

Code: Select all

  ENAME = 'abc<abc'
  EMPNO = 7499

Michel Nolard

Here is a tricky solution...

Post by Michel Nolard » Mon 03 Oct 2005 17:50

Sorry, but I didn't made it clear enough for you to reply, I think.

Luckily a friend of mines found the solution which I give here. This is a tricky solution, waiting for a better cleaner one.

So, I recall you the situation :

I have a string containing XML text which escapes some 'A<B";[/code]

I need to put it into an SQL query objet using ParamByName without having Oracle interpreting the '&' character as a substitution character.

What I want to do is : (pseudo-code)

Code: Select all

TSQLQuery query;
query.ParamByName ("PXml")->AsString = xml;
This code makes Oracle hang on the ExecSQL() call because it waits for more informations as it interprets the '&' char as a substitution char.

The solution is to transform the xml string by replacing any occurence of the ampersand by the sequence "' || char (48 )|| '" :

Code: Select all

 xml.replace ("&", "' || char (48)|| '");
and it works :-)
Note: This is a double quote " concatenated to a single quote ' !

A better solution would be to be able to tell Oracle "set define off" which is the right Oracle statement to tell it to stop to evaluate the "&" as the substitution character. The problem is that I can't find a way to tell it that.

Maybe you have a better solution, if so, feel free to tell me :D

Thank you.

Michel Nolard

Posts: 725
Joined: Thu 28 Oct 2004 14:06

Post by Paul » Tue 04 Oct 2005 06:42

We couldn't reproduce the problem with your example with VARCHAR field, DbxOda 2.50.5, C++ Builder 6.0. Please send us complete sample to demonstrate it and include script to create server objects.

Michel Nolard

Missing informations

Post by Michel Nolard » Tue 22 Nov 2005 12:50

I see now that there are some informations missing for you to reproduce :
- I was using a "LONG" field
- Its contents was feeded using a Borland AnsiString containing a text with an ampersand, like "Data&Data".

The SQL Statement was an "INSERT".

When the ExecSQL() method of TSQLQuery is called, the application stops upon it, waiting forever.

I hope you'll be able to reproduce this as it is a bug which I have found not to be present in other DB access libraries.

Posts: 725
Joined: Thu 28 Oct 2004 14:06

Post by Paul » Thu 24 Nov 2005 07:01

We cannot reproduce your problem. Please try the following code

Code: Select all

  TSQLConnection* SQLConnection2 = new TSQLConnection(NULL);
  SQLConnection2->ConnectionName = "Oracle (Core Lab)";
  SQLConnection2->DriverName = "Oracle (Core Lab)";
  SQLConnection2->GetDriverFunc = "getSQLDriverORA";
  SQLConnection2->LibraryName = "dbexpoda.dll";
  SQLConnection2->VendorLib = "OCI.DLL";
  SQLConnection2->Params->Text =
    "DriverName=Oracle (Core Lab)\r\n"
    "Oracle TransIsolation=ReadCommited\r\n"

  AnsiString xml = "A<B";
  char *ch = xml.c_str();

  TSQLQuery* query = new TSQLQuery(NULL);
  query->SQLConnection = SQLConnection2;
  query->SQL->Text = "INSERT INTO LONG_TYPE (ID, F_LONG) VALUES  (11, :PXml)";
  query->ParamByName ("PXml")->AsString = xml;

Code: Select all


Post Reply