db-ojb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Rutherfurd" <orutherf...@alloy.com>
Subject RE: Problem with keyword as column name
Date Fri, 03 Oct 2003 13:26:31 GMT
The problem is not the escaped syntax being sent to the database, rather
it's OJB looking for the escaped name in ResultSets returned from the
database.

In other words, "select [key] from foo" will result in "key" being the
column name in the returned ResultSet (not "[key]").  When OJB goes to fetch
the column value from the recordset, it asked for column "[key]", but
doesn't find it (it's "key").

I worked around this by creating my own RowReader and SqlHelper which strip
off "[" and "]", when reading values from the ResultSet.

I'd be happy to share the code if anyone's interested -- it's pretty short.

-Ollie

-----Original Message-----
From: Edson Carlos Ericksson Richter
[mailto:edson.richter@mgrinformatica.com.br]
Sent: Friday, October 03, 2003 8:46 AM
To: OJB Users List
Subject: Re: Problem with keyword as column name


MS SQL accepts keywords in two ways: using [] and using ". Have you tested

<field-descriptor column="\"Key\""
            jdbc-type="VARCHAR"
            name="key"/>


I think the only problem should be with XML sintax... Jakob, the escaped
values should be sent directly to database (but then we are loosing the
database independency, since escaped sintax could differ from database to
database).

Edson

  ----- Original Message -----
  From: Jakob Braeuchi
  To: OJB Users List
  Sent: Friday, October 03, 2003 5:20 AM
  Subject: Re: Problem with keyword as column name


  hi oliver,

  what would the correct sql look like using the escaped column name ?

  jakob

  Oliver Rutherfurd wrote:

  >I'm having problems using OBJ (1.0rc3) to access a table in SQL Server
which
  >has a column named "Key".  I defined the field in my repository.xml file
  >like so:
  >
  >    <field-descriptor column="Key"
  >            jdbc-type="VARCHAR"
  >            name="key"/>
  >
  >I get the following error:
  >
  >    java.sql.SQLException: [JCDEVDB]Incorrect syntax near the keyword
'Key'.
  >
  >I tried to escape the column name in the repository.xml file, like so:
  >
  >    <field-descriptor column="[Key]"
  >            jdbc-type="VARCHAR"
  >            name="key"/>
  >
  >I got the following error:
  >
  >    java.util.NoSuchElementException: Could not obtain next object: Error
  >reading from result set: [TDS Driver]Column '[Key]' not found.
  >
  >Much as I'd like to change the column name, so this problem would just go
  >away, it's not an option.  How can I get this to work?
  >
  >Thanks,
  >-Ollie
  >
  >
  >---------------------------------------------------------------------
  >To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
  >For additional commands, e-mail: ojb-user-help@db.apache.org
  >
  >
  >
  >


  ---------------------------------------------------------------------
  To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
  For additional commands, e-mail: ojb-user-help@db.apache.org



  ---
  Outgoing mail is certified Virus Free.
  Checked by AVG anti-virus system (http://www.grisoft.com).
  Version: 6.0.522 / Virus Database: 320 - Release Date: 29/9/2003


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Mime
View raw message